mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
feat(tests): Updated tests for getTokenData() in bch-api
This commit is contained in:
@@ -29,6 +29,61 @@ const tokenStats = {
|
||||
]
|
||||
}
|
||||
}
|
||||
// txData generated by MDA
|
||||
const txDataByMDA = {
|
||||
txData: {
|
||||
txid: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
||||
hash: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
||||
version: 2,
|
||||
size: 339,
|
||||
locktime: 0,
|
||||
vin: [
|
||||
{
|
||||
txid: '8370db30d94761ab9a11b71ecd22541151bf6125c8c613f0f6fab8ab794565a7',
|
||||
vout: 0,
|
||||
scriptSig: {
|
||||
asm: '304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4[ALL|FORKID] 02791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851',
|
||||
hex: '47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851'
|
||||
},
|
||||
sequence: 4294967295,
|
||||
address: 'bitcoincash:qrg77j4jf2pl7azgvzrz2z567ls464gkuuhplt30dp',
|
||||
value: 0.00051303,
|
||||
tokenQty: 0,
|
||||
tokenQtyStr: '0',
|
||||
tokenId: null
|
||||
}
|
||||
],
|
||||
vout: [
|
||||
{
|
||||
value: 0,
|
||||
n: 0,
|
||||
scriptPubKey: {
|
||||
asm: 'OP_RETURN 5262419 1 47454e45534953 54524f5554 54726f75742773207465737420746f6b656e 74726f757473626c6f672e636f6d 0 2 2 000000174876e800',
|
||||
hex: '6a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e800',
|
||||
type: 'nulldata'
|
||||
},
|
||||
tokenQtyStr: '0',
|
||||
tokenQty: 0
|
||||
}
|
||||
],
|
||||
hex: '0200000001a7654579abb8faf6f013c6c82561bf51115422cd1eb7119aab6147d930db7083000000006a47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851ffffffff040000000000000000476a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e80022020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088ac22020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088accec20000000000001976a9145904159f2f69bfa63eefa712633a0d96dc2e7e8888ac00000000',
|
||||
blockhash: '0000000000000000009f65225a3e12e23a7ea057c869047e0f36563a1f410267',
|
||||
confirmations: 97398,
|
||||
time: 1581773131,
|
||||
blocktime: 1581773131,
|
||||
blockheight: 622414,
|
||||
isSlpTx: true,
|
||||
tokenTxType: 'GENESIS',
|
||||
tokenId: 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
||||
tokenType: 1,
|
||||
tokenTicker: 'TROUT',
|
||||
tokenName: "Trout's test token",
|
||||
tokenDecimals: 2,
|
||||
tokenUri: 'troutsblog.com',
|
||||
tokenDocHash: '',
|
||||
isValidSlp: true
|
||||
}
|
||||
}
|
||||
|
||||
const txData = {
|
||||
txData: {
|
||||
@@ -46,7 +101,7 @@ const txData = {
|
||||
hex: '47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851'
|
||||
},
|
||||
sequence: 4294967295,
|
||||
address: 'bitcoincash:qpvsg9vl9a5mlf37a7n3yce6pktdctn73qwgaqm3wq',
|
||||
address: 'bitcoincash:qrqy3kj7r822ps6628vwqq5k8hyjl6ey3y4eea2m4s',
|
||||
value: 0.00051303,
|
||||
tokenQty: 0,
|
||||
tokenQtyStr: '0',
|
||||
@@ -156,11 +211,12 @@ const mutableData = {
|
||||
}
|
||||
|
||||
const decodedOpReturn = JSON.stringify({
|
||||
mspAdddress: 'bitcoincash:qrg77j4jf2pl7azgvzrz2z567ls464gkuuhplt30dp',
|
||||
mda: 'bitcoincash:qrg77j4jf2pl7azgvzrz2z567ls464gkuuhplt30dp',
|
||||
cid: 'bafybeie6t5uyupddc7azms737xg4hxrj7i5t5ov3lb5g2qeehaujj6ak64'
|
||||
})
|
||||
module.exports = {
|
||||
tokenStats,
|
||||
txDataByMDA,
|
||||
txData,
|
||||
balance,
|
||||
status,
|
||||
|
||||
@@ -151,6 +151,34 @@ describe('#PsfSlpIndexer', () => {
|
||||
return this.skip()
|
||||
}
|
||||
|
||||
const result = await uut.getTokenStats(req, res)
|
||||
const tokenData = result.tokenData
|
||||
assert.property(tokenData, 'type')
|
||||
assert.property(tokenData, 'ticker')
|
||||
assert.property(tokenData, 'name')
|
||||
assert.property(tokenData, 'tokenId')
|
||||
assert.property(tokenData, 'documentUri')
|
||||
assert.property(tokenData, 'documentHash')
|
||||
assert.property(tokenData, 'decimals')
|
||||
assert.property(tokenData, 'mintBatonIsActive')
|
||||
assert.property(tokenData, 'tokensInCirculationBN')
|
||||
assert.property(tokenData, 'tokensInCirculationStr')
|
||||
assert.property(tokenData, 'blockCreated')
|
||||
assert.property(tokenData, 'totalBurned')
|
||||
assert.property(tokenData, 'totalMinted')
|
||||
assert.property(tokenData, 'txs')
|
||||
})
|
||||
it('should GET tokens stats with tx hisroty', async function () {
|
||||
req.body.tokenId =
|
||||
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
||||
req.body.withTxHistory = true
|
||||
// Mock the RPC call for unit tests.
|
||||
if (process.env.TEST === 'unit') {
|
||||
sandbox.stub(uut.axios, 'post').resolves({ data: mockData.tokenStats })
|
||||
} else {
|
||||
return this.skip()
|
||||
}
|
||||
|
||||
const result = await uut.getTokenStats(req, res)
|
||||
const tokenData = result.tokenData
|
||||
assert.property(tokenData, 'type')
|
||||
@@ -826,6 +854,25 @@ describe('#PsfSlpIndexer', () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
it('should skip mutable data if was not generated by the MDA private key', async () => {
|
||||
try {
|
||||
sandbox.stub(uut, 'decodeOpReturn').resolves(mockData.decodedOpReturn)
|
||||
|
||||
sandbox.stub(uut.bchjs.Electrumx, 'transactions').resolves(mockData.transactions)
|
||||
sandbox.stub(uut.bchjs.Transaction, 'get').resolves(mockData.txData)
|
||||
|
||||
const documentHash = 'c37ba29f40ecc61662ea56324fdb72a5f1e66add2078854c2144765b9030358a'
|
||||
|
||||
await uut.getMutableData(documentHash)
|
||||
assert.fail('unexpected code path')
|
||||
} catch (error) {
|
||||
assert.include(
|
||||
error.message,
|
||||
'CID could not be found in OP_RETURN data',
|
||||
'Error message expected'
|
||||
)
|
||||
}
|
||||
})
|
||||
it('should return mutable data', async () => {
|
||||
sandbox.stub(uut, 'decodeOpReturn')
|
||||
.onFirstCall().resolves(mockData.decodedOpReturn)
|
||||
@@ -833,6 +880,8 @@ describe('#PsfSlpIndexer', () => {
|
||||
.onThirdCall().resolves(mockData.decodedOpReturn)
|
||||
|
||||
sandbox.stub(uut.bchjs.Electrumx, 'transactions').resolves(mockData.transactions)
|
||||
sandbox.stub(uut.bchjs.Transaction, 'get').resolves(mockData.txDataByMDA)
|
||||
|
||||
sandbox.stub(uut, 'getCIDData').resolves(mockData.mutableData)
|
||||
|
||||
const documentHash = 'c37ba29f40ecc61662ea56324fdb72a5f1e66add2078854c2144765b9030358a'
|
||||
|
||||
Reference in New Issue
Block a user