Skip to content

Commit

Permalink
test: point to deposit_v3 in order to test withdrawal unbonding perio…
Browse files Browse the repository at this point in the history
…d change to be based on block number
  • Loading branch information
86667 committed Dec 12, 2024
1 parent a23f9e4 commit d53d130
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/Console.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ library Console {
result = string.concat(result, Strings.toString(postdecimal));
}

function log(string memory format, uint256 amount, uint8 precision) pure internal {
function log(string memory format, uint256 amount, uint8 precision) view internal {
log(format, int256(amount), precision);
}

function log(string memory format, int256 amount, uint8 precision) pure internal {
function log(string memory format, int256 amount, uint8 precision) view internal {
(int256 predecimal, string memory zeros, uint256 postdecimal) = convert(amount, precision);
console.log(format, Strings.toStringSigned(predecimal), zeros, postdecimal);
}

function log(string memory format, uint256 amount) pure internal {
function log(string memory format, uint256 amount) view internal {
return log(format, amount, 18);
}

function log(string memory format, int256 amount) pure internal {
function log(string memory format, int256 amount) view internal {
return log(format, amount, 18);
}

function log(string memory format, uint64[] memory array) pure internal {
function log(string memory format, uint64[] memory array) view internal {
string memory s;
for (uint256 i = 0; i < array.length; i++) {
s = string.concat(s, Strings.toString(array[i]));
Expand Down
9 changes: 8 additions & 1 deletion test/BaseDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.26;

import {BaseDelegation} from "src/BaseDelegation.sol";
import {Delegation} from "src/Delegation.sol";
import {Deposit, InitialStaker} from "@zilliqa/zq2/deposit_v2.sol";
import {Deposit, InitialStaker} from "@zilliqa/zq2/deposit_v3.sol";
import {Console} from "src/Console.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Test, Vm} from "forge-std/Test.sol";
Expand All @@ -15,6 +15,12 @@ contract PopVerifyPrecompile {
}
}

contract BlsVerifyPrecompile {
function blsVerify(bytes memory, bytes memory, bytes memory) public pure returns(bool) {
return true;
}
}

abstract contract BaseDelegationTest is Test {
address payable proxy;
address oldImplementation;
Expand Down Expand Up @@ -127,6 +133,7 @@ abstract contract BaseDelegationTest is Test {
//*/

vm.etch(address(0x5a494c80), address(new PopVerifyPrecompile()).code);
vm.etch(address(0x5a494c81), address(new BlsVerifyPrecompile()).code);

vm.stopPrank();
}
Expand Down
33 changes: 18 additions & 15 deletions test/LiquidDelegation.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.26;

import {BaseDelegationTest, PopVerifyPrecompile} from "test/BaseDelegation.t.sol";
import {BaseDelegationTest, PopVerifyPrecompile, BlsVerifyPrecompile} from "test/BaseDelegation.t.sol";
import {LiquidDelegation} from "src/LiquidDelegation.sol";
import {LiquidDelegationV2} from "src/LiquidDelegationV2.sol";
import {NonRebasingLST} from "src/NonRebasingLST.sol";
import {BaseDelegation, WithdrawalQueue} from "src/BaseDelegation.sol";
import {Delegation} from "src/Delegation.sol";
import {Deposit} from "@zilliqa/zq2/deposit_v2.sol";
import {Deposit} from "@zilliqa/zq2/deposit_v3.sol";
import {Console} from "src/Console.sol";
import {Vm} from "forge-std/Test.sol";
import "forge-std/console.sol";
Expand Down Expand Up @@ -259,8 +259,6 @@ contract LiquidDelegationTest is BaseDelegationTest {
);

vm.roll(block.number + blocksUntil);
//TODO: remove the next line once https://github.com/Zilliqa/zq2/issues/1761 is fixed
vm.warp(block.timestamp + blocksUntil);

vm.recordLogs();

Expand Down Expand Up @@ -358,51 +356,56 @@ contract LiquidDelegationTest is BaseDelegationTest {
vm.deal(owner, 10_000_000 ether + 1_000_000 ether + 0 ether);
vm.deal(stakers[0], 0);
vm.startPrank(owner);

bytes memory bls_pub_key = bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2");
bytes memory peer_id = bytes(hex"002408011220bed0be7a6dfa10c2335148e04927155a726174d6bac61a09ad8e2f72ac697eda");
bytes memory signature = bytes(hex"90ec9a22e030a42d9b519b322d31b8090f796b3f75fc74261b04d0dcc632fd8c5b7a074c5ba61f0845b310fa9931d01c079eebe82813d7021ef4172e01a7d3710a5f9a4634e9a03a51e985836021c356a1eb476a14f558cbae1f4264edca5dac");

Deposit(delegation.DEPOSIT_CONTRACT()).deposit{
value: 10_000_000 ether
}(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c"),
bytes(hex"002408011220d5ed74b09dcbe84d3b32a56c01ab721cf82809848b6604535212a219d35c412f"),
bytes(hex"b14832a866a49ddf8a3104f8ee379d29c136f29aeb8fccec9d7fb17180b99e8ed29bee2ada5ce390cb704bc6fd7f5ce814f914498376c4b8bc14841a57ae22279769ec8614e2673ba7f36edc5a4bf5733aa9d70af626279ee2b2cde939b4bd8a"),
bls_pub_key,
peer_id,
signature,
address(stakers[0])
);
console.log("validator deposited");
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).blocksPerEpoch() * 2);
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
Deposit(delegation.DEPOSIT_CONTRACT()).depositTopup{
value: 1_000_000 ether
}();
console.log("validator staked");
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).blocksPerEpoch() * 2);
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
Deposit(delegation.DEPOSIT_CONTRACT()).unstake(
500_000 ether
);
console.log("validator unstaked");
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).blocksPerEpoch() * 2);
console.log("validator stake: %s", Deposit(delegation.DEPOSIT_CONTRACT()).getStake(
bytes(hex"92fbe50544dce63cfdcc88301d7412f0edea024c91ae5d6a04c7cd3819edfc1b9d75d9121080af12e00f054d221f876c")
bytes(hex"92370645a6ad97d8a4e4b44b8e6db63ab8409473310ac7b21063809450192bace7fb768d60c697a18bbf98b4ddb511f2")
));
console.log("validator balance: %s", owner.balance);
Deposit(delegation.DEPOSIT_CONTRACT()).withdraw();
console.log("validator withdrew");
console.log("validator balance: %s", owner.balance);
//vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).withdrawalPeriod());
vm.roll(block.number + Deposit(delegation.DEPOSIT_CONTRACT()).withdrawalPeriod());
//TODO: remove the next line and uncomment the previous once https://github.com/Zilliqa/zq2/issues/1761 is fixed
vm.warp(block.timestamp + Deposit(delegation.DEPOSIT_CONTRACT()).withdrawalPeriod()); // skip(WithdrawalQueue.unbondingPeriod());
// vm.warp(block.timestamp + Deposit(delegation.DEPOSIT_CONTRACT()).withdrawalPeriod()); // skip(WithdrawalQueue.unbondingPeriod());
Deposit(delegation.DEPOSIT_CONTRACT()).withdraw();
console.log("validator withdrew again");
console.log("validator balance: %s", owner.balance);
Expand Down
7 changes: 2 additions & 5 deletions test/NonLiquidDelegation.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.26;

import {BaseDelegationTest, PopVerifyPrecompile} from "test/BaseDelegation.t.sol";
import {BaseDelegationTest, PopVerifyPrecompile, BlsVerifyPrecompile} from "test/BaseDelegation.t.sol";
import {NonLiquidDelegation} from "src/NonLiquidDelegation.sol";
import {NonLiquidDelegationV2} from "src/NonLiquidDelegationV2.sol";
import {BaseDelegation, WithdrawalQueue} from "src/BaseDelegation.sol";
Expand Down Expand Up @@ -40,7 +40,7 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
revert("staker not found");
}

function snapshot(string memory s, uint256 i, uint256 x) internal view {
function snapshot(string memory s, uint256 i, uint256 x) internal {
console.log("-----------------------------------------------");
console.log(s, i, x);
uint256[] memory shares = new uint256[](stakers.length);
Expand Down Expand Up @@ -462,9 +462,6 @@ contract NonLiquidDelegationTest is BaseDelegationTest {
vm.stopPrank();

vm.roll(block.number + WithdrawalQueue.unbondingPeriod());
//TODO: remove the next line once https://github.com/Zilliqa/zq2/issues/1761 is fixed
vm.warp(block.timestamp + WithdrawalQueue.unbondingPeriod());


i = 1;
vm.startPrank(stakers[i-1]);
Expand Down

0 comments on commit d53d130

Please sign in to comment.