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

fix: coverage issues with vm #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $ forge test
Get a test coverage report:

```sh
$ forge coverage
$ forge coverage --ir-minimum
```

### Deployment
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"clean": "rimraf cache out",
"coverage": "forge coverage --report lcov",
"coverage": "forge coverage --no-match-coverage testFork --ir-minimum --report lcov",
"lint": "yarn lint:sol && yarn prettier:check",
"lint:sol": "solhint \"{src,test,script}/**/*.sol\"",
"prettier:check": "prettier --check \"**/*.{json,md,sol,yml}\"",
Expand Down
8 changes: 4 additions & 4 deletions test/ActiveProposalsLimiterProposalValidationStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract ActiveProposalsLimterTest is SpaceTest {
// max * 2 so we would revert if `cooldown` is not respected
for (uint256 i = 0; i < maxActive * 2; i++) {
_createProposal(author, proposalMetadataURI, executionStrategy, new bytes(0));
vm.warp(block.timestamp + cooldown);
vm.warp(vm.getBlockTimestamp() + cooldown);
}
}

Expand Down Expand Up @@ -110,19 +110,19 @@ contract ActiveProposalsLimterTest is SpaceTest {
}

// Advance until half of cooldown
vm.warp(block.timestamp + cooldown / 2);
vm.warp(vm.getBlockTimestamp() + cooldown / 2);

// Should still fail
vm.expectRevert(FailedToPassProposalValidation.selector);
_createProposal(author, proposalMetadataURI, executionStrategy, new bytes(0));

// Advance until ALMOST full cooldown has elapsed
vm.warp(block.timestamp + cooldown / 2 - 1);
vm.warp(vm.getBlockTimestamp() + cooldown / 2 - 1);
vm.expectRevert(FailedToPassProposalValidation.selector);
_createProposal(author, proposalMetadataURI, executionStrategy, new bytes(0));

// Advance until full cooldown has elapsed
vm.warp(block.timestamp + 1);
vm.warp(vm.getBlockTimestamp() + 1);
// We should be able to create `maxActive` proposals now
for (uint256 i = 0; i < maxActive; i++) {
_createProposal(author, proposalMetadataURI, executionStrategy, new bytes(0));
Expand Down
14 changes: 7 additions & 7 deletions test/AvatarExecutionStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit ProposalExecuted(proposalId);
Expand All @@ -67,7 +67,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
Strategy(address(avatarExecutionStrategy), abi.encode(transactions)),
new bytes(0)
);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(abi.encodeWithSelector(InvalidProposalStatus.selector, ProposalStatus.Rejected));
space.execute(proposalId, abi.encode(transactions));
Expand All @@ -83,7 +83,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

transactions[0] = MetaTransaction(recipient, 2, "", Enum.Operation.Call, 0);

Expand All @@ -102,7 +102,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(ExecutionFailed.selector);
space.execute(proposalId, abi.encode(transactions));
Expand All @@ -126,7 +126,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

assertEq(recipient.balance, 0); // sanity check
assertEq(avatar.isModuleEnabled(address(0xbeef)), false); // sanity check
Expand All @@ -153,7 +153,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(ExecutionFailed.selector);
space.execute(proposalId, abi.encode(transactions));
Expand Down Expand Up @@ -246,7 +246,7 @@ abstract contract AvatarExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(InvalidSpace.selector);
space.execute(proposalId, abi.encode(transactions));
Expand Down
50 changes: 25 additions & 25 deletions test/CompTimelockExecutionStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
uint256 eta = block.timestamp + 1000;
timelock.queueTransaction(address(timelock), 0, "", callData, eta);

vm.warp(block.timestamp + 1000);
vm.warp(vm.getBlockTimestamp() + 1000);

timelock.executeTransaction(address(timelock), 0, "", callData, eta);

Expand All @@ -76,7 +76,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.warp(block.timestamp + space.maxVotingDuration());
vm.warp(vm.getBlockTimestamp() + space.maxVotingDuration());

vm.expectRevert(InvalidSpace.selector);
space.execute(proposalId, abi.encode(transactions));
Expand All @@ -92,7 +92,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
Expand All @@ -111,7 +111,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(DuplicateMetaTransaction.selector);
space.execute(proposalId, abi.encode(transactions));
Expand Down Expand Up @@ -144,7 +144,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
_vote(author, secondProposalId, Choice.For, userVotingStrategies, voteMetadataURI);

// Move forward in time.
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

// Queue the first one: it should work properly.
space.execute(firstProposalId, abi.encode(transactions));
Expand All @@ -163,7 +163,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
Strategy(address(timelockExecutionStrategy), abi.encode(transactions)),
new bytes(0)
);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(abi.encodeWithSelector(InvalidProposalStatus.selector, ProposalStatus.Rejected));
space.execute(proposalId, abi.encode(transactions));
Expand All @@ -179,7 +179,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
Expand All @@ -206,7 +206,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
_vote(author, proposalId2, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

space.execute(proposalId, abi.encode(transactions));

Expand All @@ -225,7 +225,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

transactions[0] = MetaTransaction(recipient, 2, "", Enum.Operation.Call, 0);

Expand All @@ -243,15 +243,15 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
space.execute(proposalId, abi.encode(transactions));

assertEq(recipient.balance, 0);

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));

assertEq(recipient.balance, 1);
Expand All @@ -267,11 +267,11 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

space.execute(proposalId, abi.encode(transactions));

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());

vm.expectRevert("Timelock::executeTransaction: Transaction execution reverted.");
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));
Expand All @@ -287,11 +287,11 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

space.execute(proposalId, abi.encode(transactions));

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());
transactions[0] = MetaTransaction(recipient, 2, "", Enum.Operation.Call, 0);

vm.expectRevert(ProposalNotQueued.selector);
Expand All @@ -308,7 +308,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
Expand All @@ -328,7 +328,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(ProposalNotQueued.selector);
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));
Expand All @@ -344,15 +344,15 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
space.execute(proposalId, abi.encode(transactions));

assertEq(recipient.balance, 0);

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));

vm.expectRevert(ProposalNotQueued.selector);
Expand All @@ -377,7 +377,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectRevert(InvalidTransaction.selector);
space.execute(proposalId, abi.encode(transactions));
Expand All @@ -393,7 +393,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

space.execute(proposalId, abi.encode(transactions));

Expand All @@ -408,7 +408,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
emit ProposalVetoed(keccak256(abi.encode(transactions)));
timelockExecutionStrategy.veto(abi.encode(transactions));

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());
vm.expectRevert(ProposalNotQueued.selector);
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));
}
Expand All @@ -423,7 +423,7 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

space.execute(proposalId, abi.encode(transactions));

Expand Down Expand Up @@ -487,15 +487,15 @@ abstract contract CompTimelockExecutionStrategyTest is SpaceTest {
new bytes(0)
);
_vote(author, proposalId, Choice.For, userVotingStrategies, voteMetadataURI);
vm.roll(block.number + space.maxVotingDuration());
vm.roll(vm.getBlockNumber() + space.maxVotingDuration());

vm.expectEmit(true, true, true, true);
emit TransactionQueued(transactions[0], block.timestamp + 1000);
space.execute(proposalId, abi.encode(transactions));

assertEq(erc721.ownerOf(1), address(timelock));

vm.warp(block.timestamp + timelockExecutionStrategy.timelockDelay());
vm.warp(vm.getBlockTimestamp() + timelockExecutionStrategy.timelockDelay());
timelockExecutionStrategy.executeQueuedProposal(abi.encode(transactions));

assertEq(erc721.ownerOf(1), address(author));
Expand Down
8 changes: 4 additions & 4 deletions test/CompVotingStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract CompVotingStrategyTest is Test {
compToken.mint(user, 1);
// Must delegate to self to activate checkpoints
compToken.delegate(user);
vm.roll(block.number + 1);
vm.roll(vm.getBlockNumber() + 1);
assertEq(
compVotingStrategy.getVotingPower(uint32(block.number), user, abi.encodePacked(address(compToken)), ""),
1
Expand All @@ -33,7 +33,7 @@ contract CompVotingStrategyTest is Test {
function testGetZeroVotingPower() public {
compToken.mint(user, 1);
// No delegation, so voting power is zero
vm.roll(block.number + 1);
vm.roll(vm.getBlockNumber() + 1);
assertEq(
compVotingStrategy.getVotingPower(uint32(block.number), user, abi.encodePacked(address(compToken)), ""),
0
Expand All @@ -43,7 +43,7 @@ contract CompVotingStrategyTest is Test {
function testGetVotingPowerInvalidToken() public {
compToken.mint(user, 1);
compToken.delegate(user);
vm.roll(block.number + 1);
vm.roll(vm.getBlockNumber() + 1);
vm.expectRevert();
// Token address is set to zero
compVotingStrategy.getVotingPower(uint32(block.number), user, abi.encodePacked(address(0)), "");
Expand All @@ -52,7 +52,7 @@ contract CompVotingStrategyTest is Test {
function testGetVotingPowerInvalidParamsArray() public {
compToken.mint(user, 1);
compToken.delegate(user);
vm.roll(block.number + 1);
vm.roll(vm.getBlockNumber() + 1);
vm.expectRevert(InvalidByteArray.selector);
// Params array is too short
compVotingStrategy.getVotingPower(uint32(block.number), user, abi.encodePacked("1234"), "");
Expand Down
1 change: 1 addition & 0 deletions test/Deployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Deployer } from "../script/Deployer.s.sol";

contract DeployerTest is Test {
Deployer deployer;

Check warning on line 8 in test/Deployer.t.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

bytes internal constant singletonFactoryBytecode =
hex"6080604052348015600f57600080fd5b506004361060285760"
Expand All @@ -25,6 +25,7 @@
function setUp() public {
vm.setEnv("NETWORK", "test");
vm.setEnv("DEPLOYER_ADDRESS", vm.toString(address(this)));
vm.setEnv("PRIVATE_KEY", vm.toString(uint256(1234)));

// Setting the bytecode at the singleton address of the singleton factory.
vm.etch(address(0xce0042B868300000d44A59004Da54A005ffdcf9f), singletonFactoryBytecode);
Expand Down
Loading
Loading