Skip to content

Commit

Permalink
new changes'
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 25, 2024
1 parent e800751 commit 8659fac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
25 changes: 15 additions & 10 deletions packages/contracts/src/Admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ contract Admin is IMembership, PluginUUPSUpgradeable, ProposalUpgradeable {
using SafeCastUpgradeable for uint256;

/// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.
bytes4 internal constant ADMIN_INTERFACE_ID =
this.initialize.selector ^ this.executeProposal.selector;
bytes4 internal constant ADMIN_INTERFACE_ID = this.initialize.selector ^ this.execute.selector;

/// @notice The ID of the permission required to call the `executeProposal` function.
bytes32 public constant EXECUTE_PROPOSAL_PERMISSION_ID =
Expand Down Expand Up @@ -86,18 +85,24 @@ contract Admin is IMembership, PluginUUPSUpgradeable, ProposalUpgradeable {
/// @inheritdoc IProposal
/// @dev Admin doesn't allow creating a proposal, so we return empty string.
function createProposalParamsABI() external pure override returns (string memory) {
return "";
return "(uint256 allowFailureMap)";
}

/// @inheritdoc IProposal
function createProposal(
bytes calldata,
IDAO.Action[] calldata,
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
uint64,
uint64,
bytes memory
) public pure override returns (uint256) {
revert NotAllowedOperation();
bytes memory _data
) public override returns (uint256) {
uint256 allowFailureMap;

if (_data.length > 0) {
allowFailureMap = abi.decode(_data, (uint256));
}

execute(_metadata, _actions, allowFailureMap);
}

/// @inheritdoc IProposal
Expand All @@ -111,11 +116,11 @@ contract Admin is IMembership, PluginUUPSUpgradeable, ProposalUpgradeable {
/// @param _allowFailureMap A bitmap allowing the proposal to succeed, even if individual actions might revert.
/// If the bit at index `i` is 1, the proposal succeeds even if the `i`th action reverts. A failure map value
// of 0 requires every action to not revert.
function executeProposal(
function execute(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
uint256 _allowFailureMap
) external auth(EXECUTE_PROPOSAL_PERMISSION_ID) {
) public auth(EXECUTE_PROPOSAL_PERMISSION_ID) {
uint64 currentTimestamp64 = block.timestamp.toUint64();

uint256 proposalId = createProposalId(_actions, _metadata);
Expand Down
20 changes: 10 additions & 10 deletions packages/contracts/test/10_unit-testing/11_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
});

describe('execute proposal: ', async () => {
it('reverts when calling `executeProposal()` if `EXECUTE_PROPOSAL_PERMISSION_ID` is not granted to the admin address', async () => {
it('reverts when calling `execute()` if `EXECUTE_PROPOSAL_PERMISSION_ID` is not granted to the admin address', async () => {
const {
alice,
initializedPlugin: plugin,
Expand All @@ -142,9 +142,9 @@ describe(PLUGIN_CONTRACT_NAME, function () {
)
).to.be.false;

// Expect Alice's `executeProposal` call to be reverted because she hasn't `EXECUTE_PROPOSAL_PERMISSION_ID` on the Admin plugin
// Expect Alice's `execute` call to be reverted because she hasn't `EXECUTE_PROPOSAL_PERMISSION_ID` on the Admin plugin
await expect(
plugin.connect(alice).executeProposal(dummyMetadata, dummyActions, 0)
plugin.connect(alice).execute(dummyMetadata, dummyActions, 0)
)
.to.be.revertedWithCustomError(plugin, 'DaoUnauthorized')
.withArgs(
Expand All @@ -155,7 +155,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
);
});

it('reverts when calling `executeProposal()` if the `EXECUTE_PERMISSION_ID` on the DAO is not granted to the plugin address', async () => {
it('reverts when calling `execute()` if the `EXECUTE_PERMISSION_ID` on the DAO is not granted to the plugin address', async () => {
const {
alice,
initializedPlugin: plugin,
Expand All @@ -181,9 +181,9 @@ describe(PLUGIN_CONTRACT_NAME, function () {
)
).to.be.false;

// Expect Alice's the `executeProposal` call to be reverted because the Admin plugin hasn't `EXECUTE_PERMISSION_ID` on the DAO
// Expect Alice's the `execute` call to be reverted because the Admin plugin hasn't `EXECUTE_PERMISSION_ID` on the DAO
await expect(
plugin.connect(alice).executeProposal(dummyMetadata, dummyActions, 0)
plugin.connect(alice).execute(dummyMetadata, dummyActions, 0)
)
.to.be.revertedWithCustomError(dao, 'Unauthorized')
.withArgs(
Expand Down Expand Up @@ -224,7 +224,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

const tx = await plugin
.connect(alice)
.executeProposal(dummyMetadata, dummyActions, allowFailureMap);
.execute(dummyMetadata, dummyActions, allowFailureMap);

const eventName = plugin.interface.getEvent('ProposalCreated').name;
await expect(tx).to.emit(plugin, eventName);
Expand Down Expand Up @@ -267,7 +267,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
);

await expect(
plugin.connect(alice).executeProposal(dummyMetadata, dummyActions, 0)
plugin.connect(alice).execute(dummyMetadata, dummyActions, 0)
)
.to.emit(plugin, plugin.interface.getEvent('ProposalExecuted').name)
.withArgs(currentExpectedProposalId);
Expand Down Expand Up @@ -306,7 +306,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

const tx = await newPlugin
.connect(alice)
.executeProposal(dummyMetadata, dummyActions, allowFailureMap);
.execute(dummyMetadata, dummyActions, allowFailureMap);

const event = findEventTopicLog<DAOEvents.ExecutedEvent>(
await tx.wait(),
Expand Down Expand Up @@ -334,7 +334,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

const tx = await newPlugin
.connect(alice)
.executeProposal(newMetadata, dummyActions, 0);
.execute(newMetadata, dummyActions, 0);

const event = findEventTopicLog<DAOEvents.ExecutedEvent>(
await tx.wait(),
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/admin-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ethers} from 'hardhat';

export const ADMIN_INTERFACE = new ethers.utils.Interface([
'function initialize(address,tuple(address,uint8))',
'function executeProposal(bytes,tuple(address,uint256,bytes)[],uint256)',
'function execute(bytes,tuple(address,uint256,bytes)[],uint256)',
]);

// Permissions
Expand Down

0 comments on commit 8659fac

Please sign in to comment.