mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
Replacing previous versions of transactions() with new version
This commit is contained in:
@@ -250,8 +250,10 @@ class BchAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
async getTransactions (address) {
|
||||
async getTransactions (address, sortOrder = 'DESCENDING', page = 0) {
|
||||
try {
|
||||
console.log('Executing getTransaction() bch adapter')
|
||||
|
||||
// Throw an error if this IPFS node has not yet made a connection to a
|
||||
// wallet service provider.
|
||||
const selectedProvider =
|
||||
@@ -262,7 +264,9 @@ class BchAdapter {
|
||||
|
||||
const rpcData = {
|
||||
endpoint: 'transactions',
|
||||
addresses: [address]
|
||||
address: address,
|
||||
sortOrder,
|
||||
page
|
||||
}
|
||||
|
||||
// Generate a UUID for the call.
|
||||
@@ -271,7 +275,7 @@ class BchAdapter {
|
||||
// Generate a JSON RPC command.
|
||||
const cmd = this.jsonrpc.request(rpcId, 'bch', rpcData)
|
||||
const cmdStr = JSON.stringify(cmd)
|
||||
// console.log('cmdStr: ', cmdStr)
|
||||
console.log('cmdStr: ', cmdStr)
|
||||
|
||||
// Send the RPC command to selected wallet service.
|
||||
const thisNode = this.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
|
||||
|
||||
@@ -319,9 +319,17 @@ class BchRESTControllerLib {
|
||||
*/
|
||||
async transactions (ctx) {
|
||||
try {
|
||||
const addr = ctx.request.body.address
|
||||
console.log('transactions REST API handler called.')
|
||||
|
||||
const data = await this.adapters.bch.getTransactions(addr)
|
||||
const addr = ctx.request.body.address
|
||||
const sortOrder = ctx.request.body.sortOrder
|
||||
const page = ctx.request.body.page
|
||||
|
||||
const data = await this.adapters.bch.getTransactions(
|
||||
addr,
|
||||
sortOrder,
|
||||
page
|
||||
)
|
||||
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
|
||||
ctx.body = data
|
||||
|
||||
@@ -86,6 +86,7 @@ class BchRouter {
|
||||
}
|
||||
|
||||
async postTransactions (ctx, next) {
|
||||
console.log('Calling _this.bchRESTController.transactions()')
|
||||
await _this.bchRESTController.transactions(ctx, next)
|
||||
}
|
||||
|
||||
|
||||
+134
-82
@@ -7,7 +7,7 @@
|
||||
This test will query each REST API endpoint and ensure they are working correctly.
|
||||
*/
|
||||
|
||||
const SERVER = 'http://localhost:5001'
|
||||
const SERVER = 'http://localhost:5005'
|
||||
|
||||
const axios = require('axios')
|
||||
const assert = require('chai').assert
|
||||
@@ -23,8 +23,8 @@ describe('#BCH E2E Tests', () => {
|
||||
const result = await axios.get(url)
|
||||
// console.log(`data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.isAbove(result.data.status.state.serviceProviders.length, 0)
|
||||
assert.isOk(result.data.status.state.selectedServiceProvider)
|
||||
assert.isAbove(result.data.status.serviceProviders.length, 0)
|
||||
assert.isOk(result.data.status.selectedProvider)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -46,104 +46,156 @@ describe('#BCH E2E Tests', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#utxos', () => {
|
||||
it('should get UTXOs for an address', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/utxos`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.address, body.address)
|
||||
assert.property(result.data, 'bchUtxos')
|
||||
assert.property(result.data, 'slpUtxos')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#broadcast', () => {
|
||||
it('should attempt to broadcast a transaction', async () => {
|
||||
const body = {
|
||||
hex: '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/broadcast`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.status, 422)
|
||||
assert.equal(result.data.success, false)
|
||||
assert.equal(result.data.message, 'TX decode failed')
|
||||
assert.equal(result.data.endpoint, 'broadcast')
|
||||
})
|
||||
})
|
||||
// describe('#utxos', () => {
|
||||
// it('should get UTXOs for an address', async () => {
|
||||
// const body = {
|
||||
// address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/utxos`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data[0].address, body.address)
|
||||
// assert.property(result.data[0], 'bchUtxos')
|
||||
// assert.property(result.data[0], 'slpUtxos')
|
||||
// })
|
||||
// })
|
||||
//
|
||||
// describe('#broadcast', () => {
|
||||
// it('should attempt to broadcast a transaction', async () => {
|
||||
// const body = {
|
||||
// hex: '01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/broadcast`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.status, 422)
|
||||
// assert.equal(result.data.success, false)
|
||||
// assert.equal(result.data.message, 'Missing inputs')
|
||||
// assert.equal(result.data.endpoint, 'broadcast')
|
||||
// })
|
||||
// })
|
||||
//
|
||||
// describe('#pubkey', () => {
|
||||
// it('should return "not found" if pubkey is not on chain', async () => {
|
||||
// const body = {
|
||||
// address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/pubkey`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.success, true)
|
||||
// assert.equal(result.data.status, 200)
|
||||
// assert.equal(result.data.endpoint, 'pubkey')
|
||||
// assert.equal(result.data.pubkey.success, false)
|
||||
// assert.equal(result.data.pubkey.publicKey, 'not found')
|
||||
// })
|
||||
//
|
||||
// it('should get a public key for an address', async () => {
|
||||
// const body = {
|
||||
// address: 'bitcoincash:qznxh6yegf7nfrsd0zeksed4jcqzvg7tzqlcqw3v97'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/pubkey`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.equal(result.data.success, true)
|
||||
// assert.equal(result.data.status, 200)
|
||||
// assert.equal(result.data.endpoint, 'pubkey')
|
||||
// assert.equal(result.data.pubkey.success, true)
|
||||
// assert.equal(
|
||||
// result.data.pubkey.publicKey,
|
||||
// '03ebd6d6aae05da1c5905445e3886b30f6a31b26a88de5980de236bd22380fa942'
|
||||
// )
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('#transactions', () => {
|
||||
it('should get transaction history for an address', async () => {
|
||||
it('should get transaction history for an address, and sort by default in descending order.', async () => {
|
||||
const address = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
|
||||
const body = {
|
||||
address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
address
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
// Assert expected values and properties.
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.success, true)
|
||||
assert.property(result.data, 'transactions')
|
||||
})
|
||||
})
|
||||
assert.equal(result.data.address, address)
|
||||
assert.isArray(result.data.txs)
|
||||
|
||||
// Assert expected sorting
|
||||
assert.isAbove(result.data.txs[0].height, result.data.txs[1].height)
|
||||
})
|
||||
|
||||
it('should sort in ascending order.', async () => {
|
||||
const address = 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
|
||||
|
||||
describe('#transaction', () => {
|
||||
it('should get transaction details for a txid', async () => {
|
||||
const body = {
|
||||
txid: '01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
|
||||
address,
|
||||
sortOrder: 'ASCENDING'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transaction`
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.property(result.data, 'txid')
|
||||
assert.property(result.data, 'vin')
|
||||
// Assert expected values and properties.
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.address, address)
|
||||
assert.isArray(result.data.txs)
|
||||
|
||||
// Assert expected sorting
|
||||
assert.isAbove(result.data.txs[1].height, result.data.txs[0].height)
|
||||
})
|
||||
|
||||
it('should paginate an address with deep tx history', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const result = await axios.post(url, body)
|
||||
console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
// Assert there is no more than 100 entries
|
||||
assert.isBelow(result.data.txs.length, 101)
|
||||
})
|
||||
|
||||
it('should get the second page of results', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d',
|
||||
page: 1
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/transactions`
|
||||
const result = await axios.post(url, body)
|
||||
console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#pubkey', () => {
|
||||
it('should return "not found" if pubkey is not on chain', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/pubkey`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.endpoint, 'pubkey')
|
||||
assert.equal(result.data.pubkey.success, false)
|
||||
assert.equal(result.data.pubkey.publicKey, 'not found')
|
||||
})
|
||||
|
||||
it('should get a public key for an address', async () => {
|
||||
const body = {
|
||||
address: 'bitcoincash:qznxh6yegf7nfrsd0zeksed4jcqzvg7tzqlcqw3v97'
|
||||
}
|
||||
|
||||
const url = `${SERVER}/bch/pubkey`
|
||||
const result = await axios.post(url, body)
|
||||
// console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
|
||||
assert.equal(result.data.success, true)
|
||||
assert.equal(result.data.status, 200)
|
||||
assert.equal(result.data.endpoint, 'pubkey')
|
||||
assert.equal(result.data.pubkey.success, true)
|
||||
assert.equal(
|
||||
result.data.pubkey.publicKey,
|
||||
'03ebd6d6aae05da1c5905445e3886b30f6a31b26a88de5980de236bd22380fa942'
|
||||
)
|
||||
})
|
||||
})
|
||||
// describe('#transaction', () => {
|
||||
// it('should get transaction details for a txid', async () => {
|
||||
// const body = {
|
||||
// txid: '01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b'
|
||||
// }
|
||||
//
|
||||
// const url = `${SERVER}/bch/transaction`
|
||||
// const result = await axios.post(url, body)
|
||||
// // console.log(`result.data: ${JSON.stringify(result.data, null, 2)}`)
|
||||
//
|
||||
// assert.property(result.data, 'txid')
|
||||
// assert.property(result.data, 'vin')
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user