From 4ecdcb4635dbc106cd922efb8c2a09ae07b4368e Mon Sep 17 00:00:00 2001 From: Franco NG Date: Wed, 21 Jun 2023 10:53:50 +0200 Subject: [PATCH] Fix length requirement and dataType on getChainAccountRequestSchema and test cases --- framework/src/modules/interoperability/schemas.ts | 6 ++++-- .../test/unit/modules/interoperability/endpoint.spec.ts | 4 ++-- .../modules/interoperability/mainchain/endpoint.spec.ts | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/framework/src/modules/interoperability/schemas.ts b/framework/src/modules/interoperability/schemas.ts index ff137f66b43..54552493929 100644 --- a/framework/src/modules/interoperability/schemas.ts +++ b/framework/src/modules/interoperability/schemas.ts @@ -564,8 +564,10 @@ export const getChainAccountRequestSchema = { required: ['chainID'], properties: { chainID: { - type: 'string', - format: 'hex', + dataType: 'bytes', + fieldNumber: 1, + minLength: CHAIN_ID_LENGTH, + maxLength: CHAIN_ID_LENGTH, }, }, }; diff --git a/framework/test/unit/modules/interoperability/endpoint.spec.ts b/framework/test/unit/modules/interoperability/endpoint.spec.ts index 7f87d220dba..51cdcf39697 100644 --- a/framework/test/unit/modules/interoperability/endpoint.spec.ts +++ b/framework/test/unit/modules/interoperability/endpoint.spec.ts @@ -190,8 +190,8 @@ describe('Test interoperability endpoint', () => { getStore: (p1: Buffer, p2: Buffer) => stateStore.getStore(p1, p2), getImmutableMethodContext: jest.fn(), getOffchainStore: jest.fn(), - chainID: Buffer.alloc(0), - params: { chainID: '00000001' }, + chainID: utils.intToBuffer(1, 4), + params: { chainID: utils.intToBuffer(1, 4) }, logger: {} as any, header: { aggregateCommit: { height: 10 }, height: 12, timestamp: Date.now() }, }; diff --git a/framework/test/unit/modules/interoperability/mainchain/endpoint.spec.ts b/framework/test/unit/modules/interoperability/mainchain/endpoint.spec.ts index fa8838bf8ed..08a58443180 100644 --- a/framework/test/unit/modules/interoperability/mainchain/endpoint.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/endpoint.spec.ts @@ -138,7 +138,7 @@ describe('MainchainInteroperabilityEndpoint', () => { it('should return false when chainID equals mainchainID', async () => { context = createTransientModuleEndpointContext({ params: { - chainID: '00000000', + chainID: Buffer.from('00000000', 'hex'), }, }); const isAvailable = await endpoint.isChainIDAvailable(context); @@ -148,7 +148,7 @@ describe('MainchainInteroperabilityEndpoint', () => { it('should return false when chainID is not on the mainchain network', async () => { context = createTransientModuleEndpointContext({ params: { - chainID: '11111111', + chainID: Buffer.from('11111111', 'hex'), }, }); const isAvailable = await endpoint.isChainIDAvailable(context); @@ -158,7 +158,7 @@ describe('MainchainInteroperabilityEndpoint', () => { it('should return false when the chainID exists', async () => { context = createTransientModuleEndpointContext({ params: { - chainID: '00000001', + chainID: Buffer.from('00000001', 'hex'), }, }); chainAccountStore.has.mockResolvedValue(true);