Skip to content

Commit

Permalink
Merge branch 'main' into rename-types
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname authored Oct 16, 2023
2 parents f4163d4 + 4286760 commit 62180f7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
Empty file added .yarn/versions/cd726781.yml
Empty file.
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Update type names to be consistent with main SDK (#189)
### Fixed
- Fix contractCall filtering issue on non-object calls (#188)

## [3.0.2] - 2023-10-12
### Changed
Expand Down
5 changes: 3 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/node-cosmos",
"version": "3.0.2",
"version": "3.0.3-0",
"description": "",
"author": "Naveen Veluswamy",
"license": "GPL-3.0",
Expand Down Expand Up @@ -61,5 +61,6 @@
"files": [
"/dist",
"/bin"
]
],
"stableVersion": "3.0.2"
}
86 changes: 86 additions & 0 deletions packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,92 @@ describe('CosmosUtils', () => {
expect(result).toEqual(false);
});

describe('filterMessageData function', () => {
const baseData = {
tx: {
tx: {
code: 0,
},
},
msg: {
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
decodedMsg: {
msg: {},
},
},
} as unknown as CosmosMessage;

describe('contractCall filtering', () => {
it('should return true for non-object contractCall in msg', () => {
const data = {
...baseData,
msg: {
...baseData.msg,
decodedMsg: {
msg: 'nonObjectContractCall',
},
},
};
const filter = {
type: '/cosmwasm.wasm.v1.MsgExecuteContract',
contractCall: 'nonObjectContractCall',
};

const result = filterMessageData(data, filter);
expect(result).toBe(true);
});

it('should return false for non-object contractCall not in msg', () => {
const data = {
...baseData,
msg: {
...baseData.msg,
decodedMsg: {
msg: 'nonObjectContractCall2',
},
},
};
const filter = {
type: '/cosmwasm.wasm.v1.MsgExecuteContract',
contractCall: 'nonObjectContractCall',
};

const result = filterMessageData(data, filter);
expect(result).toBe(false);
});

it('should return false for object contractCall not in msg', () => {
const filter = {
type: '/cosmwasm.wasm.v1.MsgExecuteContract',
contractCall: 'notInMsg',
};

const result = filterMessageData(baseData, filter);
expect(result).toBe(false);
});

it('should return true for object contractCall in msg', () => {
const contractCall = { inMsg: 'inMsg' };
const data = {
...baseData,
msg: {
...baseData.msg,
decodedMsg: {
msg: contractCall,
},
},
};
const filter = {
type: '/cosmwasm.wasm.v1.MsgExecuteContract',
contractCall: 'inMsg',
};

const result = filterMessageData(data, filter);
expect(result).toBe(true);
});
});
});

afterEach(() => {
api.disconnect();
});
Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CosmosBlockFilter,
CosmosTxFilter,
} from '@subql/types-cosmos';
import { isObjectLike } from 'lodash';
import { isLong } from 'long';
import { CosmosClient } from '../indexer/api.service';
import { BlockContent } from '../indexer/types';
Expand Down Expand Up @@ -92,7 +93,8 @@ export function filterMessageData(
filter.contractCall &&
!(
filter.contractCall === data.msg.decodedMsg.msg ||
filter.contractCall in data.msg.decodedMsg.msg
(isObjectLike(data.msg.decodedMsg.msg) &&
filter.contractCall in data.msg.decodedMsg.msg)
)
) {
return false;
Expand Down

0 comments on commit 62180f7

Please sign in to comment.