Skip to content

Commit

Permalink
Rename test args
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Sep 19, 2023
1 parent c39280f commit d4b59e6
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 164 deletions.
31 changes: 3 additions & 28 deletions test/WormholeL1ERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,7 @@ import {WormholeL1ERC20Bridge} from "src/WormholeL1ERC20Bridge.sol";
import {WormholeL2ERC20} from "src/WormholeL2ERC20.sol";
import {Constants} from "test/Constants.sol";
import {GovernorMock} from "test/mock/GovernorMock.sol";

contract L1ERC20BridgeHarness is WormholeL1ERC20Bridge {
constructor(
address _l1Token,
address _l1Relayer,
address _l1Governor,
uint16 _sourceId,
uint16 _targetId
) WormholeL1ERC20Bridge(_l1Token, _l1Relayer, _l1Governor, _sourceId, _targetId) {}

function withdraw(address account, uint256 amount) public {
_withdraw(account, amount);
}

function receiveWithdrawalWormholeMessages(
bytes memory payload,
bytes[] memory additionalVaas,
bytes32 callerAddr,
uint16 sourceChain,
bytes32 deliveryHash
) public {
_receiveWithdrawalWormholeMessages(
payload, additionalVaas, callerAddr, sourceChain, deliveryHash
);
}
}
import {L1ERC20BridgeHarness} from "test/harness/L1ERC20BridgeHarness.sol";

contract L1ERC20BridgeTest is Constants, WormholeRelayerBasicTest {
WormholeL2ERC20 l2Erc20;
Expand Down Expand Up @@ -135,7 +110,7 @@ contract _ReceiveWithdrawalWormholeMessages is Test, Constants {
assertEq(l1Erc20.balanceOf(address(l1Erc20Bridge)), _amount, "The Bridge balance is incorrect");

bytes memory withdrawalCalldata = abi.encode(_account, _amount);
l1Erc20Bridge.receiveWithdrawalWormholeMessages(
l1Erc20Bridge.exposed_receiveWithdrawalWormholeMessages(
withdrawalCalldata, new bytes[](0), bytes32(""), uint16(0), bytes32("")
);
assertEq(l1Erc20.balanceOf(address(_account)), _amount, "The account balance is incorrect");
Expand All @@ -161,7 +136,7 @@ contract _Withdraw is Test, Constants {
l1Erc20.transfer(address(l1Erc20Bridge), _amount);
assertEq(l1Erc20.balanceOf(address(l1Erc20Bridge)), _amount, "The Bridge balance is incorrect");

l1Erc20Bridge.withdraw(_account, _amount);
l1Erc20Bridge.exposed_withdraw(_account, _amount);
assertEq(l1Erc20.balanceOf(address(_account)), _amount, "The account balance is incorrect");
}
}
181 changes: 85 additions & 96 deletions test/WormholeL1VotePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ contract L1VotePoolTest is Constants, WormholeRelayerBasicTest {
l1Erc20 = new FakeERC20("GovExample", "GOV");
GovernorFlexibleVotingMock gov =
new GovernorFlexibleVotingMock("Testington Dao", ERC20VotesComp(address(l1Erc20)));
l1VotePool = new L1VotePoolHarness(L1_CHAIN.wormholeRelayer, address(gov));
l1VotePool.setRegisteredSender(
L2_CHAIN.wormholeChainId, bytes32(uint256(uint160(address(l2VoteAggregator))))
);
l1VotePool = new L1VotePoolHarness(address(gov));
}
}

Expand All @@ -51,7 +48,7 @@ contract Constructor is L1VotePoolTest {
l1Erc20 = new FakeERC20("GovExample", "GOV");
GovernorFlexibleVotingMock gov =
new GovernorFlexibleVotingMock("Testington Dao", ERC20VotesComp(address(l1Erc20)));
l1VotePool = new L1VotePoolHarness(L1_CHAIN.wormholeRelayer, address(gov));
l1VotePool = new L1VotePoolHarness(address(gov));

assertEq(address(l1VotePool.governor()), address(gov), "Governor is not set correctly");
}
Expand All @@ -74,18 +71,10 @@ contract _ReceiveCastVoteWormholeMessages is L1VotePoolTest {
vm.roll(block.number + 1); // To checkpoint erc20 mint
uint256 _proposalId = l1VotePool.createProposalVote(address(l1Erc20));

vm.selectFork(sourceFork);
l2VoteAggregator.initialize(address(l1VotePool));
uint256 cost = l2VoteAggregator.quoteDeliveryCost(L1_CHAIN.wormholeChainId);
vm.recordLogs();
vm.deal(address(this), 10 ether);

l2VoteAggregator.createProposalVote(_proposalId, _l2Against, _l2InFavor, _l2Abstain);
l2VoteAggregator.bridgeVote{value: cost}(_proposalId);

performDelivery();
// Call with encoded calldata
bytes memory proposalCalldata = abi.encode(_proposalId, _l2Against, _l2InFavor, _l2Abstain);
l1VotePool.exposed_receiveCastWormholeMessages(proposalCalldata, new bytes[](0), MOCK_WORMHOLE_SERIALIZED_ADDRESS, L2_CHAIN.wormholeChainId, bytes32(""));

vm.selectFork(targetFork);
(uint128 l1InFavor, uint128 l1Against, uint128 l1Abstain) =
l1VotePool.proposalVotes(_proposalId);

Expand All @@ -94,84 +83,84 @@ contract _ReceiveCastVoteWormholeMessages is L1VotePoolTest {
assertEq(l1Abstain, _l2Abstain, "abstain value was not bridged correctly");
}

function testFuzz_CorrectlyBridgeVoteAggregationWithExistingVote(
uint32 _l2Against,
uint32 _l2InFavor,
uint32 _l2Abstain,
uint32 _l2NewAgainst,
uint32 _l2NewInFavor,
uint32 _l2NewAbstain
) public {
vm.assume(_l2NewAgainst > _l2Against);
vm.assume(_l2NewInFavor > _l2InFavor);
vm.assume(_l2NewAbstain > _l2Abstain);

vm.selectFork(targetFork);

l1Erc20.approve(
address(l1VotePool), uint96(_l2NewAgainst) + uint96(_l2NewInFavor) + uint96(_l2NewAbstain)
);
l1Erc20.mint(
address(this), uint96(_l2NewAgainst) + uint96(_l2NewInFavor) + uint96(_l2NewAbstain)
);
l1Erc20.delegate(address(l1VotePool));

vm.roll(block.number + 1); // To checkpoint erc20 mint
uint256 _proposalId =
l1VotePool.createProposalVote(address(l1Erc20), _l2Against, _l2InFavor, _l2Abstain);

vm.selectFork(sourceFork);
l2VoteAggregator.initialize(address(l1VotePool));
uint256 cost = l2VoteAggregator.quoteDeliveryCost(L1_CHAIN.wormholeChainId);
vm.recordLogs();
vm.deal(address(this), 10 ether);

l2VoteAggregator.createProposalVote(_proposalId, _l2NewAgainst, _l2NewInFavor, _l2NewAbstain);
l2VoteAggregator.bridgeVote{value: cost}(_proposalId);

performDelivery();

vm.selectFork(targetFork);
(uint128 l1InFavor, uint128 l1Against, uint128 l1Abstain) =
l1VotePool.proposalVotes(_proposalId);

assertEq(l1Against, _l2NewAgainst, "Against value was not bridged correctly");
assertEq(l1InFavor, _l2NewInFavor, "inFavor value was not bridged correctly");
assertEq(l1Abstain, _l2NewAbstain, "abstain value was not bridged correctly");
}

function testFuzz_RevertWhen_InvalidVoteHasBeenBridged(
uint32 _l2Against,
uint32 _l2InFavor,
uint32 _l2Abstain,
uint32 _l2NewAgainst,
uint32 _l2NewInFavor,
uint32 _l2NewAbstain
) public {
vm.assume(_l2NewAgainst < _l2Against);
vm.assume(_l2NewInFavor < _l2InFavor);
vm.assume(_l2NewAbstain < _l2Abstain);

vm.selectFork(targetFork);

l1Erc20.approve(
address(l1VotePool), uint96(_l2Against) + uint96(_l2InFavor) + uint96(_l2Abstain) + 1
);
l1Erc20.mint(address(this), uint96(_l2Against) + uint96(_l2InFavor) + uint96(_l2Abstain) + 1);
l1Erc20.delegate(address(l1VotePool));

vm.roll(block.number + 1); // To checkpoint erc20 mint
uint256 _proposalId =
l1VotePool.createProposalVote(address(l1Erc20), _l2Against, _l2InFavor, _l2Abstain);

vm.prank(L1_CHAIN.wormholeRelayer);
vm.expectRevert(L1VotePool.InvalidProposalVote.selector);
l1VotePool.receiveWormholeMessages(
abi.encode(_proposalId, _l2NewAgainst, _l2NewInFavor, _l2NewAbstain),
new bytes[](0),
bytes32(uint256(uint160(address(l2VoteAggregator)))),
L2_CHAIN.wormholeChainId,
bytes32("")
);
}
// function testFuzz_CorrectlyBridgeVoteAggregationWithExistingVote(
// uint32 _l2Against,
// uint32 _l2InFavor,
// uint32 _l2Abstain,
// uint32 _l2NewAgainst,
// uint32 _l2NewInFavor,
// uint32 _l2NewAbstain
// ) public {
// vm.assume(_l2NewAgainst > _l2Against);
// vm.assume(_l2NewInFavor > _l2InFavor);
// vm.assume(_l2NewAbstain > _l2Abstain);

// vm.selectFork(targetFork);

// l1Erc20.approve(
// address(l1VotePool), uint96(_l2NewAgainst) + uint96(_l2NewInFavor) + uint96(_l2NewAbstain)
// );
// l1Erc20.mint(
// address(this), uint96(_l2NewAgainst) + uint96(_l2NewInFavor) + uint96(_l2NewAbstain)
// );
// l1Erc20.delegate(address(l1VotePool));

// vm.roll(block.number + 1); // To checkpoint erc20 mint
// uint256 _proposalId =
// l1VotePool.createProposalVote(address(l1Erc20), _l2Against, _l2InFavor, _l2Abstain);

// vm.selectFork(sourceFork);
// l2VoteAggregator.initialize(address(l1VotePool));
// uint256 cost = l2VoteAggregator.quoteDeliveryCost(L1_CHAIN.wormholeChainId);
// vm.recordLogs();
// vm.deal(address(this), 10 ether);

// l2VoteAggregator.createProposalVote(_proposalId, _l2NewAgainst, _l2NewInFavor, _l2NewAbstain);
// l2VoteAggregator.bridgeVote{value: cost}(_proposalId);

// performDelivery();

// vm.selectFork(targetFork);
// (uint128 l1InFavor, uint128 l1Against, uint128 l1Abstain) =
// l1VotePool.proposalVotes(_proposalId);

// assertEq(l1Against, _l2NewAgainst, "Against value was not bridged correctly");
// assertEq(l1InFavor, _l2NewInFavor, "inFavor value was not bridged correctly");
// assertEq(l1Abstain, _l2NewAbstain, "abstain value was not bridged correctly");
// }

// function testFuzz_RevertWhen_InvalidVoteHasBeenBridged(
// uint32 _l2Against,
// uint32 _l2InFavor,
// uint32 _l2Abstain,
// uint32 _l2NewAgainst,
// uint32 _l2NewInFavor,
// uint32 _l2NewAbstain
// ) public {
// vm.assume(_l2NewAgainst < _l2Against);
// vm.assume(_l2NewInFavor < _l2InFavor);
// vm.assume(_l2NewAbstain < _l2Abstain);

// vm.selectFork(targetFork);

// l1Erc20.approve(
// address(l1VotePool), uint96(_l2Against) + uint96(_l2InFavor) + uint96(_l2Abstain) + 1
// );
// l1Erc20.mint(address(this), uint96(_l2Against) + uint96(_l2InFavor) + uint96(_l2Abstain) + 1);
// l1Erc20.delegate(address(l1VotePool));

// vm.roll(block.number + 1); // To checkpoint erc20 mint
// uint256 _proposalId =
// l1VotePool.createProposalVote(address(l1Erc20), _l2Against, _l2InFavor, _l2Abstain);

// vm.prank(L1_CHAIN.wormholeRelayer);
// vm.expectRevert(L1VotePool.InvalidProposalVote.selector);
// l1VotePool.receiveWormholeMessages(
// abi.encode(_proposalId, _l2NewAgainst, _l2NewInFavor, _l2NewAbstain),
// new bytes[](0),
// bytes32(uint256(uint160(address(l2VoteAggregator)))),
// L2_CHAIN.wormholeChainId,
// bytes32("")
// );
// }
}
6 changes: 3 additions & 3 deletions test/WormholeL2VoteAggregator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ contract L2VoteAggregatorTest is Constants, WormholeRelayerBasicTest {
l1Erc20 = new FakeERC20("GovExample", "GOV");
GovernorFlexibleVotingMock l1Governor =
new GovernorFlexibleVotingMock("Testington Dao", ERC20VotesComp(address(l1Erc20)));
l1VotePool = new L1VotePoolHarness(L1_CHAIN.wormholeRelayer, address(l1Governor));
l2VoteAggregatorWormholeAddress = bytes32(uint256(uint160(address(l2VoteAggregator))));
l1VotePool.setRegisteredSender(L2_CHAIN.wormholeChainId, l2VoteAggregatorWormholeAddress);
l1VotePool = new L1VotePoolHarness(address(l1Governor));
// l2VoteAggregatorWormholeAddress = bytes32(uint256(uint160(address(l2VoteAggregator))));
// l1VotePool.setRegisteredSender(L2_CHAIN.wormholeChainId, l2VoteAggregatorWormholeAddress);
}
}

Expand Down
21 changes: 1 addition & 20 deletions test/WormholeReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,7 @@ import {Test} from "forge-std/Test.sol";
import {WormholeBase} from "src/WormholeBase.sol";
import {WormholeReceiver} from "src/WormholeReceiver.sol";
import {Constants} from "test/Constants.sol";

contract WormholeReceiverTestHarness is WormholeReceiver {
constructor(address _relayer) WormholeBase(_relayer) {}
function receiveWormholeMessages(
bytes memory payload,
bytes[] memory additionalVaas,
bytes32 sourceAddress,
uint16 sourceChain,
bytes32 deliveryHash
) public virtual override {}

function onlyRelayerModifierFunc() public onlyRelayer {}

function isRegisteredSenderModifierFunc(uint16 sourceChain, bytes32 senderAddress)
public
isRegisteredSender(sourceChain, senderAddress)
{}

function exposed_replayProtect(bytes32 deliveryHash) public replayProtect(deliveryHash) {}
}
import {WormholeReceiverTestHarness} from "test/harness/WormholeReceiverTestHarness.sol";

contract WormholeReceiverTest is Test, Constants {
WormholeReceiverTestHarness receiver;
Expand Down
13 changes: 1 addition & 12 deletions test/WormholeSender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@
pragma solidity ^0.8.0;

import {Test} from "forge-std/Test.sol";
import {IWormholeRelayer} from "wormhole/interfaces/relayer/IWormholeRelayer.sol";
import {WormholeRelayerBasicTest} from "wormhole-solidity-sdk/testing/WormholeRelayerTest.sol";

import {WormholeBase} from "src/WormholeBase.sol";
import {WormholeSender} from "src/WormholeSender.sol";
import {Constants} from "test/Constants.sol";

contract WormholeSenderHarness is WormholeSender {
constructor(address _relayer, uint16 _sourceChain, uint16 _targetChain)
WormholeBase(_relayer)
WormholeSender(_sourceChain, _targetChain)
{}

function wormholeRelayer() public view returns (IWormholeRelayer) {
return WORMHOLE_RELAYER;
}
}
import {WormholeSenderHarness} from "test/harness/WormholeSenderHarness.sol";

contract WormholeSenderTest is Constants, WormholeRelayerBasicTest {
WormholeSender wormholeSender;
Expand Down
32 changes: 32 additions & 0 deletions test/harness/L1ERC20BridgeHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {WormholeL1ERC20Bridge} from "src/WormholeL1ERC20Bridge.sol";

contract L1ERC20BridgeHarness is WormholeL1ERC20Bridge {
constructor(
address _l1Token,
address _l1Relayer,
address _l1Governor,
uint16 _sourceId,
uint16 _targetId
) WormholeL1ERC20Bridge(_l1Token, _l1Relayer, _l1Governor, _sourceId, _targetId) {}

function exposed_withdraw(address account, uint256 amount) public {
_withdraw(account, amount);
}

function exposed_receiveWithdrawalWormholeMessages(
bytes memory payload,
bytes[] memory additionalVaas,
bytes32 callerAddr,
uint16 sourceChain,
bytes32 deliveryHash
) public {
_receiveWithdrawalWormholeMessages(
payload, additionalVaas, callerAddr, sourceChain, deliveryHash
);
}
}


10 changes: 5 additions & 5 deletions test/harness/L1VotePoolHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {WormholeL1VotePool} from "src/WormholeL1VotePool.sol";
import {WormholeReceiver} from "src/WormholeReceiver.sol";
import {WormholeBase} from "src/WormholeBase.sol";

contract L1VotePoolHarness is WormholeL1VotePool, WormholeReceiver, Test {
constructor(address _relayer, address _l1Governor)
WormholeBase(_relayer)
contract L1VotePoolHarness is WormholeL1VotePool, Test {
constructor(address _l1Governor)
WormholeL1VotePool(_l1Governor)
{}

function receiveWormholeMessages(
// We cannot use the exposed naming
function exposed_receiveCastWormholeMessages(
bytes memory payload,
bytes[] memory additionalVaas,
bytes32 sourceAddress,
uint16 sourceChain,
bytes32 deliveryHash
) public override onlyRelayer isRegisteredSender(sourceChain, sourceAddress) {
) public {
(uint256 proposalId,,,) = abi.decode(payload, (uint256, uint128, uint128, uint128));
_jumpToActiveProposal(proposalId);
_receiveCastVoteWormholeMessages(
Expand Down
Loading

0 comments on commit d4b59e6

Please sign in to comment.