From abe1c890254710d612720366f43c56249a25cef4 Mon Sep 17 00:00:00 2001 From: manolodewiner Date: Mon, 26 Mar 2018 12:15:36 +0200 Subject: [PATCH] test integration failing --- package.json | 1 + test/connection/test_connection.js | 2 +- test/constants.js | 1 + test/integration/test_integration.js | 33 ++++++++------ test/integration/test_mine.js | 64 ++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 test/integration/test_mine.js diff --git a/package.json b/package.json index 650cff6..800d18a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "build:dist": "cross-env NODE_ENV=production webpack -p", "clean": "rimraf dist/bundle dist/node", "test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage", + "testmine": "npm run lint && nyc ava test/integration/test_min*", "thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!", "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", "release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive", diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 4cdfa2b..960c11f 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -3,8 +3,8 @@ import sinon from 'sinon' import * as request from '../../src/request' // eslint-disable-line import { Connection } from '../../src' +import { API_PATH } from '../constants' -const API_PATH = 'http://localhost:9984/api/v1/' const conn = new Connection(API_PATH) test('Payload thrown at incorrect API_PATH', t => { diff --git a/test/constants.js b/test/constants.js index bcd9b5d..2194151 100644 --- a/test/constants.js +++ b/test/constants.js @@ -4,6 +4,7 @@ import { Transaction, Ed25519Keypair } from '../src' // NOTE: It's safer to cast `Math.random()` to a string, to avoid differences // in "float interpretation" between languages (e.g. JavaScript and Python) +export const API_PATH = 'http://localhost:9984/api/v1/' export function asset() { return { message: `${Math.random()}` } } export const metaData = { message: 'metaDataMessage' } diff --git a/test/integration/test_integration.js b/test/integration/test_integration.js index f46e8ba..517ab00 100644 --- a/test/integration/test_integration.js +++ b/test/integration/test_integration.js @@ -2,6 +2,7 @@ import test from 'ava' import { Ed25519Keypair, Transaction, Connection } from '../../src' import { + API_PATH, alice, aliceCondition, aliceOutput, @@ -11,8 +12,6 @@ import { metaData } from '../constants' -const API_PATH = 'http://localhost:9984/api/v1/' - test('Keypair is created', t => { const keyPair = new Ed25519Keypair() @@ -36,7 +35,7 @@ test('Valid CREATE transaction', t => { ) const txSigned = Transaction.signTransaction(tx, alice.privateKey) - return conn.postTransactionSync(txSigned) + return conn.postTransactionCommit(txSigned) .then(resTx => t.truthy(resTx)) }) @@ -199,7 +198,7 @@ test('Search for spent and unspent outputs of a given public key', t => { carol.privateKey, ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(() => conn.postTransactionSync(transferTxSigned)) .then(() => conn.listOutputs(carol.publicKey)) // now listOutputs should return us outputs 0 and 1 (unfiltered) @@ -239,7 +238,7 @@ test('Search for unspent outputs for a given public key', t => { carol.privateKey, ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(() => conn.postTransactionSync(transferTxSigned)) // now listOutputs should return us outputs 0 and 2 (1 is spent) .then(() => conn.listOutputs(carol.publicKey, 'false')) @@ -279,7 +278,7 @@ test('Search for spent outputs for a given public key', t => { carol.privateKey, ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(() => conn.postTransactionSync(transferTxSigned)) // now listOutputs should only return us output 1 (0 and 2 are unspent) .then(() => conn.listOutputs(carol.publicKey, true)) @@ -301,10 +300,10 @@ test('Search for an asset', t => { alice.privateKey ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(() => conn.searchAssets(createTxSigned.asset.data.message)) .then(assets => t.truthy( - console.log('llllllllllllllllllll', createTxSigned.asset.data.message, assets.pop()), + console.log('llllllllllllllllllll', createTxSigned.asset.data.message, assets), assets.pop(), createTxSigned.asset.data.message )) @@ -325,7 +324,7 @@ test('Search for metadata', t => { alice.privateKey ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(() => conn.searchMetadata(createTxSigned.metadata.message)) .then(assets => t.truthy( assets.pop(), @@ -348,10 +347,16 @@ test('Search blocks containing a transaction', t => { alice.privateKey ) - return conn.postTransactionSync(createTxSigned) - .then(({ id }) => conn.listBlocks(id)) - .then(blocks => conn.getBlock(blocks.pop())) - .then(({ block: { transactions } }) => transactions.filter(({ id }) => id === createTxSigned.id)) + return conn.postTransactionCommit(createTxSigned) + .then(({ id }) => { + console.log('hhhhhhhhhh', id) + return conn.listBlocks(id) + }) + .then(blockHeight => { + console.log('wwwwwwww', blockHeight) + conn.getBlock(blockHeight.pop()) + }) + .then(({ transactions }) => transactions.filter(({ id }) => id === createTxSigned.id)) .then(transactions => t.truthy(transactions.length === 1)) }) @@ -370,7 +375,7 @@ test('Search transaction containing an asset', t => { alice.privateKey ) - return conn.postTransactionSync(createTxSigned) + return conn.postTransactionCommit(createTxSigned) .then(({ id }) => conn.listTransactions(id)) .then(transactions => { console.log('cccccccccccc', transactions, createTxSigned.id) diff --git a/test/integration/test_mine.js b/test/integration/test_mine.js new file mode 100644 index 0000000..3477348 --- /dev/null +++ b/test/integration/test_mine.js @@ -0,0 +1,64 @@ +import test from 'ava' +import { Transaction, Connection } from '../../src' + +import { + API_PATH, + alice, + aliceOutput, + asset, + metaData +} from '../constants' + + +test('Search transaction containing an asset', t => { + const conn = new Connection(API_PATH) + + console.log('posting') + const createTx = Transaction.makeCreateTransaction( + asset(), + metaData, + [aliceOutput], + alice.publicKey + ) + const createTxSigned = Transaction.signTransaction( + createTx, + alice.privateKey + ) + console.log('the payload is ', JSON.stringify(createTxSigned), { showHidden: false, depth: null }) + + return conn.postTransactionCommit(createTxSigned) + .then(({ id }) => conn.listTransactions(id)) + .then(transactions => { + console.log('cccccccccccc', transactions, createTxSigned.id) + t.truthy(transactions.length === 1) + }) +}) + +test('Valid TRANSFER transaction with single Ed25519 input', t => { + const conn = new Connection(API_PATH) + const createTx = Transaction.makeCreateTransaction( + asset(), + metaData, + [aliceOutput], + alice.publicKey + ) + const createTxSigned = Transaction.signTransaction( + createTx, + alice.privateKey + ) + + return conn.postTransactionSync(createTxSigned) + .then(() => { + const transferTx = Transaction.makeTransferTransaction( + [{ tx: createTxSigned, output_index: 0 }], + [aliceOutput], + metaData + ) + const transferTxSigned = Transaction.signTransaction( + transferTx, + alice.privateKey + ) + return conn.postTransactionSync(transferTxSigned) + .then(resTx => t.truthy(resTx)) + }) +})