Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/chronik.test.js
Show First 20 Lines • Show All 778 Lines • ▼ Show 20 Lines | it(`Correctly parses an incoming eToken tx that send only XEC to the Cashtab user recipient`, () => { | ||||
}); | }); | ||||
}); | }); | ||||
it(`getMintAddress successfully parses chronik.tx response to determine mint address for TabCash token`, async () => { | it(`getMintAddress successfully parses chronik.tx response to determine mint address for TabCash token`, async () => { | ||||
// Initialize chronik | // Initialize chronik | ||||
const chronik = new ChronikClient( | const chronik = new ChronikClient( | ||||
'https://FakeChronikUrlToEnsureMocksOnly.com', | 'https://FakeChronikUrlToEnsureMocksOnly.com', | ||||
); | ); | ||||
const BCH = new BCHJS({ | |||||
restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', | |||||
}); | |||||
/* | /* | ||||
Mock the API response from chronik.tx('tokenId') called | Mock the API response from chronik.tx('tokenId') called | ||||
in returnGetTokenInfoChronikPromise -- for each tokenId used | in returnGetTokenInfoChronikPromise -- for each tokenId used | ||||
*/ | */ | ||||
chronik.tx = jest.fn(); | chronik.tx = jest.fn(); | ||||
when(chronik.tx) | when(chronik.tx) | ||||
.calledWith(mintingTxTabCash.txid) | .calledWith(mintingTxTabCash.txid) | ||||
.mockResolvedValue(mintingTxTabCash); | .mockResolvedValue(mintingTxTabCash); | ||||
// This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment | expect(await getMintAddress(chronik, mintingTxTabCash.txid)).toBe( | ||||
BCH.Address.hash160ToCash = jest | |||||
.fn() | |||||
.mockReturnValue(mintingAddressBchFormatTabCash); | |||||
expect(await getMintAddress(chronik, BCH, mintingTxTabCash.txid)).toBe( | |||||
mintingAddressTabCash, | mintingAddressTabCash, | ||||
); | ); | ||||
// spy on mintingHash160 | |||||
expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith( | |||||
mintingHash160TabCash, | |||||
); | |||||
}); | }); | ||||
it(`getMintAddress successfully parses chronik.tx response to determine mint address for PoW token`, async () => { | it(`getMintAddress successfully parses chronik.tx response to determine mint address for PoW token`, async () => { | ||||
// Initialize chronik | // Initialize chronik | ||||
const chronik = new ChronikClient( | const chronik = new ChronikClient( | ||||
'https://FakeChronikUrlToEnsureMocksOnly.com', | 'https://FakeChronikUrlToEnsureMocksOnly.com', | ||||
); | ); | ||||
const BCH = new BCHJS({ | |||||
restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', | |||||
}); | |||||
/* | /* | ||||
Mock the API response from chronik.tx('tokenId') called | Mock the API response from chronik.tx('tokenId') called | ||||
in returnGetTokenInfoChronikPromise -- for each tokenId used | in returnGetTokenInfoChronikPromise -- for each tokenId used | ||||
*/ | */ | ||||
chronik.tx = jest.fn(); | chronik.tx = jest.fn(); | ||||
when(chronik.tx) | when(chronik.tx) | ||||
.calledWith(mintingTxPoW.txid) | .calledWith(mintingTxPoW.txid) | ||||
.mockResolvedValue(mintingTxPoW); | .mockResolvedValue(mintingTxPoW); | ||||
// This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment | expect(await getMintAddress(chronik, mintingTxPoW.txid)).toBe( | ||||
BCH.Address.hash160ToCash = jest | |||||
.fn() | |||||
.mockReturnValue(mintingAddressBchFormatPoW); | |||||
expect(await getMintAddress(chronik, BCH, mintingTxPoW.txid)).toBe( | |||||
mintingAddressPoW, | mintingAddressPoW, | ||||
); | ); | ||||
// spy on mintingHash160 | |||||
expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith(mintingHash160PoW); | |||||
}); | }); | ||||
it(`getMintAddress successfully parses chronik.tx response to determine mint address for Alita token`, async () => { | it(`getMintAddress successfully parses chronik.tx response to determine mint address for Alita token`, async () => { | ||||
// Initialize chronik | // Initialize chronik | ||||
const chronik = new ChronikClient( | const chronik = new ChronikClient( | ||||
'https://FakeChronikUrlToEnsureMocksOnly.com', | 'https://FakeChronikUrlToEnsureMocksOnly.com', | ||||
); | ); | ||||
const BCH = new BCHJS({ | |||||
restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', | |||||
}); | |||||
/* | /* | ||||
Mock the API response from chronik.tx('tokenId') called | Mock the API response from chronik.tx('tokenId') called | ||||
in returnGetTokenInfoChronikPromise -- for each tokenId used | in returnGetTokenInfoChronikPromise -- for each tokenId used | ||||
*/ | */ | ||||
chronik.tx = jest.fn(); | chronik.tx = jest.fn(); | ||||
when(chronik.tx) | when(chronik.tx) | ||||
.calledWith(mintingTxAlita.txid) | .calledWith(mintingTxAlita.txid) | ||||
.mockResolvedValue(mintingTxAlita); | .mockResolvedValue(mintingTxAlita); | ||||
// This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment | expect(await getMintAddress(chronik, mintingTxAlita.txid)).toBe( | ||||
BCH.Address.hash160ToCash = jest | |||||
.fn() | |||||
.mockReturnValue(mintingAddressBchFormatAlita); | |||||
expect(await getMintAddress(chronik, BCH, mintingTxAlita.txid)).toBe( | |||||
mintingAddressAlita, | mintingAddressAlita, | ||||
); | ); | ||||
// spy on mintingHash160 | |||||
expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith(mintingHash160Alita); | |||||
}); | }); | ||||
it(`getMintAddress successfully parses chronik.tx response to determine mint address for a BUX self minted token`, async () => { | it(`getMintAddress successfully parses chronik.tx response to determine mint address for a BUX self minted token`, async () => { | ||||
// Initialize chronik | // Initialize chronik | ||||
const chronik = new ChronikClient( | const chronik = new ChronikClient( | ||||
'https://FakeChronikUrlToEnsureMocksOnly.com', | 'https://FakeChronikUrlToEnsureMocksOnly.com', | ||||
); | ); | ||||
const BCH = new BCHJS({ | |||||
restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', | |||||
}); | |||||
/* | /* | ||||
Mock the API response from chronik.tx('tokenId') called | Mock the API response from chronik.tx('tokenId') called | ||||
in returnGetTokenInfoChronikPromise -- for each tokenId used | in returnGetTokenInfoChronikPromise -- for each tokenId used | ||||
*/ | */ | ||||
chronik.tx = jest.fn(); | chronik.tx = jest.fn(); | ||||
when(chronik.tx) | when(chronik.tx) | ||||
.calledWith(mintingTxBuxSelfMint.txid) | .calledWith(mintingTxBuxSelfMint.txid) | ||||
.mockResolvedValue(mintingTxBuxSelfMint); | .mockResolvedValue(mintingTxBuxSelfMint); | ||||
// This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment | expect(await getMintAddress(chronik, mintingTxBuxSelfMint.txid)).toBe( | ||||
BCH.Address.hash160ToCash = jest | |||||
.fn() | |||||
.mockReturnValue(mintingAddressBchFormatBuxSelfMint); | |||||
expect(await getMintAddress(chronik, BCH, mintingTxBuxSelfMint.txid)).toBe( | |||||
mintingAddressBuxSelfMint, | mintingAddressBuxSelfMint, | ||||
); | ); | ||||
// spy on mintingHash160 | |||||
expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith( | |||||
mintingHash160BuxSelfMint, | |||||
); | |||||
}); | }); |