Skip to content

Commit

Permalink
Set/Get Tests for TStore
Browse files Browse the repository at this point in the history
  • Loading branch information
BCLeFevre committed Mar 27, 2024
1 parent f55dc32 commit 2e63374
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
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);
}
}

0 comments on commit 2e63374

Please sign in to comment.