From f2758b8a9bf6cc28808cfb459ea7455d51d05a24 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Thu, 13 Jul 2023 00:15:05 +0200 Subject: [PATCH 1/2] Check if terminatedState exists instead of getting terminatedStateAccount --- .../modules/interoperability/base_interoperability_method.ts | 2 +- framework/test/unit/modules/interoperability/method.spec.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/framework/src/modules/interoperability/base_interoperability_method.ts b/framework/src/modules/interoperability/base_interoperability_method.ts index f114ba2bb29..bf157b4b2b9 100644 --- a/framework/src/modules/interoperability/base_interoperability_method.ts +++ b/framework/src/modules/interoperability/base_interoperability_method.ts @@ -176,7 +176,7 @@ export abstract class BaseInteroperabilityMethod< // https://github.com/LiskHQ/lips/blob/main/proposals/lip-0045.md#terminatechain public async terminateChain(context: MethodContext, chainID: Buffer): Promise { - if (await this.getTerminatedStateAccount(context, chainID)) { + if (await this.stores.get(TerminatedStateStore).has(context, chainID)) { return; } diff --git a/framework/test/unit/modules/interoperability/method.spec.ts b/framework/test/unit/modules/interoperability/method.spec.ts index de1d941b9ae..29fb18d4d70 100644 --- a/framework/test/unit/modules/interoperability/method.spec.ts +++ b/framework/test/unit/modules/interoperability/method.spec.ts @@ -533,6 +533,7 @@ describe('Sample Method', () => { }); it('should do nothing if chain was already terminated', async () => { + jest.spyOn(terminatedStateAccountStoreMock, 'has').mockResolvedValue(true); jest.spyOn(sampleInteroperabilityMethod, 'getTerminatedStateAccount').mockResolvedValue({ stateRoot: sidechainChainAccount.lastCertificate.stateRoot, mainchainStateRoot: Buffer.alloc(HASH_LENGTH), @@ -544,9 +545,7 @@ describe('Sample Method', () => { }); it('should process with input chainID', async () => { - jest - .spyOn(sampleInteroperabilityMethod as any, 'getTerminatedStateAccount') - .mockResolvedValue(undefined); + jest.spyOn(terminatedStateAccountStoreMock, 'has').mockResolvedValue(false); await sampleInteroperabilityMethod.terminateChain(methodContext, chainID); From 3afd481d01a9c9c9f5fe2a90b5fff6b17c485dd1 Mon Sep 17 00:00:00 2001 From: Ishan Date: Fri, 21 Jul 2023 09:55:04 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=85=F0=9F=8F=BB=20Add=20comment=20?= =?UTF-8?q?and=20remove=20unnecessary=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base_interoperability_method.ts | 1 + .../modules/interoperability/method.spec.ts | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/framework/src/modules/interoperability/base_interoperability_method.ts b/framework/src/modules/interoperability/base_interoperability_method.ts index bf157b4b2b9..8df68df8752 100644 --- a/framework/src/modules/interoperability/base_interoperability_method.ts +++ b/framework/src/modules/interoperability/base_interoperability_method.ts @@ -176,6 +176,7 @@ export abstract class BaseInteroperabilityMethod< // https://github.com/LiskHQ/lips/blob/main/proposals/lip-0045.md#terminatechain public async terminateChain(context: MethodContext, chainID: Buffer): Promise { + // Chain was already terminated, do nothing. if (await this.stores.get(TerminatedStateStore).has(context, chainID)) { return; } diff --git a/framework/test/unit/modules/interoperability/method.spec.ts b/framework/test/unit/modules/interoperability/method.spec.ts index d0dfce04bbb..52354b337a0 100644 --- a/framework/test/unit/modules/interoperability/method.spec.ts +++ b/framework/test/unit/modules/interoperability/method.spec.ts @@ -18,11 +18,9 @@ import { MainchainInteroperabilityModule, TokenMethod, ChannelData } from '../.. import { BaseInteroperabilityMethod } from '../../../../src/modules/interoperability/base_interoperability_method'; import { CCMStatusCode, - CHAIN_ID_LENGTH, CROSS_CHAIN_COMMAND_CHANNEL_TERMINATED, EMPTY_BYTES, EMPTY_FEE_ADDRESS, - HASH_LENGTH, MAX_CCM_SIZE, MODULE_NAME_INTEROPERABILITY, MAX_RESERVED_ERROR_STATUS, @@ -533,18 +531,6 @@ describe('Sample Method', () => { }); describe('terminateChain', () => { - const sidechainChainAccount = { - name: 'sidechain1', - chainID: Buffer.alloc(CHAIN_ID_LENGTH), - lastCertificate: { - height: 10, - stateRoot: utils.getRandomBytes(32), - timestamp: 100, - validatorsHash: utils.getRandomBytes(32), - }, - status: ChainStatus.TERMINATED, - }; - beforeEach(() => { interopMod['internalMethod'].sendInternal = jest.fn(); interopMod['internalMethod'].createTerminatedStateAccount = jest.fn(); @@ -552,11 +538,6 @@ describe('Sample Method', () => { it('should do nothing if chain was already terminated', async () => { jest.spyOn(terminatedStateAccountStoreMock, 'has').mockResolvedValue(true); - jest.spyOn(sampleInteroperabilityMethod, 'getTerminatedStateAccount').mockResolvedValue({ - stateRoot: sidechainChainAccount.lastCertificate.stateRoot, - mainchainStateRoot: Buffer.alloc(HASH_LENGTH), - initialized: true, - }); await sampleInteroperabilityMethod.terminateChain(methodContext, chainID); expect(interopMod['internalMethod'].sendInternal).not.toHaveBeenCalled();