Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(protocol): improve test coverage #16428

Merged
merged 16 commits into from
Mar 19, 2024
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
}

/// @notice Creates a new token snapshot.
function snapshot() public onlyFromOwnerOrNamed("snapshooter") {
_snapshot();
function snapshot() public onlyFromOwnerOrNamed("snapshooter") returns (uint256) {
adaki2004 marked this conversation as resolved.
Show resolved Hide resolved
return _snapshot();
}

/// @notice Transfers tokens to a specified address.
Expand Down
110 changes: 110 additions & 0 deletions packages/protocol/test/L1/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ contract TaikoL1Test is TaikoL1TestBase {
vm.warp(block.timestamp + tierProvider().getTier(minTier).cooldownWindow * 60 + 1);

verifyBlock(Alice, 2);

(TaikoData.Block memory blk, TaikoData.TransitionState memory ts) = L1.getBlock(meta.id);
assertEq(meta.id, blk.blockId);

ts = L1.getTransition(meta.id, parentHash);
assertEq(ts.prover, Bob);

parentHash = blockHash;
}
printVariables("");
Expand Down Expand Up @@ -208,6 +215,10 @@ contract TaikoL1Test is TaikoL1TestBase {
giveEthAndTko(Henry, 0, maxAmount + 1 ether);

// So after this point we have 8 deposits

vm.prank(Alice, Alice);
bool canAliceDeposit = L1.canDepositEthToL2(1 ether);
assertEq(true, canAliceDeposit);
vm.prank(Alice, Alice);
L1.depositEtherToL2{ value: 1 ether }(address(0));
vm.prank(Bob, Bob);
Expand Down Expand Up @@ -246,4 +257,103 @@ contract TaikoL1Test is TaikoL1TestBase {
0x3b61cf81fd007398a8efd07a055ac8fb542bcfa62d76cf6dc28a889371afb21e
);
}

function test_pauseProving() external {
L1.pauseProving(true);

TaikoData.BlockMetadata memory meta;

giveEthAndTko(Alice, 1000 ether, 1000 ether);
giveEthAndTko(Bob, 1e8 ether, 100 ether);

// Proposing is still possible
(meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024);
// Proving is not, so supply the revert reason to proveBlock
proveBlock(
Bob,
Bob,
meta,
GENESIS_BLOCK_HASH,
bytes32("01"),
bytes32("02"),
meta.minTier,
TaikoErrors.L1_PROVING_PAUSED.selector
);
}

function test_unpause() external {
L1.pause();

giveEthAndTko(Alice, 1000 ether, 1000 ether);
giveEthAndTko(Bob, 1e8 ether, 100 ether);

// Proposing is also not possible
proposeButRevert(Alice, Bob, 1024, EssentialContract.INVALID_PAUSE_STATUS.selector);

// unpause
L1.unpause();

// Proposing is possible again
proposeBlock(Alice, Bob, 1_000_000, 1024);
}

function test_isBlobReusable() external {
// Need to go ahead in the future, after config's blob expiry time.
vm.warp(block.timestamp + 2 days);
// non existing, so not reusable
assertEq(false, L1.isBlobReusable(bytes32("AA")));
}

function test_burn() external {
uint256 balanceBeforeBurn = tko.balanceOf(address(this));
vm.prank(tko.owner(), tko.owner());
tko.burn(address(this), 1 ether);
uint256 balanceAfterBurn = tko.balanceOf(address(this));

assertEq(balanceBeforeBurn - 1 ether, balanceAfterBurn);
}

function test_snapshot() external {
vm.prank(tko.owner(), tko.owner());
tko.snapshot();

uint256 totalSupplyAtSnapshot = tko.totalSupplyAt(1);

vm.prank(tko.owner(), tko.owner());
tko.burn(address(this), 1 ether);

// At snapshot date vs. now, the total supply differs
assertEq(totalSupplyAtSnapshot, tko.totalSupply() + 1 ether);
}

function test_getTierIds() external {
uint16[] memory tiers = cp.getTierIds();
assertEq(tiers[0], LibTiers.TIER_OPTIMISTIC);
assertEq(tiers[1], LibTiers.TIER_SGX);
assertEq(tiers[2], LibTiers.TIER_GUARDIAN);

vm.expectRevert();
cp.getTier(123);
}

function proposeButRevert(
address proposer,
address prover,
uint24 txListSize,
bytes4 revertReason
)
internal
{
uint256 msgValue = 2 ether;
AssignmentHook.ProverAssignment memory assignment;
TaikoData.HookCall[] memory hookcalls = new TaikoData.HookCall[](1);
hookcalls[0] = TaikoData.HookCall(address(assignmentHook), abi.encode(assignment));

vm.prank(proposer, proposer);
vm.expectRevert(revertReason);
L1.proposeBlock{ value: msgValue }(
abi.encode(TaikoData.BlockParams(prover, address(0), 0, 0, 0, 0, false, 0, hookcalls)),
new bytes(txListSize)
);
}
}
18 changes: 18 additions & 0 deletions packages/protocol/test/L2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ contract TestTaikoL2 is TaikoTest {

vm.roll(block.number + 1);
vm.warp(block.timestamp + 30);

vm.deal(address(L2), 100 ether);
}

function test_L2_AnchorTx_with_constant_block_time() external {
Expand Down Expand Up @@ -137,6 +139,22 @@ contract TestTaikoL2 is TaikoTest {
LibL2Signer.signAnchor(digest, uint8(3));
}

function test_L2_withdraw() external {
vm.prank(L2.owner(), L2.owner());
L2.withdraw(address(0), Alice);
assertEq(address(L2).balance, 0 ether);
assertEq(Alice.balance, 100 ether);

// Random EOA cannot call withdraw
vm.expectRevert();
vm.prank(Alice, Alice);
L2.withdraw(address(0), Alice);
}

function test_L2_getBlockHash() external {
assertEq(L2.getBlockHash(uint64(1000)), 0);
}

function _anchor(uint32 parentGasLimit) private {
bytes32 l1Hash = randBytes32();
bytes32 l1StateRoot = randBytes32();
Expand Down
Loading