Skip to content

Commit

Permalink
watcher: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Nov 21, 2024
1 parent 1420b01 commit 49b2c2a
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 44 deletions.
20 changes: 13 additions & 7 deletions watcher/src/watchers/__tests__/AlgorandWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(25692450, 25692450);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(25692450, 25692450);
expect(messages).toMatchObject({ '25692450/2022-12-21T02:00:40.000Z': [] });
});

test('getMessagesForBlocks initial block', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(initialAlgorandBlock, initialAlgorandBlock);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(
initialAlgorandBlock,
initialAlgorandBlock
);
expect(messages).toMatchObject({
'22931277/2022-08-19T15:10:48.000Z': [
'2RBQLCETCLFV4F3PQ7IHEWVWQV3MCP4UM5S5OFZM23XMC2O2DJ6A:8/67e93fa6c8ac5c819990aa7340c0c16b508abb1178be9b30d024b8ac25193d45/1',
Expand All @@ -32,13 +35,16 @@ test('getMessagesForBlocks initial block', async () => {

test('getMessagesForBlocks indexer pagination support', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(initialAlgorandBlock, 27069946);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(
initialAlgorandBlock,
27069946
);
expect(Object.keys(messages).length).toEqual(420);
});

test('getMessagesForBlocks seq < 192', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(25428873, 25428873);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(25428873, 25428873);
expect(messages).toMatchObject({
'25428873/2022-12-09T18:10:08.000Z': [
'M6QPEZ42P5O23II7SCWZTNZ7MHBSOH6KUNAPMH5YL3XHGNTEFUSQ:8/67e93fa6c8ac5c819990aa7340c0c16b508abb1178be9b30d024b8ac25193d45/191',
Expand All @@ -48,7 +54,7 @@ test('getMessagesForBlocks seq < 192', async () => {

test('getMessagesForBlocks seq = 192', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(25433218, 25433218);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(25433218, 25433218);
expect(messages).toMatchObject({
'25433218/2022-12-09T22:40:55.000Z': [
'3PJPDBGTQK6JXAQEJNOYFE4NLLKFMCTKRY5FYNAXSEBDO25XUUJQ:8/67e93fa6c8ac5c819990aa7340c0c16b508abb1178be9b30d024b8ac25193d45/192',
Expand All @@ -58,7 +64,7 @@ test('getMessagesForBlocks seq = 192', async () => {

test('getMessagesForBlocks seq > 383', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(26856742, 26856742);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(26856742, 26856742);
expect(messages).toMatchObject({
'26856742/2023-02-09T09:05:04.000Z': [
'LJNYXPG5VLJNNTBLSZSHLZQ7XQWTSUPKGA7APVI53J3MAKHQN72Q:8/67e93fa6c8ac5c819990aa7340c0c16b508abb1178be9b30d024b8ac25193d45/384',
Expand All @@ -68,6 +74,6 @@ test('getMessagesForBlocks seq > 383', async () => {

test('getMessagesForBlocks on known empty block', async () => {
const watcher = new AlgorandWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(23761195, 23761195);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(23761195, 23761195);
expect(messages).toMatchObject({ '23761195/2022-09-28T21:42:30.000Z': [] });
});
13 changes: 6 additions & 7 deletions watcher/src/watchers/__tests__/AptosWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('getFinalizedSequenceNumber', async () => {

test('getMessagesForSequenceNumbers', async () => {
const watcher = new AptosWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(0, 1);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(0, 1);
expect(messages).toMatchObject({
'1095891/2022-10-19T00:55:54.676Z/0': [
'0x27b5808a7cfdb688e02be192ed334da683975b7487e8be7a09670b3088b58908:22/0000000000000000000000000000000000000000000000000000000000000001/0',
Expand All @@ -32,12 +32,11 @@ test('getMessagesForSequenceNumbers', async () => {

// test that block number, timestamp, and sequence number are all strictly increasing
const latestSequenceNumber = await watcher.getFinalizedBlockNumber();
const messageKeys = Object.keys(
await watcher.getMessagesForBlocks(
latestSequenceNumber - watcher.maximumBatchSize + 1,
latestSequenceNumber
)
).sort();
const { vaasByBlock } = await watcher.getMessagesForBlocks(
latestSequenceNumber - watcher.maximumBatchSize + 1,
latestSequenceNumber
);
const messageKeys = Object.keys(vaasByBlock).sort();
console.log(messageKeys);
expect(messageKeys.length).toBe(watcher.maximumBatchSize);
expect(Date.parse(messageKeys.at(-1)!.split('/')[1])).toBeLessThan(Date.now());
Expand Down
2 changes: 1 addition & 1 deletion watcher/src/watchers/__tests__/ArbitrumWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks', async () => {
const watcher = new ArbitrumWatcher('Mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(114500582, 114500584);
const { vaasByBlock } = await watcher.getMessagesForBlocks(114500582, 114500584);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(3);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(2);
Expand Down
4 changes: 2 additions & 2 deletions watcher/src/watchers/__tests__/BaseWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks', async () => {
const watcher = new EVMWatcher('Mainnet', 'Base');
const vaasByBlock = await watcher.getMessagesForBlocks(1544175, 1544185);
const { vaasByBlock } = await watcher.getMessagesForBlocks(1544175, 1544185);
expect(vaasByBlock).toMatchObject({
'1544175/2023-07-20T18:28:17.000Z': [],
'1544176/2023-07-20T18:28:19.000Z': [],
Expand All @@ -32,7 +32,7 @@ test('getMessagesForBlocks', async () => {

test('getMessagesForBlockWithWHMsg', async () => {
const watcher = new EVMWatcher('Mainnet', 'Base');
const vaasByBlock = await watcher.getMessagesForBlocks(1557420, 1557429);
const { vaasByBlock } = await watcher.getMessagesForBlocks(1557420, 1557429);
expect(vaasByBlock).toMatchObject({
'1557420/2023-07-21T01:49:47.000Z': [],
'1557421/2023-07-21T01:49:49.000Z': [],
Expand Down
16 changes: 8 additions & 8 deletions watcher/src/watchers/__tests__/CosmwasmWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.skip('getFinalizedBlockNumber(terra2)', async () => {

test.skip('getMessagesForBlocks(terra2)', async () => {
const watcher = new TerraExplorerWatcher('Mainnet', 'Terra2');
const vaasByBlock = await watcher.getMessagesForBlocks(10847656, 10847657);
const { vaasByBlock } = await watcher.getMessagesForBlocks(10847656, 10847657);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(1);
Expand All @@ -38,7 +38,7 @@ test('getFinalizedBlockNumber(terra explorer)', async () => {

test('getMessagesForBlocks(terra explorer)', async () => {
const watcher = new TerraExplorerWatcher('Mainnet', 'Terra');
const vaasByBlock = await watcher.getMessagesForBlocks(14506733, 14506740);
const { vaasByBlock } = await watcher.getMessagesForBlocks(14506733, 14506740);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(1);
Expand All @@ -54,7 +54,7 @@ test('getMessagesForBlocks(terra explorer)', async () => {
// flaky rpc, skip
test.skip('getMessagesForBlocks(terra explorer, no useful info)', async () => {
const watcher = new TerraExplorerWatcher('Mainnet', 'Terra');
const vaasByBlock = await watcher.getMessagesForBlocks(10975000, 10975010);
const { vaasByBlock } = await watcher.getMessagesForBlocks(10975000, 10975010);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(1);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(1);
Expand All @@ -70,7 +70,7 @@ test('getFinalizedBlockNumber(xpla)', async () => {

test('getMessagesForBlocks(xpla)', async () => {
const watcher = new CosmwasmWatcher('Mainnet', 'Xpla');
const vaasByBlock = await watcher.getMessagesForBlocks(1645812, 1645813);
const { vaasByBlock } = await watcher.getMessagesForBlocks(1645812, 1645813);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(1);
Expand All @@ -91,7 +91,7 @@ test('getFinalizedBlockNumber(injective)', async () => {

test.skip('getMessagesForBlocks(injective)', async () => {
const watcher = new InjectiveExplorerWatcher('Mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(61720293, 61720294);
const { vaasByBlock } = await watcher.getMessagesForBlocks(61720293, 61720294);
const entries = Object.entries(vaasByBlock);
// console.log(entries); // Leave this in for future debugging
expect(entries.length).toEqual(2);
Expand All @@ -115,7 +115,7 @@ test.skip('getFinalizedBlockNumber(sei)', async () => {
// skipped because the SeiExplorerWatcher is used
test.skip('getMessagesForBlocks(sei)', async () => {
const watcher = new CosmwasmWatcher('Mainnet', 'Sei');
const vaasByBlock = await watcher.getMessagesForBlocks(18907686, 18907687);
const { vaasByBlock } = await watcher.getMessagesForBlocks(18907686, 18907687);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(1);
Expand All @@ -138,7 +138,7 @@ test('getFinalizedBlockNumber(sei explorer)', async () => {
// skipped because it takes more and more time to paginate back
test.skip('getMessagesForBlocks(sei explorer)', async () => {
const watcher = new SeiExplorerWatcher('Mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(19061244, 19061245);
const { vaasByBlock } = await watcher.getMessagesForBlocks(19061244, 19061245);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(1);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(0);
Expand All @@ -161,7 +161,7 @@ test('getFinalizedBlockNumber(wormchain)', async () => {

test('getMessagesForBlocks(wormchain)', async () => {
const watcher = new WormchainWatcher('Mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(8978585, 8978585);
const { vaasByBlock } = await watcher.getMessagesForBlocks(8978585, 8978585);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(1);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(0);
Expand Down
8 changes: 4 additions & 4 deletions watcher/src/watchers/__tests__/EVMWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks', async () => {
const watcher = new EVMWatcher('Mainnet', 'Avalanche');
const vaasByBlock = await watcher.getMessagesForBlocks(46997500, 46997599);
const { vaasByBlock } = await watcher.getMessagesForBlocks(46997500, 46997599);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(100);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(99);
Expand Down Expand Up @@ -111,7 +111,7 @@ test('getBlock by number (Celo compatibility)', async () => {

test('getMessagesForBlocks (Celo compatibility)', async () => {
const watcher = new EVMWatcher('Mainnet', 'Celo');
const vaasByBlock = await watcher.getMessagesForBlocks(13322450, 13322549);
const { vaasByBlock } = await watcher.getMessagesForBlocks(13322450, 13322549);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(100);
expect(entries.filter(([block, vaas]) => vaas.length === 0).length).toEqual(98);
Expand Down Expand Up @@ -142,7 +142,7 @@ test('getBlock by number (Karura compatibility)', async () => {

test('getMessagesForBlocks (Karura compatibility)', async () => {
const watcher = new EVMWatcher('Mainnet', 'Karura');
const vaasByBlock = await watcher.getMessagesForBlocks(4582511, 4582513);
const { vaasByBlock } = await watcher.getMessagesForBlocks(4582511, 4582513);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(3);
expect(entries[0][0]).toEqual('4582511/2023-06-19T15:54:48.000Z');
Expand All @@ -155,7 +155,7 @@ test('getMessagesForBlocks (Karura compatibility)', async () => {
test('getMessagesForBlocks (Karura compatibility 2)', async () => {
const watcher = new EVMWatcher('Mainnet', 'Karura');
await watcher.getFinalizedBlockNumber(); // This has the side effect of initializing the latestFinalizedBlockNumber
const vaasByBlock = await watcher.getMessagesForBlocks(4595356, 4595358);
const { vaasByBlock } = await watcher.getMessagesForBlocks(4595356, 4595358);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(3);
});
Expand Down
2 changes: 1 addition & 1 deletion watcher/src/watchers/__tests__/OptimismWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks', async () => {
const watcher = new EVMWatcher('Mainnet', 'Optimism');
const vaasByBlock = await watcher.getMessagesForBlocks(105235070, 105235080);
const { vaasByBlock } = await watcher.getMessagesForBlocks(105235070, 105235080);
expect(vaasByBlock).toMatchObject({
'105235070/2023-06-06T16:28:37.000Z': [],
'105235071/2023-06-06T16:28:39.000Z': [],
Expand Down
26 changes: 13 additions & 13 deletions watcher/src/watchers/__tests__/SolanaWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('getFinalizedBlockNumber', async () => {

test('getMessagesForBlocks - single block', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(170799004, 170799004);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(170799004, 170799004);
expect(Object.keys(messages).length).toBe(1);
expect(messages).toMatchObject({
'170799004/2023-01-04T16:43:43.000Z': [
Expand All @@ -32,21 +32,21 @@ test('getMessagesForBlocks - single block', async () => {
// temporary skip due to SolanaJSONRPCError: failed to get confirmed block: Block 171774030 cleaned up, does not exist on node. First available block: 176896202
test('getMessagesForBlocks - fromSlot is skipped slot', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(171774030, 171774032); // 171774024 - 171774031 are skipped
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(171774030, 171774032); // 171774024 - 171774031 are skipped
expect(Object.keys(messages).length).toBe(1);
expect(messages).toMatchObject({ '171774032/2023-01-10T13:36:39.000Z': [] });
});

test('getMessagesForBlocks - toSlot is skipped slot', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(171774023, 171774025);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(171774023, 171774025);
expect(messages).toMatchObject({ '171774025/2023-01-10T13:36:34.000Z': [] });
});

test('getMessagesForBlocks - empty block', async () => {
// Even if there are no messages, last block should still be returned
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(170979766, 170979766);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(170979766, 170979766);
expect(Object.keys(messages).length).toBe(1);
expect(messages).toMatchObject({ '170979766/2023-01-05T18:40:25.000Z': [] });
});
Expand All @@ -58,42 +58,42 @@ test('getMessagesForBlocks - block with no transactions', async () => {
'solana: invalid block range'
);

let messages = await watcher.getMessagesForBlocks(174108661, 174108861);
let { vaasByBlock: messages } = await watcher.getMessagesForBlocks(174108661, 174108861);
expect(Object.keys(messages).length).toBe(1);
expect(Object.values(messages).flat().length).toBe(0);

messages = await watcher.getMessagesForBlocks(174108863, 174109061);
({ vaasByBlock: messages } = await watcher.getMessagesForBlocks(174108863, 174109061));
expect(Object.keys(messages).length).toBe(1);
expect(Object.values(messages).flat().length).toBe(0);
});

test('getMessagesForBlocks - multiple blocks', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(171050470, 171050474);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(171050470, 171050474);
expect(Object.keys(messages).length).toBe(2);
expect(Object.values(messages).flat().length).toBe(2);
});

test('getMessagesForBlocks - multiple blocks, last block empty', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(170823000, 170825000);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(170823000, 170825000);
expect(Object.keys(messages).length).toBe(3);
expect(Object.values(messages).flat().length).toBe(2); // 2 messages, last block has no message
});

test('getMessagesForBlocks - multiple blocks containing more than `getSignaturesLimit` WH transactions', async () => {
const watcher = new SolanaWatcher('Mainnet');
watcher.getSignaturesLimit = 10;
const messages = await watcher.getMessagesForBlocks(171582367, 171583452);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(171582367, 171583452);
expect(Object.keys(messages).length).toBe(3);
expect(Object.values(messages).flat().length).toBe(3);
});

test('getMessagesForBlocks - multiple calls', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages1 = await watcher.getMessagesForBlocks(171773021, 171773211);
const messages2 = await watcher.getMessagesForBlocks(171773212, 171773250);
const messages3 = await watcher.getMessagesForBlocks(171773251, 171773500);
const { vaasByBlock: messages1 } = await watcher.getMessagesForBlocks(171773021, 171773211);
const { vaasByBlock: messages2 } = await watcher.getMessagesForBlocks(171773212, 171773250);
const { vaasByBlock: messages3 } = await watcher.getMessagesForBlocks(171773251, 171773500);
const allMessageKeys = [
...Object.keys(messages1),
...Object.keys(messages2),
Expand All @@ -105,7 +105,7 @@ test('getMessagesForBlocks - multiple calls', async () => {

test('getMessagesForBlocks - handle failed transactions', async () => {
const watcher = new SolanaWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(94401321, 94501321);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(94401321, 94501321);
expect(Object.keys(messages).length).toBe(6);
expect(Object.values(messages).flat().length).toBe(5);
expect(
Expand Down
2 changes: 1 addition & 1 deletion watcher/src/watchers/__tests__/SuiWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('getFinalizedSequenceNumber', async () => {
// works backwards. This will cause a 429 until we clear that up.
test.skip('getMessagesForBlocks', async () => {
const watcher = new SuiWatcher('Mainnet');
const messages = await watcher.getMessagesForBlocks(1581997, 1581997);
const { vaasByBlock: messages } = await watcher.getMessagesForBlocks(1581997, 1581997);
console.log(messages);
const entries = Object.entries(messages);
expect(entries.length).toEqual(46);
Expand Down
Loading

0 comments on commit 49b2c2a

Please sign in to comment.