Skip to content

Commit

Permalink
Merge pull request #33 from EOSIO/develop
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
flux627 committed Dec 17, 2018
2 parents ea3c7a0 + 8794fc1 commit 0006774
Show file tree
Hide file tree
Showing 17 changed files with 1,440 additions and 479 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ yarn-error.log
.eslintrc.json
README.md
build-docs.sh
.npmrc.template
scripts/*
1 change: 1 addition & 0 deletions .npmrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
26 changes: 23 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@ language: node_js
node_js:
- '10.0.0'
before_install:
- npm i -g npm@6.4.1
- npm install -g typescript
script:
- npm run lint

stages:
- test
- name: deploy
if: (NOT type IN (pull_request)) AND (branch = develop)
jobs:
include:
- stage: test
name: "Lint and Test"
script:
- npm run lint
- npm run test
- stage: deploy
name: "Deploy to NPM"
script:
- npm run build
deploy:
provider: script
skip_cleanup: true
script:
- ./scripts/publish.sh
on:
branch: develop
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ yarn add demux-eos
# Using npm
npm install demux-eos --save
```

## Usage

### MongoDB Plugin
```javascript
const { BaseActionWatcher } = require("demux")
const { MongoActionReader } = require("demux-eos")

const actionHandler = ... // see https://github.com/EOSIO/demux-js-postgres for a supported ActionHandler
const actionReader = new MongoActionReader(
mongodbHost, // the url of the mongodb instance (mongodb://localhost:27017)
2, // the mongodb plugin starts at block 2
false, // whether or not to only process irreversible blocks
600, // the maximum history length
mongoDbName, // name of the database
)

const actionWatcher = new BaseActionWatcher(actionReader, actionHander, 500)

await actionReader.initialize() // This must be done before calling watch so the MongoDB connection can be made

actionWatcher.watch()
```

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "demux-eos",
"version": "2.0.0",
"version": "3.0.0",
"description": "Demux-js Action Reader implementations for EOSIO blockchains",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,6 +11,7 @@
},
"license": "MIT",
"devDependencies": {
"@types/bunyan": "^1.8.5",
"@types/jest": "^23.1.4",
"@types/mongodb": "^3.1.4",
"@types/node": "^10.5.1",
Expand All @@ -27,40 +28,39 @@
"typescript": "^2.9.2"
},
"dependencies": {
"demux": "^2.0.0",
"bunyan": "^1.8.12",
"demux": "^3.1.3",
"mongodb": "^3.1.3",
"request": "^2.87.0",
"request-promise-native": "^1.0.5"
},
"peerDependencies": {
"demux": "^2.0.0"
"demux": "^3.1.3"
},
"scripts": {
"release": "release-it",
"compile": "tsc",
"build": "tsc",
"watch": "tsc -w",
"lint": "tslint -c tslint.json src/**/*.ts",
"test": "jest",
"build-docs": "./build-docs.sh"
},
"jest": {
"moduleFileExtensions": [
"js",
"ts",
"tsx",
"js"
"tsx"
],
"transform": {
"^.+\\.(tsx?)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.json"
"tsConfig": "tsconfig.json"
}
},
"testRegex": "(/src/.*(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testEnvironment": "node",
"moduleNameMapper": {
"mongodb": "<rootDir>/src/testHelpers/mongoMock.ts"
}
"testEnvironment": "node"
}
}
49 changes: 49 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

setup_git() {
# Set the user name and email to match the API token holder
# This will make sure the git commits will have the correct photo
# and the user gets the credit for a checkin
git config --global user.email "devops@block.one"
git config --global user.name "blockone-devops"
git config --global push.default matching

# Get the credentials from a file
git config credential.helper "store --file=.git/credentials"

# This associates the API Key with the account
echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials
}

make_version() {
# Make sure that the workspace is clean
# It could be "dirty" if
# 1. package-lock.json is not aligned with package.json
# 2. npm install is run
git checkout -- .

# Echo the status to the log so that we can see it is OK
git status

# Run the deploy build and increment the package versions
current_commit="$(git rev-parse --short HEAD)";

npm version prerelease -preid "${current_commit}" -no-git-tag-version

git commit -a -m "Updating version [skip ci]"
}

echo "Running on branch ${TRAVIS_BRANCH}":

echo "Setting up git"
setup_git

echo "Creating new version"

make_version

echo "Publish to NPM"

cp .npmrc.template $HOME/.npmrc

npm publish --tag edge
91 changes: 13 additions & 78 deletions src/MongoActionReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,29 @@
import { MongoActionReader } from "./MongoActionReader"
import { MongoBlock } from "./MongoBlock"
import { mockConnect } from "./testHelpers/mongoMock"
import { MongoClient } from "mongodb"

const rawBlock = {
_id: "5b720d6238dda5e3653eb12f",
block_id: "0001796719f9556dca4dce19f7d83e3c390d76783193d59123706b7741686bac",
block: {
timestamp: "2018-08-13T22:59:46.000",
producer: "eosio",
confirmed: 0,
previous: "0001796619c493e432bcf8105d45d1c7457b58f636c89bae3f1bda6574ff7502",
transaction_mroot: "0000000000000000000000000000000000000000000000000000000000000000",
action_mroot: "ae806e8b9f4c0740ae77377cca3b187460c3ded54d882accb1c0e90cbfc8d49e",
schedule_version: 0,
new_producers: null,
header_extensions: [],
producer_signature: `SIG_K1_JuWWv2dyszpR2skBHh6rRk37Ces5WPLCaj7vB2tqe5QqWcBuH
EwKjttYApYJ27pWwFTp8SQNLS4RogLaGDHX6dCvvHoM8a`,
transactions: [{
status: "executed",
cpu_usage_us: 542,
net_usage_words: 16,
trx: {
id: "051620080b3212292f56a836c6b2f294291f6e6793dc0f12ce6a886f83d97f83",
signatures: [Array],
compression: "none",
packed_context_free_data: "",
context_free_data: [],
transaction: {
expiration: "2018-08-13T23:11:22",
ref_block_num: 32411,
ref_block_prefix: 413523387,
max_net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
context_free_actions: [],
actions: [
{
account: "eosio.token",
name: "transfer",
authorization: [{ actor: "bill", permission: "active" }],
data: { from: "bill", to: "bob", quantity: "1.0000 EOS", memo: "m" },
hex_data: "000000000010a33b0000000000000e3d102700000000000004454f5300000000016d",
},
{
account: "eosio.token",
name: "transfer",
authorization: [{ actor: "bill", permission: "active" }],
data: { from: "bill", to: "bob", quantity: "1.0000 EOS", memo: "m" },
hex_data: "000000000010a33b0000000000000e3d102700000000000004454f5300000000016d",
},
],
transaction_extensions: [],
},
},
}],
block_extensions: [],
},
block_num: 96615,
createdAt: "2018-08-13T22:59:46.010Z",
irreversible: false,
}
MongoClient.connect = jest.fn(() => mockConnect)

describe("MongoActionReader", () => {
let reader: any

beforeEach(async () => {
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, true, 600, "EOS")
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, false, 600, "EOS")
await reader.initialize()
})

it("getHeadBlockNumber returns the last irreversible blocknum", async () => {
it("returns the head block number", async () => {
const blockNum = await reader.getHeadBlockNumber()
expect(blockNum).toEqual(20)
expect(blockNum).toEqual(21)
})

describe("With onlyIrreversible set to false", () => {
beforeEach(async () => {
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, false, 600, "EOS")
await reader.initialize()
})

it("getHeadBlockNumber returns the correct blockNumber", async () => {
const blockNum = await reader.getHeadBlockNumber()
expect(blockNum).toEqual(21)
})
it("returns the last irreversible block number", async () => {
const blockNum = await reader.getLastIrreversibleBlockNumber()
expect(blockNum).toEqual(20)
})

it("getBlock returns a MongoBlock", async () => {
const returnedBlock = await reader.getBlock(20)
const block = new MongoBlock(rawBlock)
expect(returnedBlock).toEqual(block)
})
it("returns block with the expected block number", async () => {
const returnedBlock = await reader.getBlock(21)
expect(returnedBlock.blockInfo.blockNumber).toEqual(21)
})
})

0 comments on commit 0006774

Please sign in to comment.