Skip to content

Commit

Permalink
Fix defalut value reset (#34)
Browse files Browse the repository at this point in the history
Fix defalut value reset
  • Loading branch information
GalaxySciTech authored Jan 12, 2024
1 parent 3e59116 commit 25df2be
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contracts/FullCheckpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ contract FullCheckpoint {
function getHeader(
bytes32 blockHash
) public view returns (HeaderInfo memory) {
if (headerTree[blockHash].mix == 0) {
return (
HeaderInfo({
parentHash: 0,
number: 0,
roundNum: 0,
mainnetNum: -1,
finalized: false
})
);
}
bool finalized = false;
if (int64(uint64(headerTree[blockHash].mix)) != -1) {
finalized = true;
Expand Down
12 changes: 12 additions & 0 deletions contracts/LiteCheckpoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ contract LiteCheckpoint {
function getHeader(
bytes32 blockHash
) public view returns (HeaderInfo memory) {
if (headerTree[blockHash] == 0) {
return (
HeaderInfo({
parentHash: 0,
number: 0,
roundNum: 0,
mainnetNum: -1,
finalized: false
})
);
}

bool finalized = false;
if (int64(uint64(headerTree[blockHash])) != -1) {
finalized = true;
Expand Down
8 changes: 8 additions & 0 deletions test/FullCheckpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ describe("checkpoint", () => {
});

describe("test checkpoint real block data", () => {
it("should check defalut value", async () => {
const nonExistentBlock = await checkpoint.getHeader(
"0x3a9114857792f2a10b4d04ded4e29cb2371535ed749a7686aa2e9885c6007e25"
);

expect(nonExistentBlock.mainnetNum).to.eq(-1);
expect(nonExistentBlock.finalized).to.eq(false);
});
it("should verify roots", async () => {
const genesisHash = blockToHash(genesis);
const roots = await checkpoint.getRoots(genesisHash);
Expand Down
8 changes: 8 additions & 0 deletions test/LiteCheckpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ describe("lite checkpoint", () => {
await loadFixture(fixture));
});
describe("test lite checkpoint real block data", () => {
it("should check defalut value", async () => {
const nonExistentBlock = await liteCheckpoint.getHeader(
"0x3a9114857792f2a10b4d04ded4e29cb2371535ed749a7686aa2e9885c6007e25"
);

expect(nonExistentBlock.mainnetNum).to.eq(-1);
expect(nonExistentBlock.finalized).to.eq(false);
});
it("should receive a new header which has only the next and uncommitted", async () => {
await liteCheckpoint.receiveHeader([block451Encoded]);
const block2Hash = blockToHash(block451Encoded);
Expand Down

0 comments on commit 25df2be

Please sign in to comment.