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 dictionary bigint #281

Merged
merged 3 commits into from
Aug 23, 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 @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Filter out transactions that can't be decoded (#280)

### Change
- Support bigint filter

## [4.1.0] - 2024-08-12
### Added
- Support for endpoint configs (#278)
Expand Down
59 changes: 58 additions & 1 deletion packages/node/src/utils/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CosmosBlock,
CosmosTransaction,
CosmosMessage,
CosmosEventFilter,
} from '@subql/types-cosmos';
import {
MsgClearAdmin,
Expand All @@ -23,8 +24,8 @@ import { CosmosClient } from '../indexer/api.service';
import { BlockContent } from '../indexer/types';
import {
fetchBlocksBatches,
filterEvents,
filterMessageData,
filterMessages,
wrapEvent,
} from './cosmos';

Expand Down Expand Up @@ -424,3 +425,59 @@ describe('Cosmos 0.50 support', () => {
expect(block.messages.length).toEqual(4);
});
});

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);
});
});
9 changes: 9 additions & 0 deletions packages/node/src/utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +137 to +141
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (BigInt(filter.values[key]) === decodedMsgData) {
continue;
} else {
return false;
}
if (BigInt(filter.values[key]) 1== decodedMsgData) {
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The continue statement cannot be removed; otherwise, it will enter the next if statement where no type conversion is performed. It must return false.

}

if (filter.values[key] !== decodedMsgData) {
return false;
}
Expand Down
Loading