diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index cbe2cb46a..ac66b484c 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] +### Fixed +- Bring back `long` to fix missing filter `codeId` in long type + ## [3.11.1] - 2024-05-02 ### Fixed - Sandbox Uint8Array and missing pg dep issue diff --git a/packages/node/src/utils/cosmos.spec.ts b/packages/node/src/utils/cosmos.spec.ts index ab3b23142..00f3d68f3 100644 --- a/packages/node/src/utils/cosmos.spec.ts +++ b/packages/node/src/utils/cosmos.spec.ts @@ -23,6 +23,7 @@ import { MsgStoreCode, MsgUpdateAdmin, } from 'cosmjs-types/cosmwasm/wasm/v1/tx'; +import { isLong, fromInt } from 'long'; import { CosmosClient } from '../indexer/api.service'; import { HttpClient } from '../indexer/rpc-clients'; import { decodeMsg, filterMessageData, wrapEvent } from './cosmos'; @@ -173,74 +174,74 @@ describe('CosmosUtils', () => { expect(spy).toHaveBeenCalled(); }); - // it('can filter long type decoded msg for true', () => { - // const msg: CosmosMessage = { - // tx: null, - // msg: { - // typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // decodedMsg: { - // codeId: longify(4), - // }, - // }, - // } as unknown as CosmosMessage; - - // const filter: CosmosMessageFilter = { - // type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // values: { - // codeId: '4', - // }, - // includeFailedTx: true, - // }; - - // const result = filterMessageData(msg, filter); - // expect(result).toEqual(true); - // }); - - // it('can filter long type decoded msg for number filter', () => { - // const msg: CosmosMessage = { - // tx: null, - // msg: { - // typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // decodedMsg: { - // codeId: longify(4), - // }, - // }, - // } as unknown as CosmosMessage; - - // const filter: CosmosMessageFilter = { - // type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // values: { - // codeId: 4 as unknown as string, - // }, - // includeFailedTx: true, - // }; - - // const result = filterMessageData(msg, filter); - // expect(result).toEqual(true); - // }); - - // it('can filter long type decoded msg for false', () => { - // const msg: CosmosMessage = { - // tx: null, - // msg: { - // typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // decodedMsg: { - // codeId: longify(4), - // }, - // }, - // } as unknown as CosmosMessage; - - // const filter: CosmosMessageFilter = { - // type: '/cosmwasm.wasm.v1.MsgInstantiateContract', - // values: { - // codeId: '5', - // }, - // includeFailedTx: true, - // }; - - // const result = filterMessageData(msg, filter); - // expect(result).toEqual(false); - // }); + it('can filter long type decoded msg for true', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, + }, + } as unknown as CosmosMessage; + + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: '4', + }, + includeFailedTx: true, + }; + + const result = filterMessageData(msg, filter); + expect(result).toEqual(true); + }); + + it('can filter long type decoded msg for number filter', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, + }, + } as unknown as CosmosMessage; + + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: 4 as unknown as string, + }, + includeFailedTx: true, + }; + + const result = filterMessageData(msg, filter); + expect(result).toEqual(true); + }); + + it('can filter long type decoded msg for false', () => { + const msg: CosmosMessage = { + tx: null, + msg: { + typeUrl: '/cosmwasm.wasm.v1.MsgInstantiateContract', + decodedMsg: { + codeId: fromInt(4), + }, + }, + } as unknown as CosmosMessage; + + const filter: CosmosMessageFilter = { + type: '/cosmwasm.wasm.v1.MsgInstantiateContract', + values: { + codeId: '5', + }, + includeFailedTx: true, + }; + + const result = filterMessageData(msg, filter); + expect(result).toEqual(false); + }); describe('filterMessageData function', () => { const baseData = { diff --git a/packages/node/src/utils/cosmos.ts b/packages/node/src/utils/cosmos.ts index b44686e2a..e5cf398ae 100644 --- a/packages/node/src/utils/cosmos.ts +++ b/packages/node/src/utils/cosmos.ts @@ -33,6 +33,7 @@ import { CosmosTxFilter, } from '@subql/types-cosmos'; import { isObjectLike } from 'lodash'; +import { isLong } from 'long'; import { SubqlProjectBlockFilter } from '../configure/SubqueryProject'; import { CosmosClient } from '../indexer/api.service'; import { BlockContent } from '../indexer/types'; @@ -113,10 +114,17 @@ export function filterMessageData( } if (filter.values) { for (const key in filter.values) { - const decodedMsgData = key + let decodedMsgData = key .split('.') .reduce((acc, curr) => acc[curr], data.msg.decodedMsg); + //stringify Long for equality check + if (isLong(decodedMsgData)) { + decodedMsgData = + typeof filter.values[key] === 'number' + ? decodedMsgData.toNumber() + : decodedMsgData.toString(); + } if (filter.values[key] !== decodedMsgData) { return false; }