Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Fix terminate chain method #8740

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export abstract class BaseInteroperabilityMethod<

// https://github.com/LiskHQ/lips/blob/main/proposals/lip-0045.md#terminatechain
public async terminateChain(context: MethodContext, chainID: Buffer): Promise<void> {
if (await this.getTerminatedStateAccount(context, chainID)) {
// Chain was already terminated, do nothing.
if (await this.stores.get(TerminatedStateStore).has(context, chainID)) {
ishantiw marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down
24 changes: 2 additions & 22 deletions framework/test/unit/modules/interoperability/method.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -534,38 +532,20 @@ 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();
});

it('should do nothing if chain was already terminated', async () => {
jest.spyOn(sampleInteroperabilityMethod, 'getTerminatedStateAccount').mockResolvedValue({
stateRoot: sidechainChainAccount.lastCertificate.stateRoot,
mainchainStateRoot: Buffer.alloc(HASH_LENGTH),
initialized: true,
});
jest.spyOn(terminatedStateAccountStoreMock, 'has').mockResolvedValue(true);
ishantiw marked this conversation as resolved.
Show resolved Hide resolved
await sampleInteroperabilityMethod.terminateChain(methodContext, chainID);

expect(interopMod['internalMethod'].sendInternal).not.toHaveBeenCalled();
});

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);

Expand Down