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

Set/Get Tests for TStore #2

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/test/TestTstorishContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Tstorish} from "../Tstorish.sol";

contract TestTstorishContract is Tstorish {
constructor() Tstorish() {}

function setTstorish(uint256 storageSlot, uint256 value) public {
_setTstorish(storageSlot, value);
}

function getTstorish(uint256 storageSlot) public view returns (uint256) {
return _getTstorish(storageSlot);
}

function clearTstorish(uint256 storageSlot) public {
_clearTstorish(storageSlot);
}
}
38 changes: 31 additions & 7 deletions test/foundry/TestTstorish.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,51 @@ pragma solidity ^0.8.24;

import {Test} from "forge-std/Test.sol";

import {Tstorish} from "../../src/Tstorish.sol";
import {TestTstorishContract} from "../../src/test/TestTstorishContract.sol";

contract TestTstorish is Test {
Tstorish tstorish;
TestTstorishContract tstorishcontract;

function setUp() public {
_deployTstorish();
_deployTstorishContract();
}

function _deployTstorish() private {
tstorish = new Tstorish();
function _deployTstorishContract() private {
tstorishcontract = new TestTstorishContract();
}

function test_fail_activateTstore_alreadyActivated() public {
vm.expectRevert(abi.encodeWithSignature("TStoreAlreadyActivated()"));
vm.prank(address(this), address(this));
tstorish.__activateTstore();
tstorishcontract.__activateTstore();
}

function test_fail_activateTstore_onlyDirectCalls() public {
vm.expectRevert(abi.encodeWithSignature("OnlyDirectCalls()"));
tstorish.__activateTstore();
tstorishcontract.__activateTstore();
}

function testSetTstorish() public {
uint256 storageSlot = 0x1337;
uint256 value = 500;
// Set the value in the storage slot
tstorishcontract.setTstorish(storageSlot, value);
// Get the value from the storage slot
uint256 result = tstorishcontract.getTstorish(storageSlot);
// Assert that the value is equal to the value we set
assertEq(result, value);
}

function testClearTstorish() public {
uint256 storageSlot = 0x1337;
uint256 value = 500;
// Set the value in the storage slot
tstorishcontract.setTstorish(storageSlot, value);
// Clear the value in the storage slot
tstorishcontract.clearTstorish(storageSlot);
// Get the value from the storage slot
uint256 result = tstorishcontract.getTstorish(storageSlot);
// Assert that the value is equal to 0
assertEq(result, 0);
}
}
Loading