From a5efa3812163ca9b618299a3b10de7e0d9385f39 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 16 Jun 2017 11:22:23 +0200 Subject: [PATCH] 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)) }) +