Skip to content

Commit

Permalink
Fix bridgeSetting params
Browse files Browse the repository at this point in the history
  • Loading branch information
xavikh committed Mar 21, 2024
1 parent 73ef452 commit 2497888
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ contract OptimisticTokenVotingPlugin is
) external initializer {
__PluginUUPSUpgradeable_init(_dao);

bridgeSettings = _bridgeSettings;
votingToken = _token;

_updateOptimisticGovernanceSettings(_governanceSettings);

__LzApp_init(bridgeSettings.bridge);
setTrustedRemoteAddress(_bridgeSettings.chainId, abi.encodePacked(_bridgeSettings.l2VotingAggregator)); // Is this correct?
emit MembershipContractAnnounced({definingContract: address(_token)});
}

Expand Down
14 changes: 7 additions & 7 deletions src/OptimisticTokenVotingPluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
// only used for GovernanceERC20 (when token is not passed)
GovernanceERC20.MintSettings memory mintSettings,
address[] memory proposers,
address _lzAppEndpoint
OptimisticTokenVotingPlugin.BridgeSettings memory _lzAppEndpoint
) = decodeInstallationParams(_installParameters);

if (proposers.length == 0) {
Expand All @@ -102,7 +102,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
// Prepare helpers.
address[] memory helpers = new address[](1);

if (token != address(0)) {
if (token != address(0x0)) {
if (!token.isContract()) {
revert TokenNotContract(token);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
// Prepare permissions
PermissionLib.MultiTargetPermission[]
memory permissions = new PermissionLib.MultiTargetPermission[](
tokenSettings.addr != address(0)
tokenSettings.addr != address(0x0)
? 3 + proposers.length
: 4 + proposers.length
);
Expand Down Expand Up @@ -215,7 +215,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
}
}

if (tokenSettings.addr == address(0)) {
if (tokenSettings.addr == address(0x0)) {
bytes32 tokenMintPermission = GovernanceERC20(token)
.MINT_PERMISSION_ID();

Expand Down Expand Up @@ -319,7 +319,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
// only used for GovernanceERC20 (when a token is not passed)
GovernanceERC20.MintSettings calldata _mintSettings,
address[] calldata _proposers,
address _lzAppEndpoint
OptimisticTokenVotingPlugin.BridgeSettings calldata _lzAppEndpoint
) external pure returns (bytes memory) {
return
abi.encode(
Expand All @@ -344,7 +344,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
// only used for GovernanceERC20 (when token is not passed)
GovernanceERC20.MintSettings memory mintSettings,
address[] memory proposers,
address _lzAppEndpoint
OptimisticTokenVotingPlugin.BridgeSettings memory _lzAppEndpoint
)
{
(
Expand All @@ -360,7 +360,7 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
TokenSettings,
GovernanceERC20.MintSettings,
address[],
address
OptimisticTokenVotingPlugin.BridgeSettings
)
);
}
Expand Down
6 changes: 5 additions & 1 deletion test/OptimisticTokenVotingPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ contract OptimisticTokenVotingPluginTest is Test {
address alice = address(0xa11ce);
address bob = address(0xB0B);
address randomWallet = vm.addr(1234567890);
address lzAppEndpoint = address(0xDAD);
OptimisticTokenVotingPlugin.BridgeSettings lzAppEndpoint = OptimisticTokenVotingPlugin.BridgeSettings(
1,
address(0xb41d5e),
address(0x1f1d5e)
);

// Events from external contracts
event Initialized(uint8 version);
Expand Down
25 changes: 16 additions & 9 deletions test/OptimisticTokenVotingPluginSetup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
address[] proposers;

address alice = address(0xa11ce);
address lzAppEndpoint = address(0xDAD);
OptimisticTokenVotingPlugin.BridgeSettings lzAppEndpoint = OptimisticTokenVotingPlugin.BridgeSettings(
1,
address(0xb41d5e),
address(0x1f1d5e)
);

error Unimplemented();

Expand Down Expand Up @@ -102,7 +106,7 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
);

bytes
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000dad0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000b41d5e00000000000000000000000000000000000000000000000000000000001f1d5e0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
assertEq(output, expected, "Incorrect encoded bytes");
}

Expand All @@ -119,11 +123,11 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
tokenSettings,
mintSettings,
proposers,
address(0)
lzAppEndpoint
);

bytes
memory expected = hex"0000000000000000000000000000000000000000000000000000000000030d400000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000001e24000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
memory expected = hex"0000000000000000000000000000000000000000000000000000000000030d400000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000001e24000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000b41d5e00000000000000000000000000000000000000000000000000000000001f1d5e0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
assertEq(output, expected, "Incorrect encoded bytes");
}

Expand All @@ -143,7 +147,7 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
);

bytes
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000dad0000000000000000000000000000000000000000000000000000000000005678000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001057726170706564204e657720436f696e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004774e434e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000b41d5e00000000000000000000000000000000000000000000000000000000001f1d5e0000000000000000000000000000000000000000000000000000000000005678000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001057726170706564204e657720436f696e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004774e434e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
assertEq(output, expected, "Incorrect encoded bytes");
}

Expand All @@ -167,7 +171,7 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
);

bytes
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000dad0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000006789000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000499602d200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000006978000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000b41d5e00000000000000000000000000000000000000000000000000000000001f1d5e0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000006789000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000499602d200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000001234567890";
assertEq(output, expected, "Incorrect encoded bytes");
}

Expand All @@ -185,7 +189,7 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
);

bytes
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000dad0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000567890";
memory expected = hex"00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000b41d5e00000000000000000000000000000000000000000000000000000000001f1d5e0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000d5772617070656420546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000377544b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000567890";
assertEq(output, expected, "Incorrect encoded bytes");
}

Expand Down Expand Up @@ -232,7 +236,7 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
memory _tokenSettings,
GovernanceERC20.MintSettings memory _mintSettings,
address[] memory _proposers,
address _lzAppEndpoint
OptimisticTokenVotingPlugin.BridgeSettings memory _lzAppEndpoint
) = pluginSetup.decodeInstallationParams(_installationParams);

// Voting
Expand Down Expand Up @@ -284,7 +288,10 @@ contract OptimisticTokenVotingPluginSetupTest is Test {
assertEq(_mintSettings.amounts.length, 2, "Incorrect amounts.length");
assertEq(_mintSettings.amounts[0], 2000, "Incorrect amounts[0]");
assertEq(_mintSettings.amounts[1], 5000, "Incorrect amounts[1]");
assertEq(lzAppEndpoint, _lzAppEndpoint, "Incorrect lzAppEndpoint");

assertEq(_lzAppEndpoint.chainId, 1, "Incorrect chainId");
assertEq(_lzAppEndpoint.bridge, address(0xb41d5e), "Incorrect bridge");
assertEq(_lzAppEndpoint.l2VotingAggregator, address(0x1f1d5e), "Incorrect l2VotingAggregator");

// Proposers
assertEq(_proposers.length, 2, "Incorrect proposers.length");
Expand Down

0 comments on commit 2497888

Please sign in to comment.