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

fix missing filter codeId in long type #262

Merged
merged 1 commit into from
Jun 12, 2024
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
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
Loading