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

Test list transaction for an asset id

This commit is contained in:
tim 2017-06-21 11:01:28 +02:00
parent 3671c5758c
commit 1696f7c1ac
3 changed files with 46 additions and 5 deletions

View File

@ -98,14 +98,13 @@ export default class Connection {
/** /**
* @public * @public
* @param asset_id * @param assetId
* @param operation * @param operation
*/ */
// TODO: Use camel case for parameters listTransactions(assetId, operation) {
listTransactions({ asset_id, operation }) {
return this._req(this.getApiUrls('transactions'), { return this._req(this.getApiUrls('transactions'), {
query: { query: {
asset_id, asset_id: assetId,
operation operation
} }
}) })

View File

@ -59,7 +59,7 @@ test('Get block for a block id', t => {
}) })
test('Get status for a transaction', t => { test('Get status for a transaction id', t => {
const expectedPath = 'path' const expectedPath = 'path'
const transactionId = 'abc' const transactionId = 'abc'
@ -110,6 +110,27 @@ test('Get list of blocks for a transaction id', t => {
}) })
test('Get list of transactions for an asset id', t => {
const expectedPath = 'path'
const assetId = 'abc'
const operation = 'operation'
conn._req = sinon.spy()
conn.getApiUrls = sinon.stub().returns(expectedPath)
conn.listTransactions(assetId, operation)
t.truthy(conn._req.calledWith(
expectedPath,
{
query: {
asset_id: assetId,
operation
}
}
))
})
test('Get outputs for a public key and no spent flag', t => { test('Get outputs for a public key and no spent flag', t => {
const expectedPath = 'path' const expectedPath = 'path'
const publicKey = 'publicKey' const publicKey = 'publicKey'

View File

@ -294,3 +294,24 @@ test('Search blocks containing a transaction', t => {
)) ))
.then(transactions => t.truthy(transactions.length === 1)) .then(transactions => t.truthy(transactions.length === 1))
}) })
test('Search transaction containing an asset', t => {
const conn = new Connection(API_PATH)
const createTx = Transaction.makeCreateTransaction(
asset(),
metaData,
[aliceOutput],
alice.publicKey
)
const createTxSigned = Transaction.signTransaction(
createTx,
alice.privateKey
)
return conn.postTransaction(createTxSigned)
.then(({ id }) => conn.pollStatusAndFetchTransaction(id, 'CREATE'))
.then(({ id }) => conn.listTransactions(id))
.then(transactions => t.truthy(transactions.length === 1))
})