diff --git a/src/connection/index.js b/src/connection/index.js index 48d9a67..aa7131e 100644 --- a/src/connection/index.js +++ b/src/connection/index.js @@ -89,7 +89,7 @@ export default class Connection { // NOTE: If `spent` is not defined, it must not be included in the // query parameters. if (spent !== undefined) { - query.spent = spent + query.spent = spent.toString() } return this._req(this.getApiUrls('outputs'), { query diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index af398c5..eb7bf34 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -157,7 +157,7 @@ test('Get outputs for a public key and spent=false', t => { conn.listOutputs(publicKey, spent) t.truthy(conn._req.calledWith( expectedPath, - { query: { public_key: publicKey, spent } } + { query: { public_key: publicKey, spent: 'false' } } )) }) @@ -173,7 +173,7 @@ test('Get outputs for a public key and spent=true', t => { conn.listOutputs(publicKey, spent) t.truthy(conn._req.calledWith( expectedPath, - { query: { public_key: publicKey, spent } } + { query: { public_key: publicKey, spent: 'true' } } )) }) diff --git a/test/integration/test_integration.js b/test/integration/test_integration.js index 5b1d184..b6808d5 100644 --- a/test/integration/test_integration.js +++ b/test/integration/test_integration.js @@ -112,137 +112,130 @@ test('Valid TRANSFER transaction with multiple Ed25519 inputs', t => { test('Search for spent and unspent outputs of a given public key', 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 createTx = Transaction.makeCreateTransaction( asset(), metaData, - [aliceOutput, aliceOutput], - alice.publicKey + [carolOutput, carolOutput], + carol.publicKey ) const createTxSigned = Transaction.signTransaction( createTx, - alice.privateKey, - alice.privateKey + carol.privateKey, + carol.privateKey ) // We spent output 1 (of 0, 1) const transferTx = Transaction.makeTransferTransaction( createTxSigned, metaData, - [bobOutput], + [trentOutput], 1 ) const transferTxSigned = Transaction.signTransaction( transferTx, - alice.privateKey, + carol.privateKey, ) - function byTransactionId(transactionId, ...outputIndices) { - return value => transactionId === value.transaction_id && - outputIndices.includes(value.output) - } - return conn.postTransaction(createTxSigned) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) .then(() => conn.postTransaction(transferTxSigned)) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) - .then(() => conn.listOutputs(alice.publicKey)) + .then(() => conn.listOutputs(carol.publicKey)) // now listOutputs should return us outputs 0 and 1 (unfiltered) - .then(outputs => outputs.filter(byTransactionId( - createTxSigned.id, - 0, - 1 - ))) .then(outputs => t.truthy(outputs.length === 2)) }) test('Search for unspent outputs for a given public key', 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 createTx = Transaction.makeCreateTransaction( asset(), metaData, - [aliceOutput, aliceOutput, aliceOutput], - alice.publicKey + [carolOutput, carolOutput, carolOutput], + carol.publicKey ) const createTxSigned = Transaction.signTransaction( createTx, - alice.privateKey, - alice.privateKey + carol.privateKey, + carol.privateKey ) // We spent output 1 (of 0, 1, 2) const transferTx = Transaction.makeTransferTransaction( createTxSigned, metaData, - [bobOutput], + [trentOutput], 1 ) const transferTxSigned = Transaction.signTransaction( transferTx, - alice.privateKey, + carol.privateKey, ) - function byTransactionId(transactionId, ...outputIndices) { - return value => transactionId === value.transaction_id && - outputIndices.includes(value.output) - } - return conn.postTransaction(createTxSigned) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) .then(() => conn.postTransaction(transferTxSigned)) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) // now listOutputs should return us outputs 0 and 2 (1 is spent) - .then(() => conn.listOutputs(alice.publicKey, false)) - .then(outputs => outputs.filter(byTransactionId( - createTxSigned.id, - 0, - 2 - ))) + .then(() => conn.listOutputs(carol.publicKey, 'false')) .then(outputs => t.truthy(outputs.length === 2)) }) test('Search for spent outputs for a given public key', 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 createTx = Transaction.makeCreateTransaction( asset(), metaData, - [aliceOutput, aliceOutput, aliceOutput], - alice.publicKey + [carolOutput, carolOutput, carolOutput], + carol.publicKey ) const createTxSigned = Transaction.signTransaction( createTx, - alice.privateKey, - alice.privateKey + carol.privateKey, + carol.privateKey ) // We spent output 1 (of 0, 1, 2) const transferTx = Transaction.makeTransferTransaction( createTxSigned, metaData, - [bobOutput], + [trentOutput], 1 ) const transferTxSigned = Transaction.signTransaction( transferTx, - alice.privateKey, + carol.privateKey, ) - function byTransactionId(transactionId, ...outputIndices) { - return value => transactionId === value.transaction_id && - outputIndices.includes(value.output) - } - return conn.postTransaction(createTxSigned) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) .then(() => conn.postTransaction(transferTxSigned)) .then(({ id }) => conn.pollStatusAndFetchTransaction(id)) // now listOutputs should only return us output 1 (0 and 2 are unspent) - .then(() => conn.listOutputs(alice.publicKey, true)) - .then(outputs => outputs.filter(byTransactionId(createTxSigned.id, 1))) + .then(() => conn.listOutputs(carol.publicKey, true)) .then(outputs => t.truthy(outputs.length === 1)) })