Skip to content

Commit

Permalink
refactor code & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
manolodewiner committed Jun 19, 2018
1 parent d812e64 commit 34c82a1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/connection/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
34 changes: 33 additions & 1 deletion test/integration/test_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

Expand Down

0 comments on commit 34c82a1

Please sign in to comment.