From f1b4fb13614d0bc3e801d80d23bb60a03913ce58 Mon Sep 17 00:00:00 2001 From: Tate Date: Thu, 22 Aug 2024 07:14:50 +0000 Subject: [PATCH 1/2] fix-dictionary-bigint --- packages/node/CHANGELOG.md | 3 +++ packages/node/src/utils/cosmos.ts | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index 89b2f9ef..add71571 100644 --- a/packages/node/CHANGELOG.md +++ b/packages/node/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Change +- Support bigint filter + ## [4.1.0] - 2024-08-12 ### Added - Support for endpoint configs (#278) diff --git a/packages/node/src/utils/cosmos.ts b/packages/node/src/utils/cosmos.ts index 5989adc2..87f8c5c6 100644 --- a/packages/node/src/utils/cosmos.ts +++ b/packages/node/src/utils/cosmos.ts @@ -132,6 +132,15 @@ export function filterMessageData( ? decodedMsgData.toNumber() : decodedMsgData.toString(); } + + if (typeof decodedMsgData === 'bigint') { + if (BigInt(filter.values[key]) === decodedMsgData) { + continue; + } else { + return false; + } + } + if (filter.values[key] !== decodedMsgData) { return false; } From 2fc1c4a31183921830c4dcd4a34145e73dfa83fd Mon Sep 17 00:00:00 2001 From: Tate Date: Thu, 22 Aug 2024 07:57:08 +0000 Subject: [PATCH 2/2] unit test --- packages/node/src/utils/cosmos.spec.ts | 64 +++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/packages/node/src/utils/cosmos.spec.ts b/packages/node/src/utils/cosmos.spec.ts index fefb01bf..75c3c6d7 100644 --- a/packages/node/src/utils/cosmos.spec.ts +++ b/packages/node/src/utils/cosmos.spec.ts @@ -9,6 +9,7 @@ import { CosmosBlock, CosmosTransaction, CosmosMessage, + CosmosEventFilter, } from '@subql/types-cosmos'; import { MsgClearAdmin, @@ -21,7 +22,12 @@ import { import { fromInt } from 'long'; import { CosmosClient } from '../indexer/api.service'; import { BlockContent } from '../indexer/types'; -import { fetchBlocksBatches, filterMessageData, wrapEvent } from './cosmos'; +import { + fetchBlocksBatches, + filterEvents, + filterMessageData, + wrapEvent, +} from './cosmos'; const ENDPOINT = 'https://rpc.mainnet.archway.io'; @@ -401,3 +407,59 @@ describe('Cosmos 0.50 support', () => { expect(event.log.events.length).toEqual(0); }); }); + +describe('Cosmos bigint support', () => { + const TEST_BIGINT_BLOCKNUMBER = 17838575; + const TEST_BIGINT_SUCC: CosmosEventFilter = { + type: 'transfer', + messageFilter: { + type: '/ibc.applications.transfer.v1.MsgTransfer', + values: { + timeoutTimestamp: '1723738770000000000', + }, + }, + }; + + const TEST_BIGINT_FAIL: CosmosEventFilter = { + type: 'transfer', + messageFilter: { + type: '/ibc.applications.transfer.v1.MsgTransfer', + values: { + timeoutTimestamp: '2723738770000000000', + }, + }, + }; + let api: CosmosClient; + let client: CometClient; + let block: BlockContent; + + beforeAll(async () => { + // chainId: fetchhub-4 + // endpoint: https://rpc-fetchhub.fetch.ai + client = await connectComet('https://rpc-fetchhub.fetch.ai'); + const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [ + ['/cosmwasm.wasm.v1.MsgClearAdmin', MsgClearAdmin], + ['/cosmwasm.wasm.v1.MsgExecuteContract', MsgExecuteContract], + ['/cosmwasm.wasm.v1.MsgMigrateContract', MsgMigrateContract], + ['/cosmwasm.wasm.v1.MsgStoreCode', MsgStoreCode], + ['/cosmwasm.wasm.v1.MsgInstantiateContract', MsgInstantiateContract], + ['/cosmwasm.wasm.v1.MsgUpdateAdmin', MsgUpdateAdmin], + ]; + + const registry = new Registry([...defaultRegistryTypes, ...wasmTypes]); + api = new CosmosClient(client, registry); + + const [firstBlock] = await fetchBlocksBatches(api, [ + TEST_BIGINT_BLOCKNUMBER, + ]); + block = firstBlock.block; + }); + + it('bigint field check', () => { + const succEvents = filterEvents(block.events, TEST_BIGINT_SUCC); + const failEvents = filterEvents(block.events, TEST_BIGINT_FAIL); + + expect(succEvents.length).toEqual(1); + expect(failEvents.length).toEqual(0); + }); +});