Skip to content

Commit

Permalink
add Storage test
Browse files Browse the repository at this point in the history
  • Loading branch information
ephess committed Nov 30, 2023
1 parent ccb623f commit 0226166
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
37 changes: 37 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Environment Setup

You will need to make sure you have these packages installed:

* foundry

The you need to ensure your environment has these variables set:

```
MAINNET_RPC_URL=
```


# Project Initialization

```
foundryup
```

# Running a build

```
forge build
```

# Running the tests

```
forge test
```

# Generating a coverage report

```
forge coverage --ir-minimum --report lcov
```

55 changes: 55 additions & 0 deletions test/Storage.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import "forge-std/Test.sol";

import { Storage } from "src/contracts/atlas/Storage.sol";

using stdStorage for StdStorage;


contract StorageTest is Test {
function testNewStorage() public {
Storage s = new Storage(
1, // _escrowDuration
address(1), // _factory
address(2), // _verification
address(3), // _gasAccLib
address(4), // _safetyLocksLib
address(5) // _simulator
);

assertEq(s.ESCROW_DURATION(), 1);
assertEq(s.FACTORY(), address(1));
assertEq(s.VERIFICATION(), address(2));
assertEq(s.GAS_ACC_LIB(), address(3));
assertEq(s.SAFETY_LOCKS_LIB(), address(4));
assertEq(s.SIMULATOR(), address(5));
}

function testStorageSlotsDontChange() public {
Storage s = new Storage(
1, // _escrowDuration
address(1), // _factory
address(2), // _verification
address(3), // _gasAccLib
address(4), // _safetyLocksLib
address(5) // _simulator
);

// look up the storage slots so that we can make sure they don't change by accident

uint256 totalSupplySlot = stdstore.target(address(s)).sig('totalSupply()').find();
uint256 noncesSlot = stdstore.target(address(s)).sig('nonces(address)').with_key(address(this)).find();
uint256 lockSlot = stdstore.target(address(s)).sig('lock()').find();

// TODO: figure out how to check the allowance and ledger slots, haven't been able to make these work yet

// if you're getting an error from one of these assertions, it means that the storage slot has changed
// and you either need to update the slot number or revert the change

assertEq(totalSupplySlot, 0);
assertEq(noncesSlot, 49784443915320261189887103614045882155521089248264299114442679287293484801912);
assertEq(lockSlot, 4);
}
}

0 comments on commit 0226166

Please sign in to comment.