ghost-dao-contracts/test/gatekeeper/GatekeeperMetadata.t.sol
Uncle Fatso 379cc331e2
make metadata historically dependant
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-08-02 22:13:31 +03:00

54 lines
1.9 KiB
Solidity

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);
}
}