1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

fix tests

This commit is contained in:
manolodewiner 2018-03-27 16:44:59 +02:00
parent b4e31fe786
commit 99a049056b
4 changed files with 15 additions and 88 deletions

View File

@ -18,7 +18,7 @@ before_install:
-e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D -e BIGCHAINDB_KEYPAIR_PRIVATE=5C5Cknco7YxBRP9AgB1cbUVTL4FAcooxErLygw1DeG2D
-e BIGCHAINDB_DATABASE_BACKEND=mongodb -e BIGCHAINDB_DATABASE_BACKEND=mongodb
-e BIGCHAINDB_DATABASE_HOST=172.17.0.1 -e BIGCHAINDB_DATABASE_HOST=172.17.0.1
bigchaindb/bigchaindb:1.4.0 bigchaindb/bigchaindb:2.0.0
start start
- gem install cowsay - gem install cowsay
- npm install -g codecov - npm install -g codecov

View File

@ -1,6 +1,6 @@
{ {
"name": "bigchaindb-driver", "name": "bigchaindb-driver",
"version": "3.2.0", "version": "4.0.0",
"description": "Node.js driver for BigchainDB", "description": "Node.js driver for BigchainDB",
"homepage": "https://www.bigchaindb.com/", "homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues", "bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",

View File

@ -53,7 +53,7 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
alice.privateKey alice.privateKey
) )
return conn.postTransactionSync(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => { .then(() => {
const transferTx = Transaction.makeTransferTransaction( const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }], [{ tx: createTxSigned, output_index: 0 }],
@ -64,7 +64,7 @@ test('Valid TRANSFER transaction with single Ed25519 input', t => {
transferTx, transferTx,
alice.privateKey alice.privateKey
) )
return conn.postTransactionSync(transferTxSigned) return conn.postTransactionCommit(transferTxSigned)
.then(resTx => t.truthy(resTx)) .then(resTx => t.truthy(resTx))
}) })
}) })
@ -83,7 +83,7 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
alice.privateKey alice.privateKey
) )
return conn.postTransactionSync(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => { .then(() => {
const transferTx = Transaction.makeTransferTransaction( const transferTx = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }, { tx: createTxSigned, output_index: 1 }], [{ tx: createTxSigned, output_index: 0 }, { tx: createTxSigned, output_index: 1 }],
@ -95,7 +95,7 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
alice.privateKey, alice.privateKey,
bob.privateKey bob.privateKey
) )
return conn.postTransactionSync(transferTxSigned) return conn.postTransactionCommit(transferTxSigned)
.then(resTx => t.truthy(resTx)) .then(resTx => t.truthy(resTx))
}) })
}) })
@ -123,7 +123,7 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs from different tra
alice.privateKey alice.privateKey
) )
return conn.postTransactionSync(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => { .then(() => {
const transferTx1 = Transaction.makeTransferTransaction( const transferTx1 = Transaction.makeTransferTransaction(
[{ tx: createTxSigned, output_index: 0 }], [{ tx: createTxSigned, output_index: 0 }],
@ -144,8 +144,8 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs from different tra
bob.privateKey bob.privateKey
) )
return conn.postTransactionSync(transferTxSigned1) return conn.postTransactionCommit(transferTxSigned1)
.then(conn.postTransactionSync(transferTxSigned2)) .then(conn.postTransactionCommit(transferTxSigned2))
.then(() => { .then(() => {
const transferTxMultipleInputs = Transaction.makeTransferTransaction( const transferTxMultipleInputs = Transaction.makeTransferTransaction(
[{ tx: transferTxSigned1, output_index: 0 }, [{ tx: transferTxSigned1, output_index: 0 },
@ -158,13 +158,12 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs from different tra
carol.privateKey, carol.privateKey,
trent.privateKey trent.privateKey
) )
return conn.postTransactionSync(transferTxSignedMultipleInputs) return conn.postTransactionCommit(transferTxSignedMultipleInputs)
.then(resTx => t.truthy(resTx)) .then(resTx => t.truthy(resTx))
}) })
}) })
}) })
test('Search for spent and unspent outputs of a given public key', t => { test('Search for spent and unspent outputs of a given public key', t => {
const conn = new Connection(API_PATH) const conn = new Connection(API_PATH)
const carol = new Ed25519Keypair() const carol = new Ed25519Keypair()
@ -199,7 +198,7 @@ test('Search for spent and unspent outputs of a given public key', t => {
) )
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionSync(transferTxSigned)) .then(() => conn.postTransactionCommit(transferTxSigned))
.then(() => conn.listOutputs(carol.publicKey)) .then(() => conn.listOutputs(carol.publicKey))
// now listOutputs should return us outputs 0 and 1 (unfiltered) // now listOutputs should return us outputs 0 and 1 (unfiltered)
.then(outputs => t.truthy(outputs.length === 2)) .then(outputs => t.truthy(outputs.length === 2))
@ -239,7 +238,7 @@ test('Search for unspent outputs for a given public key', t => {
) )
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionSync(transferTxSigned)) .then(() => conn.postTransactionCommit(transferTxSigned))
// now listOutputs should return us outputs 0 and 2 (1 is spent) // now listOutputs should return us outputs 0 and 2 (1 is spent)
.then(() => conn.listOutputs(carol.publicKey, 'false')) .then(() => conn.listOutputs(carol.publicKey, 'false'))
.then(outputs => t.truthy(outputs.length === 2)) .then(outputs => t.truthy(outputs.length === 2))
@ -279,7 +278,7 @@ test('Search for spent outputs for a given public key', t => {
) )
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => conn.postTransactionSync(transferTxSigned)) .then(() => conn.postTransactionCommit(transferTxSigned))
// now listOutputs should only return us output 1 (0 and 2 are unspent) // now listOutputs should only return us output 1 (0 and 2 are unspent)
.then(() => conn.listOutputs(carol.publicKey, true)) .then(() => conn.listOutputs(carol.publicKey, true))
.then(outputs => t.truthy(outputs.length === 1)) .then(outputs => t.truthy(outputs.length === 1))
@ -303,7 +302,6 @@ test('Search for an asset', t => {
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(() => conn.searchAssets(createTxSigned.asset.data.message)) .then(() => conn.searchAssets(createTxSigned.asset.data.message))
.then(assets => t.truthy( .then(assets => t.truthy(
console.log('llllllllllllllllllll', createTxSigned.asset.data.message, assets),
assets.pop(), assets.pop(),
createTxSigned.asset.data.message createTxSigned.asset.data.message
)) ))
@ -348,14 +346,8 @@ test('Search blocks containing a transaction', t => {
) )
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(({ id }) => { .then(({ id }) => conn.listBlocks(id))
console.log('hhhhhhhhhh', id) .then(blockHeight => conn.getBlock(blockHeight.pop()))
return conn.listBlocks(id)
})
.then(blockHeight => {
console.log('wwwwwwww', blockHeight)
conn.getBlock(blockHeight.pop())
})
.then(({ transactions }) => transactions.filter(({ id }) => id === createTxSigned.id)) .then(({ transactions }) => transactions.filter(({ id }) => id === createTxSigned.id))
.then(transactions => t.truthy(transactions.length === 1)) .then(transactions => t.truthy(transactions.length === 1))
}) })
@ -378,7 +370,6 @@ test('Search transaction containing an asset', t => {
return conn.postTransactionCommit(createTxSigned) return conn.postTransactionCommit(createTxSigned)
.then(({ id }) => conn.listTransactions(id)) .then(({ id }) => conn.listTransactions(id))
.then(transactions => { .then(transactions => {
console.log('cccccccccccc', transactions, createTxSigned.id)
t.truthy(transactions.length === 1) t.truthy(transactions.length === 1)
}) })
}) })

View File

@ -1,64 +0,0 @@
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))
})
})