Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/chronik.test.js
Show All 35 Lines | import { | ||||
mockSortedFlatTxHistoryWithUnconfirmed, | mockSortedFlatTxHistoryWithUnconfirmed, | ||||
mockFlatTxHistoryWithAllUnconfirmed, | mockFlatTxHistoryWithAllUnconfirmed, | ||||
mockSortedFlatTxHistoryWithAllUnconfirmed, | mockSortedFlatTxHistoryWithAllUnconfirmed, | ||||
mockParseTxWallet, | mockParseTxWallet, | ||||
lambdaIncomingXecTx, | lambdaIncomingXecTx, | ||||
lambdaOutgoingXecTx, | lambdaOutgoingXecTx, | ||||
lambdaIncomingEtokenTx, | lambdaIncomingEtokenTx, | ||||
lambdaOutgoingEtokenTx, | lambdaOutgoingEtokenTx, | ||||
eTokenGenesisTx, | |||||
anotherMockParseTxWallet, | |||||
} from '../__mocks__/chronikTxHistory'; | } from '../__mocks__/chronikTxHistory'; | ||||
import { ChronikClient } from 'chronik-client'; | import { ChronikClient } from 'chronik-client'; | ||||
import { when } from 'jest-when'; | import { when } from 'jest-when'; | ||||
import BCHJS from '@psf/bch-js'; | import BCHJS from '@psf/bch-js'; | ||||
it(`getTokenStats successfully returns a token stats object`, async () => { | it(`getTokenStats successfully returns a token stats object`, async () => { | ||||
// Initialize chronik | // Initialize chronik | ||||
const chronik = new ChronikClient( | const chronik = new ChronikClient( | ||||
▲ Show 20 Lines • Show All 293 Lines • ▼ Show 20 Lines | ).toStrictEqual({ | ||||
isEncryptedMessage: false, | isEncryptedMessage: false, | ||||
opReturnMessage: '', | opReturnMessage: '', | ||||
outgoingTx: true, | outgoingTx: true, | ||||
replyAddress: 'ecash:qpmytrdsakt0axrrlswvaj069nat3p9s7cjctmjasj', | replyAddress: 'ecash:qpmytrdsakt0axrrlswvaj069nat3p9s7cjctmjasj', | ||||
tokenTx: true, | tokenTx: true, | ||||
}, | }, | ||||
}); | }); | ||||
}); | }); | ||||
it(`Successfully parses a genesis eToken tx`, () => { | |||||
const BCH = new BCHJS({ | |||||
restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', | |||||
}); | |||||
// This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment | |||||
BCH.Address.hash160ToCash = jest | |||||
.fn() | |||||
.mockReturnValue( | |||||
'bitcoincash:qz2708636snqhsxu8wnlka78h6fdp77ar5ulhz04hr', | |||||
); | |||||
expect( | |||||
parseChronikTx(BCH, eTokenGenesisTx, anotherMockParseTxWallet), | |||||
).toStrictEqual({ | |||||
incoming: false, | |||||
xecAmount: '0', | |||||
originatingHash160: '95e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d', | |||||
isEtokenTx: true, | |||||
etokenAmount: '7777777777', | |||||
slpMeta: { | |||||
tokenType: 'FUNGIBLE', | |||||
txType: 'GENESIS', | |||||
tokenId: | |||||
'cf601c56b58bc05a39a95374a4a865f0a8b56544ea937b30fb46315441717c50', | |||||
}, | |||||
legacy: { | |||||
amountSent: '0', | |||||
amountReceived: 0, | |||||
outgoingTx: true, | |||||
tokenTx: true, | |||||
airdropFlag: false, | |||||
airdropTokenId: '', | |||||
opReturnMessage: '', | |||||
isCashtabMessage: false, | |||||
isEncryptedMessage: false, | |||||
decryptionSuccess: false, | |||||
replyAddress: 'ecash:qz2708636snqhsxu8wnlka78h6fdp77ar59jrf5035', | |||||
}, | |||||
}); | |||||
}); |