1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-29 08:07:51 +01:00

Dynamically generated keys for /outputs tests + bool fix

This commit is contained in:
tim 2017-06-21 15:59:28 +02:00
parent b883e1f6d9
commit c17d614ab6
3 changed files with 43 additions and 50 deletions

View File

@ -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

View File

@ -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' } }
))
})

View File

@ -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))
})