Skip to content

Commit

Permalink
fix: test after adding the lzEndpoint to the init
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgj94 committed Mar 21, 2024
1 parent 258a7b8 commit f85740a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 45 deletions.
19 changes: 18 additions & 1 deletion src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ contract OptimisticTokenVotingPlugin is
function initialize(
IDAO _dao,
OptimisticGovernanceSettings calldata _governanceSettings,
IVotesUpgradeable _token
IVotesUpgradeable _token,
address _lzEndpoint
) external initializer {
__PluginUUPSUpgradeable_init(_dao);

votingToken = _token;

_updateOptimisticGovernanceSettings(_governanceSettings);

// __LzApp_init(_lzEndpoint);
emit MembershipContractAnnounced({definingContract: address(_token)});
}

Expand Down Expand Up @@ -555,6 +558,20 @@ contract OptimisticTokenVotingPlugin is
}
}

// This function is called when data is received. It overrides the equivalent function in the parent contract.
// This function should only be called from the L2 to send the aggregated votes and nothing else
/*
function _nonBlockingLzReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint64 _nonce,
bytes memory _payload
) internal override {
// The LayerZero _payload (message) is decoded as a string and stored in the "data" variable.
string memory data = abi.decode(_payload, (string));
}
*/

/// @notice This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain (see [OpenZeppelin's guide about storage gaps](https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps)).
uint256[50] private __gap;
}
30 changes: 23 additions & 7 deletions src/OptimisticTokenVotingPluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
TokenSettings memory tokenSettings,
// only used for GovernanceERC20 (when token is not passed)
GovernanceERC20.MintSettings memory mintSettings,
address[] memory proposers
address[] memory proposers,
address _lzAppEndpoint
) = decodeInstallationParams(_installParameters);

if (proposers.length == 0) {
Expand Down Expand Up @@ -150,7 +151,12 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
address(optimisticTokenVotingPluginBase),
abi.encodeCall(
OptimisticTokenVotingPlugin.initialize,
(IDAO(_dao), votingSettings, IVotesUpgradeable(token))
(
IDAO(_dao),
votingSettings,
IVotesUpgradeable(token),
_lzAppEndpoint
)
)
);

Expand Down Expand Up @@ -312,14 +318,16 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
TokenSettings calldata _tokenSettings,
// only used for GovernanceERC20 (when a token is not passed)
GovernanceERC20.MintSettings calldata _mintSettings,
address[] calldata _proposers
address[] calldata _proposers,
address _lzAppEndpoint
) external pure returns (bytes memory) {
return
abi.encode(
_votingSettings,
_tokenSettings,
_mintSettings,
_proposers
_proposers,
_lzAppEndpoint
);
}

Expand All @@ -335,16 +343,24 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
TokenSettings memory tokenSettings,
// only used for GovernanceERC20 (when token is not passed)
GovernanceERC20.MintSettings memory mintSettings,
address[] memory proposers
address[] memory proposers,
address _lzAppEndpoint
)
{
(votingSettings, tokenSettings, mintSettings, proposers) = abi.decode(
(
votingSettings,
tokenSettings,
mintSettings,
proposers,
_lzAppEndpoint
) = abi.decode(
_data,
(
OptimisticTokenVotingPlugin.OptimisticGovernanceSettings,
TokenSettings,
GovernanceERC20.MintSettings,
address[]
address[],
address
)
);
}
Expand Down
51 changes: 34 additions & 17 deletions test/OptimisticTokenVotingPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract OptimisticTokenVotingPluginTest is Test {
address alice = address(0xa11ce);
address bob = address(0xB0B);
address randomWallet = vm.addr(1234567890);
address lzAppEndpoint = address(0xDAD);

// Events from external contracts
event Initialized(uint8 version);
Expand Down Expand Up @@ -97,7 +98,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand All @@ -122,7 +124,7 @@ contract OptimisticTokenVotingPluginTest is Test {
vm.expectRevert(
bytes("Initializable: contract is already initialized")
);
plugin.initialize(dao, settings, votingToken);
plugin.initialize(dao, settings, votingToken, lzAppEndpoint);
}

function test_InitializeSetsTheProperValues() public {
Expand All @@ -141,7 +143,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -171,7 +174,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand All @@ -190,7 +194,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand All @@ -213,7 +218,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand All @@ -232,7 +238,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -262,7 +269,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -352,7 +360,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -407,7 +416,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -447,7 +457,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -478,7 +489,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -519,7 +531,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -567,7 +580,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -680,7 +694,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -831,7 +846,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down Expand Up @@ -1520,7 +1536,8 @@ contract OptimisticTokenVotingPluginTest is Test {
OptimisticTokenVotingPlugin.initialize.selector,
dao,
settings,
votingToken
votingToken,
lzAppEndpoint
)
)
);
Expand Down
Loading

0 comments on commit f85740a

Please sign in to comment.