Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerLamTd committed May 25, 2023
1 parent 10be2fb commit 99e5829
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

pragma solidity ^0.8.18;

import {LibEthDepositing} from "./libs/LibEthDepositing.sol";

library TaikoData {
struct Config {
uint256 chainId;
Expand Down Expand Up @@ -151,4 +153,22 @@ library TaikoData {
// Reserved
uint256[42] __gap;
}

function abiEncodeBlockMeta(BlockMetadata memory meta) public pure returns (uint256[7] memory){
uint256[7] memory inputs;

inputs[0] = (uint256(meta.id) << 192) | (uint256(meta.timestamp) << 128)
| (uint256(meta.l1Height) << 64);

inputs[1] = uint256(meta.l1Hash);
inputs[2] = uint256(meta.mixHash);
inputs[3] = uint256(LibEthDepositing.hashEthDeposits(meta.depositsProcessed));
inputs[4] = uint256(meta.txListHash);

inputs[5] = (uint256(meta.txListByteStart) << 232) | (uint256(meta.txListByteEnd) << 208)
| (uint256(meta.gasLimit) << 176) | (uint256(uint160(meta.beneficiary)) << 16);

inputs[6] = (uint256(uint160(meta.treasury)) << 96);
return inputs;
}
}
35 changes: 35 additions & 0 deletions packages/protocol/test/TaikoData.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.8.18;

import {Test} from "forge-std/Test.sol";
import {console2} from "forge-std/console2.sol";
import {TaikoData} from "../contracts/L1/TaikoData.sol";


contract TestTaikoData is Test {
TaikoData.EthDeposit[] lst;
TaikoData.BlockMetadata meta;

function setUp() public {
lst = new TaikoData.EthDeposit[](0);
meta = TaikoData.BlockMetadata({
id: uint64(1),
timestamp: uint64(1),
l1Height: uint64(1),
l1Hash: bytes32("abcd"),
mixHash: bytes32("abcd"),
txListHash: bytes32("abcd"),
txListByteStart: uint24(1),
txListByteEnd: uint24(100),
gasLimit: uint32(10000),
beneficiary: address(0x10020FCb72e27650651B05eD2CEcA493bC807Ba4),
treasury: address(0x50081b12838240B1bA02b3177153Bca678a86078),
depositsProcessed: lst
// TaikoData.EthDeposit({recipient: address(0x10020FCb72e27650651B05eD2CEcA493bC807Ba4), amount: uint96(2)})
});
}

function test_abiEncode() public {

}

}
1 change: 1 addition & 0 deletions packages/protocol/test/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract TaikoL1Test is TaikoL1TestBase {
printVariables("after propose");
mine(1);

console2.logBytes(abi.encode(meta));
bytes32 blockHash = bytes32(1e10 + blockId);
bytes32 signalRoot = bytes32(1e9 + blockId);
proveBlock(Bob, Bob, meta, parentHash, parentGasUsed, gasUsed, blockHash, signalRoot);
Expand Down

0 comments on commit 99e5829

Please sign in to comment.