From 7942968edcdb9f9186b54f8801cba1df8bfa3e8d Mon Sep 17 00:00:00 2001 From: Tschakki Date: Thu, 21 Dec 2023 19:01:28 +0100 Subject: [PATCH] Update plugin tests --- .../test/unit/certificate_generation.spec.ts | 14 ++--- .../test/unit/db.spec.ts | 23 +++---- .../test/unit/endpoint.spec.ts | 13 +--- .../test/unit/inbox_update.spec.ts | 4 +- .../test/unit/plugin.spec.ts | 63 +++++++++---------- .../test/unit/utils.spec.ts | 4 +- .../test/unit/auth.spec.ts | 4 +- .../test/unit/db.spec.ts | 4 +- .../test/unit/subscribe_event.spec.ts | 4 +- 9 files changed, 54 insertions(+), 79 deletions(-) diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/certificate_generation.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/certificate_generation.spec.ts index 60c6f7ec4a9..f38e528071e 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/certificate_generation.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/certificate_generation.spec.ts @@ -12,13 +12,7 @@ * Removal or modification of this copyright notice is prohibited. */ -import { - BFTHeights, - chain, - computeUnsignedCertificateFromBlockHeader, - cryptography, - testing, -} from 'lisk-sdk'; +import { chain, Engine, cryptography, testing } from 'lisk-sdk'; import { checkChainOfTrust, getCertificateFromAggregateCommit, @@ -103,7 +97,7 @@ describe('certificate generation', () => { validatorsHash: cryptography.utils.getRandomBytes(HASH_LENGTH), }; - const bftHeights: BFTHeights = { + const bftHeights: Engine.BFTHeights = { maxHeightPrevoted: 5, maxHeightPrecommitted: 5, maxHeightCertified: 3, @@ -123,7 +117,7 @@ describe('certificate generation', () => { const firstBlockHeader = sampleBlockHeaders[0]; const { aggregateCommit } = firstBlockHeader; - const unsignedCertificate = computeUnsignedCertificateFromBlockHeader( + const unsignedCertificate = Engine.computeUnsignedCertificateFromBlockHeader( new chain.BlockHeader(firstBlockHeader), ); const expectedCertificate = { @@ -275,7 +269,7 @@ describe('certificate generation', () => { it('should return a valid certificate passing chainOfTrust check', () => { const secondBlockHeader = sampleBlockHeaders[1]; - const unsignedCertificate = computeUnsignedCertificateFromBlockHeader( + const unsignedCertificate = Engine.computeUnsignedCertificateFromBlockHeader( new chain.BlockHeader(secondBlockHeader), ); const expectedCertificate = { diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/db.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/db.spec.ts index 38dea0d0b15..43f2925370f 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/db.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/db.spec.ts @@ -12,16 +12,7 @@ * Removal or modification of this copyright notice is prohibited. */ -import { - AggregateCommit, - db, - testing, - cryptography, - chain, - SubmitMainchainCrossChainUpdateCommand, - CROSS_CHAIN_COMMAND_NAME_TRANSFER, - MODULE_NAME_INTEROPERABILITY, -} from 'lisk-sdk'; +import { Engine, db, testing, cryptography, chain, Modules } from 'lisk-sdk'; import * as fs from 'fs-extra'; import { homedir } from 'os'; import { join } from 'path'; @@ -99,7 +90,7 @@ describe('Plugins DB', () => { }); describe('aggregateCommits', () => { - let sampleAggregateCommits: AggregateCommit[]; + let sampleAggregateCommits: Engine.AggregateCommit[]; beforeEach(() => { sampleAggregateCommits = [ @@ -240,7 +231,7 @@ describe('Plugins DB', () => { beforeEach(() => { sampleLastSentCCM = { - crossChainCommand: CROSS_CHAIN_COMMAND_NAME_TRANSFER, + crossChainCommand: Modules.Token.CROSS_CHAIN_COMMAND_NAME_TRANSFER, fee: BigInt(1000), height: 1, module: 'token', @@ -270,8 +261,8 @@ describe('Plugins DB', () => { listOfCCUs = [ testing .createTransaction({ - commandClass: SubmitMainchainCrossChainUpdateCommand as any, - module: MODULE_NAME_INTEROPERABILITY, + commandClass: Modules.Interoperability.SubmitMainchainCrossChainUpdateCommand as any, + module: Modules.Interoperability.MODULE_NAME_INTEROPERABILITY, params: { activeValidatorsUpdate: { blsKeysUpdate: [], @@ -295,8 +286,8 @@ describe('Plugins DB', () => { .toObject(), testing .createTransaction({ - commandClass: SubmitMainchainCrossChainUpdateCommand as any, - module: MODULE_NAME_INTEROPERABILITY, + commandClass: Modules.Interoperability.SubmitMainchainCrossChainUpdateCommand as any, + module: Modules.Interoperability.MODULE_NAME_INTEROPERABILITY, params: { activeValidatorsUpdate: { blsKeysUpdate: [], diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/endpoint.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/endpoint.spec.ts index b918a9d387d..0e5d7676843 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/endpoint.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/endpoint.spec.ts @@ -14,14 +14,7 @@ import { removeSync } from 'fs-extra'; import { when } from 'jest-when'; -import { - ApplicationConfigForPlugin, - GenesisConfig, - testing, - cryptography, - apiClient, - db, -} from 'lisk-sdk'; +import { Types, testing, cryptography, apiClient, db } from 'lisk-sdk'; import { ChainConnectorPlugin } from '../../src/chain_connector_plugin'; import * as chainConnectorDB from '../../src/db'; import { CCMsFromEvents, CCMsFromEventsJSON, LastSentCCMWithHeightJSON } from '../../src/types'; @@ -29,11 +22,11 @@ import { ccmsFromEventsToJSON, getMainchainID } from '../../src/utils'; describe('endpoints', () => { const ownChainID = Buffer.from('10000000', 'hex'); - const appConfigForPlugin: ApplicationConfigForPlugin = { + const appConfigForPlugin: Types.ApplicationConfigForPlugin = { ...testing.fixtures.defaultConfig, genesis: { chainID: ownChainID.toString('hex'), - } as GenesisConfig, + } as Types.GenesisConfig, generator: { keys: { fromFile: '', diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/inbox_update.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/inbox_update.spec.ts index 4e68cead9a9..1b75727cd04 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/inbox_update.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/inbox_update.spec.ts @@ -12,14 +12,14 @@ * Removal or modification of this copyright notice is prohibited. */ -import { CCMsg, tree } from 'lisk-sdk'; +import { Modules, tree } from 'lisk-sdk'; import { CCU_TOTAL_CCM_SIZE } from '../../src/constants'; import { CCMsFromEvents } from '../../src/types'; import { calculateMessageWitnesses } from '../../src/inbox_update'; import { getSampleCCM } from '../utils/sampleCCM'; describe('inboxUpdate', () => { - let sampleCCMs: CCMsg[]; + let sampleCCMs: Modules.Interoperability.CCMsg[]; let sampleCCMsFromEvents: CCMsFromEvents[]; beforeEach(() => { diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/plugin.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/plugin.spec.ts index 3c592feeaea..75ceec21b95 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/plugin.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/plugin.spec.ts @@ -16,22 +16,15 @@ import { cryptography, testing, apiClient, - ApplicationConfigForPlugin, + Types, codec, db, Block, - AggregateCommit, chain, - ccmSchema, - ChannelDataJSON, - CCMsg, - certificateSchema, + Modules, + Engine, tree, - CrossChainUpdateTransactionParams, - Certificate, - BFTHeights, transactions, - ccuParamsSchema, } from 'lisk-sdk'; import { when } from 'jest-when'; import { @@ -63,7 +56,7 @@ import { getSampleCCU } from '../utils/sampleCCU'; describe('ChainConnectorPlugin', () => { const BLS_SIGNATURE_LENGTH = 96; const ownChainID = Buffer.from('04000000', 'hex'); - const appConfigForPlugin: ApplicationConfigForPlugin = { + const appConfigForPlugin: Types.ApplicationConfigForPlugin = { ...testing.fixtures.defaultConfig, genesis: { chainID: ownChainID.toString('hex'), @@ -90,10 +83,10 @@ describe('ChainConnectorPlugin', () => { properties: { ccm: { fieldNumber: 1, - type: ccmSchema.type, - required: [...ccmSchema.required], + type: Modules.Interoperability.ccmSchema.type, + required: [...Modules.Interoperability.ccmSchema.required], properties: { - ...ccmSchema.properties, + ...Modules.Interoperability.ccmSchema.properties, }, }, }, @@ -106,10 +99,10 @@ describe('ChainConnectorPlugin', () => { properties: { ccm: { fieldNumber: 1, - type: ccmSchema.type, - required: [...ccmSchema.required], + type: Modules.Interoperability.ccmSchema.type, + required: [...Modules.Interoperability.ccmSchema.required], properties: { - ...ccmSchema.properties, + ...Modules.Interoperability.ccmSchema.properties, }, }, result: { @@ -154,7 +147,7 @@ describe('ChainConnectorPlugin', () => { '6c5e2b24ff1cc99da7a49bd28420b93b2a91e2e2a3b0a0ce07676966b707d3c2859bbd02747cf8e26dab592c02155dfddd4a16b0fe83fd7e7ffaec0b5391f3f7'; const defaultPassword = '123'; const defaultCCUFee = '500000'; - const sampleCCUParams: CrossChainUpdateTransactionParams = { + const sampleCCUParams: Modules.Interoperability.CrossChainUpdateTransactionParams = { sendingChainID: Buffer.from('04000001', 'hex'), activeValidatorsUpdate: { bftWeightsUpdate: [], @@ -199,7 +192,7 @@ describe('ChainConnectorPlugin', () => { let defaultEncryptedPrivateKey: string; let defaultConfig: ChainConnectorPluginConfig & Record; - let sampleBFTHeights: BFTHeights; + let sampleBFTHeights: Engine.BFTHeights; beforeEach(async () => { sampleBFTHeights = { @@ -467,7 +460,7 @@ describe('ChainConnectorPlugin', () => { let height = 0; return new Array(count).fill(0).map(() => { height += 1; - const aggregateCommit: AggregateCommit = { + const aggregateCommit: Engine.AggregateCommit = { height, aggregationBits: Buffer.from('00', 'hex'), certificateSignature: Buffer.alloc(0), @@ -571,7 +564,7 @@ describe('ChainConnectorPlugin', () => { describe('_newBlockHandler', () => { let block: Block; - let sampleNextCertificate: Certificate; + let sampleNextCertificate: Engine.Certificate; beforeEach(async () => { block = await testing.createBlock({ @@ -1078,9 +1071,13 @@ describe('ChainConnectorPlugin', () => { }); await expect(chainConnectorPlugin['_getCcuFee'](transactionTemplate)).resolves.toBe( - transactions.computeMinFee(transactionTemplate, ccuParamsSchema, { - additionalFee: initializationFees.userAccount, - }), + transactions.computeMinFee( + transactionTemplate, + Modules.Interoperability.ccuParamsSchema, + { + additionalFee: initializationFees.userAccount, + }, + ), ); }); }); @@ -1108,7 +1105,7 @@ describe('ChainConnectorPlugin', () => { }); await expect(chainConnectorPlugin['_getCcuFee'](transactionTemplate)).resolves.toBe( - transactions.computeMinFee(transactionTemplate, ccuParamsSchema), + transactions.computeMinFee(transactionTemplate, Modules.Interoperability.ccuParamsSchema), ); }); }); @@ -1116,9 +1113,9 @@ describe('ChainConnectorPlugin', () => { describe('_computeCCUParams', () => { let sampleCCMsWithEvents: CCMsFromEvents[]; let sampleBlockHeaders: BlockHeader[]; - let sampleAggregateCommits: AggregateCommit[]; + let sampleAggregateCommits: Engine.AggregateCommit[]; let sampleValidatorsHashPreimage: ValidatorsData[]; - let sampleChannelDataJSON: ChannelDataJSON; + let sampleChannelDataJSON: Modules.Interoperability.ChannelDataJSON; beforeEach(async () => { sampleBlockHeaders = new Array(10).fill(0).map((_, index) => { @@ -1341,14 +1338,14 @@ describe('ChainConnectorPlugin', () => { const lastSentCCMsFromEvents = sampleCCMsWithEvents[5]; const expectedCCMsToBeSent = sampleCCMsWithEvents .slice(5, 7) - .reduce((ccms: CCMsg[], record: CCMsFromEvents) => { + .reduce((ccms: Modules.Interoperability.CCMsg[], record: CCMsFromEvents) => { for (const ccm of record.ccms) { ccms.push(ccm); } return ccms; }, []) - .map(ccm => codec.encode(ccmSchema, ccm)); + .map(ccm => codec.encode(Modules.Interoperability.ccmSchema, ccm)); await chainConnectorPlugin['_chainConnectorStore'].setLastSentCCM({ ...lastSentCCMsFromEvents.ccms[0], height: lastSentCCMsFromEvents.height, @@ -1500,7 +1497,7 @@ describe('ChainConnectorPlugin', () => { validatorsData[0].certificateThreshold, ); expect(result?.ccuParams.certificate).toEqual( - codec.encode(certificateSchema, newCertificate), + codec.encode(Engine.certificateSchema, newCertificate), ); expect(result?.ccuParams.inboxUpdate.crossChainMessages).toEqual([]); expect(result?.ccuParams.inboxUpdate.messageWitnessHashes).toEqual([]); @@ -1580,7 +1577,7 @@ describe('ChainConnectorPlugin', () => { validatorsUpdateResult.certificateThreshold, ); expect(result?.ccuParams.certificate).toEqual( - codec.encode(certificateSchema, newCertificate), + codec.encode(Engine.certificateSchema, newCertificate), ); expect(result?.ccuParams.inboxUpdate.crossChainMessages.length).toEqual( @@ -1681,7 +1678,7 @@ describe('ChainConnectorPlugin', () => { validatorsUpdateResult.certificateThreshold, ); expect(result?.ccuParams.certificate).toEqual( - codec.encode(certificateSchema, newCertificate), + codec.encode(Engine.certificateSchema, newCertificate), ); expect(result?.ccuParams.inboxUpdate.crossChainMessages.length).toEqual( sampleCCMsWithEvents.slice(5, 8).length, @@ -1773,7 +1770,7 @@ describe('ChainConnectorPlugin', () => { validatorsUpdateResult.certificateThreshold, ); expect(result?.ccuParams.certificate).toEqual( - codec.encode(certificateSchema, newCertificate), + codec.encode(Engine.certificateSchema, newCertificate), ); expect(result?.ccuParams.inboxUpdate.crossChainMessages).toEqual([]); expect(result?.ccuParams.inboxUpdate.messageWitnessHashes).toEqual([]); diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/utils.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/utils.spec.ts index 4e18d347c14..48e0e5e9660 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/utils.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/utils.spec.ts @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. */ -import { BLS_SIGNATURE_LENGTH, cryptography } from 'lisk-sdk'; +import { Modules, cryptography } from 'lisk-sdk'; import * as utils from '../../src/active_validators_update'; import { calculateActiveValidatorsUpdate, @@ -29,7 +29,7 @@ describe('calculateActiveValidatorsUpdate', () => { aggregationBits: Buffer.alloc(1), blockID: cryptography.utils.getRandomBytes(HASH_LENGTH), height: 10, - signature: cryptography.utils.getRandomBytes(BLS_SIGNATURE_LENGTH), + signature: cryptography.utils.getRandomBytes(Modules.Interoperability.BLS_SIGNATURE_LENGTH), stateRoot: cryptography.utils.getRandomBytes(HASH_LENGTH), timestamp: Date.now(), validatorsHash: certificateValidatorsHash, diff --git a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/auth.spec.ts b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/auth.spec.ts index 4dbf1a31c7c..cf2678f7439 100644 --- a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/auth.spec.ts +++ b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/auth.spec.ts @@ -12,11 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { ApplicationConfigForPlugin, testing } from 'lisk-sdk'; +import { Types, testing } from 'lisk-sdk'; import { ReportMisbehaviorPlugin } from '../../src'; import { configSchema } from '../../src/schemas'; -const appConfigForPlugin: ApplicationConfigForPlugin = { +const appConfigForPlugin: Types.ApplicationConfigForPlugin = { ...testing.fixtures.defaultConfig, }; diff --git a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/db.spec.ts b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/db.spec.ts index a0ab3f3c307..4a59dfc296c 100644 --- a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/db.spec.ts +++ b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/db.spec.ts @@ -14,7 +14,7 @@ import { rmSync } from 'fs-extra'; import * as sdk from 'lisk-sdk'; -import { chain, db as liskDB, blockHeaderSchema, codec, BlockHeader } from 'lisk-sdk'; +import { chain, db as liskDB, blockHeaderSchema, codec, Types } from 'lisk-sdk'; import { getContradictingBlockHeader, saveBlockHeaders } from '../../src/db'; describe('db', () => { @@ -62,7 +62,7 @@ describe('db', () => { }); describe('getContradictingBlockHeader', () => { - const headerClone = BlockHeader.fromBytes(headerBytes1); + const headerClone = Types.BlockHeader.fromBytes(headerBytes1); const header2 = new chain.BlockHeader({ id: Buffer.from('ff', 'hex'), diff --git a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/subscribe_event.spec.ts b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/subscribe_event.spec.ts index fe0aef005aa..85216da86b3 100644 --- a/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/subscribe_event.spec.ts +++ b/framework-plugins/lisk-framework-report-misbehavior-plugin/test/unit/subscribe_event.spec.ts @@ -12,11 +12,11 @@ * Removal or modification of this copyright notice is prohibited. */ -import { ApplicationConfigForPlugin, testing } from 'lisk-sdk'; +import { Types, testing } from 'lisk-sdk'; import { ReportMisbehaviorPlugin } from '../../src'; import { configSchema } from '../../src/schemas'; -const appConfigForPlugin: ApplicationConfigForPlugin = { +const appConfigForPlugin: Types.ApplicationConfigForPlugin = { ...testing.fixtures.defaultConfig, };