mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-01-01 01:27:54 +01:00
Add integration tests
This commit is contained in:
parent
9bc0773b4e
commit
03c17ef70c
@ -129,12 +129,10 @@ export default class Connection {
|
|||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
this.getStatus(txId)
|
this.getStatus(txId)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log('Fetched transaction status:', res) // eslint-disable-line no-console
|
|
||||||
if (res.status === 'valid') {
|
if (res.status === 'valid') {
|
||||||
clearInterval(timer)
|
clearInterval(timer)
|
||||||
this.getTransaction(txId)
|
this.getTransaction(txId)
|
||||||
.then((res_) => {
|
.then((res_) => {
|
||||||
console.log('Fetched transaction:', res_) // eslint-disable-line no-console
|
|
||||||
resolve(res_)
|
resolve(res_)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
110
test/integration/test_integration.js
Normal file
110
test/integration/test_integration.js
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import { Ed25519Keypair, Transaction, Connection } from '../../src'
|
||||||
|
|
||||||
|
import {
|
||||||
|
alice,
|
||||||
|
aliceCondition,
|
||||||
|
aliceOutput,
|
||||||
|
bob,
|
||||||
|
bobOutput,
|
||||||
|
assetMessage,
|
||||||
|
metaDataMessage
|
||||||
|
} from '../constants'
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: The following tests are a bit messy currently, please do:
|
||||||
|
//
|
||||||
|
// - tidy up dependency on `pollStatusAndFetchTransaction`
|
||||||
|
test('Valid CREATE transaction', t => {
|
||||||
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
const tx = Transaction.makeCreateTransaction(
|
||||||
|
assetMessage,
|
||||||
|
metaDataMessage,
|
||||||
|
[aliceOutput],
|
||||||
|
alice.publicKey
|
||||||
|
)
|
||||||
|
|
||||||
|
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
||||||
|
return conn.postTransaction(txSigned)
|
||||||
|
.then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId))
|
||||||
|
.then(resTx => t.truthy(resTx))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test('Valid TRANSFER transaction with single Ed25519 input', t => {
|
||||||
|
const conn = new Connection(API_PATH)
|
||||||
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
|
assetMessage,
|
||||||
|
metaDataMessage,
|
||||||
|
[aliceOutput],
|
||||||
|
alice.publicKey
|
||||||
|
)
|
||||||
|
const createTxSigned = Transaction.signTransaction(
|
||||||
|
createTx,
|
||||||
|
alice.privateKey
|
||||||
|
)
|
||||||
|
|
||||||
|
return conn.postTransaction(createTxSigned)
|
||||||
|
.then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId))
|
||||||
|
.then(() => {
|
||||||
|
const transferTx = Transaction.makeTransferTransaction(
|
||||||
|
createTxSigned,
|
||||||
|
metaDataMessage,
|
||||||
|
[aliceOutput],
|
||||||
|
0
|
||||||
|
)
|
||||||
|
const transferTxSigned = Transaction.signTransaction(
|
||||||
|
transferTx,
|
||||||
|
alice.privateKey
|
||||||
|
)
|
||||||
|
return conn.postTransaction(transferTxSigned)
|
||||||
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
|
.then(resTx => t.truthy(resTx))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => {
|
||||||
|
const conn = new Connection(API_PATH)
|
||||||
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
|
assetMessage,
|
||||||
|
metaDataMessage,
|
||||||
|
[aliceOutput, bobOutput],
|
||||||
|
alice.publicKey
|
||||||
|
)
|
||||||
|
const createTxSigned = Transaction.signTransaction(
|
||||||
|
createTx,
|
||||||
|
alice.privateKey
|
||||||
|
)
|
||||||
|
|
||||||
|
return conn.postTransaction(createTxSigned)
|
||||||
|
.then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId))
|
||||||
|
.then(() => {
|
||||||
|
const transferTx = Transaction.makeTransferTransaction(
|
||||||
|
createTxSigned,
|
||||||
|
metaDataMessage,
|
||||||
|
[Transaction.makeOutput(aliceCondition, '2')],
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
const transferTxSigned = Transaction.signTransaction(
|
||||||
|
transferTx,
|
||||||
|
alice.privateKey,
|
||||||
|
bob.privateKey
|
||||||
|
)
|
||||||
|
return conn.postTransaction(transferTxSigned)
|
||||||
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
|
.then(resTx => t.truthy(resTx))
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user