From 0e37eef359cdf05753573b767d084f5a363cb56d Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:04:47 +0200 Subject: [PATCH 01/15] Update constants.ts --- framework/src/modules/interoperability/constants.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/src/modules/interoperability/constants.ts b/framework/src/modules/interoperability/constants.ts index 6e776b86f9e..e73a2742945 100644 --- a/framework/src/modules/interoperability/constants.ts +++ b/framework/src/modules/interoperability/constants.ts @@ -19,6 +19,8 @@ export const MODULE_NAME_INTEROPERABILITY = 'interoperability'; export const MAINCHAIN_ID = 1; export const LIVENESS_LIMIT = 2592000; // 30*24*3600 export const MAX_CCM_SIZE = 10240; +export const EMPTY_FEE_ADDRESS = Buffer.alloc(0); +export const EMPTY_BYTES = Buffer.alloc(0); // Store prefixes export const STORE_PREFIX_OUTBOX_ROOT = 0x0000; @@ -35,3 +37,7 @@ export const STORE_PREFIX_REGISTERED_NETWORK_IDS = 0xf000; export const CHAIN_REGISTERED = 0; export const CHAIN_ACTIVE = 1; export const CHAIN_TERMINATED = 2; + +// Cross chain commands +export const CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED = 1; +export const CCM_STATUS_OK = 0; From dcb8268a45827c025c10e2ca748d836b59286a7a Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:06:07 +0200 Subject: [PATCH 02/15] Update base_interoperability_store.ts --- .../base_interoperability_store.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/framework/src/modules/interoperability/base_interoperability_store.ts b/framework/src/modules/interoperability/base_interoperability_store.ts index 0436ad39c9e..479cba4c199 100644 --- a/framework/src/modules/interoperability/base_interoperability_store.ts +++ b/framework/src/modules/interoperability/base_interoperability_store.ts @@ -38,6 +38,7 @@ import { } from './schema'; import { BaseInteroperableModule } from './base_interoperable_module'; import { + BeforeSendCCMsgAPIContext, ChannelData, CCMsg, CCUpdateParams, @@ -136,7 +137,7 @@ export abstract class BaseInteroperabilityStore { return chainSubstore.getWithSchema(chainID, chainAccountSchema); } - public async chainAccountExist(chainID: Buffer): Promise { + public async chainAccountExist(chainID: Buffer): Promise { const chainSubstore = this.getStore(MODULE_ID_INTEROPERABILITY, STORE_PREFIX_CHAIN_DATA); try { await chainSubstore.getWithSchema(chainID, chainAccountSchema); @@ -183,12 +184,21 @@ export abstract class BaseInteroperabilityStore { // Different in mainchain and sidechain so to be implemented in each module store separately public abstract isLive(chainID: Buffer, timestamp?: number): Promise; - public abstract sendInternal(sendContext: SendInternalContext): Promise; + public abstract sendInternal( + sendContext: SendInternalContext, + beforeSendContext: BeforeSendCCMsgAPIContext, + ): Promise; // To be implemented in base class public abstract apply(ccu: CCUpdateParams, ccm: CCMsg): Promise; - public abstract terminateChainInternal(chainID: number): Promise; - public abstract createTerminatedStateAccount(chainID: Buffer, stateRoot?: Buffer): Promise; + public abstract terminateChainInternal( + chainID: number, + beforeSendContext: BeforeSendCCMsgAPIContext, + ): Promise; + public abstract createTerminatedStateAccount( + chainID: number, + stateRoot?: Buffer, + ): Promise; public abstract getInboxRoot(chainID: number): Promise; public abstract getOutboxRoot(chainID: number): Promise; public abstract getChannel(chainID: number): Promise; // TODO: Update to Promise after implementation From 1180c8157966cde88e49f1aec86215c6ca10648f Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:06:27 +0200 Subject: [PATCH 03/15] Add terminateChainInternal mainchain --- .../interoperability/mainchain/store.ts | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/framework/src/modules/interoperability/mainchain/store.ts b/framework/src/modules/interoperability/mainchain/store.ts index 6d5e1c33c3d..9a5163c6a87 100644 --- a/framework/src/modules/interoperability/mainchain/store.ts +++ b/framework/src/modules/interoperability/mainchain/store.ts @@ -14,8 +14,15 @@ import { NotFoundError } from '@liskhq/lisk-chain'; import { BaseInteroperabilityStore } from '../base_interoperability_store'; -import { CHAIN_ACTIVE, LIVENESS_LIMIT } from '../constants'; -import { CCMsg, CCUpdateParams, SendInternalContext } from '../types'; +import { + MODULE_ID_INTEROPERABILITY, + CCM_STATUS_OK, + CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + CHAIN_ACTIVE, + LIVENESS_LIMIT, + EMPTY_BYTES, +} from '../constants'; +import { BeforeSendCCMsgAPIContext, CCMsg, CCUpdateParams, SendInternalContext } from '../types'; import { getIDAsKeyForStore, validateFormat } from '../utils'; export class MainchainInteroperabilityStore extends BaseInteroperabilityStore { @@ -101,6 +108,28 @@ export class MainchainInteroperabilityStore extends BaseInteroperabilityStore { return true; } + public async terminateChainInternal( + chainID: number, + beforeSendContext: BeforeSendCCMsgAPIContext, + ): Promise { + const messageSent = await this.sendInternal({ + moduleID: MODULE_ID_INTEROPERABILITY, + crossChainCommandID: CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + receivingChainID: chainID, + fee: BigInt(0), + status: CCM_STATUS_OK, + params: EMPTY_BYTES, + timestamp: Date.now(), + beforeSendContext, + }); + + if (!messageSent) { + return false; + } + + return this.createTerminatedStateAccount(chainID); + } + // eslint-disable-next-line @typescript-eslint/require-await public async getChannel(chainID: number): Promise { // eslint-disable-next-line no-console @@ -108,15 +137,12 @@ export class MainchainInteroperabilityStore extends BaseInteroperabilityStore { } // eslint-disable-next-line @typescript-eslint/require-await - public async createTerminatedStateAccount(chainID: Buffer, stateRoot?: Buffer): Promise { + public async createTerminatedStateAccount(chainID: number, stateRoot?: Buffer): Promise { // eslint-disable-next-line no-console console.log(chainID, stateRoot); - } - // eslint-disable-next-line @typescript-eslint/require-await - public async terminateChainInternal(chainID: number): Promise { - // eslint-disable-next-line no-console - console.log(chainID); + // TODO: Update after implementation + return true; } // eslint-disable-next-line @typescript-eslint/require-await From 403fa7d985285120f565dfbd786b12d3e21add6b Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:06:37 +0200 Subject: [PATCH 04/15] Add terminateChainInternal sidechain --- .../interoperability/sidechain/store.ts | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/framework/src/modules/interoperability/sidechain/store.ts b/framework/src/modules/interoperability/sidechain/store.ts index ccaf8af94e4..91f6abebf9f 100644 --- a/framework/src/modules/interoperability/sidechain/store.ts +++ b/framework/src/modules/interoperability/sidechain/store.ts @@ -13,8 +13,15 @@ */ import { BaseInteroperabilityStore } from '../base_interoperability_store'; -import { CHAIN_ACTIVE, MAINCHAIN_ID } from '../constants'; -import { CCMsg, CCUpdateParams, SendInternalContext } from '../types'; +import { + CCM_STATUS_OK, + CHAIN_ACTIVE, + CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + EMPTY_BYTES, + MAINCHAIN_ID, + MODULE_ID_INTEROPERABILITY, +} from '../constants'; +import { BeforeSendCCMsgAPIContext, CCMsg, CCUpdateParams, SendInternalContext } from '../types'; import { getIDAsKeyForStore, validateFormat } from '../utils'; export class SidechainInteroperabilityStore extends BaseInteroperabilityStore { @@ -88,6 +95,28 @@ export class SidechainInteroperabilityStore extends BaseInteroperabilityStore { return true; } + public async terminateChainInternal( + chainID: number, + beforeSendContext: BeforeSendCCMsgAPIContext, + ): Promise { + const messageSent = await this.sendInternal({ + moduleID: MODULE_ID_INTEROPERABILITY, + crossChainCommandID: CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + receivingChainID: chainID, + fee: BigInt(0), + status: CCM_STATUS_OK, + params: EMPTY_BYTES, + timestamp: Date.now(), + beforeSendContext, + }); + + if (!messageSent) { + return false; + } + + return this.createTerminatedStateAccount(chainID); + } + // eslint-disable-next-line @typescript-eslint/require-await public async getChannel(chainID: number): Promise { // eslint-disable-next-line no-console @@ -95,15 +124,12 @@ export class SidechainInteroperabilityStore extends BaseInteroperabilityStore { } // eslint-disable-next-line @typescript-eslint/require-await - public async createTerminatedStateAccount(chainID: Buffer, stateRoot?: Buffer): Promise { + public async createTerminatedStateAccount(chainID: number, stateRoot?: Buffer): Promise { // eslint-disable-next-line no-console console.log(chainID, stateRoot); - } - // eslint-disable-next-line @typescript-eslint/require-await - public async terminateChainInternal(chainID: number): Promise { - // eslint-disable-next-line no-console - console.log(chainID); + // TODO: Update after implementation + return true; } // eslint-disable-next-line @typescript-eslint/require-await From edde4f1cfe4cce8663739e233ef41e6a43fad6de Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:41:27 +0200 Subject: [PATCH 05/15] Add mainchain test --- .../interoperability/mainchain/store.spec.ts | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/framework/test/unit/modules/interoperability/mainchain/store.spec.ts b/framework/test/unit/modules/interoperability/mainchain/store.spec.ts index a126006fb2b..c8e90111fc2 100644 --- a/framework/test/unit/modules/interoperability/mainchain/store.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/store.spec.ts @@ -337,4 +337,63 @@ describe('Mainchain interoperability store', () => { expect(mod2.crossChainAPI.beforeSendCCM).toHaveBeenCalledTimes(1); }); }); + + describe('terminateChainInternal', () => { + const ccm = { + nonce: BigInt(0), + moduleID: 1, + crossChainCommandID: 1, + sendingChainID: 2, + receivingChainID: 3, + fee: BigInt(1), + status: 1, + params: Buffer.alloc(0), + }; + const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ + ccm, + feeAddress: getRandomBytes(32), + }); + + beforeEach(() => { + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(true); + }); + + it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + MAINCHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(true); + }); + + it('should return false if sendInternal returns false', async () => { + // Arrange + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + MAINCHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + + it('should return false if createTerminatedStateAccount returns false', async () => { + // Arrange + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + MAINCHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + }); }); From 6724af65dce57f0882ce60a5c828b70590d52c3a Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:41:37 +0200 Subject: [PATCH 06/15] Add sidechain test --- .../interoperability/sidechain/store.spec.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/framework/test/unit/modules/interoperability/sidechain/store.spec.ts b/framework/test/unit/modules/interoperability/sidechain/store.spec.ts index 54ab3de3c0a..201d36416df 100644 --- a/framework/test/unit/modules/interoperability/sidechain/store.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/store.spec.ts @@ -382,4 +382,64 @@ describe('Sidechain interoperability store', () => { expect(mod2.crossChainAPI.beforeSendCCM).toHaveBeenCalledTimes(1); }); }); + + describe('terminateChainInternal', () => { + const SIDECHAIN_ID = 2; + const ccm = { + nonce: BigInt(0), + moduleID: 1, + crossChainCommandID: 1, + sendingChainID: 2, + receivingChainID: 3, + fee: BigInt(1), + status: 1, + params: Buffer.alloc(0), + }; + const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ + ccm, + feeAddress: getRandomBytes(32), + }); + + beforeEach(() => { + sidechainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); + sidechainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(true); + }); + + it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { + expect( + await sidechainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(true); + }); + + it('should return false if sendInternal returns false', async () => { + // Arrange + sidechainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); + + expect( + await sidechainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + + it('should return false if createTerminatedStateAccount returns false', async () => { + // Arrange + sidechainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(false); + + expect( + await sidechainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + }); }); From 5eee0bb2801651e5d453abf32a9946445d3e0ab6 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 11:58:41 +0200 Subject: [PATCH 07/15] Update base_interoperability_store.ts --- .../modules/interoperability/base_interoperability_store.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/src/modules/interoperability/base_interoperability_store.ts b/framework/src/modules/interoperability/base_interoperability_store.ts index 479cba4c199..973e99a51a4 100644 --- a/framework/src/modules/interoperability/base_interoperability_store.ts +++ b/framework/src/modules/interoperability/base_interoperability_store.ts @@ -184,10 +184,7 @@ export abstract class BaseInteroperabilityStore { // Different in mainchain and sidechain so to be implemented in each module store separately public abstract isLive(chainID: Buffer, timestamp?: number): Promise; - public abstract sendInternal( - sendContext: SendInternalContext, - beforeSendContext: BeforeSendCCMsgAPIContext, - ): Promise; + public abstract sendInternal(sendContext: SendInternalContext): Promise; // To be implemented in base class public abstract apply(ccu: CCUpdateParams, ccm: CCMsg): Promise; From ece97ceb202b95d0d3f9b89192389fbdc3dd3232 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:30:36 +0200 Subject: [PATCH 08/15] Update base_interoperability_store.ts --- .../base_interoperability_store.ts | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/framework/src/modules/interoperability/base_interoperability_store.ts b/framework/src/modules/interoperability/base_interoperability_store.ts index 973e99a51a4..c0ec7bb0669 100644 --- a/framework/src/modules/interoperability/base_interoperability_store.ts +++ b/framework/src/modules/interoperability/base_interoperability_store.ts @@ -18,6 +18,9 @@ import { hash } from '@liskhq/lisk-cryptography'; import { regularMerkleTree } from '@liskhq/lisk-tree'; import { SubStore } from '../../node/state_machine/types'; import { + CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + CCM_STATUS_OK, + EMPTY_BYTES, MODULE_ID_INTEROPERABILITY, STORE_PREFIX_CHAIN_DATA, STORE_PREFIX_TERMINATED_STATE, @@ -182,16 +185,35 @@ export abstract class BaseInteroperabilityStore { await terminatedOutboxSubstore.setWithSchema(chainID, terminatedOutbox, terminatedOutboxSchema); } + public async terminateChainInternal( + chainID: number, + beforeSendContext: BeforeSendCCMsgAPIContext, + ): Promise { + const messageSent = await this.sendInternal({ + moduleID: MODULE_ID_INTEROPERABILITY, + crossChainCommandID: CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, + receivingChainID: chainID, + fee: BigInt(0), + status: CCM_STATUS_OK, + params: EMPTY_BYTES, + timestamp: Date.now(), + beforeSendContext, + }); + + if (!messageSent) { + return false; + } + + return this.createTerminatedStateAccount(chainID); + } + // Different in mainchain and sidechain so to be implemented in each module store separately public abstract isLive(chainID: Buffer, timestamp?: number): Promise; public abstract sendInternal(sendContext: SendInternalContext): Promise; // To be implemented in base class public abstract apply(ccu: CCUpdateParams, ccm: CCMsg): Promise; - public abstract terminateChainInternal( - chainID: number, - beforeSendContext: BeforeSendCCMsgAPIContext, - ): Promise; + public abstract createTerminatedStateAccount( chainID: number, stateRoot?: Buffer, From 24abf378524656773dcad0daea3fa2b4a34da706 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:31:00 +0200 Subject: [PATCH 09/15] Update store.ts --- .../interoperability/mainchain/store.ts | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/framework/src/modules/interoperability/mainchain/store.ts b/framework/src/modules/interoperability/mainchain/store.ts index 9a5163c6a87..25a4aa2e780 100644 --- a/framework/src/modules/interoperability/mainchain/store.ts +++ b/framework/src/modules/interoperability/mainchain/store.ts @@ -14,15 +14,8 @@ import { NotFoundError } from '@liskhq/lisk-chain'; import { BaseInteroperabilityStore } from '../base_interoperability_store'; -import { - MODULE_ID_INTEROPERABILITY, - CCM_STATUS_OK, - CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, - CHAIN_ACTIVE, - LIVENESS_LIMIT, - EMPTY_BYTES, -} from '../constants'; -import { BeforeSendCCMsgAPIContext, CCMsg, CCUpdateParams, SendInternalContext } from '../types'; +import { CHAIN_ACTIVE, LIVENESS_LIMIT } from '../constants'; +import { CCMsg, CCUpdateParams, SendInternalContext } from '../types'; import { getIDAsKeyForStore, validateFormat } from '../utils'; export class MainchainInteroperabilityStore extends BaseInteroperabilityStore { @@ -108,28 +101,6 @@ export class MainchainInteroperabilityStore extends BaseInteroperabilityStore { return true; } - public async terminateChainInternal( - chainID: number, - beforeSendContext: BeforeSendCCMsgAPIContext, - ): Promise { - const messageSent = await this.sendInternal({ - moduleID: MODULE_ID_INTEROPERABILITY, - crossChainCommandID: CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, - receivingChainID: chainID, - fee: BigInt(0), - status: CCM_STATUS_OK, - params: EMPTY_BYTES, - timestamp: Date.now(), - beforeSendContext, - }); - - if (!messageSent) { - return false; - } - - return this.createTerminatedStateAccount(chainID); - } - // eslint-disable-next-line @typescript-eslint/require-await public async getChannel(chainID: number): Promise { // eslint-disable-next-line no-console From 4d5217b6fca4a97f8f8f7e87680c346fe7f7c2c2 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:31:14 +0200 Subject: [PATCH 10/15] Update store.ts --- .../interoperability/sidechain/store.ts | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/framework/src/modules/interoperability/sidechain/store.ts b/framework/src/modules/interoperability/sidechain/store.ts index 91f6abebf9f..1d0e876bde0 100644 --- a/framework/src/modules/interoperability/sidechain/store.ts +++ b/framework/src/modules/interoperability/sidechain/store.ts @@ -13,15 +13,8 @@ */ import { BaseInteroperabilityStore } from '../base_interoperability_store'; -import { - CCM_STATUS_OK, - CHAIN_ACTIVE, - CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, - EMPTY_BYTES, - MAINCHAIN_ID, - MODULE_ID_INTEROPERABILITY, -} from '../constants'; -import { BeforeSendCCMsgAPIContext, CCMsg, CCUpdateParams, SendInternalContext } from '../types'; +import { CHAIN_ACTIVE, MAINCHAIN_ID } from '../constants'; +import { CCMsg, CCUpdateParams, SendInternalContext } from '../types'; import { getIDAsKeyForStore, validateFormat } from '../utils'; export class SidechainInteroperabilityStore extends BaseInteroperabilityStore { @@ -95,28 +88,6 @@ export class SidechainInteroperabilityStore extends BaseInteroperabilityStore { return true; } - public async terminateChainInternal( - chainID: number, - beforeSendContext: BeforeSendCCMsgAPIContext, - ): Promise { - const messageSent = await this.sendInternal({ - moduleID: MODULE_ID_INTEROPERABILITY, - crossChainCommandID: CROSS_CHAIN_COMMAND_ID_CHANNEL_TERMINATED, - receivingChainID: chainID, - fee: BigInt(0), - status: CCM_STATUS_OK, - params: EMPTY_BYTES, - timestamp: Date.now(), - beforeSendContext, - }); - - if (!messageSent) { - return false; - } - - return this.createTerminatedStateAccount(chainID); - } - // eslint-disable-next-line @typescript-eslint/require-await public async getChannel(chainID: number): Promise { // eslint-disable-next-line no-console From 0889cc16694b28a6b8ff80174a6fd4f9360c44da Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:31:20 +0200 Subject: [PATCH 11/15] Update store.spec.ts --- .../interoperability/mainchain/store.spec.ts | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/framework/test/unit/modules/interoperability/mainchain/store.spec.ts b/framework/test/unit/modules/interoperability/mainchain/store.spec.ts index c8e90111fc2..a126006fb2b 100644 --- a/framework/test/unit/modules/interoperability/mainchain/store.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/store.spec.ts @@ -337,63 +337,4 @@ describe('Mainchain interoperability store', () => { expect(mod2.crossChainAPI.beforeSendCCM).toHaveBeenCalledTimes(1); }); }); - - describe('terminateChainInternal', () => { - const ccm = { - nonce: BigInt(0), - moduleID: 1, - crossChainCommandID: 1, - sendingChainID: 2, - receivingChainID: 3, - fee: BigInt(1), - status: 1, - params: Buffer.alloc(0), - }; - const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ - ccm, - feeAddress: getRandomBytes(32), - }); - - beforeEach(() => { - mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); - mainchainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(true); - }); - - it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - MAINCHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(true); - }); - - it('should return false if sendInternal returns false', async () => { - // Arrange - mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); - - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - MAINCHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - - it('should return false if createTerminatedStateAccount returns false', async () => { - // Arrange - mainchainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(false); - - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - MAINCHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - }); }); From 772372a60b000cf48ae4ba2afa93c26b8a5e59ea Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:31:54 +0200 Subject: [PATCH 12/15] Update store.spec.ts --- .../modules/interoperability/store.spec.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/framework/test/unit/modules/interoperability/store.spec.ts b/framework/test/unit/modules/interoperability/store.spec.ts index 98ca00ed7a9..d545fca8c8b 100644 --- a/framework/test/unit/modules/interoperability/store.spec.ts +++ b/framework/test/unit/modules/interoperability/store.spec.ts @@ -12,6 +12,7 @@ * Removal or modification of this copyright notice is prohibited. */ +import { getRandomBytes } from '@liskhq/lisk-cryptography'; import { regularMerkleTree } from '@liskhq/lisk-tree'; import { when } from 'jest-when'; import { @@ -26,6 +27,7 @@ import { outboxRootSchema, terminatedOutboxSchema, } from '../../../../src/modules/interoperability/schema'; +import { testing } from '../../../../src'; describe('Base interoperability store', () => { const chainID = Buffer.from('01', 'hex'); @@ -188,4 +190,64 @@ describe('Base interoperability store', () => { ); }); }); + + describe('terminateChainInternal', () => { + const SIDECHAIN_ID = 2; + const ccm = { + nonce: BigInt(0), + moduleID: 1, + crossChainCommandID: 1, + sendingChainID: 2, + receivingChainID: 3, + fee: BigInt(1), + status: 1, + params: Buffer.alloc(0), + }; + const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ + ccm, + feeAddress: getRandomBytes(32), + }); + + beforeEach(() => { + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(true); + }); + + it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(true); + }); + + it('should return false if sendInternal returns false', async () => { + // Arrange + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + + it('should return false if createTerminatedStateAccount returns false', async () => { + // Arrange + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + }); }); From 1fcfb26d5a35e9a819292d3f44643042da6e9045 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:33:15 +0200 Subject: [PATCH 13/15] Update store.spec.ts --- .../modules/interoperability/store.spec.ts | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/framework/test/unit/modules/interoperability/store.spec.ts b/framework/test/unit/modules/interoperability/store.spec.ts index d545fca8c8b..9f190b02448 100644 --- a/framework/test/unit/modules/interoperability/store.spec.ts +++ b/framework/test/unit/modules/interoperability/store.spec.ts @@ -190,64 +190,4 @@ describe('Base interoperability store', () => { ); }); }); - - describe('terminateChainInternal', () => { - const SIDECHAIN_ID = 2; - const ccm = { - nonce: BigInt(0), - moduleID: 1, - crossChainCommandID: 1, - sendingChainID: 2, - receivingChainID: 3, - fee: BigInt(1), - status: 1, - params: Buffer.alloc(0), - }; - const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ - ccm, - feeAddress: getRandomBytes(32), - }); - - beforeEach(() => { - mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); - mainchainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(true); - }); - - it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(true); - }); - - it('should return false if sendInternal returns false', async () => { - // Arrange - mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); - - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - - it('should return false if createTerminatedStateAccount returns false', async () => { - // Arrange - mainchainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(false); - - expect( - await mainchainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - }); }); From 19631e2646d2a051ba640aca7745adbab083f467 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:34:17 +0200 Subject: [PATCH 14/15] Update store.spec.ts --- .../modules/interoperability/store.spec.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/framework/test/unit/modules/interoperability/store.spec.ts b/framework/test/unit/modules/interoperability/store.spec.ts index 9f190b02448..d545fca8c8b 100644 --- a/framework/test/unit/modules/interoperability/store.spec.ts +++ b/framework/test/unit/modules/interoperability/store.spec.ts @@ -190,4 +190,64 @@ describe('Base interoperability store', () => { ); }); }); + + describe('terminateChainInternal', () => { + const SIDECHAIN_ID = 2; + const ccm = { + nonce: BigInt(0), + moduleID: 1, + crossChainCommandID: 1, + sendingChainID: 2, + receivingChainID: 3, + fee: BigInt(1), + status: 1, + params: Buffer.alloc(0), + }; + const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ + ccm, + feeAddress: getRandomBytes(32), + }); + + beforeEach(() => { + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(true); + }); + + it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(true); + }); + + it('should return false if sendInternal returns false', async () => { + // Arrange + mainchainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + + it('should return false if createTerminatedStateAccount returns false', async () => { + // Arrange + mainchainInteroperabilityStore.createTerminatedStateAccount = jest + .fn() + .mockResolvedValue(false); + + expect( + await mainchainInteroperabilityStore.terminateChainInternal( + SIDECHAIN_ID, + beforeSendCCMContext, + ), + ).toBe(false); + }); + }); }); From 92e24f6399153254e5f5540b103a1ca838652beb Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Thu, 31 Mar 2022 14:35:26 +0200 Subject: [PATCH 15/15] Update store.spec.ts --- .../interoperability/sidechain/store.spec.ts | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/framework/test/unit/modules/interoperability/sidechain/store.spec.ts b/framework/test/unit/modules/interoperability/sidechain/store.spec.ts index 201d36416df..54ab3de3c0a 100644 --- a/framework/test/unit/modules/interoperability/sidechain/store.spec.ts +++ b/framework/test/unit/modules/interoperability/sidechain/store.spec.ts @@ -382,64 +382,4 @@ describe('Sidechain interoperability store', () => { expect(mod2.crossChainAPI.beforeSendCCM).toHaveBeenCalledTimes(1); }); }); - - describe('terminateChainInternal', () => { - const SIDECHAIN_ID = 2; - const ccm = { - nonce: BigInt(0), - moduleID: 1, - crossChainCommandID: 1, - sendingChainID: 2, - receivingChainID: 3, - fee: BigInt(1), - status: 1, - params: Buffer.alloc(0), - }; - const beforeSendCCMContext = testing.createBeforeSendCCMsgAPIContext({ - ccm, - feeAddress: getRandomBytes(32), - }); - - beforeEach(() => { - sidechainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(true); - sidechainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(true); - }); - - it('should return true if sendInternal and createTerminatedStateAccount return true', async () => { - expect( - await sidechainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(true); - }); - - it('should return false if sendInternal returns false', async () => { - // Arrange - sidechainInteroperabilityStore.sendInternal = jest.fn().mockResolvedValue(false); - - expect( - await sidechainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - - it('should return false if createTerminatedStateAccount returns false', async () => { - // Arrange - sidechainInteroperabilityStore.createTerminatedStateAccount = jest - .fn() - .mockResolvedValue(false); - - expect( - await sidechainInteroperabilityStore.terminateChainInternal( - SIDECHAIN_ID, - beforeSendCCMContext, - ), - ).toBe(false); - }); - }); });