Skip to content

Commit

Permalink
style: prettier contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Dec 18, 2023
1 parent e7be47a commit 6695a65
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 62 deletions.
12 changes: 6 additions & 6 deletions test/invariant/BasicInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

pragma solidity ^0.8.19;

import {IERC20} from "oz/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import { IERC20 } from "oz/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import "oz/utils/Strings.sol";
import {Voter} from "./actors/Voter.t.sol";
import {Fixture, AngleGovernor} from "../Fixture.t.sol";
import {ProposalStore} from "./stores/ProposalStore.sol";
import { Voter } from "./actors/Voter.t.sol";
import { Fixture, AngleGovernor } from "../Fixture.t.sol";
import { ProposalStore } from "./stores/ProposalStore.sol";

//solhint-disable
import {console} from "forge-std/console.sol";
import { console } from "forge-std/console.sol";

contract BasicInvariants is Fixture {
uint256 internal constant _NUM_VOTER = 10;
Expand Down
24 changes: 12 additions & 12 deletions test/invariant/MainnetGovernorInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

pragma solidity ^0.8.19;

import {IERC20} from "oz/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import { IERC20 } from "oz/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import "oz/utils/Strings.sol";
import {Voter} from "./actors/Voter.t.sol";
import {Proposer} from "./actors/Proposer.t.sol";
import {BadVoter} from "./actors/BadVoter.t.sol";
import {Fixture, AngleGovernor} from "../Fixture.t.sol";
import {ProposalStore} from "./stores/ProposalStore.sol";
import { Voter } from "./actors/Voter.t.sol";
import { Proposer } from "./actors/Proposer.t.sol";
import { BadVoter } from "./actors/BadVoter.t.sol";
import { Fixture, AngleGovernor } from "../Fixture.t.sol";
import { ProposalStore } from "./stores/ProposalStore.sol";

//solhint-disable
import {console} from "forge-std/console.sol";
import { console } from "forge-std/console.sol";

contract MainnetGovernorInvariants is Fixture {
uint256 internal constant _NUM_VOTER = 10;
Expand All @@ -33,7 +33,7 @@ contract MainnetGovernorInvariants is Fixture {
_badVoterHandler = new BadVoter(angleGovernor, ANGLE, _NUM_VOTER, _proposalStore);

// Label newly created addresses
vm.label({account: address(_proposalStore), newLabel: "ProposalStore"});
vm.label({ account: address(_proposalStore), newLabel: "ProposalStore" });
for (uint256 i; i < _NUM_VOTER; i++) {
vm.label(_voterHandler.actors(i), string.concat("Voter ", Strings.toString(i)));
_setupDealAndLockANGLE(_voterHandler.actors(i), 100000000e18, 4 * 365 days);
Expand All @@ -54,20 +54,20 @@ contract MainnetGovernorInvariants is Fixture {
{
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = Voter.vote.selector;
targetSelector(FuzzSelector({addr: address(_voterHandler), selectors: selectors}));
targetSelector(FuzzSelector({ addr: address(_voterHandler), selectors: selectors }));
}
{
bytes4[] memory selectors = new bytes4[](4);
selectors[0] = Proposer.propose.selector;
selectors[1] = Proposer.execute.selector;
selectors[2] = Proposer.skipVotingDelay.selector;
selectors[3] = Proposer.shortCircuit.selector;
targetSelector(FuzzSelector({addr: address(_proposerHandler), selectors: selectors}));
targetSelector(FuzzSelector({ addr: address(_proposerHandler), selectors: selectors }));
}
{
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = BadVoter.vote.selector;
targetSelector(FuzzSelector({addr: address(_badVoterHandler), selectors: selectors}));
targetSelector(FuzzSelector({ addr: address(_badVoterHandler), selectors: selectors }));
}
}

Expand Down
25 changes: 16 additions & 9 deletions test/invariant/actors/BadVoter.t.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage} from "./BaseActor.t.sol";
import {console} from "forge-std/console.sol";
import {ProposalStore, Proposal} from "../stores/ProposalStore.sol";
import {IGovernor} from "oz/governance/IGovernor.sol";
import { BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage } from "./BaseActor.t.sol";
import { console } from "forge-std/console.sol";
import { ProposalStore, Proposal } from "../stores/ProposalStore.sol";
import { IGovernor } from "oz/governance/IGovernor.sol";

contract BadVoter is BaseActor {
AngleGovernor internal _angleGovernor;
ProposalStore public proposalStore;

constructor(AngleGovernor angleGovernor, IERC20 _agToken, uint256 nbrVoter, ProposalStore _proposalStore)
BaseActor(nbrVoter, "BadVoter", _agToken)
{
constructor(
AngleGovernor angleGovernor,
IERC20 _agToken,
uint256 nbrVoter,
ProposalStore _proposalStore
) BaseActor(nbrVoter, "BadVoter", _agToken) {
_angleGovernor = angleGovernor;
proposalStore = _proposalStore;
}
Expand All @@ -24,8 +27,12 @@ contract BadVoter is BaseActor {
Proposal[] memory proposals = proposalStore.getProposals();
for (uint256 i; i < proposals.length; i++) {
Proposal memory proposal = proposals[i];
uint256 proposalHash =
_angleGovernor.hashProposal(proposal.target, proposal.value, proposal.data, proposal.description);
uint256 proposalHash = _angleGovernor.hashProposal(
proposal.target,
proposal.value,
proposal.data,
proposal.description
);
if (proposalHash != proposalId || proposalStore.doesOldProposalExists(proposalHash)) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions test/invariant/actors/BaseActor.t.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {IERC20} from "oz/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import {Test, stdMath, StdStorage, stdStorage} from "forge-std/Test.sol";
import {IVotes} from "oz/governance/utils/IVotes.sol";
import {AngleGovernor} from "contracts/AngleGovernor.sol";
import { IERC20 } from "oz/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "oz/token/ERC20/extensions/IERC20Metadata.sol";
import { Test, stdMath, StdStorage, stdStorage } from "forge-std/Test.sol";
import { IVotes } from "oz/governance/utils/IVotes.sol";
import { AngleGovernor } from "contracts/AngleGovernor.sol";
import "contracts/utils/Errors.sol";

struct TestStorage {
Expand Down
30 changes: 19 additions & 11 deletions test/invariant/actors/Proposer.t.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage} from "./BaseActor.t.sol";
import {console} from "forge-std/console.sol";
import {IGovernor} from "oz/governance/IGovernor.sol";
import {ProposalStore, Proposal} from "../stores/ProposalStore.sol";
import {IERC5805} from "oz/interfaces/IERC5805.sol";
import { BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage } from "./BaseActor.t.sol";
import { console } from "forge-std/console.sol";
import { IGovernor } from "oz/governance/IGovernor.sol";
import { ProposalStore, Proposal } from "../stores/ProposalStore.sol";
import { IERC5805 } from "oz/interfaces/IERC5805.sol";

contract Proposer is BaseActor {
AngleGovernor internal _angleGovernor;
Expand Down Expand Up @@ -55,8 +55,12 @@ contract Proposer is BaseActor {
return;
}
Proposal memory proposal = proposalStore.getRandomProposal(proposalId);
uint256 proposalHash =
_angleGovernor.hashProposal(proposal.target, proposal.value, proposal.data, proposal.description);
uint256 proposalHash = _angleGovernor.hashProposal(
proposal.target,
proposal.value,
proposal.data,
proposal.description
);
IGovernor.ProposalState currentState = _angleGovernor.state(proposalHash);
if (currentState != IGovernor.ProposalState.Active) {
return;
Expand All @@ -81,8 +85,12 @@ contract Proposer is BaseActor {
return;
}
Proposal memory proposal = proposalStore.getRandomProposal(proposalId);
uint256 proposalHash =
_angleGovernor.hashProposal(proposal.target, proposal.value, proposal.data, proposal.description);
uint256 proposalHash = _angleGovernor.hashProposal(
proposal.target,
proposal.value,
proposal.data,
proposal.description
);
uint256 proposalSnapshot = _angleGovernor.proposalSnapshot(proposalHash);
vm.warp(_angleGovernor.proposalDeadline(proposalHash) + 1);
vm.roll(_angleGovernor.$snapshotTimestampToSnapshotBlockNumber(proposalSnapshot) + 1);
Expand All @@ -93,8 +101,8 @@ contract Proposer is BaseActor {
IGovernor.GovernorUnexpectedProposalState.selector,
proposalHash,
currentState,
bytes32(1 << uint8(IGovernor.ProposalState.Succeeded))
| bytes32(1 << uint8(IGovernor.ProposalState.Queued))
bytes32(1 << uint8(IGovernor.ProposalState.Succeeded)) |
bytes32(1 << uint8(IGovernor.ProposalState.Queued))
)
);
}
Expand Down
25 changes: 16 additions & 9 deletions test/invariant/actors/Voter.t.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage} from "./BaseActor.t.sol";
import {console} from "forge-std/console.sol";
import {ProposalStore, Proposal} from "../stores/ProposalStore.sol";
import {IGovernor} from "oz/governance/IGovernor.sol";
import { BaseActor, IERC20, IERC20Metadata, AngleGovernor, TestStorage } from "./BaseActor.t.sol";
import { console } from "forge-std/console.sol";
import { ProposalStore, Proposal } from "../stores/ProposalStore.sol";
import { IGovernor } from "oz/governance/IGovernor.sol";

contract Voter is BaseActor {
AngleGovernor internal _angleGovernor;
ProposalStore public proposalStore;

constructor(AngleGovernor angleGovernor, IERC20 _agToken, uint256 nbrVoter, ProposalStore _proposalStore)
BaseActor(nbrVoter, "Voter", _agToken)
{
constructor(
AngleGovernor angleGovernor,
IERC20 _agToken,
uint256 nbrVoter,
ProposalStore _proposalStore
) BaseActor(nbrVoter, "Voter", _agToken) {
_angleGovernor = angleGovernor;
proposalStore = _proposalStore;
}
Expand All @@ -22,8 +25,12 @@ contract Voter is BaseActor {
return;
}
Proposal memory proposal = proposalStore.getRandomProposal(proposalSeed);
uint256 proposalHash =
_angleGovernor.hashProposal(proposal.target, proposal.value, proposal.data, proposal.description);
uint256 proposalHash = _angleGovernor.hashProposal(
proposal.target,
proposal.value,
proposal.data,
proposal.description
);
IGovernor.ProposalState currentState = _angleGovernor.state(proposalHash);
if (currentState != IGovernor.ProposalState.Active) {
vm.expectRevert(
Expand Down
29 changes: 19 additions & 10 deletions test/invariant/stores/ProposalStore.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

import {StdUtils} from "forge-std/StdUtils.sol";
import { StdUtils } from "forge-std/StdUtils.sol";

struct Proposal {
address[] target;
Expand All @@ -18,16 +18,22 @@ contract ProposalStore is StdUtils {

constructor() {}

function addProposal(address[] memory target, uint256[] memory value, bytes[] memory data, bytes32 description)
external
{
proposals.push(Proposal({target: target, value: value, data: data, description: description}));
function addProposal(
address[] memory target,
uint256[] memory value,
bytes[] memory data,
bytes32 description
) external {
proposals.push(Proposal({ target: target, value: value, data: data, description: description }));
}

function addOldProposal(address[] memory target, uint256[] memory value, bytes[] memory data, bytes32 description)
external
{
oldProposals.push(Proposal({target: target, value: value, data: data, description: description}));
function addOldProposal(
address[] memory target,
uint256[] memory value,
bytes[] memory data,
bytes32 description
) external {
oldProposals.push(Proposal({ target: target, value: value, data: data, description: description }));
}

function removeProposal(uint256 proposalHash) external {
Expand Down Expand Up @@ -62,7 +68,10 @@ contract ProposalStore is StdUtils {
uint256 proposalId = uint256(
keccak256(
abi.encode(
oldProposals[i].target, oldProposals[i].value, oldProposals[i].data, oldProposals[i].description
oldProposals[i].target,
oldProposals[i].value,
oldProposals[i].data,
oldProposals[i].description
)
)
);
Expand Down

0 comments on commit 6695a65

Please sign in to comment.