Skip to content

Commit

Permalink
More unit testing for reverts
Browse files Browse the repository at this point in the history
Formatting
  • Loading branch information
corydickson committed Aug 12, 2024
1 parent 44db376 commit d012289
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/ProposalTypesConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ contract ProposalTypesConfigurator is IProposalTypesConfigurator {

scopeExists[proposalTypeId][txTypeHash] = true;


_proposalTypes[proposalTypeId].txTypeHashes.push(txTypeHash);
}

Expand Down
27 changes: 27 additions & 0 deletions test/ProposalTypesConfigurator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,40 @@ contract UpdateScopeForProposalType is ProposalTypesConfiguratorTest {
proposalTypesConfigurator.updateScopeForProposalType(0, scope);
vm.stopPrank();
}

function testRevert_updateScopeForProposalType_InvalidParametersCondition() public {
vm.startPrank(admin);
bytes32 txTypeHash = keccak256("transfer(address,address,uint)");
bytes memory txEncoded = abi.encode("transfer(address,address,uint)", 0xdeadbeef, 0xdeadbeef, 10);

IProposalTypesConfigurator.Scope memory scope = IProposalTypesConfigurator.Scope(
txTypeHash, txEncoded, new bytes[](1), new IProposalTypesConfigurator.Comparators[](2)
);
vm.expectRevert(IProposalTypesConfigurator.InvalidParameterConditions.selector);
proposalTypesConfigurator.updateScopeForProposalType(0, scope);
vm.stopPrank();
}
}

contract getLimit is ProposalTypesConfiguratorTest {
function testRevert_getLimit_InvalidProposalType() public {
vm.expectRevert(IProposalTypesConfigurator.InvalidProposalType.selector);
proposalTypesConfigurator.getLimit(3, keccak256("foobar(address,address)"));
}

function testRevert_getLimit_InvalidScope() public {
vm.startPrank(admin);
bytes32 txTypeHash = keccak256("transfer(address,address,uint)");
bytes memory txEncoded = abi.encode("transfer(address,address,uint)", 0xdeadbeef, 0xdeadbeef, 10);

proposalTypesConfigurator.setScopeForProposalType(
0, txTypeHash, txEncoded, new bytes[](1), new IProposalTypesConfigurator.Comparators[](1)
);
vm.stopPrank();

vm.expectRevert(IProposalTypesConfigurator.InvalidScope.selector);
proposalTypesConfigurator.getLimit(0, keccak256("foobar(address,address)"));
}
}

contract GovernorMock {
Expand Down

0 comments on commit d012289

Please sign in to comment.