Skip to content

Commit

Permalink
fix: add readme and slight refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bowd committed Aug 18, 2024
1 parent 46d9f17 commit 1f59038
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
15 changes: 11 additions & 4 deletions test/CeloPrecompiles.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8;

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

import {TRANSFER_PRECOMPILE} from "src/Constants.sol";

Expand All @@ -13,7 +12,7 @@ contract CeloPrecompilesTest is Test {
address to = address(0x2);

vm.deal(from, 100);
(bool ok,) = TRANSFER_PRECOMPILE.call(abi.encode(from, to, 100));
(bool ok, ) = TRANSFER_PRECOMPILE.call(abi.encode(from, to, 100));

assertEq(ok, true);
assertEq(from.balance, 0);
Expand All @@ -24,8 +23,16 @@ contract CeloPrecompilesTest is Test {
address from = address(0x1);
address to = address(0x2);

(bool ok, bytes memory data) = TRANSFER_PRECOMPILE.call(abi.encode(from, to, 100));
(bool ok, bytes memory data) = TRANSFER_PRECOMPILE.call(
abi.encode(from, to, 100)
);
assertEq(ok, false);
assertEq(data, abi.encodeWithSignature("Error(string)", "TransferPrecompile: insufficient balance"));
assertEq(
data,
abi.encodeWithSignature(
"Error(string)",
"TransferPrecompile: insufficient balance"
)
);
}
}
34 changes: 23 additions & 11 deletions test/Contracts.t.sol → test/ContractsLookup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8;

import {console} from "forge-std/console.sol";
import {Test} from "src/Test.sol";
import {Contracts} from "src/Contracts.sol";
import {ContractsLookup} from "src/ContractsLookup.sol";

import {CELO_ID, BAKLAVA_ID, ALFAJORES_ID} from "src/Constants.sol";

Expand All @@ -19,13 +19,17 @@ contract MockGovernanceFactory is Test {
mentoToken = makeAddr(string(abi.encodePacked(prefix, "/MentoToken")));
emission = makeAddr(string(abi.encodePacked(prefix, "/Emission")));
airgrab = makeAddr(string(abi.encodePacked(prefix, "/Airgrab")));
governanceTimelock = makeAddr(string(abi.encodePacked(prefix, "/GovernanceTimelock")));
mentoGovernor = makeAddr(string(abi.encodePacked(prefix, "/MentoGovernor")));
governanceTimelock = makeAddr(
string(abi.encodePacked(prefix, "/GovernanceTimelock"))
);
mentoGovernor = makeAddr(
string(abi.encodePacked(prefix, "/MentoGovernor"))
);
locking = makeAddr(string(abi.encodePacked(prefix, "/Locking")));
}
}

abstract contract ContractsTest is Test, Contracts {
abstract contract ContractsLookupTest is Test, ContractsLookup {
function dependenciesPath() internal pure override returns (string memory) {
return "/test/fixtures/dependencies.json";
}
Expand Down Expand Up @@ -101,7 +105,9 @@ abstract contract ContractsTest is Test, Contracts {
address mentoToken = lookupGovernanceFactory("MentoToken");
address emission = lookupGovernanceFactory("Emission");
address airgrab = lookupGovernanceFactory("Airgrab");
address governanceTimelock = lookupGovernanceFactory("GovernanceTimelock");
address governanceTimelock = lookupGovernanceFactory(
"GovernanceTimelock"
);
address mentoGovernor = lookupGovernanceFactory("MentoGovernor");
address locking = lookupGovernanceFactory("Locking");

Expand All @@ -122,7 +128,7 @@ abstract contract ContractsTest is Test, Contracts {
}
}

contract CeloContractsTest is ContractsTest {
contract CeloContractsLookupTest is ContractsLookupTest {
function setUp() public override {
fork(CELO_ID);
contract01Expected = makeAddr("celo/Contract01");
Expand All @@ -135,14 +141,16 @@ contract CeloContractsTest is ContractsTest {
mentoGovernorExpected = makeAddr("celo/MentoGovernor");
lockingExpected = makeAddr("celo/Locking");
sortedOraclesExpected = 0xefB84935239dAcdecF7c5bA76d8dE40b077B7b33;
address mockGovernanceFactory = address(new MockGovernanceFactory("celo"));
address mockGovernanceFactory = address(
new MockGovernanceFactory("celo")
);
address governanceFactory = lookup("GovernanceFactory");
vm.etch(governanceFactory, mockGovernanceFactory.code);
super.setUp();
}
}

contract BaklavaContractsTest is ContractsTest {
contract BaklavaContractsLookupTest is ContractsLookupTest {
function setUp() public override {
fork(BAKLAVA_ID);
contract01Expected = makeAddr("baklava/Contract01");
Expand All @@ -155,14 +163,16 @@ contract BaklavaContractsTest is ContractsTest {
mentoGovernorExpected = makeAddr("baklava/MentoGovernor");
lockingExpected = makeAddr("baklava/Locking");
sortedOraclesExpected = 0x88A187a876290E9843175027902B9f7f1B092c88;
address mockGovernanceFactory = address(new MockGovernanceFactory("baklava"));
address mockGovernanceFactory = address(
new MockGovernanceFactory("baklava")
);
address governanceFactory = lookup("GovernanceFactory");
vm.etch(governanceFactory, mockGovernanceFactory.code);
super.setUp();
}
}

contract AlfajoresContractsTest is ContractsTest {
contract AlfajoresContractsLookupTest is ContractsLookupTest {
function setUp() public override {
fork(ALFAJORES_ID);
contract01Expected = makeAddr("alfajores/Contract01");
Expand All @@ -175,7 +185,9 @@ contract AlfajoresContractsTest is ContractsTest {
mentoGovernorExpected = makeAddr("alfajores/MentoGovernor");
lockingExpected = makeAddr("alfajores/Locking");
sortedOraclesExpected = 0xFdd8bD58115FfBf04e47411c1d228eCC45E93075;
address mockGovernanceFactory = address(new MockGovernanceFactory("alfajores"));
address mockGovernanceFactory = address(
new MockGovernanceFactory("alfajores")
);
address governanceFactory = lookup("GovernanceFactory");
vm.etch(governanceFactory, mockGovernanceFactory.code);
super.setUp();
Expand Down

0 comments on commit 1f59038

Please sign in to comment.