From 969be40b43fcb61bfa02538b4c67fa2573babab1 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Tue, 25 Oct 2022 17:17:14 +0200 Subject: [PATCH 1/9] Update Schema and `execute` function of ChannelTerminated --- .../cc_commands/channel_terminated.ts | 27 +++++++++++++++---- .../src/modules/interoperability/schemas.ts | 15 ++++++++++- .../cc_commands/channel_terminated.ts | 27 +++++++++++++++---- .../src/modules/interoperability/types.ts | 5 ++++ 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts index b85fae31a01..c247574a94f 100644 --- a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts @@ -12,11 +12,12 @@ * Removal or modification of this copyright notice is prohibited. */ +import { codec } from '@liskhq/lisk-codec'; import { StoreGetter } from '../../../base_store'; import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; import { channelTerminatedCCMParamsSchema } from '../../schemas'; -import { CCCommandExecuteContext } from '../../types'; +import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; import { MainchainInteroperabilityStore } from '../store'; export class MainchainCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { @@ -27,11 +28,27 @@ export class MainchainCCChannelTerminatedCommand extends BaseInteroperabilityCCC } public async execute(context: CCCommandExecuteContext): Promise { - const interoperabilityStore = this.getInteroperabilityStore(context); - if (!context.ccm) { - throw new Error('CCM to execute channel terminated cross chain command is missing.'); + if (await this.getInteroperabilityStore(context).isLive(context.chainID, Date.now())) { + const interoperabilityStore = this.getInteroperabilityStore(context); + if (!context.ccm) { + throw new Error('CCM to execute channel terminated cross chain command is missing.'); + } + const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); + const channelTerminatedCCMParams = codec.decode( + this.schema, + context.ccm.params, + ); + await interoperabilityStore.createTerminatedStateAccount( + context.ccm.sendingChainID, + channelTerminatedCCMParams.stateRoot, + ); + await interoperabilityStore.createTerminatedOutboxAccount( + context.ccm.sendingChainID, + ccmParamsChannel.outbox.root, + ccmParamsChannel.outbox.size, + channelTerminatedCCMParams.inboxSize, + ); } - await interoperabilityStore.createTerminatedStateAccount(context.ccm.sendingChainID); } protected getInteroperabilityStore(context: StoreGetter): MainchainInteroperabilityStore { diff --git a/framework/src/modules/interoperability/schemas.ts b/framework/src/modules/interoperability/schemas.ts index 415e88ebd13..eae913eb68c 100644 --- a/framework/src/modules/interoperability/schemas.ts +++ b/framework/src/modules/interoperability/schemas.ts @@ -27,6 +27,7 @@ import { MAX_CHAIN_NAME_LENGTH, BLS_PUBLIC_KEY_LENGTH, BLS_SIGNATURE_LENGTH, + HASH_LENGTH, } from './constants'; import { chainAccountSchema } from './stores/chain_account'; import { chainValidatorsSchema } from './stores/chain_validators'; @@ -354,7 +355,19 @@ export const registrationCCMParamsSchema = { export const channelTerminatedCCMParamsSchema = { $id: '/modules/interoperability/ccCommand/channelTerminated', type: 'object', - properties: {}, + required: ['stateRoot', 'inboxSize'], + properties: { + stateRoot: { + dataType: 'bytes', + minLength: HASH_LENGTH, + maxLength: HASH_LENGTH, + fieldNumber: 1, + }, + inboxSize: { + dataType: 'uint32', + fieldNumber: 2, + }, + }, }; export const sidechainTerminatedCCMParamsSchema = { diff --git a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts index 8d3fc3db057..ad9c7c5b0d0 100644 --- a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts @@ -12,11 +12,12 @@ * Removal or modification of this copyright notice is prohibited. */ +import { codec } from '@liskhq/lisk-codec'; import { ImmutableStoreGetter, StoreGetter } from '../../../base_store'; import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; import { channelTerminatedCCMParamsSchema } from '../../schemas'; -import { CCCommandExecuteContext } from '../../types'; +import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; import { SidechainInteroperabilityStore } from '../store'; export class SidechainCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { @@ -27,11 +28,27 @@ export class SidechainCCChannelTerminatedCommand extends BaseInteroperabilityCCC } public async execute(context: CCCommandExecuteContext): Promise { - const interoperabilityStore = this.getInteroperabilityStore(context); - if (!context.ccm) { - throw new Error('CCM to execute channel terminated cross chain command is missing.'); + if (await this.getInteroperabilityStore(context).isLive(context.chainID)) { + const interoperabilityStore = this.getInteroperabilityStore(context); + if (!context.ccm) { + throw new Error('CCM to execute channel terminated cross chain command is missing.'); + } + const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); + const channelTerminatedCCMParams = codec.decode( + this.schema, + context.ccm.params, + ); + await interoperabilityStore.createTerminatedStateAccount( + context.ccm.sendingChainID, + channelTerminatedCCMParams.stateRoot, + ); + await interoperabilityStore.createTerminatedOutboxAccount( + context.ccm.sendingChainID, + ccmParamsChannel.outbox.root, + ccmParamsChannel.outbox.size, + channelTerminatedCCMParams.inboxSize, + ); } - await interoperabilityStore.createTerminatedStateAccount(context.ccm.sendingChainID); } protected getInteroperabilityStore( diff --git a/framework/src/modules/interoperability/types.ts b/framework/src/modules/interoperability/types.ts index a8b46ed6054..429fb7610b4 100644 --- a/framework/src/modules/interoperability/types.ts +++ b/framework/src/modules/interoperability/types.ts @@ -380,3 +380,8 @@ export interface GenesisInteroperabilityStore { storeValue: ChainID; }[]; } + +export interface ChannelTerminatedCCMParams { + stateRoot: Buffer; + inboxSize: number; +} From 38d7babe7ce497760974c3ca2c07434bcf91239d Mon Sep 17 00:00:00 2001 From: Franco NG Date: Wed, 26 Oct 2022 13:18:47 +0200 Subject: [PATCH 2/9] Added seperate channel file and updated test cases --- .../base/cc_commands/channel_terminated.ts | 51 +++++++++++++++++++ .../cc_commands/channel_terminated.ts | 38 +------------- .../cc_commands/channel_terminated.ts | 38 +------------- .../cc_commands/channel_terminated.spec.ts | 39 ++++++++++++-- .../cc_commands/channel_terminated.spec.ts | 46 ++++++++++++++--- 5 files changed, 130 insertions(+), 82 deletions(-) create mode 100644 framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts diff --git a/framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts new file mode 100644 index 00000000000..509b492b177 --- /dev/null +++ b/framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts @@ -0,0 +1,51 @@ +/* + * Copyright © 2022 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +import { codec } from '@liskhq/lisk-codec'; +import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; +import { channelTerminatedCCMParamsSchema } from '../../schemas'; +import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; +import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; + +export abstract class BaseCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { + public schema = channelTerminatedCCMParamsSchema; + + public get name(): string { + return CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED; + } + + public async execute(context: CCCommandExecuteContext): Promise { + const interoperabilityStore = this.getInteroperabilityStore(context); + if (await interoperabilityStore.isLive(context.chainID, Date.now())) { + if (!context.ccm) { + throw new Error('CCM to execute channel terminated cross chain command is missing.'); + } + const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); + const channelTerminatedCCMParams = codec.decode( + this.schema, + context.ccm.params, + ); + await interoperabilityStore.createTerminatedStateAccount( + context.ccm.sendingChainID, + channelTerminatedCCMParams.stateRoot, + ); + await interoperabilityStore.createTerminatedOutboxAccount( + context.ccm.sendingChainID, + ccmParamsChannel.outbox.root, + ccmParamsChannel.outbox.size, + channelTerminatedCCMParams.inboxSize, + ); + } + } +} diff --git a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts index c247574a94f..2845e315f11 100644 --- a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts @@ -12,45 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { codec } from '@liskhq/lisk-codec'; import { StoreGetter } from '../../../base_store'; -import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; -import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; -import { channelTerminatedCCMParamsSchema } from '../../schemas'; -import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; import { MainchainInteroperabilityStore } from '../store'; +import { BaseCCChannelTerminatedCommand } from '../../base/cc_commands/channel_terminated'; -export class MainchainCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { - public schema = channelTerminatedCCMParamsSchema; - - public get name(): string { - return CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED; - } - - public async execute(context: CCCommandExecuteContext): Promise { - if (await this.getInteroperabilityStore(context).isLive(context.chainID, Date.now())) { - const interoperabilityStore = this.getInteroperabilityStore(context); - if (!context.ccm) { - throw new Error('CCM to execute channel terminated cross chain command is missing.'); - } - const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); - const channelTerminatedCCMParams = codec.decode( - this.schema, - context.ccm.params, - ); - await interoperabilityStore.createTerminatedStateAccount( - context.ccm.sendingChainID, - channelTerminatedCCMParams.stateRoot, - ); - await interoperabilityStore.createTerminatedOutboxAccount( - context.ccm.sendingChainID, - ccmParamsChannel.outbox.root, - ccmParamsChannel.outbox.size, - channelTerminatedCCMParams.inboxSize, - ); - } - } - +export class MainchainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { protected getInteroperabilityStore(context: StoreGetter): MainchainInteroperabilityStore { return new MainchainInteroperabilityStore( this.stores, diff --git a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts index ad9c7c5b0d0..493065c04a4 100644 --- a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts @@ -12,45 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { codec } from '@liskhq/lisk-codec'; import { ImmutableStoreGetter, StoreGetter } from '../../../base_store'; -import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; -import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; -import { channelTerminatedCCMParamsSchema } from '../../schemas'; -import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; import { SidechainInteroperabilityStore } from '../store'; +import { BaseCCChannelTerminatedCommand } from '../../base/cc_commands/channel_terminated'; -export class SidechainCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { - public schema = channelTerminatedCCMParamsSchema; - - public get name(): string { - return CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED; - } - - public async execute(context: CCCommandExecuteContext): Promise { - if (await this.getInteroperabilityStore(context).isLive(context.chainID)) { - const interoperabilityStore = this.getInteroperabilityStore(context); - if (!context.ccm) { - throw new Error('CCM to execute channel terminated cross chain command is missing.'); - } - const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); - const channelTerminatedCCMParams = codec.decode( - this.schema, - context.ccm.params, - ); - await interoperabilityStore.createTerminatedStateAccount( - context.ccm.sendingChainID, - channelTerminatedCCMParams.stateRoot, - ); - await interoperabilityStore.createTerminatedOutboxAccount( - context.ccm.sendingChainID, - ccmParamsChannel.outbox.root, - ccmParamsChannel.outbox.size, - channelTerminatedCCMParams.inboxSize, - ); - } - } - +export class SidechainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { protected getInteroperabilityStore( context: StoreGetter | ImmutableStoreGetter, ): SidechainInteroperabilityStore { diff --git a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts index d0b430fa4a0..bb0118fda0e 100644 --- a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts @@ -12,6 +12,7 @@ * Removal or modification of this copyright notice is prohibited. */ +import { codec } from '@liskhq/lisk-codec'; import { utils } from '@liskhq/lisk-cryptography'; import { MainchainInteroperabilityModule } from '../../../../../../src'; import { @@ -23,10 +24,12 @@ import { MainchainInteroperabilityStore } from '../../../../../../src/modules/in import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; +import { channelTerminatedCCMParamsSchema } from '../../../../../../dist-node/modules/interoperability/schemas'; describe('MainchainCCChannelTerminatedCommand', () => { const interopMod = new MainchainInteroperabilityModule(); const createTerminatedStateAccountMock = jest.fn(); + const createTerminatedOutboxAccountMock = jest.fn(); const ccMethodMod1 = { beforeSendCCM: jest.fn(), @@ -40,6 +43,10 @@ describe('MainchainCCChannelTerminatedCommand', () => { ccMethodsMap.set(1, ccMethodMod1); ccMethodsMap.set(2, ccMethodMod2); const chainID = utils.getRandomBytes(32); + const ccmParams = { + stateRoot: Buffer.from('10000000', 'hex'), + inboxSize: 1, + }; const ccm = { nonce: BigInt(0), module: MODULE_NAME_INTEROPERABILITY, @@ -48,9 +55,10 @@ describe('MainchainCCChannelTerminatedCommand', () => { receivingChainID: utils.intToBuffer(3, 4), fee: BigInt(20000), status: 0, - params: Buffer.alloc(0), + params: codec.encode(channelTerminatedCCMParamsSchema, ccmParams), }; const sampleExecuteContext: CCCommandExecuteContext = createExecuteCCMsgMethodContext({ + ccm, chainID, }); @@ -66,15 +74,40 @@ describe('MainchainCCChannelTerminatedCommand', () => { new NamedRegistry(), ); mainchainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; + mainchainInteroperabilityStore.createTerminatedOutboxAccount = createTerminatedOutboxAccountMock; + mainchainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(false); (ccChannelTerminatedCommand as any)['getInteroperabilityStore'] = jest .fn() .mockReturnValue(mainchainInteroperabilityStore); + const channelOutbox = { + size: 10, + root: Buffer.from('01', 'hex'), + }; + mainchainInteroperabilityStore.getChannel = jest.fn().mockResolvedValue({ + outbox: channelOutbox, + }); describe('execute', () => { - it('should call validators Method registerValidatorKeys', async () => { + it('should skip if isLive is false ', async () => { await ccChannelTerminatedCommand.execute(sampleExecuteContext); + expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); + expect(createTerminatedOutboxAccountMock).toHaveBeenCalledTimes(0); + }); + + it('should call createTerminatedStateAccount and createTerminatedOutboxAccount if isLive', async () => { + mainchainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(true); - expect(createTerminatedStateAccountMock).toHaveBeenCalledWith(ccm.sendingChainID); + await ccChannelTerminatedCommand.execute(sampleExecuteContext); + expect(createTerminatedStateAccountMock).toHaveBeenCalledWith( + ccm.sendingChainID, + ccmParams.stateRoot, + ); + expect(createTerminatedOutboxAccountMock).toHaveBeenCalledWith( + ccm.sendingChainID, + channelOutbox.root, + channelOutbox.size, + ccmParams.inboxSize, + ); }); }); }); diff --git a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts index 267c80952d3..64abeaf8bc4 100644 --- a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts @@ -12,21 +12,24 @@ * Removal or modification of this copyright notice is prohibited. */ +import { codec } from '@liskhq/lisk-codec'; import { utils } from '@liskhq/lisk-cryptography'; import { SidechainInteroperabilityModule } from '../../../../../../src'; import { CROSS_CHAIN_COMMAND_NAME_REGISTRATION, MODULE_NAME_INTEROPERABILITY, } from '../../../../../../src/modules/interoperability/constants'; -import { SidechainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/sidechain/cc_commands/channel_terminated'; +import { SidechainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/sidechain/cc_commands'; import { SidechainInteroperabilityStore } from '../../../../../../src/modules/interoperability/sidechain/store'; import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; +import { channelTerminatedCCMParamsSchema } from '../../../../../../dist-node/modules/interoperability/schemas'; describe('SidechainCCChannelTerminatedCommand', () => { const interopMod = new SidechainInteroperabilityModule(); const createTerminatedStateAccountMock = jest.fn(); + const createTerminatedOutboxAccountMock = jest.fn(); const ccMethodMod1 = { beforeSendCCM: jest.fn(), @@ -40,6 +43,10 @@ describe('SidechainCCChannelTerminatedCommand', () => { ccMethodsMap.set(1, ccMethodMod1); ccMethodsMap.set(2, ccMethodMod2); const chainID = utils.getRandomBytes(32); + const ccmParams = { + stateRoot: Buffer.from('10000000', 'hex'), + inboxSize: 1, + }; const ccm = { nonce: BigInt(0), module: MODULE_NAME_INTEROPERABILITY, @@ -48,7 +55,7 @@ describe('SidechainCCChannelTerminatedCommand', () => { receivingChainID: utils.intToBuffer(3, 4), fee: BigInt(20000), status: 0, - params: Buffer.alloc(0), + params: codec.encode(channelTerminatedCCMParamsSchema, ccmParams), }; const sampleExecuteContext: CCCommandExecuteContext = createExecuteCCMsgMethodContext({ ccm, @@ -60,22 +67,47 @@ describe('SidechainCCChannelTerminatedCommand', () => { interopMod.events, ccMethodsMap, ); - const mainchainInteroperabilityStore = new SidechainInteroperabilityStore( + const sidechainInteroperabilityStore = new SidechainInteroperabilityStore( interopMod.stores, sampleExecuteContext, ccMethodsMap, new NamedRegistry(), ); - mainchainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; + sidechainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; + sidechainInteroperabilityStore.createTerminatedOutboxAccount = createTerminatedOutboxAccountMock; + sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(false); (ccChannelTerminatedCommand as any)['getInteroperabilityStore'] = jest .fn() - .mockReturnValue(mainchainInteroperabilityStore); + .mockReturnValue(sidechainInteroperabilityStore); + const channelOutbox = { + size: 10, + root: Buffer.from('01', 'hex'), + }; + sidechainInteroperabilityStore.getChannel = jest.fn().mockResolvedValue({ + outbox: channelOutbox, + }); describe('execute', () => { - it('should call validators Method registerValidatorKeys', async () => { + it('should skip if isLive is false ', async () => { await ccChannelTerminatedCommand.execute(sampleExecuteContext); + expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); + expect(createTerminatedOutboxAccountMock).toHaveBeenCalledTimes(0); + }); + + it('should call createTerminatedStateAccount and createTerminatedOutboxAccount if isLive', async () => { + sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(true); - expect(createTerminatedStateAccountMock).toHaveBeenCalledWith(ccm.sendingChainID); + await ccChannelTerminatedCommand.execute(sampleExecuteContext); + expect(createTerminatedStateAccountMock).toHaveBeenCalledWith( + ccm.sendingChainID, + ccmParams.stateRoot, + ); + expect(createTerminatedOutboxAccountMock).toHaveBeenCalledWith( + ccm.sendingChainID, + channelOutbox.root, + channelOutbox.size, + ccmParams.inboxSize, + ); }); }); }); From aac1230969dcae22b23603a610ddb7cb5abea611 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Thu, 27 Oct 2022 12:20:20 +0200 Subject: [PATCH 3/9] Edit incorrect import --- .../mainchain/cc_commands/channel_terminated.spec.ts | 2 +- .../sidechain/cc_commands/channel_terminated.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts index d302386ba0e..471e9362cbd 100644 --- a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts @@ -24,7 +24,7 @@ import { MainchainInteroperabilityStore } from '../../../../../../src/modules/in import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; -import { channelTerminatedCCMParamsSchema } from '../../../../../../dist-node/modules/interoperability/schemas'; +import { channelTerminatedCCMParamsSchema } from '../../../../../../src/modules/interoperability/schemas'; describe('MainchainCCChannelTerminatedCommand', () => { const interopMod = new MainchainInteroperabilityModule(); diff --git a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts index 186c69b8080..fe93902d2b9 100644 --- a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts @@ -24,7 +24,7 @@ import { SidechainInteroperabilityStore } from '../../../../../../src/modules/in import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; -import { channelTerminatedCCMParamsSchema } from '../../../../../../dist-node/modules/interoperability/schemas'; +import { channelTerminatedCCMParamsSchema } from '../../../../../../src/modules/interoperability/schemas'; describe('SidechainCCChannelTerminatedCommand', () => { const interopMod = new SidechainInteroperabilityModule(); From 69a8bc9faefcf397665b7fcc0df66478d0ea9b56 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Fri, 28 Oct 2022 13:31:02 +0200 Subject: [PATCH 4/9] Update code according to new requirement --- .../cc_commands/channel_terminated.ts | 21 +++---------------- .../cc_commands/channel_terminated.ts | 3 ++- .../src/modules/interoperability/schemas.ts | 16 ++------------ .../cc_commands/channel_terminated.ts | 3 ++- .../cc_commands/channel_terminated.spec.ts | 21 +++---------------- .../cc_commands/channel_terminated.spec.ts | 21 +++---------------- 6 files changed, 15 insertions(+), 70 deletions(-) rename framework/src/modules/interoperability/{base => base_classes}/cc_commands/channel_terminated.ts (64%) diff --git a/framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts similarity index 64% rename from framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts rename to framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts index 8aff7e97806..4a110749891 100644 --- a/framework/src/modules/interoperability/base/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts @@ -12,12 +12,12 @@ * Removal or modification of this copyright notice is prohibited. */ -import { codec } from '@liskhq/lisk-codec'; import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; import { channelTerminatedCCMParamsSchema } from '../../schemas'; import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; -import { CCCommandExecuteContext, ChannelTerminatedCCMParams } from '../../types'; +import { CCCommandExecuteContext } from '../../types'; +// LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export abstract class BaseCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { public schema = channelTerminatedCCMParamsSchema; @@ -31,22 +31,7 @@ export abstract class BaseCCChannelTerminatedCommand extends BaseInteroperabilit if (!context.ccm) { throw new Error('CCM to execute channel terminated cross chain command is missing.'); } - const ccmParamsChannel = await interoperabilityStore.getChannel(context.chainID); - const channelTerminatedCCMParams = codec.decode( - this.schema, - context.ccm.params, - ); - await interoperabilityStore.createTerminatedStateAccount( - context, - context.ccm.sendingChainID, - channelTerminatedCCMParams.stateRoot, - ); - await interoperabilityStore.createTerminatedOutboxAccount( - context.ccm.sendingChainID, - ccmParamsChannel.outbox.root, - ccmParamsChannel.outbox.size, - channelTerminatedCCMParams.inboxSize, - ); + await interoperabilityStore.createTerminatedStateAccount(context, context.ccm.sendingChainID); } } } diff --git a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts index 2845e315f11..d5da25f03eb 100644 --- a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts @@ -14,8 +14,9 @@ import { StoreGetter } from '../../../base_store'; import { MainchainInteroperabilityStore } from '../store'; -import { BaseCCChannelTerminatedCommand } from '../../base/cc_commands/channel_terminated'; +import { BaseCCChannelTerminatedCommand } from '../../base_classes/cc_commands/channel_terminated'; +// LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export class MainchainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { protected getInteroperabilityStore(context: StoreGetter): MainchainInteroperabilityStore { return new MainchainInteroperabilityStore( diff --git a/framework/src/modules/interoperability/schemas.ts b/framework/src/modules/interoperability/schemas.ts index 667bf7843d0..2592d4f6a8b 100644 --- a/framework/src/modules/interoperability/schemas.ts +++ b/framework/src/modules/interoperability/schemas.ts @@ -27,7 +27,6 @@ import { MAX_CHAIN_NAME_LENGTH, BLS_PUBLIC_KEY_LENGTH, BLS_SIGNATURE_LENGTH, - HASH_LENGTH, } from './constants'; import { chainAccountSchema } from './stores/chain_account'; import { chainValidatorsSchema } from './stores/chain_validators'; @@ -346,19 +345,8 @@ export const registrationCCMParamsSchema = { export const channelTerminatedCCMParamsSchema = { $id: '/modules/interoperability/ccCommand/channelTerminated', type: 'object', - required: ['stateRoot', 'inboxSize'], - properties: { - stateRoot: { - dataType: 'bytes', - minLength: HASH_LENGTH, - maxLength: HASH_LENGTH, - fieldNumber: 1, - }, - inboxSize: { - dataType: 'uint32', - fieldNumber: 2, - }, - }, + required: [], + properties: {}, }; export const sidechainTerminatedCCMParamsSchema = { diff --git a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts index 493065c04a4..dd20c1a3200 100644 --- a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts @@ -14,8 +14,9 @@ import { ImmutableStoreGetter, StoreGetter } from '../../../base_store'; import { SidechainInteroperabilityStore } from '../store'; -import { BaseCCChannelTerminatedCommand } from '../../base/cc_commands/channel_terminated'; +import { BaseCCChannelTerminatedCommand } from '../../base_classes/cc_commands/channel_terminated'; +// LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export class SidechainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { protected getInteroperabilityStore( context: StoreGetter | ImmutableStoreGetter, diff --git a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts index 471e9362cbd..524fe9b70c6 100644 --- a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts @@ -12,11 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { codec } from '@liskhq/lisk-codec'; import { utils } from '@liskhq/lisk-cryptography'; import { MainchainInteroperabilityModule } from '../../../../../../src'; import { CROSS_CHAIN_COMMAND_NAME_REGISTRATION, + EMPTY_BYTES, MODULE_NAME_INTEROPERABILITY, } from '../../../../../../src/modules/interoperability/constants'; import { MainchainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/mainchain/cc_commands/channel_terminated'; @@ -24,12 +24,10 @@ import { MainchainInteroperabilityStore } from '../../../../../../src/modules/in import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; -import { channelTerminatedCCMParamsSchema } from '../../../../../../src/modules/interoperability/schemas'; describe('MainchainCCChannelTerminatedCommand', () => { const interopMod = new MainchainInteroperabilityModule(); const createTerminatedStateAccountMock = jest.fn(); - const createTerminatedOutboxAccountMock = jest.fn(); const ccMethodMod1 = { beforeSendCCM: jest.fn(), @@ -43,10 +41,6 @@ describe('MainchainCCChannelTerminatedCommand', () => { ccMethodsMap.set(1, ccMethodMod1); ccMethodsMap.set(2, ccMethodMod2); const chainID = utils.getRandomBytes(32); - const ccmParams = { - stateRoot: Buffer.from('10000000', 'hex'), - inboxSize: 1, - }; const ccm = { nonce: BigInt(0), module: MODULE_NAME_INTEROPERABILITY, @@ -55,7 +49,7 @@ describe('MainchainCCChannelTerminatedCommand', () => { receivingChainID: utils.intToBuffer(3, 4), fee: BigInt(20000), status: 0, - params: codec.encode(channelTerminatedCCMParamsSchema, ccmParams), + params: EMPTY_BYTES, }; const sampleExecuteContext: CCCommandExecuteContext = createExecuteCCMsgMethodContext({ ccm, @@ -74,7 +68,6 @@ describe('MainchainCCChannelTerminatedCommand', () => { new NamedRegistry(), ); mainchainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; - mainchainInteroperabilityStore.createTerminatedOutboxAccount = createTerminatedOutboxAccountMock; mainchainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(false); (ccChannelTerminatedCommand as any)['getInteroperabilityStore'] = jest .fn() @@ -91,23 +84,15 @@ describe('MainchainCCChannelTerminatedCommand', () => { it('should skip if isLive is false ', async () => { await ccChannelTerminatedCommand.execute(sampleExecuteContext); expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); - expect(createTerminatedOutboxAccountMock).toHaveBeenCalledTimes(0); }); - it('should call createTerminatedStateAccount and createTerminatedOutboxAccount if isLive', async () => { + it('should call createTerminatedStateAccount if isLive', async () => { mainchainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(true); await ccChannelTerminatedCommand.execute(sampleExecuteContext); expect(createTerminatedStateAccountMock).toHaveBeenCalledWith( sampleExecuteContext, ccm.sendingChainID, - ccmParams.stateRoot, - ); - expect(createTerminatedOutboxAccountMock).toHaveBeenCalledWith( - ccm.sendingChainID, - channelOutbox.root, - channelOutbox.size, - ccmParams.inboxSize, ); }); }); diff --git a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts index fe93902d2b9..c4776a3b7b4 100644 --- a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts @@ -12,11 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { codec } from '@liskhq/lisk-codec'; import { utils } from '@liskhq/lisk-cryptography'; import { SidechainInteroperabilityModule } from '../../../../../../src'; import { CROSS_CHAIN_COMMAND_NAME_REGISTRATION, + EMPTY_BYTES, MODULE_NAME_INTEROPERABILITY, } from '../../../../../../src/modules/interoperability/constants'; import { SidechainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/sidechain/cc_commands'; @@ -24,12 +24,10 @@ import { SidechainInteroperabilityStore } from '../../../../../../src/modules/in import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; import { NamedRegistry } from '../../../../../../src/modules/named_registry'; import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; -import { channelTerminatedCCMParamsSchema } from '../../../../../../src/modules/interoperability/schemas'; describe('SidechainCCChannelTerminatedCommand', () => { const interopMod = new SidechainInteroperabilityModule(); const createTerminatedStateAccountMock = jest.fn(); - const createTerminatedOutboxAccountMock = jest.fn(); const ccMethodMod1 = { beforeSendCCM: jest.fn(), @@ -43,10 +41,6 @@ describe('SidechainCCChannelTerminatedCommand', () => { ccMethodsMap.set(1, ccMethodMod1); ccMethodsMap.set(2, ccMethodMod2); const chainID = utils.getRandomBytes(32); - const ccmParams = { - stateRoot: Buffer.from('10000000', 'hex'), - inboxSize: 1, - }; const ccm = { nonce: BigInt(0), module: MODULE_NAME_INTEROPERABILITY, @@ -55,7 +49,7 @@ describe('SidechainCCChannelTerminatedCommand', () => { receivingChainID: utils.intToBuffer(3, 4), fee: BigInt(20000), status: 0, - params: codec.encode(channelTerminatedCCMParamsSchema, ccmParams), + params: EMPTY_BYTES, }; const sampleExecuteContext: CCCommandExecuteContext = createExecuteCCMsgMethodContext({ ccm, @@ -74,7 +68,6 @@ describe('SidechainCCChannelTerminatedCommand', () => { new NamedRegistry(), ); sidechainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; - sidechainInteroperabilityStore.createTerminatedOutboxAccount = createTerminatedOutboxAccountMock; sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(false); (ccChannelTerminatedCommand as any)['getInteroperabilityStore'] = jest .fn() @@ -91,23 +84,15 @@ describe('SidechainCCChannelTerminatedCommand', () => { it('should skip if isLive is false ', async () => { await ccChannelTerminatedCommand.execute(sampleExecuteContext); expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); - expect(createTerminatedOutboxAccountMock).toHaveBeenCalledTimes(0); }); - it('should call createTerminatedStateAccount and createTerminatedOutboxAccount if isLive', async () => { + it('should call createTerminatedStateAccount if isLive', async () => { sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(true); await ccChannelTerminatedCommand.execute(sampleExecuteContext); expect(createTerminatedStateAccountMock).toHaveBeenCalledWith( sampleExecuteContext, ccm.sendingChainID, - ccmParams.stateRoot, - ); - expect(createTerminatedOutboxAccountMock).toHaveBeenCalledWith( - ccm.sendingChainID, - channelOutbox.root, - channelOutbox.size, - ccmParams.inboxSize, ); }); }); From 89e571b31190aea592a923cb7fcf23f6bbc19c7f Mon Sep 17 00:00:00 2001 From: Franco NG Date: Fri, 28 Oct 2022 15:25:59 +0200 Subject: [PATCH 5/9] Rename Base Class file --- .../channel_terminated.ts | 8 ++++---- .../mainchain/cc_commands/channel_terminated.ts | 2 +- .../sidechain/cc_commands/channel_terminated.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename framework/src/modules/interoperability/{base_classes/cc_commands => base_cc_commands}/channel_terminated.ts (85%) diff --git a/framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/base_cc_commands/channel_terminated.ts similarity index 85% rename from framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts rename to framework/src/modules/interoperability/base_cc_commands/channel_terminated.ts index 4a110749891..8333a638646 100644 --- a/framework/src/modules/interoperability/base_classes/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/base_cc_commands/channel_terminated.ts @@ -12,10 +12,10 @@ * Removal or modification of this copyright notice is prohibited. */ -import { BaseInteroperabilityCCCommand } from '../../base_interoperability_cc_commands'; -import { channelTerminatedCCMParamsSchema } from '../../schemas'; -import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../../constants'; -import { CCCommandExecuteContext } from '../../types'; +import { BaseInteroperabilityCCCommand } from '../base_interoperability_cc_commands'; +import { channelTerminatedCCMParamsSchema } from '../schemas'; +import { CROSS_CHAIN_COMMAND_NAME_CHANNEL_TERMINATED } from '../constants'; +import { CCCommandExecuteContext } from '../types'; // LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export abstract class BaseCCChannelTerminatedCommand extends BaseInteroperabilityCCCommand { diff --git a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts index d5da25f03eb..53fc2e830cb 100644 --- a/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/mainchain/cc_commands/channel_terminated.ts @@ -14,7 +14,7 @@ import { StoreGetter } from '../../../base_store'; import { MainchainInteroperabilityStore } from '../store'; -import { BaseCCChannelTerminatedCommand } from '../../base_classes/cc_commands/channel_terminated'; +import { BaseCCChannelTerminatedCommand } from '../../base_cc_commands/channel_terminated'; // LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export class MainchainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { diff --git a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts index dd20c1a3200..90cad3febfb 100644 --- a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts @@ -14,7 +14,7 @@ import { ImmutableStoreGetter, StoreGetter } from '../../../base_store'; import { SidechainInteroperabilityStore } from '../store'; -import { BaseCCChannelTerminatedCommand } from '../../base_classes/cc_commands/channel_terminated'; +import { BaseCCChannelTerminatedCommand } from '../../base_cc_commands/channel_terminated'; // LIP-0049 https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export class SidechainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { From f13b31ef17b3bccdcf7c0c6d22e2d79d68b0c9ed Mon Sep 17 00:00:00 2001 From: Franco NG Date: Mon, 31 Oct 2022 16:14:16 +0100 Subject: [PATCH 6/9] Remove unused interface and update link --- framework/src/modules/interoperability/schemas.ts | 2 +- framework/src/modules/interoperability/types.ts | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/framework/src/modules/interoperability/schemas.ts b/framework/src/modules/interoperability/schemas.ts index 9cfda0c5a79..a3804edfac1 100644 --- a/framework/src/modules/interoperability/schemas.ts +++ b/framework/src/modules/interoperability/schemas.ts @@ -341,7 +341,7 @@ export const registrationCCMParamsSchema = { }, }; -// https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 +// https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#parameters-1 export const channelTerminatedCCMParamsSchema = { $id: '/modules/interoperability/ccCommand/channelTerminated', type: 'object', diff --git a/framework/src/modules/interoperability/types.ts b/framework/src/modules/interoperability/types.ts index a071ac9dcab..7f897a51fa3 100644 --- a/framework/src/modules/interoperability/types.ts +++ b/framework/src/modules/interoperability/types.ts @@ -363,8 +363,3 @@ export interface GenesisInteroperabilityStore { storeValue: ChainID; }[]; } - -export interface ChannelTerminatedCCMParams { - stateRoot: Buffer; - inboxSize: number; -} From 27274b59a8887d58f7784db6d15c2ee9a2dd72f0 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Wed, 2 Nov 2022 10:42:12 +0100 Subject: [PATCH 7/9] Simplify test cases --- .../channel_terminated.spec.ts | 16 +-- .../cc_commands/channel_terminated.spec.ts | 99 ------------------- 2 files changed, 8 insertions(+), 107 deletions(-) rename framework/test/unit/modules/interoperability/{mainchain/cc_commands => base_cc_commands}/channel_terminated.spec.ts (85%) delete mode 100644 framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts diff --git a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts similarity index 85% rename from framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts rename to framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts index 524fe9b70c6..f93c3025752 100644 --- a/framework/test/unit/modules/interoperability/mainchain/cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts @@ -13,19 +13,19 @@ */ import { utils } from '@liskhq/lisk-cryptography'; -import { MainchainInteroperabilityModule } from '../../../../../../src'; +import { MainchainInteroperabilityModule } from '../../../../../src'; import { CROSS_CHAIN_COMMAND_NAME_REGISTRATION, EMPTY_BYTES, MODULE_NAME_INTEROPERABILITY, -} from '../../../../../../src/modules/interoperability/constants'; -import { MainchainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/mainchain/cc_commands/channel_terminated'; -import { MainchainInteroperabilityStore } from '../../../../../../src/modules/interoperability/mainchain/store'; -import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; -import { NamedRegistry } from '../../../../../../src/modules/named_registry'; -import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; +} from '../../../../../src/modules/interoperability/constants'; +import { MainchainCCChannelTerminatedCommand } from '../../../../../src/modules/interoperability/mainchain/cc_commands'; +import { MainchainInteroperabilityStore } from '../../../../../src/modules/interoperability/mainchain/store'; +import { CCCommandExecuteContext } from '../../../../../src/modules/interoperability/types'; +import { NamedRegistry } from '../../../../../src/modules/named_registry'; +import { createExecuteCCMsgMethodContext } from '../../../../../src/testing'; -describe('MainchainCCChannelTerminatedCommand', () => { +describe('BaseCCChannelTerminatedCommand', () => { const interopMod = new MainchainInteroperabilityModule(); const createTerminatedStateAccountMock = jest.fn(); diff --git a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts deleted file mode 100644 index c4776a3b7b4..00000000000 --- a/framework/test/unit/modules/interoperability/sidechain/cc_commands/channel_terminated.spec.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright © 2022 Lisk Foundation - * - * See the LICENSE file at the top-level directory of this distribution - * for licensing information. - * - * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, - * no part of this software, including this file, may be copied, modified, - * propagated, or distributed except according to the terms contained in the - * LICENSE file. - * - * Removal or modification of this copyright notice is prohibited. - */ - -import { utils } from '@liskhq/lisk-cryptography'; -import { SidechainInteroperabilityModule } from '../../../../../../src'; -import { - CROSS_CHAIN_COMMAND_NAME_REGISTRATION, - EMPTY_BYTES, - MODULE_NAME_INTEROPERABILITY, -} from '../../../../../../src/modules/interoperability/constants'; -import { SidechainCCChannelTerminatedCommand } from '../../../../../../src/modules/interoperability/sidechain/cc_commands'; -import { SidechainInteroperabilityStore } from '../../../../../../src/modules/interoperability/sidechain/store'; -import { CCCommandExecuteContext } from '../../../../../../src/modules/interoperability/types'; -import { NamedRegistry } from '../../../../../../src/modules/named_registry'; -import { createExecuteCCMsgMethodContext } from '../../../../../../src/testing'; - -describe('SidechainCCChannelTerminatedCommand', () => { - const interopMod = new SidechainInteroperabilityModule(); - const createTerminatedStateAccountMock = jest.fn(); - - const ccMethodMod1 = { - beforeSendCCM: jest.fn(), - beforeApplyCCM: jest.fn(), - }; - const ccMethodMod2 = { - beforeSendCCM: jest.fn(), - beforeApplyCCM: jest.fn(), - }; - const ccMethodsMap = new Map(); - ccMethodsMap.set(1, ccMethodMod1); - ccMethodsMap.set(2, ccMethodMod2); - const chainID = utils.getRandomBytes(32); - const ccm = { - nonce: BigInt(0), - module: MODULE_NAME_INTEROPERABILITY, - crossChainCommand: CROSS_CHAIN_COMMAND_NAME_REGISTRATION, - sendingChainID: utils.intToBuffer(2, 4), - receivingChainID: utils.intToBuffer(3, 4), - fee: BigInt(20000), - status: 0, - params: EMPTY_BYTES, - }; - const sampleExecuteContext: CCCommandExecuteContext = createExecuteCCMsgMethodContext({ - ccm, - chainID, - }); - - const ccChannelTerminatedCommand = new SidechainCCChannelTerminatedCommand( - interopMod.stores, - interopMod.events, - ccMethodsMap, - ); - const sidechainInteroperabilityStore = new SidechainInteroperabilityStore( - interopMod.stores, - sampleExecuteContext, - ccMethodsMap, - new NamedRegistry(), - ); - sidechainInteroperabilityStore.createTerminatedStateAccount = createTerminatedStateAccountMock; - sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(false); - (ccChannelTerminatedCommand as any)['getInteroperabilityStore'] = jest - .fn() - .mockReturnValue(sidechainInteroperabilityStore); - const channelOutbox = { - size: 10, - root: Buffer.from('01', 'hex'), - }; - sidechainInteroperabilityStore.getChannel = jest.fn().mockResolvedValue({ - outbox: channelOutbox, - }); - - describe('execute', () => { - it('should skip if isLive is false ', async () => { - await ccChannelTerminatedCommand.execute(sampleExecuteContext); - expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); - }); - - it('should call createTerminatedStateAccount if isLive', async () => { - sidechainInteroperabilityStore.isLive = jest.fn().mockResolvedValue(true); - - await ccChannelTerminatedCommand.execute(sampleExecuteContext); - expect(createTerminatedStateAccountMock).toHaveBeenCalledWith( - sampleExecuteContext, - ccm.sendingChainID, - ); - }); - }); -}); From ee16d6b9396e5545ca0fab0b4d067052157742f7 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Fri, 4 Nov 2022 11:33:34 +0100 Subject: [PATCH 8/9] Moving mockResolvedValue inside it block --- .../base_cc_commands/channel_terminated.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts b/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts index 48a0f9de571..46605aee777 100644 --- a/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts +++ b/framework/test/unit/modules/interoperability/base_cc_commands/channel_terminated.spec.ts @@ -68,13 +68,14 @@ describe('BaseCCChannelTerminatedCommand', () => { ccMethodsMap, ); mainchainInteroperabilityInternalMethod.createTerminatedStateAccount = createTerminatedStateAccountMock; - mainchainInteroperabilityInternalMethod.isLive = jest.fn().mockResolvedValue(false); (ccChannelTerminatedCommand as any)[ 'getInteroperabilityInternalMethod' ] = jest.fn().mockReturnValue(mainchainInteroperabilityInternalMethod); describe('execute', () => { it('should skip if isLive is false ', async () => { + mainchainInteroperabilityInternalMethod.isLive = jest.fn().mockResolvedValue(false); + await ccChannelTerminatedCommand.execute(sampleExecuteContext); expect(createTerminatedStateAccountMock).toHaveBeenCalledTimes(0); }); From 8da2be32656af407ba88fc121ea0e163ea63a986 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Mon, 7 Nov 2022 09:44:59 +0100 Subject: [PATCH 9/9] Removing ImmutableStoreGetter from SidechainCCChannelTerminatedCommand --- .../sidechain/cc_commands/channel_terminated.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts index 71869d9a673..01c1bce4072 100644 --- a/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts +++ b/framework/src/modules/interoperability/sidechain/cc_commands/channel_terminated.ts @@ -12,14 +12,14 @@ * Removal or modification of this copyright notice is prohibited. */ -import { ImmutableStoreGetter, StoreGetter } from '../../../base_store'; +import { StoreGetter } from '../../../base_store'; import { SidechainInteroperabilityInternalMethod } from '../store'; import { BaseCCChannelTerminatedCommand } from '../../base_cc_commands/channel_terminated'; // https://github.com/LiskHQ/lips/blob/main/proposals/lip-0049.md#channel-terminated-message-1 export class SidechainCCChannelTerminatedCommand extends BaseCCChannelTerminatedCommand { protected getInteroperabilityInternalMethod( - context: StoreGetter | ImmutableStoreGetter, + context: StoreGetter, ): SidechainInteroperabilityInternalMethod { return new SidechainInteroperabilityInternalMethod( this.stores,