From a5efa3812163ca9b618299a3b10de7e0d9385f39 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 16 Jun 2017 11:22:23 +0200 Subject: [PATCH 1/4] Add few tests --- .babelrc | 9 +++++++-- package.json | 20 +++++++++++++++++++- src/transaction/makeOutput.js | 2 +- test/test.js | 29 ++++++++++++++++++++++++----- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.babelrc b/.babelrc index c7cf3a4..034673a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,10 @@ { - "presets": ["es2015-no-commonjs"], + "presets": [ + "@ava/stage-4", + "@ava/transform-test-files", + "es2015-no-commonjs" + ], + "plugins": [ "transform-export-extensions", "transform-object-assign", @@ -23,4 +28,4 @@ ] } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index ee6776d..87707fc 100644 --- a/package.json +++ b/package.json @@ -71,5 +71,23 @@ "blockchain", "decentralized", "dapp" - ] + ], + "ava": { + "files": [ + "test/*.js" + ], + "source": [ + "**/*.{js,jsx}", + "!node_modules/**/*", + "!dist/**/*" + ], + "failFast": true, + "failWithoutAssertions": false, + "tap": true, + "powerAssert": false, + "require": [ + "babel-register" + ], + "babel": "inherit" + } } diff --git a/src/transaction/makeOutput.js b/src/transaction/makeOutput.js index bf1172d..d8eb1f3 100644 --- a/src/transaction/makeOutput.js +++ b/src/transaction/makeOutput.js @@ -8,7 +8,7 @@ */ export default function makeOutput(condition, amount = 1) { return { - 'amount': amount.toString(), + 'amount': amount, condition, 'public_keys': condition.details.hasOwnProperty('public_key') ? [condition.details.public_key] : [], diff --git a/test/test.js b/test/test.js index 991578a..5a1e216 100644 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,30 @@ import test from 'ava' +import { Ed25519Keypair, Transaction, Connection } from '../src' -test('foo', t => { - t.pass() +const API_PATH = 'http://localhost:9984/api/v1/' + +test('Keypair is created', t => { + const keyPair = new Ed25519Keypair() + + t.truthy(keyPair.publicKey) + t.truthy(keyPair.privateKey) }) -test('bar', async t => { - const bar = Promise.resolve('bar') +test('Valid CREATE transaction is evaluated by BigchainDB', t => { + const alice = new Ed25519Keypair() + const asset = { name: 'Shmui', type: 'cat' } + const metadata = { dayOfTheWeek: 'Caturday' } - t.is(await bar, 'bar') + const tx = Transaction.makeCreateTransaction( + asset, + metadata, + [Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))], + alice.publicKey + ) + + const txSigned = Transaction.signTransaction(tx, alice.privateKey) + const conn = new Connection(API_PATH) + return conn.postTransaction(txSigned) + .then(resTx => t.truthy(resTx)) }) + From 0200ffb2fbc96897d8a47da17c82324ef148babb Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 16 Jun 2017 14:21:33 +0200 Subject: [PATCH 2/4] Diversify node and browser builds --- package.json | 40 +++++++++++++++++++++------------------- webpack.config.js | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 87707fc..724b35d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bigchaindb-driver", - "version": "1.0.2", + "version": "0.1.0", "description": "Node.js driver for BigchainDB", "homepage": "https://www.bigchaindb.com/", "bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues", @@ -11,9 +11,10 @@ "license": "Apache-2.0", "author": "BigchainDB", "main": "./dist/node/index.js", + "browser": "./dist/browser/bundle.min.js", "scripts": { "lint": "eslint ./", - "build": "npm run clean && npm run build:bundle && npm run build:cjs && npm run build:dist", + "build": "npm run clean && npm run build:cjs && npm run build:dist", "build:bundle": "webpack", "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node", "build:dist": "cross-env NODE_ENV=production webpack -p", @@ -22,7 +23,7 @@ "release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", "release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive", "release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive", - "prepublishOnly": "npm update && npm run build", + "prepublish": "npm update && npm run build", "precommit": "npm run lint" }, "devDependencies": { @@ -49,6 +50,7 @@ "webpack": "^2.2.1" }, "dependencies": { + "browser-resolve": "^1.11.2", "bs58": "^4.0.0", "buffer": "^5.0.2", "clone": "^2.1.0", @@ -73,21 +75,21 @@ "dapp" ], "ava": { - "files": [ - "test/*.js" - ], - "source": [ - "**/*.{js,jsx}", - "!node_modules/**/*", - "!dist/**/*" - ], - "failFast": true, - "failWithoutAssertions": false, - "tap": true, - "powerAssert": false, - "require": [ - "babel-register" - ], - "babel": "inherit" + "files": [ + "test/*.js" + ], + "source": [ + "**/*.{js,jsx}", + "!node_modules/**/*", + "!dist/**/*" + ], + "failFast": true, + "failWithoutAssertions": false, + "tap": true, + "powerAssert": false, + "require": [ + "babel-register" + ], + "babel": "inherit" } } diff --git a/webpack.config.js b/webpack.config.js index 7aba528..211f43e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,7 @@ const PRODUCTION = process.env.NODE_ENV === 'production' const PATHS = { ENTRY: path.resolve(__dirname, './src/index.js'), - BUNDLE: path.resolve(__dirname, 'dist/bundle'), + BUNDLE: path.resolve(__dirname, 'dist/browser'), NODE_MODULES: path.resolve(__dirname, 'node_modules'), } From 32efda71c1b0f6064110d4f3ed2d5fc63726eaec Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 16 Jun 2017 14:21:52 +0200 Subject: [PATCH 3/4] Simplify README.md --- README.md | 80 +++---------------------------------------------------- 1 file changed, 4 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index df78eb5..3e57c68 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,14 @@ | BigchainDB Server | BigchainDB JavaScript Driver | | ----------------- |------------------------------| -| `~=0.10.1` | `~=1.0.0` | +| `0.10` | `0.1.0` | ## Contents * [Installation](#installation) -* [Usage](#usage) * [Example: Create a transaction](#example-create-a-transaction) - * [More examples](#more-examples) * [Documentation](#bigchaindb-documentation) -* [Speed Optimizations](#speed-optimizations) -* [Warnings](#warnings) -* [npm Releases](#npm-releases) * [Authors](#authors) * [License](#license) @@ -33,13 +28,6 @@ npm install bigchaindb-driver ``` -## Usage - -You'll probably need a babel here and a bundler there. Alternatively, use one of the bundled dist versions: - -- `dist/bundle/`: Babelified and packaged with dependencies, so you can drop it in anywhere you want. -- `dist/node/`: Babelified into a CommonJS module, so you can drop it in on any node project. - ### Example: Create a transaction ```js @@ -67,8 +55,8 @@ const tx = driver.Transaction.makeCreateTransaction( alice.publicKey ) -// Optional: You've got everything you need, except for an asset -// and metadata. Maybe define them here, any JSON-serializable object +// Optional: You've got everything you need, except for an asset +// and metadata. Maybe define them here, any JSON-serializable object // will do // Ok, now that you have a transaction, you need to *sign* it @@ -85,12 +73,6 @@ conn.postTransaction(txSigned) .then((res) => console.log('Transaction status:', res.status)) ``` -### More examples - -You may also be interested in some [long-form tutorials with actual code](https://github.com/bigchaindb/kyber): - -- [Kyber](https://github.com/bigchaindb/kyber): full suite of BigchainDB repos with tutorials, examples and experiments included. - ## BigchainDB Documentation - [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html) @@ -101,65 +83,11 @@ You may also be interested in some [long-form tutorials with actual code](https: ## Speed Optimizations -This implementation plays "safe" by using JS-native (or downgradable) libraries for its crypto-related functions to keep compatibilities with the browser. If you do want some more speed, feel free to explore the following: +This implementation plays "safe" by using JS-native (or downgradable) libraries for its crypto-related functions to keep compatibilities with the browser. If you do want some more speed, feel free to explore the following: * [chloride](https://github.com/dominictarr/chloride), or its underlying [sodium](https://github.com/paixaop/node-sodium) library * [node-sha3](https://github.com/phusion/node-sha3) -- **MAKE SURE** to use [steakknife's fork](https://github.com/steakknife/node-sha3) if [the FIPS 202 upgrade](https://github.com/phusion/node-sha3/pull/25) hasn't been merged (otherwise, you'll run into all kinds of hashing problems) -## Warnings - -> Crypto-conditions - -Make sure you keep using a crypto-conditions implementation that implements the older v1 draft (e.g. -[`five-bells-condition@v3.3.1`](https://github.com/interledgerjs/five-bells-condition/releases/tag/v3.3.1)). - -BigchainDB Server 0.10 does not implement the newer version of the spec and **WILL** fail if you try using a newer implementation of crypto-conditions. - -> SHA3 - -Make sure to use a SHA3 implementation that has been upgraded as per [FIPS 202](http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf). Otherwise, the hashes you generate **WILL** be invalid in the eyes of the BigchainDB Server. - -> Ed25519 - -If you do end up replacing `tweetnacl` with `chloride` (or any other `Ed25519` package), you might want to double check that it gives you a correct public/private (or verifying/signing, if they use -that lingo) key pair. - -An example BigchainDB Server-generated key pair (encoded in `base58`): - -- Public: `DjPMHDD9JtgypDKY38mPz9f6owjAMAKhLuN1JfRAat8C` -- Private: `7Gf5YRch2hYTyeLxqNLgTY63D9K5QH2UQ7LYFeBGuKvo` - -Your package should be able to take in the decoded version of the **private** key and return you the same **public** key (once you encode that to `base58`). - -## npm Releases - -For a new **patch release**, execute on the machine where you're logged into your npm account: - -```bash -npm run release -``` - -Command is powered by [`release-it`](https://github.com/webpro/release-it) package, defined in the `package.json`. - -That's what the command does without any user interaction: - -1. create release commit by updating version in `package.json` -1. create tag for that release commit -1. push commit & tag -1. create a new release on GitHub, with change log auto-generated from commit messages -1. update local dependencies to latest version -1. build bundled dist versions -1. publish to npm as a new release - -If you want to create a **minor** or **major release**, use these commands: - -```bash -npm run release-minor -``` - -```bash -npm run release-major -``` ## Authors From cdddef3d96483f1d65adcf7e68108b7a61470e6e Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 16 Jun 2017 14:58:06 +0200 Subject: [PATCH 4/4] Remove Travis --- .travis.yml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f5a7f3a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: node_js -node_js: node - -env: - - CXX=g++-4.9 - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.9 - -install: npm install - -script: - - npm test - - npm run build - -cache: - directories: - - node_modules - -notifications: - email: false \ No newline at end of file