mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-01-01 01:27:54 +01:00
Dynamically generated keys for /outputs tests + bool fix
This commit is contained in:
parent
b883e1f6d9
commit
c17d614ab6
@ -89,7 +89,7 @@ export default class Connection {
|
|||||||
// NOTE: If `spent` is not defined, it must not be included in the
|
// NOTE: If `spent` is not defined, it must not be included in the
|
||||||
// query parameters.
|
// query parameters.
|
||||||
if (spent !== undefined) {
|
if (spent !== undefined) {
|
||||||
query.spent = spent
|
query.spent = spent.toString()
|
||||||
}
|
}
|
||||||
return this._req(this.getApiUrls('outputs'), {
|
return this._req(this.getApiUrls('outputs'), {
|
||||||
query
|
query
|
||||||
|
@ -157,7 +157,7 @@ test('Get outputs for a public key and spent=false', t => {
|
|||||||
conn.listOutputs(publicKey, spent)
|
conn.listOutputs(publicKey, spent)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
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)
|
conn.listOutputs(publicKey, spent)
|
||||||
t.truthy(conn._req.calledWith(
|
t.truthy(conn._req.calledWith(
|
||||||
expectedPath,
|
expectedPath,
|
||||||
{ query: { public_key: publicKey, spent } }
|
{ query: { public_key: publicKey, spent: 'true' } }
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -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 => {
|
test('Search for spent and unspent outputs of a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
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(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
asset(),
|
asset(),
|
||||||
metaData,
|
metaData,
|
||||||
[aliceOutput, aliceOutput],
|
[carolOutput, carolOutput],
|
||||||
alice.publicKey
|
carol.publicKey
|
||||||
)
|
)
|
||||||
const createTxSigned = Transaction.signTransaction(
|
const createTxSigned = Transaction.signTransaction(
|
||||||
createTx,
|
createTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
alice.privateKey
|
carol.privateKey
|
||||||
)
|
)
|
||||||
|
|
||||||
// We spent output 1 (of 0, 1)
|
// We spent output 1 (of 0, 1)
|
||||||
const transferTx = Transaction.makeTransferTransaction(
|
const transferTx = Transaction.makeTransferTransaction(
|
||||||
createTxSigned,
|
createTxSigned,
|
||||||
metaData,
|
metaData,
|
||||||
[bobOutput],
|
[trentOutput],
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
const transferTxSigned = Transaction.signTransaction(
|
const transferTxSigned = Transaction.signTransaction(
|
||||||
transferTx,
|
transferTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
function byTransactionId(transactionId, ...outputIndices) {
|
|
||||||
return value => transactionId === value.transaction_id &&
|
|
||||||
outputIndices.includes(value.output)
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn.postTransaction(createTxSigned)
|
return conn.postTransaction(createTxSigned)
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
.then(() => conn.postTransaction(transferTxSigned))
|
.then(() => conn.postTransaction(transferTxSigned))
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.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)
|
// 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))
|
.then(outputs => t.truthy(outputs.length === 2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for unspent outputs for a given public key', t => {
|
test('Search for unspent outputs for a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
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(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
asset(),
|
asset(),
|
||||||
metaData,
|
metaData,
|
||||||
[aliceOutput, aliceOutput, aliceOutput],
|
[carolOutput, carolOutput, carolOutput],
|
||||||
alice.publicKey
|
carol.publicKey
|
||||||
)
|
)
|
||||||
const createTxSigned = Transaction.signTransaction(
|
const createTxSigned = Transaction.signTransaction(
|
||||||
createTx,
|
createTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
alice.privateKey
|
carol.privateKey
|
||||||
)
|
)
|
||||||
|
|
||||||
// We spent output 1 (of 0, 1, 2)
|
// We spent output 1 (of 0, 1, 2)
|
||||||
const transferTx = Transaction.makeTransferTransaction(
|
const transferTx = Transaction.makeTransferTransaction(
|
||||||
createTxSigned,
|
createTxSigned,
|
||||||
metaData,
|
metaData,
|
||||||
[bobOutput],
|
[trentOutput],
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
const transferTxSigned = Transaction.signTransaction(
|
const transferTxSigned = Transaction.signTransaction(
|
||||||
transferTx,
|
transferTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
function byTransactionId(transactionId, ...outputIndices) {
|
|
||||||
return value => transactionId === value.transaction_id &&
|
|
||||||
outputIndices.includes(value.output)
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn.postTransaction(createTxSigned)
|
return conn.postTransaction(createTxSigned)
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
.then(() => conn.postTransaction(transferTxSigned))
|
.then(() => conn.postTransaction(transferTxSigned))
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
// now listOutputs should return us outputs 0 and 2 (1 is spent)
|
// now listOutputs should return us outputs 0 and 2 (1 is spent)
|
||||||
.then(() => conn.listOutputs(alice.publicKey, false))
|
.then(() => conn.listOutputs(carol.publicKey, 'false'))
|
||||||
.then(outputs => outputs.filter(byTransactionId(
|
|
||||||
createTxSigned.id,
|
|
||||||
0,
|
|
||||||
2
|
|
||||||
)))
|
|
||||||
.then(outputs => t.truthy(outputs.length === 2))
|
.then(outputs => t.truthy(outputs.length === 2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('Search for spent outputs for a given public key', t => {
|
test('Search for spent outputs for a given public key', t => {
|
||||||
const conn = new Connection(API_PATH)
|
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(
|
const createTx = Transaction.makeCreateTransaction(
|
||||||
asset(),
|
asset(),
|
||||||
metaData,
|
metaData,
|
||||||
[aliceOutput, aliceOutput, aliceOutput],
|
[carolOutput, carolOutput, carolOutput],
|
||||||
alice.publicKey
|
carol.publicKey
|
||||||
)
|
)
|
||||||
const createTxSigned = Transaction.signTransaction(
|
const createTxSigned = Transaction.signTransaction(
|
||||||
createTx,
|
createTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
alice.privateKey
|
carol.privateKey
|
||||||
)
|
)
|
||||||
|
|
||||||
// We spent output 1 (of 0, 1, 2)
|
// We spent output 1 (of 0, 1, 2)
|
||||||
const transferTx = Transaction.makeTransferTransaction(
|
const transferTx = Transaction.makeTransferTransaction(
|
||||||
createTxSigned,
|
createTxSigned,
|
||||||
metaData,
|
metaData,
|
||||||
[bobOutput],
|
[trentOutput],
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
const transferTxSigned = Transaction.signTransaction(
|
const transferTxSigned = Transaction.signTransaction(
|
||||||
transferTx,
|
transferTx,
|
||||||
alice.privateKey,
|
carol.privateKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
function byTransactionId(transactionId, ...outputIndices) {
|
|
||||||
return value => transactionId === value.transaction_id &&
|
|
||||||
outputIndices.includes(value.output)
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn.postTransaction(createTxSigned)
|
return conn.postTransaction(createTxSigned)
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
.then(() => conn.postTransaction(transferTxSigned))
|
.then(() => conn.postTransaction(transferTxSigned))
|
||||||
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
.then(({ id }) => conn.pollStatusAndFetchTransaction(id))
|
||||||
// now listOutputs should only return us output 1 (0 and 2 are unspent)
|
// now listOutputs should only return us output 1 (0 and 2 are unspent)
|
||||||
.then(() => conn.listOutputs(alice.publicKey, true))
|
.then(() => conn.listOutputs(carol.publicKey, true))
|
||||||
.then(outputs => outputs.filter(byTransactionId(createTxSigned.id, 1)))
|
|
||||||
.then(outputs => t.truthy(outputs.length === 1))
|
.then(outputs => t.truthy(outputs.length === 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user