From 8d807223d0c24da76991121782222cb63950c673 Mon Sep 17 00:00:00 2001 From: shuse2 Date: Wed, 1 Nov 2023 15:45:53 +0100 Subject: [PATCH] :recycle: Revert removed test --- .../interoperability/mainchain/module.spec.ts | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/framework/test/unit/modules/interoperability/mainchain/module.spec.ts b/framework/test/unit/modules/interoperability/mainchain/module.spec.ts index 7404c48ba4..c85cc6294a 100644 --- a/framework/test/unit/modules/interoperability/mainchain/module.spec.ts +++ b/framework/test/unit/modules/interoperability/mainchain/module.spec.ts @@ -29,6 +29,7 @@ import { import { ChainInfo, GenesisInteroperability, + TerminatedStateAccountWithChainID, } from '../../../../../src/modules/interoperability/types'; import { InMemoryPrefixedStateDB, @@ -37,6 +38,7 @@ import { } from '../../../../../src/testing'; import { computeValidatorsHash, + getMainchainID, validNameChars, } from '../../../../../src/modules/interoperability/utils'; @@ -450,6 +452,46 @@ describe('initGenesisState', () => { expect(interopMod['_verifyTerminatedStateAccountsIDs']).toHaveBeenCalledTimes(1); }); + it('should call _verifyChainID the same number of times as size of terminatedStateAccounts', () => { + const interopModPrototype = Object.getPrototypeOf(interopMod); + jest.spyOn(interopModPrototype, '_verifyChainID' as any); + + const chainInfoLocal: ChainInfo = { + ...chainInfo, + chainData: { + ...chainData, + status: ChainStatus.TERMINATED, + lastCertificate: { + ...lastCertificate, + validatorsHash: computeValidatorsHash(activeValidators, certificateThreshold), + }, + }, + chainValidators: { + activeValidators, + certificateThreshold, + }, + }; + + const terminatedStateAccounts: TerminatedStateAccountWithChainID[] = [ + { + chainID: chainInfoLocal.chainID, + terminatedStateAccount, + }, + { + chainID: Buffer.from([0, 0, 0, 2]), + terminatedStateAccount, + }, + ]; + + interopModPrototype._verifyTerminatedStateAccountsCommon( + terminatedStateAccounts, + getMainchainID(params.chainID as Buffer), + ); + expect(interopModPrototype['_verifyChainID']).toHaveBeenCalledTimes( + terminatedStateAccounts.length, + ); + }); + it('should throw error if chainInfo.chainID exists in terminatedStateAccounts & chainInfo.chainData.status is ACTIVE', async () => { const context = createInitGenesisStateContext( { @@ -732,43 +774,6 @@ describe('initGenesisState', () => { 'For each terminatedStateAccount there should be a corresponding chainInfo at TERMINATED state', ); }); - - it('should call _verifyTerminatedStateAccounts', async () => { - jest.spyOn(interopMod, '_verifyTerminatedStateAccounts' as any); - - const context = createInitGenesisStateContext( - { - ...genesisInteroperability, - chainInfos: [ - { - ...chainInfo, - chainData: { - ...chainData, - status: ChainStatus.TERMINATED, - lastCertificate: { - ...lastCertificate, - validatorsHash: computeValidatorsHash(activeValidators, certificateThreshold), - }, - }, - chainValidators: { - activeValidators, - certificateThreshold, - }, - }, - ], - terminatedStateAccounts: [ - { - chainID: chainInfo.chainID, - terminatedStateAccount, - }, - ], - }, - params, - ); - - await expect(interopMod.initGenesisState(context)).resolves.toBeUndefined(); - expect(interopMod['_verifyTerminatedStateAccounts']).toHaveBeenCalledTimes(1); - }); }); it(`should call _verifyTerminatedOutboxAccounts from initGenesisState `, async () => {