Skip to content

Commit

Permalink
watcher: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jan 25, 2024
1 parent a6fcc2f commit 4f6a064
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 145 deletions.
23 changes: 10 additions & 13 deletions watcher/src/watchers/__tests__/AlgorandWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import { expect, jest, test } from '@jest/globals';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import { AlgorandWatcher } from '../AlgorandWatcher';

jest.setTimeout(180000);

const initialAlgorandBlock = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].algorand
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].algorand
);

test('getFinalizedBlockNumber', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(initialAlgorandBlock);
});

test('getMessagesForBlocks', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const 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(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(initialAlgorandBlock, initialAlgorandBlock);
expect(messages).toMatchObject({
'22931277/2022-08-19T15:10:48.000Z': [
Expand All @@ -34,13 +31,13 @@ test('getMessagesForBlocks initial block', async () => {
});

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

test('getMessagesForBlocks seq < 192', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(25428873, 25428873);
expect(messages).toMatchObject({
'25428873/2022-12-09T18:10:08.000Z': [
Expand All @@ -50,7 +47,7 @@ test('getMessagesForBlocks seq < 192', async () => {
});

test('getMessagesForBlocks seq = 192', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(25433218, 25433218);
expect(messages).toMatchObject({
'25433218/2022-12-09T22:40:55.000Z': [
Expand All @@ -60,7 +57,7 @@ test('getMessagesForBlocks seq = 192', async () => {
});

test('getMessagesForBlocks seq > 383', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(26856742, 26856742);
expect(messages).toMatchObject({
'26856742/2023-02-09T09:05:04.000Z': [
Expand All @@ -70,7 +67,7 @@ test('getMessagesForBlocks seq > 383', async () => {
});

test('getMessagesForBlocks on known empty block', async () => {
const watcher = new AlgorandWatcher(NETWORK.MAINNET);
const watcher = new AlgorandWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(23761195, 23761195);
expect(messages).toMatchObject({ '23761195/2022-09-28T21:42:30.000Z': [] });
});
11 changes: 4 additions & 7 deletions watcher/src/watchers/__tests__/AptosWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { expect, jest, test } from '@jest/globals';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common/dist/consts';
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common/dist/consts';
import { AptosWatcher } from '../AptosWatcher';

jest.setTimeout(60000);

const INITAL_SEQUENCE_NUMBER = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].aptos ?? 0
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].aptos ?? 0
);

test('getFinalizedSequenceNumber', async () => {
const watcher = new AptosWatcher(NETWORK.MAINNET);
const watcher = new AptosWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(INITAL_SEQUENCE_NUMBER);
});

test('getMessagesForSequenceNumbers', async () => {
const watcher = new AptosWatcher(NETWORK.MAINNET);
const watcher = new AptosWatcher('mainnet');
const messages = await watcher.getMessagesForBlocks(0, 1);
expect(messages).toMatchObject({
'1095891/2022-10-19T00:55:54.676Z/0': [
Expand Down
15 changes: 5 additions & 10 deletions watcher/src/watchers/__tests__/ArbitrumWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { expect, jest, test } from '@jest/globals';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import { ArbitrumWatcher } from '../ArbitrumWatcher';

jest.setTimeout(60000);

const initialArbitrumBlock = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].arbitrum
);
const initialEthBlock = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].ethereum
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].arbitrum
);
const initialEthBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].ethereum);

test('getFinalizedBlockNumber', async () => {
const watcher = new ArbitrumWatcher(NETWORK.MAINNET);
const watcher = new ArbitrumWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
// The blockNumber is 0 because the most recent L2 block isn't in
// a finalized L1 block, yet. It's in an L1 block. That L1 block
Expand All @@ -28,7 +23,7 @@ test('getFinalizedBlockNumber', async () => {
});

test('getMessagesForBlocks', async () => {
const watcher = new ArbitrumWatcher(NETWORK.MAINNET);
const watcher = new ArbitrumWatcher('mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(114500582, 114500584);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(3);
Expand Down
15 changes: 5 additions & 10 deletions watcher/src/watchers/__tests__/BaseWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { expect, jest, test } from '@jest/globals';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import { EVMWatcher } from '../EVMWatcher';
import { NEAR_ARCHIVE_RPC } from '../../utils/near';

jest.setTimeout(60000);

const initialBaseBlock = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].base
);
const initialBaseBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].base);

test('getFinalizedBlockNumber', async () => {
const watcher = new EVMWatcher(NETWORK.MAINNET, 'base');
const watcher = new EVMWatcher('mainnet', 'base');
const blockNumber = await watcher.getFinalizedBlockNumber();
console.log('blockNumber', blockNumber);
expect(blockNumber).toBeGreaterThan(initialBaseBlock);
});

test('getMessagesForBlocks', async () => {
const watcher = new EVMWatcher(NETWORK.MAINNET, 'base');
const watcher = new EVMWatcher('mainnet', 'base');
const vaasByBlock = await watcher.getMessagesForBlocks(1544175, 1544185);
expect(vaasByBlock).toMatchObject({
'1544175/2023-07-20T18:28:17.000Z': [],
Expand All @@ -38,7 +33,7 @@ test('getMessagesForBlocks', async () => {
});

test('getMessagesForBlockWithWHMsg', async () => {
const watcher = new EVMWatcher(NETWORK.MAINNET, 'base');
const watcher = new EVMWatcher('mainnet', 'base');
const vaasByBlock = await watcher.getMessagesForBlocks(1557420, 1557429);
expect(vaasByBlock).toMatchObject({
'1557420/2023-07-21T01:49:47.000Z': [],
Expand Down
43 changes: 20 additions & 23 deletions watcher/src/watchers/__tests__/CosmwasmWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ import { TerraExplorerWatcher } from '../TerraExplorerWatcher';
import { InjectiveExplorerWatcher } from '../InjectiveExplorerWatcher';
import { SeiExplorerWatcher } from '../SeiExplorerWatcher';
import { WormchainWatcher } from '../WormchainWatcher';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import { isBase64Encoded } from '../../utils/isBase64Encoded';

jest.setTimeout(60000);

test('getFinalizedBlockNumber(terra2)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'terra2');
const watcher = new CosmwasmWatcher('mainnet', 'terra2');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(3181746);
});

test('getMessagesForBlocks(terra2)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'terra2');
const watcher = new CosmwasmWatcher('mainnet', 'terra2');
const vaasByBlock = await watcher.getMessagesForBlocks(3165191, 3165192);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
Expand All @@ -34,7 +31,7 @@ test('getMessagesForBlocks(terra2)', async () => {
});

test('getMessagesForBlocks(terra2)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'terra2');
const watcher = new CosmwasmWatcher('mainnet', 'terra2');
const vaasByBlock = await watcher.getMessagesForBlocks(5635710, 5635712);
const entries = Object.entries(vaasByBlock);
console.log(entries);
Expand All @@ -48,14 +45,14 @@ test('getMessagesForBlocks(terra2)', async () => {
});

test.skip('getFinalizedBlockNumber(terra)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'terra');
const watcher = new CosmwasmWatcher('mainnet', 'terra');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(10980872);
});

// flaky rpc, skip
test.skip('getMessagesForBlocks(terra)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'terra');
const watcher = new CosmwasmWatcher('mainnet', 'terra');
const vaasByBlock = await watcher.getMessagesForBlocks(10974196, 10974197);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
Expand All @@ -70,14 +67,14 @@ test.skip('getMessagesForBlocks(terra)', async () => {
});

test('getFinalizedBlockNumber(terra explorer)', async () => {
const watcher = new TerraExplorerWatcher(NETWORK.MAINNET, 'terra');
const watcher = new TerraExplorerWatcher('mainnet', 'terra');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(10980872);
});

// flaky rpc, skip
test('getMessagesForBlocks(terra explorer)', async () => {
const watcher = new TerraExplorerWatcher(NETWORK.MAINNET, 'terra');
const watcher = new TerraExplorerWatcher('mainnet', 'terra');
const vaasByBlock = await watcher.getMessagesForBlocks(14506733, 14506740);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
Expand All @@ -93,7 +90,7 @@ test('getMessagesForBlocks(terra explorer)', async () => {

// flaky rpc, skip
test.skip('getMessagesForBlocks(terra explorer, no useful info)', async () => {
const watcher = new TerraExplorerWatcher(NETWORK.MAINNET, 'terra');
const watcher = new TerraExplorerWatcher('mainnet', 'terra');
const vaasByBlock = await watcher.getMessagesForBlocks(10975000, 10975010);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(1);
Expand All @@ -103,13 +100,13 @@ test.skip('getMessagesForBlocks(terra explorer, no useful info)', async () => {
});

test('getFinalizedBlockNumber(xpla)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'xpla');
const watcher = new CosmwasmWatcher('mainnet', 'xpla');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(1980633);
});

test('getMessagesForBlocks(xpla)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'xpla');
const watcher = new CosmwasmWatcher('mainnet', 'xpla');
const vaasByBlock = await watcher.getMessagesForBlocks(1645812, 1645813);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(2);
Expand All @@ -124,13 +121,13 @@ test('getMessagesForBlocks(xpla)', async () => {
});

test('getFinalizedBlockNumber(injective)', async () => {
const watcher = new InjectiveExplorerWatcher(NETWORK.MAINNET);
const watcher = new InjectiveExplorerWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
expect(blockNumber).toBeGreaterThan(23333696);
});

test('getMessagesForBlocks(injective)', async () => {
const watcher = new InjectiveExplorerWatcher(NETWORK.MAINNET);
const watcher = new InjectiveExplorerWatcher('mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(56405501, 56405502);
// const vaasByBlock = await watcher.getMessagesForBlocks(4209642, 4209643); // Testnet
const entries = Object.entries(vaasByBlock);
Expand All @@ -147,15 +144,15 @@ test('getMessagesForBlocks(injective)', async () => {

// skipped because the SeiExplorerWatcher is used
test.skip('getFinalizedBlockNumber(sei)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'sei');
const watcher = new CosmwasmWatcher('mainnet', 'sei');
const blockNumber = await watcher.getFinalizedBlockNumber();
console.log(blockNumber);
expect(blockNumber).toBeGreaterThan(0);
});

// skipped because the SeiExplorerWatcher is used
test.skip('getMessagesForBlocks(sei)', async () => {
const watcher = new CosmwasmWatcher(NETWORK.MAINNET, 'sei');
const watcher = new CosmwasmWatcher('mainnet', 'sei');
const vaasByBlock = await watcher.getMessagesForBlocks(18907686, 18907687);
const entries = Object.entries(vaasByBlock);
console.log(entries);
Expand All @@ -172,15 +169,15 @@ test.skip('getMessagesForBlocks(sei)', async () => {
});

test('getFinalizedBlockNumber(sei explorer)', async () => {
const watcher = new SeiExplorerWatcher(NETWORK.MAINNET);
const watcher = new SeiExplorerWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
console.log(blockNumber);
expect(blockNumber).toBeGreaterThan(0);
});

// skipped because it takes more and more time to paginate back
test.skip('getMessagesForBlocks(sei explorer)', async () => {
const watcher = new SeiExplorerWatcher(NETWORK.MAINNET);
const watcher = new SeiExplorerWatcher('mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(19061244, 19061245);
const entries = Object.entries(vaasByBlock);
console.log(entries);
Expand All @@ -196,16 +193,16 @@ test.skip('getMessagesForBlocks(sei explorer)', async () => {
});

test('getFinalizedBlockNumber(wormchain)', async () => {
const watcher = new WormchainWatcher(NETWORK.MAINNET);
const watcher = new WormchainWatcher('mainnet');
const blockNumber = await watcher.getFinalizedBlockNumber();
console.log(blockNumber);
expect(blockNumber).toBeGreaterThan(
Number(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].wormchain)
Number(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN['mainnet'].wormchain)
);
});

test('getMessagesForBlocks(wormchain)', async () => {
const watcher = new WormchainWatcher(NETWORK.MAINNET);
const watcher = new WormchainWatcher('mainnet');
const vaasByBlock = await watcher.getMessagesForBlocks(4510119, 4510119);
const entries = Object.entries(vaasByBlock);
console.log(entries);
Expand Down
Loading

0 comments on commit 4f6a064

Please sign in to comment.