Skip to content

Commit

Permalink
test(bridge): LibBridgeProcess unit tests (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerLamTd authored Nov 21, 2022
1 parent 06ceee2 commit 6675626
Show file tree
Hide file tree
Showing 12 changed files with 1,182 additions and 140 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
artifacts
cache
coverage
coverage
10 changes: 5 additions & 5 deletions packages/protocol/contracts/L2/V1TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ contract V1TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
* External Functions *
**********************/

/**
* Persist the latest L1 block height and hash to L2 for cross-layer
* bridging. This function will also check certain block-level global
* variables because they are not part of the Trie structure.
* Note: this transaction shall be the first transaction in everyL2 block.
/** Persist the latest L1 block height and hash to L2 for cross-layer
* bridging. This function will also check certain block-level global
* variables because they are not part of the Trie structure.
*
* Note that this transaction shall be the first transaction in every L2 block.
*
* @param l1Height The latest L1 block height when this block was proposed.
* @param l1Hash The latest L1 block hash when this block was proposed.
Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/contracts/bridge/libs/LibBridgeSignal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ library LibBridgeSignal {
bytes32(uint256(1)),
mkp.proof
);

// get synced header hash of the header height specified in the proof
bytes32 syncedHeaderHash = IHeaderSync(resolver.resolve("taiko"))
.getSyncedHeader(mkp.header.height);

// check header hash specified in the proof matches the current chain
return
syncedHeaderHash != 0 &&
Expand Down
28 changes: 28 additions & 0 deletions packages/protocol/contracts/test/bridge/TestHeaderSync.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../../common/IHeaderSync.sol";

contract TestHeaderSync is IHeaderSync {
bytes32 public headerHash;

function setSyncedHeader(bytes32 header) external {
headerHash = header;
}

function getSyncedHeader(uint256 number) external view returns (bytes32) {
number;
return headerHash;
}

function getLatestSyncedHeader() external view returns (bytes32) {
return headerHash;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../../../common/EssentialContract.sol";
import "../../../bridge/libs/LibBridgeProcess.sol";

contract TestLibBridgeProcess is EssentialContract {
LibBridgeData.State public state;

function init(address _addressManager) external initializer {
EssentialContract._init(_addressManager);
}

function processMessage(
IBridge.Message calldata message,
bytes calldata proof
) public payable {
LibBridgeProcess.processMessage(
state,
AddressResolver(this),
message,
proof
);
}
}
7 changes: 7 additions & 0 deletions packages/protocol/tasks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ async function decode(hre: any, type: any, data: any) {
return hre.ethers.utils.defaultAbiCoder.decode([type], data).toString()
}

const MessageStatus = {
NEW: 0,
RETRIABLE: 1,
DONE: 2,
}

export {
deployContract,
getDeployer,
Expand All @@ -86,4 +92,5 @@ export {
getDeployments,
getSlot,
decode,
MessageStatus,
}
Loading

0 comments on commit 6675626

Please sign in to comment.