Skip to content

Commit

Permalink
initializeFrom with build number and data
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 10, 2024
1 parent 84ef2cd commit 207d988
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 10 additions & 6 deletions packages/contracts/src/TokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ contract TokenVoting is IMembership, MajorityVotingBase {
emit MembershipContractAnnounced({definingContract: address(_token)});
}

/// @notice Initializes the plugin after an upgrade from a previous version.
/// @param _minApprovals The minimal amount of approvals the proposal needs to succeed.
/// @notice Reinitializes the TokenVoting after an upgrade from a previous protocol version.
/// @param _fromBuild The build version number of the previous implementation contract this upgrade is transitioning from.
/// @param _initData The initialization data to be passed to via `upgradeToAndCall` (see [ERC-1967](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Upgrade)).
function initializeFrom(
uint256 _minApprovals,
TargetConfig calldata _targetConfig
uint16 _fromBuild,
bytes calldata _initData
) external reinitializer(2) {
_updateMinApprovals(_minApprovals);
if(_fromBuild < 3) {
(uint256 minApprovals, TargetConfig memory targetConfig) = abi.decode(_initData, (uint256, TargetConfig));
_updateMinApprovals(minApprovals);

_setTargetConfig(_targetConfig);
_setTargetConfig(targetConfig);
}
}

/// @notice Checks if this or the parent contract supports an interface by its ID.
Expand Down
7 changes: 1 addition & 6 deletions packages/contracts/src/TokenVotingSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,9 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
preparedSetupData.helpers = new address[](1);
preparedSetupData.helpers[0] = votingPowerCondition;

// initialize the minApprovals and targetConfig
(uint256 _minApprovals, PluginUUPSUpgradeable.TargetConfig memory _targetConfig) = abi.decode(
_payload.data,
(uint256, PluginUUPSUpgradeable.TargetConfig)
);
initData = abi.encodeCall(
TokenVoting.initializeFrom,
(_minApprovals, _targetConfig)
(_fromBuild, _payload.data)
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/contracts/test/10_unit-testing/12_plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,13 @@ describe('TokenVotingSetup', function () {
data: prepareUpdateBuild3Inputs,
plugin
});


// Check the return data.
expect(initData).to.be.eq(
TokenVoting__factory.createInterface().encodeFunctionData(
'initializeFrom',
[updateMinApproval, updateTargetConfig]
[1, prepareUpdateBuild3Inputs]
)
);

Expand Down Expand Up @@ -810,7 +811,7 @@ describe('TokenVotingSetup', function () {
expect(initData).to.be.eq(
TokenVoting__factory.createInterface().encodeFunctionData(
'initializeFrom',
[updateMinApproval, updateTargetConfig]
[2, prepareUpdateBuild3Inputs]
)
);
expect(helpers).to.be.eql([anticipatedCondition]);
Expand Down

0 comments on commit 207d988

Please sign in to comment.