Skip to content

Commit

Permalink
add rules updated event
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Oct 29, 2024
1 parent d8935c2 commit 2ac46a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ abstract contract RuledCondition is PermissionConditionUpgradeable {
/// @notice Identifier for a rule that involves direct value comparison.
uint8 internal constant VALUE_RULE_ID = 204;

/// @notice Emitted when the rules are updated.
/// @param rules The new rules that replaces old rules.
event RulesUpdated(Rule[] rules);

/// @notice Represents a rule used in the condition contract.
/// @param id The ID representing the identifier of the rule.
/// @param op The operation to apply, as defined in the `Op` enum.
Expand Down Expand Up @@ -94,6 +98,8 @@ abstract contract RuledCondition is PermissionConditionUpgradeable {
++i;
}
}

emit RulesUpdated(_rules);
}

/// @notice Evaluates a rule by its index.
Expand Down
16 changes: 14 additions & 2 deletions contracts/test/permission/condition/extensions/ruled-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DAOMock,
DAOMock__factory,
} from '../../../../typechain';
import {RulesUpdatedEvent} from '../../../../typechain/src/permission/condition/extensions/RuledCondition';
import {
BLOCK_NUMBER_RULE_ID,
TIMESTAMP_RULE_ID,
Expand All @@ -15,22 +16,33 @@ import {
Op,
RULE_VALUE_RULE_ID,
} from '../../../utils/condition/condition';
import {findEvent} from '@aragon/osx-commons-sdk';
import {loadFixture} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {ethers} from 'hardhat';

describe('RuledCondition', async () => {
it('should be able to update the condition rules', async () => {
it('updates the rules and emits the event', async () => {
const {conditionMock} = await loadFixture(fixture);

await conditionMock.updateRules([
const newRules = [
{
id: CONDITION_RULE_ID,
op: Op.EQ,
value: 777,
permissionId: DUMMY_PERMISSION_ID,
},
];
const tx = await conditionMock.updateRules(newRules);
const event = findEvent<RulesUpdatedEvent>(await tx.wait(), 'RulesUpdated');
expect(event.args.rules).to.deep.equal([
[
newRules[0].id,
newRules[0].op,
newRules[0].value,
newRules[0].permissionId,
],
]);

const rules = await conditionMock.getRules();
Expand Down

0 comments on commit 2ac46a3

Please sign in to comment.