From 34c82a1ae8ded10571bd8b8a3d1e7fe931402a87 Mon Sep 17 00:00:00 2001 From: manolodewiner Date: Tue, 19 Jun 2018 16:52:23 +0200 Subject: [PATCH] refactor code & add test --- src/connection.js | 5 +--- test/connection/test_connection.js | 3 +++ test/integration/test_integration.js | 34 +++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/connection.js b/src/connection.js index e462b58..0f9a2ef 100644 --- a/src/connection.js +++ b/src/connection.js @@ -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) } /** diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 960c11f..f9e1e7a 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -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', } diff --git a/test/integration/test_integration.js b/test/integration/test_integration.js index a3fa072..9862822 100644 --- a/test/integration/test_integration.js +++ b/test/integration/test_integration.js @@ -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)) })