Skip to content

Commit

Permalink
test: a specific and a generic condition are granted at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Sep 1, 2023
1 parent cc7179e commit 182fe93
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IEIP4824__factory,
IProtocolVersion__factory,
PermissionConditionMock__factory,
PermissionConditionMock,
} from '../../../typechain';
import {DAO__factory as DAO_V1_0_0__factory} from '../../../typechain/@aragon/osx-v1.0.1/core/dao/DAO.sol';
import {DAO__factory as DAO_V1_3_0__factory} from '../../../typechain/@aragon/osx-v1.3.0-rc0.2/core/dao/DAO.sol';
Expand Down Expand Up @@ -54,6 +55,7 @@ import {
IMPLICIT_INITIAL_PROTOCOL_VERSION,
} from '../../test-utils/protocol-version';
import {ANY_ADDR} from '../permission/permission-manager';
import {defaultAbiCoder} from 'ethers/lib/utils';

chai.use(smock.matchers);

Expand Down Expand Up @@ -1347,6 +1349,62 @@ describe('DAO', function () {
).to.equal(INVALID_ERC1271_SIGNATURE);
});

context(
'A caller-specfic and a generic condition are both set',
async () => {
let specificMockCondition: PermissionConditionMock;
let genericMockCondition: PermissionConditionMock;

beforeEach(async () => {
// Setup the specfic condition for a specific caller
specificMockCondition = await mockConditionFactory.deploy();
await dao.grantWithCondition(
dao.address,
caller.address,
PERMISSION_IDS.VALIDATE_SIGNATURE_PERMISSION_ID,
specificMockCondition.address
);

// Setup the generic condition for ANY caller
genericMockCondition = await mockConditionFactory.deploy();
await dao.grantWithCondition(
dao.address,
ANY_ADDR,
PERMISSION_IDS.VALIDATE_SIGNATURE_PERMISSION_ID,
genericMockCondition.address
);
});

it('returns valid if both conditions are met', async () => {
expect(
await dao.connect(caller).isValidSignature(hash, signature)
).to.equal(VALID_ERC1271_SIGNATURE);
});

it('returns valid if only the specific condition is met', async () => {
await genericMockCondition.setAnswer(false);
expect(
await dao.connect(caller).isValidSignature(hash, signature)
).to.equal(VALID_ERC1271_SIGNATURE);
});

it('returns valid if only the generic condition is met', async () => {
await specificMockCondition.setAnswer(false);
expect(
await dao.connect(caller).isValidSignature(hash, signature)
).to.equal(VALID_ERC1271_SIGNATURE);
});

it('returns invalid if both conditions are not met', async () => {
await specificMockCondition.setAnswer(false);
await genericMockCondition.setAnswer(false);
expect(
await dao.connect(caller).isValidSignature(hash, signature)
).to.equal(INVALID_ERC1271_SIGNATURE);
});
}
);

it('should revert if `setSignatureValidator` is called', async () => {
await expect(
dao
Expand Down

0 comments on commit 182fe93

Please sign in to comment.