Skip to content

Commit

Permalink
watcher: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jan 3, 2024
1 parent 769fc49 commit 70d1408
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 104 deletions.
17 changes: 10 additions & 7 deletions watcher/src/databases/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { CHAIN_ID_SOLANA } from '@certusone/wormhole-sdk/lib/cjs/utils/consts';
import { expect, test } from '@jest/globals';
import { INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { JsonDatabase } from '../JsonDatabase';
import { getResumeBlockByChain, initDb, makeBlockKey } from '../utils';

Expand All @@ -11,13 +14,13 @@ test('getResumeBlockByChain', async () => {
db.lastBlockByChain = { [CHAIN_ID_SOLANA]: blockKey };
// if a chain is in the database, that number should be returned
expect(await db.getLastBlockByChain('solana')).toEqual(fauxBlock);
expect(await getResumeBlockByChain('solana')).toEqual(Number(fauxBlock) + 1);
expect(await getResumeBlockByChain(NETWORK.MAINNET, 'solana')).toEqual(Number(fauxBlock) + 1);
// if a chain is not in the database, the initial deployment block should be returned
expect(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.moonbeam).toBeDefined();
expect(await getResumeBlockByChain('moonbeam')).toEqual(
Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.moonbeam)
expect(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].moonbeam).toBeDefined();
expect(await getResumeBlockByChain(NETWORK.MAINNET, 'moonbeam')).toEqual(
Number(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].moonbeam)
);
// if neither, null should be returned
expect(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.unset).toBeUndefined();
expect(await getResumeBlockByChain('unset')).toEqual(null);
expect(INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].unset).toBeUndefined();
expect(await getResumeBlockByChain(NETWORK.MAINNET, 'unset')).toEqual(null);
});
25 changes: 15 additions & 10 deletions watcher/src/watchers/__tests__/AlgorandWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import { expect, jest, test } from '@jest/globals';
import { INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} from '@wormhole-foundation/wormhole-monitor-common';
import { AlgorandWatcher } from '../AlgorandWatcher';

jest.setTimeout(180000);

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

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

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

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

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

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

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

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

jest.setTimeout(60000);

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

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

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

jest.setTimeout(60000);

const initialArbitrumBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.arbitrum);
const initialEthBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.ethereum);
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
);

test('getFinalizedBlockNumber', async () => {
const watcher = new ArbitrumWatcher();
const watcher = new ArbitrumWatcher(NETWORK.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 @@ -21,7 +28,7 @@ test('getFinalizedBlockNumber', async () => {
});

test('getMessagesForBlocks', async () => {
const watcher = new ArbitrumWatcher();
const watcher = new ArbitrumWatcher(NETWORK.MAINNET);
const vaasByBlock = await watcher.getMessagesForBlocks(114500582, 114500584);
const entries = Object.entries(vaasByBlock);
expect(entries.length).toEqual(3);
Expand Down
16 changes: 11 additions & 5 deletions watcher/src/watchers/__tests__/BaseWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { expect, jest, test } from '@jest/globals';
import { INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
import {
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN,
NETWORK,
} 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_CHAIN.base);
const initialBaseBlock = Number(
INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN[NETWORK.MAINNET].base
);

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

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

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

jest.setTimeout(60000);

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

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

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

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

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

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

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

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

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

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

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

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

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

test('getFinalizedBlockNumber(sei explorer)', async () => {
const watcher = new SeiExplorerWatcher();
const watcher = new SeiExplorerWatcher(NETWORK.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();
const watcher = new SeiExplorerWatcher(NETWORK.MAINNET);
const vaasByBlock = await watcher.getMessagesForBlocks(19061244, 19061245);
const entries = Object.entries(vaasByBlock);
console.log(entries);
Expand All @@ -193,14 +196,16 @@ test.skip('getMessagesForBlocks(sei explorer)', async () => {
});

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

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

0 comments on commit 70d1408

Please sign in to comment.