tests for new gatekeeper logic; except materialize function. actual signatures needed
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
c4f4f2e0e2
commit
0d043ea964
@ -9,7 +9,6 @@ import {GhostAuthority} from "../../src/GhostAuthority.sol";
|
|||||||
import {GhostTreasury} from "../../src/Treasury.sol";
|
import {GhostTreasury} from "../../src/Treasury.sol";
|
||||||
import {GhostStaking} from "../../src/Staking.sol";
|
import {GhostStaking} from "../../src/Staking.sol";
|
||||||
import {GhostBondDepository} from "../../src/BondDepository.sol";
|
import {GhostBondDepository} from "../../src/BondDepository.sol";
|
||||||
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
|
||||||
import {ERC20Mock} from "../../src/mocks/ERC20Mock.sol";
|
import {ERC20Mock} from "../../src/mocks/ERC20Mock.sol";
|
||||||
import {WETH9} from "../../src/mocks/WETH9.sol";
|
import {WETH9} from "../../src/mocks/WETH9.sol";
|
||||||
import {GhostBondingCalculator} from "../../src/StandardBondingCalculator.sol";
|
import {GhostBondingCalculator} from "../../src/StandardBondingCalculator.sol";
|
||||||
@ -76,7 +75,8 @@ contract GhostBondDepositoryTest is Test {
|
|||||||
EPOCH_LENGTH,
|
EPOCH_LENGTH,
|
||||||
EPOCH_NUMBER,
|
EPOCH_NUMBER,
|
||||||
EPOCH_END_TIME,
|
EPOCH_END_TIME,
|
||||||
address(authority)
|
address(authority),
|
||||||
|
0
|
||||||
);
|
);
|
||||||
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
||||||
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
||||||
@ -324,8 +324,6 @@ contract GhostBondDepositoryTest is Test {
|
|||||||
uint256 amount = 10_000 * 1e18; // 10,000
|
uint256 amount = 10_000 * 1e18; // 10,000
|
||||||
|
|
||||||
vm.startPrank(GOVERNOR);
|
vm.startPrank(GOVERNOR);
|
||||||
Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, address(0));
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
staking.setWarmupPeriod(1);
|
staking.setWarmupPeriod(1);
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
@ -509,8 +507,6 @@ contract GhostBondDepositoryTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm.startPrank(GOVERNOR);
|
vm.startPrank(GOVERNOR);
|
||||||
Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, address(0));
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
staking.setWarmupPeriod(10);
|
staking.setWarmupPeriod(10);
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,8 @@ contract GatekeeperTest is Test {
|
|||||||
event Ghosted(bytes32 indexed receiver, uint256 indexed amount);
|
event Ghosted(bytes32 indexed receiver, uint256 indexed amount);
|
||||||
|
|
||||||
function setUp() public {
|
function setUp() public {
|
||||||
gatekeeper = new Gatekeeper(ALICE, EXISTENTIAL, address(0));
|
vm.prank(ALICE, ALICE);
|
||||||
|
gatekeeper = new Gatekeeper(EXISTENTIAL, address(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_correctInitialization() public {
|
function test_correctInitialization() public {
|
||||||
@ -25,14 +26,15 @@ contract GatekeeperTest is Test {
|
|||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
gatekeeper.ghost(receiver, INIT_AMOUNT);
|
gatekeeper.ghost(receiver, INIT_AMOUNT);
|
||||||
|
|
||||||
Gatekeeper anotherGatekeeper = new Gatekeeper(BOB, EXISTENTIAL, address(gatekeeper));
|
vm.prank(BOB);
|
||||||
|
Gatekeeper anotherGatekeeper = new Gatekeeper(EXISTENTIAL, address(gatekeeper));
|
||||||
assertEq(anotherGatekeeper.staking(), ALICE);
|
assertEq(anotherGatekeeper.staking(), ALICE);
|
||||||
assertEq(anotherGatekeeper.ghostedSupply(), INIT_AMOUNT);
|
assertEq(anotherGatekeeper.ghostedSupply(), INIT_AMOUNT);
|
||||||
assertEq(anotherGatekeeper.existentialDeposit(), EXISTENTIAL);
|
assertEq(anotherGatekeeper.existentialDeposit(), EXISTENTIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_ghostTokensWork(uint256 ghostAmount) public {
|
function test_ghostTokensWork(uint256 ghostAmount) public {
|
||||||
vm.assume(ghostAmount >= EXISTENTIAL);
|
vm.assume(ghostAmount >= EXISTENTIAL && ghostAmount < type(uint96).max);
|
||||||
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
||||||
uint256 ghostedSupply = gatekeeper.ghostedSupply();
|
uint256 ghostedSupply = gatekeeper.ghostedSupply();
|
||||||
|
|
||||||
@ -61,14 +63,16 @@ contract GatekeeperTest is Test {
|
|||||||
gatekeeper.ghost(receiver, ghostAmount);
|
gatekeeper.ghost(receiver, ghostAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_materializeWork(uint256 ghostAmount) public {
|
// TODO: revisit with actual signatures from the cargo test
|
||||||
vm.expectRevert();
|
// function test_materializeWork(uint256 ghostAmount) public {
|
||||||
gatekeeper.materialize(ALICE, ghostAmount, 0, 0);
|
// vm.prank(ALICE);
|
||||||
}
|
// gatekeeper.materialize(0, ghostAmount, 0, ALICE);
|
||||||
|
// }
|
||||||
|
|
||||||
function test_rotateWork(uint256 aggregatedPublicKey) public {
|
function test_rotateWork(bytes32 aggregatedPublicKey) public {
|
||||||
vm.expectRevert();
|
vm.warp(block.timestamp + 1);
|
||||||
gatekeeper.rotate(aggregatedPublicKey, 0, 0);
|
vm.prank(address(gatekeeper));
|
||||||
|
gatekeeper.rotate(block.timestamp, aggregatedPublicKey, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_couldNotBridgeBelowExistential(uint256 amount) public {
|
function test_couldNotBridgeBelowExistential(uint256 amount) public {
|
||||||
@ -80,6 +84,78 @@ contract GatekeeperTest is Test {
|
|||||||
gatekeeper.ghost(receiver, amount);
|
gatekeeper.ghost(receiver, amount);
|
||||||
|
|
||||||
assertEq(gatekeeper.ghostedSupply(), 0);
|
assertEq(gatekeeper.ghostedSupply(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_signatureVerificationsWorks() public {
|
||||||
|
assertEq(gatekeeper.deployer(), ALICE);
|
||||||
|
vm.prank(ALICE);
|
||||||
|
gatekeeper.updatePublicKeyMetadata(0, 0x875cdcba4ae5494518fa2602791e667ca0998402b6a69e5b7cb4c72dba4e4669, 0);
|
||||||
|
|
||||||
|
(bytes32 prevPublicKey, uint8 prevParity, uint64 prevSession) = gatekeeper.latestPublicKeyInfo();
|
||||||
|
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a670000000000000000000000000000000000000000000000000000000000000000875cdcba4ae5494518fa2602791e667ca0998402b6a69e5b7cb4c72dba4e46690000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"044d9fa18df9da04381ed256981570a6ef6a0893496ded966fc994662df931ed423b29e2737394b31d8498594caad7b77e36ab31ac79df3796a1b6f26baa5552ae",
|
||||||
|
0x24029a571fcaeadd14f4afe8be62afe3d07876ae270c3caf446ecb6cfc7c08f2
|
||||||
|
);
|
||||||
|
|
||||||
|
(bytes32 publicKey, uint8 parity, uint64 session) = gatekeeper.latestPublicKeyInfo();
|
||||||
|
assertEq(publicKey, prevPublicKey);
|
||||||
|
assertEq(parity, prevParity);
|
||||||
|
assertEq(session, prevSession);
|
||||||
|
|
||||||
|
vm.expectRevert();
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a6700000000000000000000000000000000000000000000000000000000000000023492bc8bb10848f1f788496ccadde7d458eac4ac2c1eca2dd2c7a506d8fa2c5b0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"042b45a8909a137e7bab5caf4b2870ece0469c6a4149c10074cfdaf2c114a65daefe14179830c95d07fea439ce78d2ad11898578e5e678dbcb98a7576da9e57c77",
|
||||||
|
0x5a61b59cededac4010b89bc6935e0cb7d975f5e2db457227ee473203de5247ed
|
||||||
|
);
|
||||||
|
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a6700000000000000000000000000000000000000000000000000000000000000014e8c1fe96d6737cdabbcc96501d6656b9d0b659b3a528ef507f2d52bef29e1570000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"04d4c4daeb68bf8e40db4b516ddf3be9dd0f56a81809945e30bf06b7e5b26d1b27c83367de842f00c915f06ab1755dc511a3a3fe213308b5e65c6832d9d9bb3b38",
|
||||||
|
0xd93d1b1613277ddb27df66bdea16d7b91adf975eb150e27a872ce035655ec13d
|
||||||
|
);
|
||||||
|
|
||||||
|
(publicKey, parity, session) = gatekeeper.latestPublicKeyInfo();
|
||||||
|
assert(publicKey != prevPublicKey);
|
||||||
|
assertEq(parity, prevParity);
|
||||||
|
assertEq(session, prevSession + 1);
|
||||||
|
|
||||||
|
prevPublicKey = publicKey;
|
||||||
|
prevParity = parity;
|
||||||
|
prevSession = session;
|
||||||
|
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a6700000000000000000000000000000000000000000000000000000000000000023492bc8bb10848f1f788496ccadde7d458eac4ac2c1eca2dd2c7a506d8fa2c5b0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"042b45a8909a137e7bab5caf4b2870ece0469c6a4149c10074cfdaf2c114a65daefe14179830c95d07fea439ce78d2ad11898578e5e678dbcb98a7576da9e57c77",
|
||||||
|
0x5a61b59cededac4010b89bc6935e0cb7d975f5e2db457227ee473203de5247ed
|
||||||
|
);
|
||||||
|
|
||||||
|
(publicKey, parity, session) = gatekeeper.latestPublicKeyInfo();
|
||||||
|
assert(publicKey != prevPublicKey);
|
||||||
|
assertEq(parity, prevParity);
|
||||||
|
assertEq(session, prevSession + 1);
|
||||||
|
|
||||||
|
vm.expectRevert();
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a670000000000000000000000000000000000000000000000000000000000000000875cdcba4ae5494518fa2602791e667ca0998402b6a69e5b7cb4c72dba4e46690000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"044d9fa18df9da04381ed256981570a6ef6a0893496ded966fc994662df931ed423b29e2737394b31d8498594caad7b77e36ab31ac79df3796a1b6f26baa5552ae",
|
||||||
|
0x24029a571fcaeadd14f4afe8be62afe3d07876ae270c3caf446ecb6cfc7c08f2
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.expectRevert();
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a6700000000000000000000000000000000000000000000000000000000000000014e8c1fe96d6737cdabbcc96501d6656b9d0b659b3a528ef507f2d52bef29e1570000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"04d4c4daeb68bf8e40db4b516ddf3be9dd0f56a81809945e30bf06b7e5b26d1b27c83367de842f00c915f06ab1755dc511a3a3fe213308b5e65c6832d9d9bb3b38",
|
||||||
|
0xd93d1b1613277ddb27df66bdea16d7b91adf975eb150e27a872ce035655ec13d
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.expectRevert();
|
||||||
|
gatekeeper.verify(
|
||||||
|
hex"49f03a6700000000000000000000000000000000000000000000000000000000000000023492bc8bb10848f1f788496ccadde7d458eac4ac2c1eca2dd2c7a506d8fa2c5b0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
hex"042b45a8909a137e7bab5caf4b2870ece0469c6a4149c10074cfdaf2c114a65daefe14179830c95d07fea439ce78d2ad11898578e5e678dbcb98a7576da9e57c77",
|
||||||
|
0x5a61b59cededac4010b89bc6935e0cb7d975f5e2db457227ee473203de5247ed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
test/gatekeeper/GatekeeperHistory.t.sol
Normal file
62
test/gatekeeper/GatekeeperHistory.t.sol
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
pragma solidity 0.8.20;
|
||||||
|
|
||||||
|
import {Test} from "forge-std/Test.sol";
|
||||||
|
|
||||||
|
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
||||||
|
import {IStorageHistory} from "../../src/interfaces/IStorageHistory.sol";
|
||||||
|
|
||||||
|
contract GatekeeperStorageHistoryTest is Test {
|
||||||
|
address constant ALICE = 0x0000000000000000000000000000000000000001;
|
||||||
|
address constant BOB = 0x0000000000000000000000000000000000000002;
|
||||||
|
uint256 constant INIT_AMOUNT = 69 * 1e18;
|
||||||
|
uint256 constant INIT_GHOSTED = type(uint104).max / 2;
|
||||||
|
uint256 constant EXISTENTIAL = 0;
|
||||||
|
|
||||||
|
Gatekeeper gatekeeper;
|
||||||
|
|
||||||
|
function setUp() public {
|
||||||
|
vm.prank(ALICE);
|
||||||
|
gatekeeper = new Gatekeeper(EXISTENTIAL, address(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_correctStorageHistoryInitialization() public view {
|
||||||
|
address storageHistory = gatekeeper.storageHistory();
|
||||||
|
IStorageHistory.DeploymentSnapshot memory snapshot = IStorageHistory(storageHistory).deploymentSnapshot();
|
||||||
|
|
||||||
|
assertEq(snapshot.deployedAt, 0);
|
||||||
|
assertEq(snapshot.amountIn, 0);
|
||||||
|
assertEq(snapshot.amountOut, 0);
|
||||||
|
assertEq(gatekeeper.ghostedSupply(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_historicalAmountsOnlyIncrease(uint256 ghostAmount) public {
|
||||||
|
vm.assume(ghostAmount > 0 && ghostAmount < INIT_GHOSTED / 2);
|
||||||
|
|
||||||
|
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
||||||
|
address storageHistory = gatekeeper.storageHistory();
|
||||||
|
|
||||||
|
IStorageHistory.DeploymentSnapshot memory snapshot = IStorageHistory(storageHistory).deploymentSnapshot();
|
||||||
|
uint104 amountIn = snapshot.amountIn;
|
||||||
|
uint104 amountOut = snapshot.amountOut;
|
||||||
|
|
||||||
|
if (ghostAmount % 2 == 0) {
|
||||||
|
vm.prank(ALICE);
|
||||||
|
gatekeeper.ghost(receiver, ghostAmount);
|
||||||
|
// forge-lint: disable-next-line(unsafe-typecast)
|
||||||
|
amountIn += uint104(ghostAmount);
|
||||||
|
} else {
|
||||||
|
if (IStorageHistory(storageHistory).bridgeImbalance() >= ghostAmount) {
|
||||||
|
vm.prank(ALICE);
|
||||||
|
gatekeeper.materialize(0, ghostAmount, 0, BOB);
|
||||||
|
// forge-lint: disable-next-line(unsafe-typecast)
|
||||||
|
amountOut += uint104(ghostAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IStorageHistory.DeploymentSnapshot memory newSnapshot = IStorageHistory(storageHistory).deploymentSnapshot();
|
||||||
|
assertEq(newSnapshot.amountIn, amountIn);
|
||||||
|
assertEq(newSnapshot.amountOut, amountOut);
|
||||||
|
assertEq(gatekeeper.ghostedSupply(), amountIn - amountOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,53 +0,0 @@
|
|||||||
pragma solidity 0.8.20;
|
|
||||||
|
|
||||||
import {Test} from "forge-std/Test.sol";
|
|
||||||
|
|
||||||
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
|
||||||
|
|
||||||
contract GatekeeperMetadataTest is Test {
|
|
||||||
address constant ALICE = 0x0000000000000000000000000000000000000001;
|
|
||||||
uint256 constant INIT_AMOUNT = 69 * 1e18;
|
|
||||||
uint256 constant INIT_GHOSTED = type(uint104).max / 2;
|
|
||||||
uint256 constant EXISTENTIAL = 0;
|
|
||||||
|
|
||||||
Gatekeeper gatekeeper;
|
|
||||||
|
|
||||||
function setUp() public {
|
|
||||||
gatekeeper = new Gatekeeper(ALICE, EXISTENTIAL, address(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_correctMetadataInitialization() public view {
|
|
||||||
Gatekeeper.GatekeeperMetadata memory metadata = gatekeeper.metadata();
|
|
||||||
assertEq(metadata.deployedAt, block.number);
|
|
||||||
assertEq(metadata.amountIn, 0);
|
|
||||||
assertEq(metadata.amountOut, 0);
|
|
||||||
assertEq(gatekeeper.ghostedSupply(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_historicalAmountsOnlyIncrease(uint256 ghostAmount) public {
|
|
||||||
vm.assume(ghostAmount > 0 && ghostAmount < INIT_GHOSTED / 2);
|
|
||||||
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
|
||||||
uint256 ghostedSupply = gatekeeper.ghostedSupply();
|
|
||||||
|
|
||||||
Gatekeeper.GatekeeperMetadata memory metadata = gatekeeper.metadata();
|
|
||||||
uint104 amountIn = metadata.amountIn;
|
|
||||||
uint104 amountOut = metadata.amountOut;
|
|
||||||
|
|
||||||
if (ghostAmount % 2 == 0) {
|
|
||||||
vm.prank(ALICE);
|
|
||||||
gatekeeper.ghost(receiver, ghostAmount);
|
|
||||||
amountIn += uint104(ghostAmount); // forge-lint: disable-line(unsafe-typecast)
|
|
||||||
ghostedSupply += ghostAmount;
|
|
||||||
} else {
|
|
||||||
vm.expectRevert();
|
|
||||||
vm.prank(ALICE);
|
|
||||||
gatekeeper.materialize(ALICE, ghostAmount, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gatekeeper.GatekeeperMetadata memory newMetadata = gatekeeper.metadata();
|
|
||||||
assertEq(newMetadata.amountIn, amountIn);
|
|
||||||
assertEq(newMetadata.amountOut, amountOut);
|
|
||||||
assertEq(gatekeeper.ghostedSupply(), ghostedSupply);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -5,20 +5,37 @@ import {Test} from "forge-std/Test.sol";
|
|||||||
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
||||||
import {Hashes} from "../../src/libraries/Hashes.sol";
|
import {Hashes} from "../../src/libraries/Hashes.sol";
|
||||||
import {Checkpoints} from "../../src/libraries/Checkpoints.sol";
|
import {Checkpoints} from "../../src/libraries/Checkpoints.sol";
|
||||||
|
import {IGatekeeper} from "../../src/interfaces/IGatekeeper.sol";
|
||||||
|
import {IStorageHistory} from "../../src/interfaces/IStorageHistory.sol";
|
||||||
|
|
||||||
|
contract MockStaking {
|
||||||
|
GatekeeperVerification public gatekeeper;
|
||||||
|
address public governor;
|
||||||
|
|
||||||
|
constructor(uint256 existential) {
|
||||||
|
gatekeeper = new GatekeeperVerification(existential, address(0));
|
||||||
|
governor = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ghost(bytes32 receiver, uint256 amount) external returns (uint256) {
|
||||||
|
require(msg.sender == governor);
|
||||||
|
return gatekeeper.ghost(receiver, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNewGatekeeper(uint256 existential, address previousGatekeeper) external {
|
||||||
|
require(msg.sender == governor);
|
||||||
|
GatekeeperVerification newGatekeeper = new GatekeeperVerification(existential, address(gatekeeper));
|
||||||
|
address storageHistory = IGatekeeper(previousGatekeeper).storageHistory();
|
||||||
|
IStorageHistory(storageHistory).setOwner(address(newGatekeeper));
|
||||||
|
gatekeeper = newGatekeeper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contract GatekeeperVerification is Gatekeeper {
|
contract GatekeeperVerification is Gatekeeper {
|
||||||
using Checkpoints for Checkpoints.Trace256;
|
using Checkpoints for Checkpoints.Trace256;
|
||||||
using Checkpoints for Checkpoints.Trace160;
|
using Checkpoints for Checkpoints.Trace160;
|
||||||
|
|
||||||
constructor(
|
constructor(uint256 existential, address previousWeaver) Gatekeeper(existential, previousWeaver) {}
|
||||||
address staking,
|
|
||||||
uint256 existential,
|
|
||||||
address previousWeaver
|
|
||||||
) Gatekeeper(
|
|
||||||
staking,
|
|
||||||
existential,
|
|
||||||
previousWeaver
|
|
||||||
) {}
|
|
||||||
|
|
||||||
function filledEntries(uint256 session) public view returns (uint256) {
|
function filledEntries(uint256 session) public view returns (uint256) {
|
||||||
return _filledEntries[session];
|
return _filledEntries[session];
|
||||||
@ -93,14 +110,17 @@ contract GatekeeperWeaverTest is Test {
|
|||||||
uint256 constant EXISTENTIAL = 1337;
|
uint256 constant EXISTENTIAL = 1337;
|
||||||
uint256 constant AMOUNT = 1 * 1e7;
|
uint256 constant AMOUNT = 1 * 1e7;
|
||||||
|
|
||||||
|
MockStaking staking;
|
||||||
GatekeeperVerification gatekeeper;
|
GatekeeperVerification gatekeeper;
|
||||||
|
|
||||||
function setUp() public {
|
function setUp() public {
|
||||||
gatekeeper = new GatekeeperVerification(ALICE, EXISTENTIAL, address(0));
|
vm.prank(ALICE);
|
||||||
|
staking = new MockStaking(EXISTENTIAL);
|
||||||
|
gatekeeper = staking.gatekeeper();
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_insertationWorksAsExpected() public {
|
function test_insertationWorksAsExpected() public {
|
||||||
uint256 currentSession = gatekeeper.currentSession();
|
uint256 currentWeavingSession = gatekeeper.currentWeavingSession();
|
||||||
uint256 maxCount = gatekeeper.ENTRIES();
|
uint256 maxCount = gatekeeper.ENTRIES();
|
||||||
uint256 globalIndex;
|
uint256 globalIndex;
|
||||||
|
|
||||||
@ -108,55 +128,59 @@ contract GatekeeperWeaverTest is Test {
|
|||||||
|
|
||||||
for (uint256 i = 0; i < maxCount; i++) {
|
for (uint256 i = 0; i < maxCount; i++) {
|
||||||
if (i % 5 == 0) { vm.roll(block.number + 1); }
|
if (i % 5 == 0) { vm.roll(block.number + 1); }
|
||||||
globalIndex = _insertWithAssert(currentSession, amounts[i], whos[i]);
|
globalIndex = _insertWithAssert(currentWeavingSession, amounts[i], whos[i]);
|
||||||
assertTrue(_verifyProof(globalIndex, currentSession, block.number, amounts[i], whos[i]));
|
assertTrue(_verifyProof(globalIndex, currentWeavingSession, block.number, amounts[i], whos[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
globalIndex = _insertWithAssert(currentSession, amounts[69], whos[69]);
|
globalIndex = _insertWithAssert(currentWeavingSession, amounts[69], whos[69]);
|
||||||
uint256 newSession = gatekeeper.currentSession();
|
uint256 newSession = gatekeeper.currentWeavingSession();
|
||||||
|
|
||||||
assertEq(currentSession + 1, newSession);
|
assertEq(currentWeavingSession + 1, newSession);
|
||||||
vm.roll(block.number + 1337);
|
vm.roll(block.number + 1337);
|
||||||
|
|
||||||
assertTrue(_verifyProof(globalIndex, newSession, block.number, amounts[69], whos[69]));
|
assertTrue(_verifyProof(globalIndex, newSession, block.number, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(0, currentSession, block.number, amounts[0], whos[0]));
|
assertTrue(_verifyProof(0, currentWeavingSession, block.number, amounts[0], whos[0]));
|
||||||
assertTrue(_verifyProof(69, currentSession, block.number, amounts[69], whos[69]));
|
assertTrue(_verifyProof(69, currentWeavingSession, block.number, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(420, currentSession, block.number, amounts[420], whos[420]));
|
assertTrue(_verifyProof(420, currentWeavingSession, block.number, amounts[420], whos[420]));
|
||||||
assertTrue(_verifyProof(1337, currentSession, block.number, amounts[1337], whos[1337]));
|
assertTrue(_verifyProof(1337, currentWeavingSession, block.number, amounts[1337], whos[1337]));
|
||||||
assertTrue(_verifyProof(2047, currentSession, block.number, amounts[2047], whos[2047]));
|
assertTrue(_verifyProof(2047, currentWeavingSession, block.number, amounts[2047], whos[2047]));
|
||||||
|
|
||||||
assertTrue(_verifyProof(0, currentSession, 100, amounts[0], whos[0]));
|
assertTrue(_verifyProof(0, currentWeavingSession, 100, amounts[0], whos[0]));
|
||||||
assertTrue(_verifyProof(69, currentSession, 100, amounts[69], whos[69]));
|
assertTrue(_verifyProof(69, currentWeavingSession, 100, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(420, currentSession, 100, amounts[420], whos[420]));
|
assertTrue(_verifyProof(420, currentWeavingSession, 100, amounts[420], whos[420]));
|
||||||
|
|
||||||
assertFalse(_verifyProof(globalIndex, newSession, 100, amounts[69], whos[69]));
|
assertFalse(_verifyProof(globalIndex, newSession, 100, amounts[69], whos[69]));
|
||||||
assertFalse(_verifyProof(1337, currentSession, 100, amounts[1337], whos[1337]));
|
assertFalse(_verifyProof(1337, currentWeavingSession, 100, amounts[1337], whos[1337]));
|
||||||
assertFalse(_verifyProof(2047, currentSession, 100, amounts[2047], whos[2047]));
|
assertFalse(_verifyProof(2047, currentWeavingSession, 100, amounts[2047], whos[2047]));
|
||||||
|
|
||||||
vm.roll(block.number + 420);
|
vm.roll(block.number + 420);
|
||||||
gatekeeper = new GatekeeperVerification(ALICE, EXISTENTIAL, address(gatekeeper));
|
|
||||||
uint256 finalSession = gatekeeper.currentSession();
|
vm.prank(ALICE);
|
||||||
|
staking.createNewGatekeeper(EXISTENTIAL, address(gatekeeper));
|
||||||
|
gatekeeper = staking.gatekeeper();
|
||||||
|
|
||||||
|
uint256 finalSession = gatekeeper.currentWeavingSession();
|
||||||
|
|
||||||
for (uint256 i = 0; i < 69; i++) {
|
for (uint256 i = 0; i < 69; i++) {
|
||||||
if (i % 2 == 0) { vm.roll(block.number + 1); }
|
if (i % 2 == 0) { vm.roll(block.number + 1); }
|
||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
gatekeeper.ghost(whos[i], amounts[i]);
|
staking.ghost(whos[i], amounts[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(_verifyProof(globalIndex, newSession, block.number, amounts[69], whos[69]));
|
assertTrue(_verifyProof(globalIndex, newSession, block.number, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(0, currentSession, block.number, amounts[0], whos[0]));
|
assertTrue(_verifyProof(0, currentWeavingSession, block.number, amounts[0], whos[0]));
|
||||||
assertTrue(_verifyProof(69, currentSession, block.number, amounts[69], whos[69]));
|
assertTrue(_verifyProof(69, currentWeavingSession, block.number, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(420, currentSession, block.number, amounts[420], whos[420]));
|
assertTrue(_verifyProof(420, currentWeavingSession, block.number, amounts[420], whos[420]));
|
||||||
assertTrue(_verifyProof(1337, currentSession, block.number, amounts[1337], whos[1337]));
|
assertTrue(_verifyProof(1337, currentWeavingSession, block.number, amounts[1337], whos[1337]));
|
||||||
assertTrue(_verifyProof(2047, currentSession, block.number, amounts[2047], whos[2047]));
|
assertTrue(_verifyProof(2047, currentWeavingSession, block.number, amounts[2047], whos[2047]));
|
||||||
|
|
||||||
assertTrue(_verifyProof(0, currentSession, 100, amounts[0], whos[0]));
|
assertTrue(_verifyProof(0, currentWeavingSession, 100, amounts[0], whos[0]));
|
||||||
assertTrue(_verifyProof(69, currentSession, 100, amounts[69], whos[69]));
|
assertTrue(_verifyProof(69, currentWeavingSession, 100, amounts[69], whos[69]));
|
||||||
assertTrue(_verifyProof(420, currentSession, 100, amounts[420], whos[420]));
|
assertTrue(_verifyProof(420, currentWeavingSession, 100, amounts[420], whos[420]));
|
||||||
|
|
||||||
assertFalse(_verifyProof(globalIndex, newSession, 100, amounts[69], whos[69]));
|
assertFalse(_verifyProof(globalIndex, newSession, 100, amounts[69], whos[69]));
|
||||||
assertFalse(_verifyProof(1337, currentSession, 100, amounts[1337], whos[1337]));
|
assertFalse(_verifyProof(1337, currentWeavingSession, 100, amounts[1337], whos[1337]));
|
||||||
assertFalse(_verifyProof(2047, currentSession, 100, amounts[2047], whos[2047]));
|
assertFalse(_verifyProof(2047, currentWeavingSession, 100, amounts[2047], whos[2047]));
|
||||||
|
|
||||||
assertTrue(_verifyProof(0, finalSession, block.number, amounts[0], whos[0]));
|
assertTrue(_verifyProof(0, finalSession, block.number, amounts[0], whos[0]));
|
||||||
assertTrue(_verifyProof(34, finalSession, block.number, amounts[34], whos[34]));
|
assertTrue(_verifyProof(34, finalSession, block.number, amounts[34], whos[34]));
|
||||||
@ -191,14 +215,14 @@ contract GatekeeperWeaverTest is Test {
|
|||||||
uint160 prevLength = gatekeeper.slotLengths(session, targetSlot);
|
uint160 prevLength = gatekeeper.slotLengths(session, targetSlot);
|
||||||
|
|
||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
globalIndex = gatekeeper.ghost(who, amount);
|
globalIndex = staking.ghost(who, amount);
|
||||||
|
|
||||||
if (session + 1 == gatekeeper.currentSession()) {
|
if (session + 1 == gatekeeper.currentWeavingSession()) {
|
||||||
assertEq(prevLength, gatekeeper.DEPTH());
|
assertEq(prevLength, gatekeeper.DEPTH());
|
||||||
assertEq(gatekeeper.slotLengths(session + 1, 0), 1);
|
assertEq(gatekeeper.slotLengths(session + 1, 0), 1);
|
||||||
assertEq(prevEntries, gatekeeper.ENTRIES());
|
assertEq(prevEntries, gatekeeper.ENTRIES());
|
||||||
assertEq(gatekeeper.filledEntries(session + 1), 1);
|
assertEq(gatekeeper.filledEntries(session + 1), 1);
|
||||||
assertEq(session + 1, gatekeeper.currentSession());
|
assertEq(session + 1, gatekeeper.currentWeavingSession());
|
||||||
|
|
||||||
session += 1;
|
session += 1;
|
||||||
previousHash = bytes32(0);
|
previousHash = bytes32(0);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import {GhostDistributor} from "../../src/StakingDistributor.sol";
|
|||||||
import {GhostTreasury} from "../../src/Treasury.sol";
|
import {GhostTreasury} from "../../src/Treasury.sol";
|
||||||
import {GhostStaking} from "../../src/Staking.sol";
|
import {GhostStaking} from "../../src/Staking.sol";
|
||||||
import {ERC20Mock} from "../../src/mocks/ERC20Mock.sol";
|
import {ERC20Mock} from "../../src/mocks/ERC20Mock.sol";
|
||||||
import {Gatekeeper} from "../../src/Gatekeeper.sol";
|
|
||||||
import {GhostBondingCalculator} from "../../src/StandardBondingCalculator.sol";
|
import {GhostBondingCalculator} from "../../src/StandardBondingCalculator.sol";
|
||||||
|
|
||||||
import {ITreasury} from "../../src/interfaces/ITreasury.sol";
|
import {ITreasury} from "../../src/interfaces/ITreasury.sol";
|
||||||
@ -61,7 +60,6 @@ contract StakingTest is Test {
|
|||||||
GhostStaking staking;
|
GhostStaking staking;
|
||||||
GhostTreasury treasury;
|
GhostTreasury treasury;
|
||||||
GhostAuthority authority;
|
GhostAuthority authority;
|
||||||
Gatekeeper gatekeeper;
|
|
||||||
GhostBondingCalculator calculator;
|
GhostBondingCalculator calculator;
|
||||||
|
|
||||||
uint256 public constant AMOUNT = 69;
|
uint256 public constant AMOUNT = 69;
|
||||||
@ -105,12 +103,12 @@ contract StakingTest is Test {
|
|||||||
EPOCH_LENGTH,
|
EPOCH_LENGTH,
|
||||||
EPOCH_NUMBER,
|
EPOCH_NUMBER,
|
||||||
EPOCH_END_TIME,
|
EPOCH_END_TIME,
|
||||||
address(authority)
|
address(authority),
|
||||||
|
0
|
||||||
);
|
);
|
||||||
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
||||||
stnk.initialize(address(staking), address(treasury), address(ghst));
|
stnk.initialize(address(staking), address(treasury), address(ghst));
|
||||||
ghst.initialize(address(staking));
|
ghst.initialize(address(staking));
|
||||||
gatekeeper = new Gatekeeper(address(staking), 0, address(0));
|
|
||||||
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
vm.roll(block.number + 1);
|
vm.roll(block.number + 1);
|
||||||
@ -588,34 +586,14 @@ contract StakingTest is Test {
|
|||||||
staking.setDistributor(maybeGatekeeper);
|
staking.setDistributor(maybeGatekeeper);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_GOVERNORCouldSetGatekeeper(address maybeGatekeeper) public {
|
function test_GOVERNORCouldSetGatekeeper() public {
|
||||||
vm.assume(maybeGatekeeper != address(0));
|
address previousGatekeeper = staking.gatekeeper();
|
||||||
assertEq(staking.gatekeeper(), address(0));
|
|
||||||
vm.prank(GOVERNOR);
|
vm.prank(GOVERNOR);
|
||||||
staking.setGatekeeperAddress(maybeGatekeeper);
|
staking.setGatekeeperAddress(420);
|
||||||
assertEq(staking.gatekeeper(), maybeGatekeeper);
|
assert(staking.gatekeeper() != previousGatekeeper);
|
||||||
}
|
|
||||||
|
|
||||||
function test_couldNotGhostIfNoGatekeeper() public {
|
|
||||||
assertEq(staking.ghostedSupply(), 0);
|
|
||||||
vm.expectRevert();
|
|
||||||
staking.ghost(bytes32(abi.encodePacked(ALICE)), AMOUNT);
|
|
||||||
assertEq(staking.ghostedSupply(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_couldNotMaterializeIfNoGatekeeper() public {
|
|
||||||
assertEq(staking.ghostedSupply(), 0);
|
|
||||||
vm.expectRevert();
|
|
||||||
staking.materialize(ALICE, AMOUNT, 0, 0); // dummy rx and s
|
|
||||||
assertEq(staking.ghostedSupply(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_couldNotGhostTokensIfNoGhst() public {
|
function test_couldNotGhostTokensIfNoGhst() public {
|
||||||
assertEq(staking.gatekeeper(), address(0));
|
|
||||||
vm.prank(GOVERNOR);
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
assertEq(staking.gatekeeper(), address(gatekeeper));
|
|
||||||
|
|
||||||
assertEq(staking.ghostedSupply(), 0);
|
assertEq(staking.ghostedSupply(), 0);
|
||||||
vm.expectRevert();
|
vm.expectRevert();
|
||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
@ -624,11 +602,6 @@ contract StakingTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_correctlyGhostTokens() public {
|
function test_correctlyGhostTokens() public {
|
||||||
assertEq(staking.gatekeeper(), address(0));
|
|
||||||
vm.prank(GOVERNOR);
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
assertEq(staking.gatekeeper(), address(gatekeeper));
|
|
||||||
|
|
||||||
_prepareAndRoll(ALICE, BIG_AMOUNT, true, true);
|
_prepareAndRoll(ALICE, BIG_AMOUNT, true, true);
|
||||||
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
||||||
|
|
||||||
@ -650,11 +623,6 @@ contract StakingTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_ghostTokensEmitsEvent() public {
|
function test_ghostTokensEmitsEvent() public {
|
||||||
assertEq(staking.gatekeeper(), address(0));
|
|
||||||
vm.prank(GOVERNOR);
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
assertEq(staking.gatekeeper(), address(gatekeeper));
|
|
||||||
|
|
||||||
_prepareAndRoll(ALICE, BIG_AMOUNT, true, true);
|
_prepareAndRoll(ALICE, BIG_AMOUNT, true, true);
|
||||||
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
||||||
|
|
||||||
@ -664,7 +632,7 @@ contract StakingTest is Test {
|
|||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
||||||
vm.expectEmit(true, true, true, false, address(gatekeeper));
|
vm.expectEmit(true, true, true, false, staking.gatekeeper());
|
||||||
emit Ghosted(receiver, ghstBalance);
|
emit Ghosted(receiver, ghstBalance);
|
||||||
|
|
||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
@ -672,11 +640,6 @@ contract StakingTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_breakoutLogicWorks() public {
|
function test_breakoutLogicWorks() public {
|
||||||
assertEq(staking.gatekeeper(), address(0));
|
|
||||||
vm.prank(GOVERNOR);
|
|
||||||
staking.setGatekeeperAddress(address(gatekeeper));
|
|
||||||
assertEq(staking.gatekeeper(), address(gatekeeper));
|
|
||||||
|
|
||||||
uint256 initialIndex = staking.index();
|
uint256 initialIndex = staking.index();
|
||||||
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
bytes32 receiver = bytes32(abi.encodePacked(ALICE));
|
||||||
uint256 rebased = _prepareAndRoll(ALICE, BIG_AMOUNT, false, false);
|
uint256 rebased = _prepareAndRoll(ALICE, BIG_AMOUNT, false, false);
|
||||||
@ -697,7 +660,7 @@ contract StakingTest is Test {
|
|||||||
uint256 range = (payout * 3) / 100;
|
uint256 range = (payout * 3) / 100;
|
||||||
requestedPayout = (pseudoRandom % range) + 1;
|
requestedPayout = (pseudoRandom % range) + 1;
|
||||||
|
|
||||||
vm.expectEmit(true, true, true, false, address(gatekeeper));
|
vm.expectEmit(true, true, true, false, staking.gatekeeper());
|
||||||
emit Ghosted(receiver, requestedPayout);
|
emit Ghosted(receiver, requestedPayout);
|
||||||
|
|
||||||
vm.prank(ALICE);
|
vm.prank(ALICE);
|
||||||
|
|||||||
@ -61,7 +61,8 @@ contract StakingDistributorTest is Test {
|
|||||||
EPOCH_LENGTH,
|
EPOCH_LENGTH,
|
||||||
EPOCH_NUMBER,
|
EPOCH_NUMBER,
|
||||||
EPOCH_END_TIME,
|
EPOCH_END_TIME,
|
||||||
address(authority)
|
address(authority),
|
||||||
|
0
|
||||||
);
|
);
|
||||||
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
treasury = new GhostTreasury(address(ftso), 69, address(authority));
|
||||||
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
|
||||||
|
|||||||
@ -53,7 +53,8 @@ contract GhostTest is
|
|||||||
69,
|
69,
|
||||||
1337,
|
1337,
|
||||||
1337,
|
1337,
|
||||||
address(authority)
|
address(authority),
|
||||||
|
0
|
||||||
);
|
);
|
||||||
stnk.initialize(address(staking), TREASURY, address(ghst));
|
stnk.initialize(address(staking), TREASURY, address(ghst));
|
||||||
ghst.initialize(address(staking));
|
ghst.initialize(address(staking));
|
||||||
|
|||||||
@ -59,7 +59,8 @@ contract StinkyTest is Test, ERC20PermitTest, ERC20AllowanceTest, ERC20TransferT
|
|||||||
69,
|
69,
|
||||||
1337,
|
1337,
|
||||||
1337,
|
1337,
|
||||||
address(authority)
|
address(authority),
|
||||||
|
0
|
||||||
);
|
);
|
||||||
ghst.initialize(address(staking));
|
ghst.initialize(address(staking));
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user