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

Commit

Permalink
Update plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschakki committed Dec 21, 2023
1 parent 480ab5c commit 7942968
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -99,7 +90,7 @@ describe('Plugins DB', () => {
});

describe('aggregateCommits', () => {
let sampleAggregateCommits: AggregateCommit[];
let sampleAggregateCommits: Engine.AggregateCommit[];

beforeEach(() => {
sampleAggregateCommits = [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: [],
Expand All @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,19 @@

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';
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: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'),
Expand All @@ -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,
},
},
},
Expand All @@ -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: {
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -199,7 +192,7 @@ describe('ChainConnectorPlugin', () => {

let defaultEncryptedPrivateKey: string;
let defaultConfig: ChainConnectorPluginConfig & Record<string, unknown>;
let sampleBFTHeights: BFTHeights;
let sampleBFTHeights: Engine.BFTHeights;

beforeEach(async () => {
sampleBFTHeights = {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -571,7 +564,7 @@ describe('ChainConnectorPlugin', () => {

describe('_newBlockHandler', () => {
let block: Block;
let sampleNextCertificate: Certificate;
let sampleNextCertificate: Engine.Certificate;

beforeEach(async () => {
block = await testing.createBlock({
Expand Down Expand Up @@ -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,
},
),
);
});
});
Expand Down Expand Up @@ -1108,17 +1105,17 @@ describe('ChainConnectorPlugin', () => {
});

await expect(chainConnectorPlugin['_getCcuFee'](transactionTemplate)).resolves.toBe(
transactions.computeMinFee(transactionTemplate, ccuParamsSchema),
transactions.computeMinFee(transactionTemplate, Modules.Interoperability.ccuParamsSchema),
);
});
});
});
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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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([]);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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'),
Expand Down
Loading

0 comments on commit 7942968

Please sign in to comment.