From 9f385c440db43209b5ba682b84546439f3aeff55 Mon Sep 17 00:00:00 2001 From: manolodewiner Date: Tue, 31 Oct 2017 17:58:47 +0100 Subject: [PATCH] Add test of transaction with multiple inputs --- test/integration/test_integration.js | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/integration/test_integration.js b/test/integration/test_integration.js index 0d6f49c..1c71764 100644 --- a/test/integration/test_integration.js +++ b/test/integration/test_integration.js @@ -107,6 +107,74 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => { }) +test('Valid TRANSFER transaction with multiple Ed25519 inputs from different transactions', t => { + const conn = new Connection(API_PATH) + const carol = new Ed25519Keypair() + const carolCondition = Transaction.makeEd25519Condition(carol.publicKey) + const carolOutput = Transaction.makeOutput(carolCondition) + const trent = new Ed25519Keypair() + const trentCondition = Transaction.makeEd25519Condition(trent.publicKey) + const trentOutput = Transaction.makeOutput(trentCondition) + const eli = new Ed25519Keypair() + const eliCondition = Transaction.makeEd25519Condition(eli.publicKey) + + const createTx = Transaction.makeCreateTransaction( + asset(), + metaData, + [aliceOutput, bobOutput], + alice.publicKey + ) + const createTxSigned = Transaction.signTransaction( + createTx, + alice.privateKey + ) + + return conn.postTransaction(createTxSigned) + .then(({ 'id': txId }) => conn.pollStatusAndFetchTransaction(txId)) + .then(() => { + const transferTx1 = Transaction.makeTransferTransaction( + [{ tx: createTxSigned, output_index: 0 }], + [carolOutput], + metaData + ) + const transferTxSigned1 = Transaction.signTransaction( + transferTx1, + alice.privateKey + ) + const transferTx2 = Transaction.makeTransferTransaction( + [{ tx: createTxSigned, output_index: 1 }], + [trentOutput], + metaData + ) + const transferTxSigned2 = Transaction.signTransaction( + transferTx2, + bob.privateKey + ) + + return conn.postTransaction(transferTxSigned1) + .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) + .then(conn.postTransaction(transferTxSigned2)) + .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) + .then(() => { + const transferTxMultipleInputs = Transaction.makeTransferTransaction( + [{ tx: transferTxSigned1, output_index: 0 }, + { tx: transferTxSigned2, output_index: 0 }], + [Transaction.makeOutput(eliCondition, '2')], + metaData + ) + const transferTxSignedMultipleInputs = Transaction.signTransaction( + transferTxMultipleInputs, + carol.privateKey, + trent.privateKey + ) + return conn.postTransaction(transferTxSignedMultipleInputs) + .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) + .then(resTx => t.truthy(resTx)) + }) + }) +}) + + test('Search for spent and unspent outputs of a given public key', t => { const conn = new Connection(API_PATH) const carol = new Ed25519Keypair()