Skip to content

Commit

Permalink
fix missing filter codeId in long type (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 authored Jun 12, 2024
1 parent 40f4caa commit 6a33c03
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 69 deletions.
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
137 changes: 69 additions & 68 deletions packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand Down
10 changes: 9 additions & 1 deletion packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6a33c03

Please sign in to comment.