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

Commit

Permalink
Merge pull request #6259 from LiskHQ/6257-bugfix-testing-utils-namespace
Browse files Browse the repository at this point in the history
Resolve conflicting testing export namespace from lisk-chain and lisk-framework - Closes #6257
  • Loading branch information
ManuGowda committed Mar 18, 2021
2 parents 367b719 + b653b19 commit f655812
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 459 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Validator,
BlockHeader,
StateStore,
testing,
} from '@liskhq/lisk-chain';
import { getAddressFromPublicKey } from '@liskhq/lisk-cryptography';
import * as scenario4DelegatesMissedSlots from '../bft_specs/4_delegates_missed_slots.json';
Expand All @@ -34,7 +35,6 @@ import {
VotingLedger,
BFTVotingLedgerSchema,
} from '../../src/finality_manager';
import { StateStoreMock } from '../utils/state_store_mock';
import { convertHeader } from '../fixtures/blocks';

const prevotesAndCommits = async (stateStore: StateStore) => {
Expand Down Expand Up @@ -64,6 +64,7 @@ const prevotesAndCommits = async (stateStore: StateStore) => {

describe('FinalityManager', () => {
// Arrange
const { StateStoreMock } = testing;
const bftScenarios = [
scenario4DelegatesMissedSlots,
scenario4DelegatesSimple,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import {
CONSENSUS_STATE_VALIDATORS_KEY,
validatorsSchema,
StateStore,
testing,
} from '@liskhq/lisk-chain';
import { codec } from '@liskhq/lisk-codec';
import * as invalidBlockHeaderSpec from '../bft_specs/bft_invalid_block_headers.json';

import { FinalityManager } from '../../src/finality_manager';
import { StateStoreMock } from '../utils/state_store_mock';
import { convertHeader } from '../fixtures/blocks';

describe('FinalityManager', () => {
const { StateStoreMock } = testing;

describe('addBlockHeader', () => {
let stateStore: StateStore;
let chainStub: Chain;
Expand Down
140 changes: 71 additions & 69 deletions elements/lisk-bft/test/unit/bft.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
CONSENSUS_STATE_VALIDATORS_KEY,
validatorsSchema,
StateStore,
testing,
} from '@liskhq/lisk-chain';
import { createFakeBlockHeader } from '../fixtures/blocks';
import {
Expand All @@ -29,7 +30,6 @@ import {
BFTVotingLedgerSchema,
} from '../../src/finality_manager';
import { BFT, BFTPersistedValues, BFTFinalizedHeightCodecSchema } from '../../src';
import { StateStoreMock } from '../utils/state_store_mock';

const generateBlocks = ({
startHeight,
Expand All @@ -45,6 +45,8 @@ const generateBlocks = ({
};

describe('bft', () => {
const { StateStoreMock } = testing;

describe('BFT', () => {
let threshold: number;
let genesisHeight: number;
Expand Down Expand Up @@ -107,20 +109,20 @@ describe('bft', () => {

it('should set the finality height to the value from chain state', async () => {
const finalizedHeight = 5;
const stateStore = (new StateStoreMock(
[],
{
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: [
{ address: getRandomBytes(20), isConsensusParticipant: true, minActiveHeight: 104 },
],
}),
},
{ lastBlockHeaders: [lastBlock] },
) as unknown) as StateStore;
const consensus = {
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: [
{ address: getRandomBytes(20), isConsensusParticipant: true, minActiveHeight: 104 },
],
}),
};
const stateStore = (new StateStoreMock({
consensus,
lastBlockHeaders: [lastBlock],
}) as unknown) as StateStore;
const bft = new BFT(bftParams);

await bft.init(stateStore);
Expand All @@ -144,22 +146,22 @@ describe('bft', () => {
});

bft = new BFT(bftParams);
stateStore = (new StateStoreMock(
[],
{
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: 1,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: blocks.map(b => ({
address: getAddressFromPublicKey(b.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 0,
})),
}),
},
{ lastBlockHeaders: blocks },
) as unknown) as StateStore;
const consensus = {
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: 1,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: blocks.map(b => ({
address: getAddressFromPublicKey(b.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 0,
})),
}),
};
stateStore = (new StateStoreMock({
consensus,
lastBlockHeaders: blocks,
}) as unknown) as StateStore;
await bft.init(stateStore);
});

Expand Down Expand Up @@ -226,28 +228,28 @@ describe('bft', () => {
let stateStore: StateStore;

beforeEach(async () => {
stateStore = (new StateStoreMock(
[],
{
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: lastFinalizedHeight,
}),
[CONSENSUS_STATE_VALIDATOR_LEDGER_KEY]: codec.encode(
BFTVotingLedgerSchema,
validatorLedger,
),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: [
{
address: getAddressFromPublicKey(block1.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 104,
},
],
}),
},
{ lastBlockHeaders: [lastBlock] },
) as unknown) as StateStore;
const consensus = {
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: lastFinalizedHeight,
}),
[CONSENSUS_STATE_VALIDATOR_LEDGER_KEY]: codec.encode(
BFTVotingLedgerSchema,
validatorLedger,
),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: [
{
address: getAddressFromPublicKey(block1.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 104,
},
],
}),
};
stateStore = (new StateStoreMock({
consensus,
lastBlockHeaders: [lastBlock],
}) as unknown) as StateStore;

bft = new BFT(bftParams);
await bft.init(stateStore);
Expand Down Expand Up @@ -276,22 +278,22 @@ describe('bft', () => {
let stateStore: StateStore;

const getNewStateStore = (minHeight = 0) => {
return (new StateStoreMock(
[],
{
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: 1,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: blocks.map(b => ({
address: getAddressFromPublicKey(b.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 0,
})),
}),
},
{ lastBlockHeaders: blocks.filter(b => b.height >= minHeight) },
) as unknown) as StateStore;
const consensus = {
[CONSENSUS_STATE_FINALIZED_HEIGHT_KEY]: codec.encode(BFTFinalizedHeightCodecSchema, {
finalizedHeight: 1,
}),
[CONSENSUS_STATE_VALIDATORS_KEY]: codec.encode(validatorsSchema, {
validators: blocks.map(b => ({
address: getAddressFromPublicKey(b.generatorPublicKey),
isConsensusParticipant: true,
minActiveHeight: 0,
})),
}),
};
return (new StateStoreMock({
consensus,
lastBlockHeaders: blocks.filter(b => b.height >= minHeight),
}) as unknown) as StateStore;
};

beforeEach(async () => {
Expand Down
Loading

0 comments on commit f655812

Please sign in to comment.