Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watcher: terra classic change #130

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions watcher/src/watchers/TerraExplorerWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export class TerraExplorerWatcher extends Watcher {
if (!this.rpc) {
throw new Error(`${this.chain} RPC is not defined!`);
}
this.latestBlockTag = 'blocks/latest';
this.getBlockTag = 'blocks/';
this.latestBlockTag = 'v1/blocks/latest';
this.getBlockTag = 'v1/blocks/';
this.allTxsTag = 'v1/txs?';
this.latestBlockHeight = 0;
}

async getFinalizedBlockNumber(): Promise<number> {
const result = (await axios.get(`${this.rpc}/${this.latestBlockTag}`, AXIOS_CONFIG_JSON)).data;
if (result && result.block.header.height) {
let blockHeight: number = parseInt(result.block.header.height);
if (result && result.height) {
let blockHeight: number = parseInt(result.height);
if (blockHeight !== this.latestBlockHeight) {
this.latestBlockHeight = blockHeight;
this.logger.debug('blockHeight = ' + blockHeight);
Expand Down Expand Up @@ -149,13 +149,13 @@ export class TerraExplorerWatcher extends Watcher {
// become the new starting point for subsequent calls.
this.logger.debug(`Adding filler for block ${toBlock}`);
const blkUrl = `${this.rpc}/${this.getBlockTag}${toBlock}`;
const result: CosmwasmBlockResult = (await axios.get(blkUrl, AXIOS_CONFIG_JSON)).data;
const result: NewCosmwasmBlockResult = (await axios.get(blkUrl, AXIOS_CONFIG_JSON)).data;
if (!result) {
throw new Error(`Unable to get block information for block ${toBlock}`);
}
const blockKey = makeBlockKey(
result.block.header.height.toString(),
new Date(result.block.header.time).toISOString()
result.height.toString(),
new Date(result.timestamp).toISOString()
);
vaasByBlock[blockKey] = [];
}
Expand Down Expand Up @@ -232,3 +232,27 @@ type CosmwasmBlockResult = {
};
};
};

type NewCosmwasmBlockResult = {
chainId: string; //'columbus-5';
height: number; //14520709;
timestamp: string; //'2023-09-13T13:38:23.081Z';
proposer: {
moniker: string; //'ISS';
identity: string; //'';
operatorAddress: string; //'terravaloper15khv8dsaxqmf7nwu4jdlp9slxl7aczte3x068c';
};
txs: [
{
id: number;
tx: Object;
logs: Object[];
height: string;
txhash: string;
raw_log: string;
gas_used: string;
timestamp: string;
gas_wanted: string;
}
];
};
12 changes: 6 additions & 6 deletions watcher/src/watchers/__tests__/CosmwasmWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ test('getFinalizedBlockNumber(terra explorer)', async () => {
});

// flaky rpc, skip
test.skip('getMessagesForBlocks(terra explorer)', async () => {
test('getMessagesForBlocks(terra explorer)', async () => {
const watcher = new TerraExplorerWatcher('terra');
const vaasByBlock = await watcher.getMessagesForBlocks(10974196, 10974197);
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);
expect(entries.filter(([block, vaas]) => vaas.length === 1).length).toEqual(1);
expect(entries.filter(([block, vaas]) => vaas.length === 2).length).toEqual(0);
expect(vaasByBlock['10974196/2023-01-06T04:23:21.000Z']).toBeDefined();
expect(vaasByBlock['10974196/2023-01-06T04:23:21.000Z'].length).toEqual(1);
expect(vaasByBlock['10974196/2023-01-06T04:23:21.000Z'][0]).toEqual(
'8A31CDE56ED3ACB7239D705949BD6C164747210A6C4C69D98756E0CF6D22C9EB:3/0000000000000000000000007cf7b764e38a0a5e967972c1df77d432510564e2/256813'
expect(vaasByBlock['14506733/2023-09-11T21:59:36.000Z']).toBeDefined();
expect(vaasByBlock['14506733/2023-09-11T21:59:36.000Z'].length).toEqual(1);
expect(vaasByBlock['14506733/2023-09-11T21:59:36.000Z'][0]).toEqual(
'A0A0161B162DCD23845C32022320C21862B08F8B16A23CD04C68EF3BCBCFCFE5:3/0000000000000000000000007cf7b764e38a0a5e967972c1df77d432510564e2/259253'
);
});

Expand Down
2 changes: 2 additions & 0 deletions watcher/src/watchers/__tests__/EVMWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const initialCeloBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.celo);
const initialOasisBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.oasis);
const initialKaruraBlock = Number(INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN.karura);

jest.setTimeout(30000);

test('getBlock by tag', async () => {
const watcher = new EVMWatcher('avalanche');
const block = await watcher.getBlock('latest');
Expand Down