diff --git a/framework/test/unit/modules/interoperability/base_cross_chain_update_command.spec.ts b/framework/test/unit/modules/interoperability/base_cross_chain_update_command.spec.ts index 769a49c9a9b..328baebba70 100644 --- a/framework/test/unit/modules/interoperability/base_cross_chain_update_command.spec.ts +++ b/framework/test/unit/modules/interoperability/base_cross_chain_update_command.spec.ts @@ -321,6 +321,19 @@ describe('BaseCrossChainUpdateCommand', () => { .set(stateStore, params.sendingChainID, chainAccount); }); + it('should reject when ccu params validation fails', async () => { + const nonBufferSendingChainID = 2; + verifyContext = { + ...verifyContext, + params: { ...params, sendingChainID: nonBufferSendingChainID } as any, + }; + + // 2nd param `isMainchain` could be false + await expect(command['verifyCommon'](verifyContext, false)).rejects.toThrow( + `Property '.sendingChainID' should pass "dataType" keyword validation`, + ); + }); + it('should call validator.validate with crossChainUpdateTransactionParams schema', async () => { jest.spyOn(validator, 'validate'); diff --git a/framework/test/unit/modules/interoperability/mainchain/commands/submit_mainchain_cross_chain_update.spec.ts b/framework/test/unit/modules/interoperability/mainchain/commands/submit_mainchain_cross_chain_update.spec.ts index 2e5d92d3480..9bf2a422351 100644 --- a/framework/test/unit/modules/interoperability/mainchain/commands/submit_mainchain_cross_chain_update.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/commands/submit_mainchain_cross_chain_update.spec.ts @@ -413,7 +413,7 @@ describe('SubmitMainchainCrossChainUpdateCommand', () => { }); }); - it('should verify verifyCommon is called', async () => { + it('should check if verifyCommon is called', async () => { jest.spyOn(mainchainCCUUpdateCommand, 'verifyCommon' as any); await expect(mainchainCCUUpdateCommand.verify(verifyContext)).resolves.toEqual({ @@ -423,6 +423,23 @@ describe('SubmitMainchainCrossChainUpdateCommand', () => { expect(mainchainCCUUpdateCommand['verifyCommon']).toHaveBeenCalled(); }); + it('should call isLive with 3 params', async () => { + jest.spyOn(mainchainCCUUpdateCommand['internalMethod'], 'isLive'); + + await expect( + mainchainCCUUpdateCommand.verify({ + ...verifyContext, + params: { ...params } as any, + }), + ).resolves.toEqual({ status: VerifyStatus.OK }); + + expect(mainchainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith( + verifyContext, + verifyContext.params.sendingChainID, + verifyContext.header.timestamp, + ); + }); + it(`should not verify liveness condition when sendingChainAccount.status == ${ChainStatus.REGISTERED} and inboxUpdate is empty`, async () => { await expect( mainchainCCUUpdateCommand.verify({ diff --git a/framework/test/unit/modules/interoperability/sidechain/commands/submit_sidechain_cross_chain_update.spec.ts b/framework/test/unit/modules/interoperability/sidechain/commands/submit_sidechain_cross_chain_update.spec.ts index decb0fbe118..e2dcf9db178 100644 --- a/framework/test/unit/modules/interoperability/sidechain/commands/submit_sidechain_cross_chain_update.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/commands/submit_sidechain_cross_chain_update.spec.ts @@ -303,7 +303,7 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => { jest.spyOn(sidechainCCUUpdateCommand['internalMethod'], 'isLive').mockResolvedValue(true); }); - it('should verify verifyCommon is called', async () => { + it('should check if verifyCommon is called', async () => { jest.spyOn(sidechainCCUUpdateCommand, 'verifyCommon' as any); await expect(sidechainCCUUpdateCommand.verify(verifyContext)).resolves.toEqual({ @@ -313,15 +313,6 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => { expect(sidechainCCUUpdateCommand['verifyCommon']).toHaveBeenCalled(); }); - it('should reject when ccu params validation fails', async () => { - await expect( - sidechainCCUUpdateCommand.verify({ - ...verifyContext, - params: { ...params, sendingChainID: 2 } as any, - }), - ).rejects.toThrow('.sendingChainID'); - }); - it('should call isLive with only 2 params', async () => { jest.spyOn(sidechainCCUUpdateCommand['internalMethod'], 'isLive'); @@ -332,15 +323,16 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => { }), ).resolves.toEqual({ status: VerifyStatus.OK }); - expect(sidechainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith( + expect(sidechainCCUUpdateCommand['internalMethod'].isLive).not.toHaveBeenCalledWith( verifyContext, verifyContext.params.sendingChainID, + verifyContext.header.timestamp, ); - expect(sidechainCCUUpdateCommand['internalMethod'].isLive).not.toHaveBeenCalledWith( + // should be tested later, otherwise, it can pass even if above fails + expect(sidechainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith( verifyContext, verifyContext.params.sendingChainID, - verifyContext.header.timestamp, ); }); });