mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-02-14 21:10:32 +01:00
refactor code & add test
This commit is contained in:
parent
d812e64b30
commit
34c82a1ae8
@ -119,10 +119,7 @@ export default class Connection {
|
|||||||
* @param transaction
|
* @param transaction
|
||||||
*/
|
*/
|
||||||
postTransaction(transaction) {
|
postTransaction(transaction) {
|
||||||
return this._req(this.getApiUrls('transactionsCommit'), {
|
return this.postTransactionCommit(transaction)
|
||||||
method: 'POST',
|
|
||||||
jsonBody: transaction
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,9 @@ test('Generate API URLS', t => {
|
|||||||
'blocksDetail': 'blocks/%(blockHeight)s',
|
'blocksDetail': 'blocks/%(blockHeight)s',
|
||||||
'outputs': 'outputs',
|
'outputs': 'outputs',
|
||||||
'transactions': 'transactions',
|
'transactions': 'transactions',
|
||||||
|
'transactionsSync': 'transactions?mode=sync',
|
||||||
|
'transactionsAsync': 'transactions?mode=async',
|
||||||
|
'transactionsCommit': 'transactions?mode=commit',
|
||||||
'transactionsDetail': 'transactions/%(transactionId)s',
|
'transactionsDetail': 'transactions/%(transactionId)s',
|
||||||
'assets': 'assets',
|
'assets': 'assets',
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,39 @@ test('Valid CREATE transaction', t => {
|
|||||||
)
|
)
|
||||||
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
||||||
|
|
||||||
return conn.postTransactionCommit(txSigned)
|
return conn.postTransaction(txSigned)
|
||||||
|
.then(resTx => t.truthy(resTx))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test('Valid CREATE transaction using async', t => {
|
||||||
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
const tx = Transaction.makeCreateTransaction(
|
||||||
|
asset(),
|
||||||
|
metaData,
|
||||||
|
[aliceOutput],
|
||||||
|
alice.publicKey
|
||||||
|
)
|
||||||
|
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
||||||
|
|
||||||
|
return conn.postTransactionAsync(txSigned)
|
||||||
|
.then(resTx => t.truthy(resTx))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test('Valid CREATE transaction using sync', t => {
|
||||||
|
const conn = new Connection(API_PATH)
|
||||||
|
|
||||||
|
const tx = Transaction.makeCreateTransaction(
|
||||||
|
asset(),
|
||||||
|
metaData,
|
||||||
|
[aliceOutput],
|
||||||
|
alice.publicKey
|
||||||
|
)
|
||||||
|
const txSigned = Transaction.signTransaction(tx, alice.privateKey)
|
||||||
|
|
||||||
|
return conn.postTransactionSync(txSigned)
|
||||||
.then(resTx => t.truthy(resTx))
|
.then(resTx => t.truthy(resTx))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user