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

Commit

Permalink
✅ Update genesis block tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed May 12, 2023
1 parent 475be59 commit 91ec97b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions elements/lisk-chain/test/unit/block_header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ describe('block_header', () => {
);
});

it('should throw error if maxHeightGenerated is not zero', () => {
const block = getGenesisBlockAttrs();
const blockHeader = new BlockHeader({ ...block, maxHeightGenerated: 10 });

expect(() => blockHeader.validateGenesis()).toThrow(
'Genesis block header maxHeightGenerated must equal 0',
);
});

it('should throw error if maxHeightPrevoted is not equal to header.height', () => {
const block = getGenesisBlockAttrs();
const blockHeader = new BlockHeader({ ...block, maxHeightPrevoted: 10 });
Expand Down Expand Up @@ -296,6 +305,18 @@ describe('block_header', () => {
);
});

it('should throw error if impliesMaxPrevotes is false', () => {
const block = getGenesisBlockAttrs();
const blockHeader = new BlockHeader({
...block,
impliesMaxPrevotes: false,
});

expect(() => blockHeader.validateGenesis()).toThrow(
'Genesis block header impliesMaxPrevotes must be true',
);
});

it('should throw error if signature is not empty buffer', () => {
const block = getGenesisBlockAttrs();
const blockHeader = new BlockHeader({ ...block, signature: utils.getRandomBytes(32) });
Expand Down
17 changes: 17 additions & 0 deletions framework/test/unit/state_machine/state_machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ describe('state_machine', () => {
// expect(systemMod.verifyAssets).toHaveBeenCalledTimes(1);
expect(mod.verifyAssets).toHaveBeenCalledTimes(1);
});

it('should fail if module is not registered', async () => {
await expect(
stateMachine.verifyAssets(
new BlockContext({
eventQueue,
logger,
stateStore,
contextStore,
header,
assets: new BlockAssets([{ module: 'unknown', data: Buffer.alloc(30) }]),
chainID,
transactions: [transaction],
}),
),
).rejects.toThrow('Module unknown is not registered');
});
});

describe('beforeExecuteBlock', () => {
Expand Down

0 comments on commit 91ec97b

Please sign in to comment.