refactor code & add test

This commit is contained in:
manolodewiner 2018-06-19 16:52:23 +02:00
parent d812e64b30
commit 34c82a1ae8
3 changed files with 37 additions and 5 deletions

View File

@ -119,10 +119,7 @@ export default class Connection {
* @param transaction
*/
postTransaction(transaction) {
return this._req(this.getApiUrls('transactionsCommit'), {
method: 'POST',
jsonBody: transaction
})
return this.postTransactionCommit(transaction)
}
/**

View File

@ -27,6 +27,9 @@ test('Generate API URLS', t => {
'blocksDetail': 'blocks/%(blockHeight)s',
'outputs': 'outputs',
'transactions': 'transactions',
'transactionsSync': 'transactions?mode=sync',
'transactionsAsync': 'transactions?mode=async',
'transactionsCommit': 'transactions?mode=commit',
'transactionsDetail': 'transactions/%(transactionId)s',
'assets': 'assets',
}

View File

@ -35,7 +35,39 @@ test('Valid CREATE transaction', t => {
)
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))
})