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

test: adding codebase/deployed tests scenarios [PoC] #378

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
101 changes: 69 additions & 32 deletions src/DssSpell.t.base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ interface FlapperMomAbstract {
function stop() external;
}

contract DssSpellTestBase is Config, DssTest {
abstract contract DssSpellTestBase is Config, DssTest {
Rates rates = new Rates();
Addresses addr = new Addresses();
Deployers deployers = new Deployers();
Expand Down Expand Up @@ -310,37 +310,7 @@ contract DssSpellTestBase is Config, DssTest {
}
}

function setUp() public {
setValues(address(chief));
_castPreviousSpell();

spellValues.deployed_spell_created = spellValues.deployed_spell != address(0)
? spellValues.deployed_spell_created
: block.timestamp;
spell = spellValues.deployed_spell != address(0)
? DssSpell(spellValues.deployed_spell)
: new DssSpell();

if (spellValues.deployed_spell_block != 0 && spell.eta() != 0) {
// if we have a deployed spell in the config
// we want to roll our fork to the block where it was deployed
// this means the test suite will continue to accurately pass/fail
// even if mainnet has already scheduled/cast the spell
vm.makePersistent(address(rates));
vm.makePersistent(address(addr));
vm.makePersistent(address(deployers));
vm.rollFork(spellValues.deployed_spell_block);

// Reset `eta` to `0`, otherwise the tests will fail with "This spell has already been scheduled".
// This is a workaround for the issue described here:
// @see { https://github.com/foundry-rs/foundry/issues/5739 }
vm.store(
address(spell),
bytes32(0),
bytes32(0)
);
}
}
function setUp() virtual public;

function _vote(address spell_) internal {
if (chief.hat() != spell_) {
Expand Down Expand Up @@ -1990,3 +1960,70 @@ contract DssSpellTestBase is Config, DssTest {
}

}

contract DssSpellTestCodebaseBase is DssSpellTestBase {
function setUp() public override {
setValues(address(chief));
_castPreviousSpell();

spellValues.deployed_spell_created = spellValues.deployed_spell != address(0)
? spellValues.deployed_spell_created
: block.timestamp;
spell = new DssSpell();

if (spellValues.deployed_spell_block != 0 && spell.eta() != 0) {
// if we have a deployed spell in the config
// we want to roll our fork to the block where it was deployed
// this means the test suite will continue to accurately pass/fail
// even if mainnet has already scheduled/cast the spell
vm.makePersistent(address(rates));
vm.makePersistent(address(addr));
// NOTE: adding fix presented in #377
vm.makePersistent(address(wallets));
vm.makePersistent(address(deployers));
vm.rollFork(spellValues.deployed_spell_block);

// Reset `eta` to `0`, otherwise the tests will fail with "This spell has already been scheduled".
// This is a workaround for the issue described here:
// @see { https://github.com/foundry-rs/foundry/issues/5739 }
vm.store(
address(spell),
bytes32(0),
bytes32(0)
);
}
}
}

contract DssSpellTestDeployedBase is DssSpellTestBase {
function setUp() public override {
setValues(address(chief));
_castPreviousSpell();

if (spellValues.deployed_spell == address(0)
|| spellValues.deployed_spell_block == 0
|| spellValues.deployed_spell_created == 0) revert("TestError/spell-not-deployed");

spell = DssSpell(spellValues.deployed_spell);

// if we have a deployed spell in the config
// we want to roll our fork to the block where it was deployed
// this means the test suite will continue to accurately pass/fail
// even if mainnet has already scheduled/cast the spell
vm.makePersistent(address(rates));
vm.makePersistent(address(addr));
// NOTE: adding fix presented in #377
vm.makePersistent(address(wallets));
vm.makePersistent(address(deployers));
vm.rollFork(spellValues.deployed_spell_block);

// Reset `eta` to `0`, otherwise the tests will fail with "This spell has already been scheduled".
// This is a workaround for the issue described here:
// @see { https://github.com/foundry-rs/foundry/issues/5739 }
vm.store(
address(spell),
bytes32(0),
bytes32(0)
);
}
}
21 changes: 14 additions & 7 deletions src/DssSpell.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface RwaLiquidationOracleLike {
function ilks(bytes32) external view returns (string memory, address, uint48 toc, uint48 tau);
}

contract DssSpellTest is DssSpellTestBase {
abstract contract DssSpellTest is DssSpellTestBase {
string config;
RootDomain rootDomain;
OptimismDomain optimismDomain;
Expand Down Expand Up @@ -103,18 +103,14 @@ contract DssSpellTest is DssSpellTestBase {
_testUseEta();
}

function testAuth() public {
function testAuth() private { // NOTE: disabling for performance reasons #374
_checkAuth(false);
}

function testAuthInSources() public {
function testAuthInSources() private { // NOTE: disabling for performance reasons #374
_checkAuth(true);
}

function testBytecodeMatches() public {
_testBytecodeMatches();
}

function testChainlogValues() public {
_testChainlogValues();
}
Expand Down Expand Up @@ -929,3 +925,14 @@ contract DssSpellTest is DssSpellTestBase {
assertEq(spot, 1_500_000_000 * RAY, "RWA014: Bad spot value after bump()");
}
}

contract DssSpellTestDeployed is DssSpellTest, DssSpellTestDeployedBase { // NOTE: make abstract to disable

// NOTE: moving test to be only run on forked scope
function testBytecodeMatches() public {
_testBytecodeMatches();
}

}

contract DssSpellTestCodebase is DssSpellTest, DssSpellTestCodebaseBase {} // NOTE: make abstract to disable
2 changes: 1 addition & 1 deletion src/test/starknet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface DaiLike {
function allowance(address, address) external view returns (uint256);
}

contract StarknetTests is DssSpellTestBase, ConfigStarknet {
abstract contract StarknetTests is DssSpellTestBase, ConfigStarknet { // NOTE: disabling whole test for PoC PR

event LogMessageToL2(
address indexed fromAddress,
Expand Down