Skip to content

Commit 0006774

Browse files
authored
Merge pull request #33 from EOSIO/develop
Release 3.0.0
2 parents ea3c7a0 + 8794fc1 commit 0006774

17 files changed

+1440
-479
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ yarn-error.log
88
.eslintrc.json
99
README.md
1010
build-docs.sh
11+
.npmrc.template
12+
scripts/*

.npmrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}

.travis.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,27 @@ language: node_js
33
node_js:
44
- '10.0.0'
55
before_install:
6+
- npm i -g npm@6.4.1
67
- npm install -g typescript
7-
script:
8-
- npm run lint
9-
8+
stages:
9+
- test
10+
- name: deploy
11+
if: (NOT type IN (pull_request)) AND (branch = develop)
12+
jobs:
13+
include:
14+
- stage: test
15+
name: "Lint and Test"
16+
script:
17+
- npm run lint
18+
- npm run test
19+
- stage: deploy
20+
name: "Deploy to NPM"
21+
script:
22+
- npm run build
23+
deploy:
24+
provider: script
25+
skip_cleanup: true
26+
script:
27+
- ./scripts/publish.sh
28+
on:
29+
branch: develop

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,27 @@ yarn add demux-eos
1111
# Using npm
1212
npm install demux-eos --save
1313
```
14+
15+
## Usage
16+
17+
### MongoDB Plugin
18+
```javascript
19+
const { BaseActionWatcher } = require("demux")
20+
const { MongoActionReader } = require("demux-eos")
21+
22+
const actionHandler = ... // see https://github.com/EOSIO/demux-js-postgres for a supported ActionHandler
23+
const actionReader = new MongoActionReader(
24+
mongodbHost, // the url of the mongodb instance (mongodb://localhost:27017)
25+
2, // the mongodb plugin starts at block 2
26+
false, // whether or not to only process irreversible blocks
27+
600, // the maximum history length
28+
mongoDbName, // name of the database
29+
)
30+
31+
const actionWatcher = new BaseActionWatcher(actionReader, actionHander, 500)
32+
33+
await actionReader.initialize() // This must be done before calling watch so the MongoDB connection can be made
34+
35+
actionWatcher.watch()
36+
```
37+

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "demux-eos",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "Demux-js Action Reader implementations for EOSIO blockchains",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -11,6 +11,7 @@
1111
},
1212
"license": "MIT",
1313
"devDependencies": {
14+
"@types/bunyan": "^1.8.5",
1415
"@types/jest": "^23.1.4",
1516
"@types/mongodb": "^3.1.4",
1617
"@types/node": "^10.5.1",
@@ -27,40 +28,39 @@
2728
"typescript": "^2.9.2"
2829
},
2930
"dependencies": {
30-
"demux": "^2.0.0",
31+
"bunyan": "^1.8.12",
32+
"demux": "^3.1.3",
3133
"mongodb": "^3.1.3",
3234
"request": "^2.87.0",
3335
"request-promise-native": "^1.0.5"
3436
},
3537
"peerDependencies": {
36-
"demux": "^2.0.0"
38+
"demux": "^3.1.3"
3739
},
3840
"scripts": {
3941
"release": "release-it",
4042
"compile": "tsc",
43+
"build": "tsc",
4144
"watch": "tsc -w",
4245
"lint": "tslint -c tslint.json src/**/*.ts",
4346
"test": "jest",
4447
"build-docs": "./build-docs.sh"
4548
},
4649
"jest": {
4750
"moduleFileExtensions": [
51+
"js",
4852
"ts",
49-
"tsx",
50-
"js"
53+
"tsx"
5154
],
5255
"transform": {
5356
"^.+\\.(tsx?)$": "ts-jest"
5457
},
5558
"globals": {
5659
"ts-jest": {
57-
"tsConfigFile": "tsconfig.json"
60+
"tsConfig": "tsconfig.json"
5861
}
5962
},
6063
"testRegex": "(/src/.*(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
61-
"testEnvironment": "node",
62-
"moduleNameMapper": {
63-
"mongodb": "<rootDir>/src/testHelpers/mongoMock.ts"
64-
}
64+
"testEnvironment": "node"
6565
}
6666
}

scripts/publish.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
setup_git() {
4+
# Set the user name and email to match the API token holder
5+
# This will make sure the git commits will have the correct photo
6+
# and the user gets the credit for a checkin
7+
git config --global user.email "devops@block.one"
8+
git config --global user.name "blockone-devops"
9+
git config --global push.default matching
10+
11+
# Get the credentials from a file
12+
git config credential.helper "store --file=.git/credentials"
13+
14+
# This associates the API Key with the account
15+
echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials
16+
}
17+
18+
make_version() {
19+
# Make sure that the workspace is clean
20+
# It could be "dirty" if
21+
# 1. package-lock.json is not aligned with package.json
22+
# 2. npm install is run
23+
git checkout -- .
24+
25+
# Echo the status to the log so that we can see it is OK
26+
git status
27+
28+
# Run the deploy build and increment the package versions
29+
current_commit="$(git rev-parse --short HEAD)";
30+
31+
npm version prerelease -preid "${current_commit}" -no-git-tag-version
32+
33+
git commit -a -m "Updating version [skip ci]"
34+
}
35+
36+
echo "Running on branch ${TRAVIS_BRANCH}":
37+
38+
echo "Setting up git"
39+
setup_git
40+
41+
echo "Creating new version"
42+
43+
make_version
44+
45+
echo "Publish to NPM"
46+
47+
cp .npmrc.template $HOME/.npmrc
48+
49+
npm publish --tag edge

src/MongoActionReader.test.ts

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,29 @@
11
import { MongoActionReader } from "./MongoActionReader"
2-
import { MongoBlock } from "./MongoBlock"
2+
import { mockConnect } from "./testHelpers/mongoMock"
3+
import { MongoClient } from "mongodb"
34

4-
const rawBlock = {
5-
_id: "5b720d6238dda5e3653eb12f",
6-
block_id: "0001796719f9556dca4dce19f7d83e3c390d76783193d59123706b7741686bac",
7-
block: {
8-
timestamp: "2018-08-13T22:59:46.000",
9-
producer: "eosio",
10-
confirmed: 0,
11-
previous: "0001796619c493e432bcf8105d45d1c7457b58f636c89bae3f1bda6574ff7502",
12-
transaction_mroot: "0000000000000000000000000000000000000000000000000000000000000000",
13-
action_mroot: "ae806e8b9f4c0740ae77377cca3b187460c3ded54d882accb1c0e90cbfc8d49e",
14-
schedule_version: 0,
15-
new_producers: null,
16-
header_extensions: [],
17-
producer_signature: `SIG_K1_JuWWv2dyszpR2skBHh6rRk37Ces5WPLCaj7vB2tqe5QqWcBuH
18-
EwKjttYApYJ27pWwFTp8SQNLS4RogLaGDHX6dCvvHoM8a`,
19-
transactions: [{
20-
status: "executed",
21-
cpu_usage_us: 542,
22-
net_usage_words: 16,
23-
trx: {
24-
id: "051620080b3212292f56a836c6b2f294291f6e6793dc0f12ce6a886f83d97f83",
25-
signatures: [Array],
26-
compression: "none",
27-
packed_context_free_data: "",
28-
context_free_data: [],
29-
transaction: {
30-
expiration: "2018-08-13T23:11:22",
31-
ref_block_num: 32411,
32-
ref_block_prefix: 413523387,
33-
max_net_usage_words: 0,
34-
max_cpu_usage_ms: 0,
35-
delay_sec: 0,
36-
context_free_actions: [],
37-
actions: [
38-
{
39-
account: "eosio.token",
40-
name: "transfer",
41-
authorization: [{ actor: "bill", permission: "active" }],
42-
data: { from: "bill", to: "bob", quantity: "1.0000 EOS", memo: "m" },
43-
hex_data: "000000000010a33b0000000000000e3d102700000000000004454f5300000000016d",
44-
},
45-
{
46-
account: "eosio.token",
47-
name: "transfer",
48-
authorization: [{ actor: "bill", permission: "active" }],
49-
data: { from: "bill", to: "bob", quantity: "1.0000 EOS", memo: "m" },
50-
hex_data: "000000000010a33b0000000000000e3d102700000000000004454f5300000000016d",
51-
},
52-
],
53-
transaction_extensions: [],
54-
},
55-
},
56-
}],
57-
block_extensions: [],
58-
},
59-
block_num: 96615,
60-
createdAt: "2018-08-13T22:59:46.010Z",
61-
irreversible: false,
62-
}
5+
MongoClient.connect = jest.fn(() => mockConnect)
636

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

6710
beforeEach(async () => {
68-
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, true, 600, "EOS")
11+
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, false, 600, "EOS")
6912
await reader.initialize()
7013
})
7114

72-
it("getHeadBlockNumber returns the last irreversible blocknum", async () => {
15+
it("returns the head block number", async () => {
7316
const blockNum = await reader.getHeadBlockNumber()
74-
expect(blockNum).toEqual(20)
17+
expect(blockNum).toEqual(21)
7518
})
7619

77-
describe("With onlyIrreversible set to false", () => {
78-
beforeEach(async () => {
79-
reader = new MongoActionReader("mongodb://127.0.0.1:27017", 0, false, 600, "EOS")
80-
await reader.initialize()
81-
})
82-
83-
it("getHeadBlockNumber returns the correct blockNumber", async () => {
84-
const blockNum = await reader.getHeadBlockNumber()
85-
expect(blockNum).toEqual(21)
86-
})
20+
it("returns the last irreversible block number", async () => {
21+
const blockNum = await reader.getLastIrreversibleBlockNumber()
22+
expect(blockNum).toEqual(20)
23+
})
8724

88-
it("getBlock returns a MongoBlock", async () => {
89-
const returnedBlock = await reader.getBlock(20)
90-
const block = new MongoBlock(rawBlock)
91-
expect(returnedBlock).toEqual(block)
92-
})
25+
it("returns block with the expected block number", async () => {
26+
const returnedBlock = await reader.getBlock(21)
27+
expect(returnedBlock.blockInfo.blockNumber).toEqual(21)
9328
})
9429
})

0 commit comments

Comments
 (0)