Skip to content

Commit

Permalink
Add new error: UnsuitableDynamic32CompValueSize
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jan 16, 2022
1 parent 1d275aa commit c776249
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
9 changes: 9 additions & 0 deletions contracts/Permissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ library Permissions {
/// CompValue for static types should have a size of exactly 32 bytes
error UnsuitableStaticCompValueSize();

/// CompValue for Dynamic32 types should be a multiple of exactly 32 bytes
error UnsuitableDynamic32CompValueSize();

/// Exceeds the max number of params supported
error ScopeMaxParametersExceeded();

Expand Down Expand Up @@ -639,6 +642,12 @@ library Permissions {
if (paramType == ParameterType.STATIC && compValue.length != 32) {
revert UnsuitableStaticCompValueSize();
}

if (
paramType == ParameterType.DYNAMIC32 && compValue.length % 32 != 0
) {
revert UnsuitableDynamic32CompValueSize();
}
}

/*
Expand Down
51 changes: 44 additions & 7 deletions test/Scoping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe("Scoping", async () => {
const avatar = await Avatar.deploy();
const TestContract = await hre.ethers.getContractFactory("TestContract");
const testContract = await TestContract.deploy();
const testContractClone = await TestContract.deploy();
return { Avatar, avatar, testContract, testContractClone };
return { Avatar, avatar, testContract };
});

const setupRolesWithOwnerAndInvoker = deployments.createFixture(async () => {
Expand Down Expand Up @@ -877,7 +876,6 @@ describe("Scoping", async () => {
testContract.interface.getFunction("doNothing")
);

const COMP_EQUAL = 0;
const ROLE_ID = 0;
await expect(
modifier
Expand Down Expand Up @@ -918,7 +916,6 @@ describe("Scoping", async () => {
testContract.interface.getFunction("doNothing")
);

const COMP_EQUAL = 0;
const ROLE_ID = 0;

await expect(
Expand Down Expand Up @@ -1009,7 +1006,7 @@ describe("Scoping", async () => {
});
});

describe("Enforces Static Parameter Size limit", () => {
describe("Enforces Parameter Size constraints", () => {
const MORE_THAN_32_BYTES_TEXT =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
const A_32_BYTES_VALUE = ethers.utils.defaultAbiCoder.encode(
Expand All @@ -1025,7 +1022,6 @@ describe("Scoping", async () => {
testContract.interface.getFunction("doNothing")
);

const COMP_EQUAL = 0;
const ROLE_ID = 0;
const IS_SCOPED = true;

Expand All @@ -1044,6 +1040,21 @@ describe("Scoping", async () => {
)
).to.be.revertedWith("UnsuitableStaticCompValueSize()");

await expect(
modifier
.connect(owner)
.scopeFunction(
ROLE_ID,
testContract.address,
SELECTOR,
[IS_SCOPED],
[TYPE_DYNAMIC32],
[COMP_EQUAL],
[ethers.utils.solidityPack(["string"], ["abcdefghijg"])],
OPTIONS_NONE
)
).to.be.revertedWith("UnsuitableDynamic32CompValueSize()");

await expect(
modifier
.connect(owner)
Expand Down Expand Up @@ -1087,7 +1098,6 @@ describe("Scoping", async () => {
testContract.interface.getFunction("doNothing")
);

const COMP_EQUAL = 0;
const ROLE_ID = 0;
await expect(
modifier
Expand All @@ -1103,6 +1113,20 @@ describe("Scoping", async () => {
)
).to.be.revertedWith("UnsuitableStaticCompValueSize()");

await expect(
modifier
.connect(owner)
.scopeParameter(
ROLE_ID,
testContract.address,
SELECTOR,
0,
TYPE_DYNAMIC32,
COMP_EQUAL,
ethers.utils.solidityPack(["string"], ["abcdefghijg"])
)
).to.be.revertedWith("UnsuitableDynamic32CompValueSize()");

await expect(
modifier
.connect(owner)
Expand Down Expand Up @@ -1140,6 +1164,19 @@ describe("Scoping", async () => {
)
).to.be.revertedWith("UnsuitableStaticCompValueSize()");

await expect(
modifier
.connect(owner)
.scopeParameterAsOneOf(
ROLE_ID,
testContract.address,
SELECTOR,
0,
TYPE_DYNAMIC32,
[ethers.utils.solidityPack(["string"], ["abcdefghijg"])]
)
).to.be.revertedWith("UnsuitableDynamic32CompValueSize()");

await expect(
modifier
.connect(owner)
Expand Down

0 comments on commit c776249

Please sign in to comment.