Skip to content

Commit

Permalink
Added missed .withArgs() to error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
aritkulova committed Aug 21, 2024
1 parent e995cf5 commit a2fb96f
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 110 deletions.
9 changes: 4 additions & 5 deletions test/access/MultiOwnable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ describe("MultiOwnable", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(multiOwnable.mockInit()).to.be.revertedWithCustomError(multiOwnable, "NotInitializing");
await expect(multiOwnable.__MultiOwnableMock_init()).to.be.revertedWithCustomError(
multiOwnable,
"InvalidInitialization",
);
await expect(multiOwnable.mockInit()).to.be.revertedWithCustomError(multiOwnable, "NotInitializing").withArgs();
await expect(multiOwnable.__MultiOwnableMock_init())
.to.be.revertedWithCustomError(multiOwnable, "InvalidInitialization")
.withArgs();
});

it("only owner should call these functions", async () => {
Expand Down
7 changes: 3 additions & 4 deletions test/access/PermanentOwnable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ describe("PermanentOwnable", () => {
it("should reject zero address during the owner initialization", async () => {
const permanentOwnableMock = await ethers.getContractFactory("PermanentOwnableMock");

await expect(permanentOwnableMock.deploy(ethers.ZeroAddress)).to.be.revertedWithCustomError(
permanentOwnable,
"InvalidOwner",
);
await expect(permanentOwnableMock.deploy(ethers.ZeroAddress))
.to.be.revertedWithCustomError(permanentOwnable, "InvalidOwner")
.withArgs();
});

it("only owner should call this function", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/access/RBAC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("RBAC", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(rbac.mockInit()).to.be.revertedWithCustomError(rbac, "NotInitializing");
await expect(rbac.mockInit()).to.be.revertedWithCustomError(rbac, "NotInitializing").withArgs();
});
});

Expand Down
68 changes: 33 additions & 35 deletions test/contracts-registry/ContractsRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,55 @@ describe("ContractsRegistry", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(contractsRegistry.mockInit()).to.be.revertedWithCustomError(contractsRegistry, "NotInitializing");
await expect(contractsRegistry.mockInit())
.to.be.revertedWithCustomError(contractsRegistry, "NotInitializing")
.withArgs();

await expect(contractsRegistry.__OwnableContractsRegistry_init()).to.be.revertedWithCustomError(
contractsRegistry,
"InvalidInitialization",
);
await expect(contractsRegistry.__OwnableContractsRegistry_init())
.to.be.revertedWithCustomError(contractsRegistry, "InvalidInitialization")
.withArgs();
});

it("should get proxy upgrader", async () => {
await contractsRegistry.getProxyUpgrader();
});

it("only owner should call these functions", async () => {
await expect(contractsRegistry.connect(SECOND).injectDependencies("")).to.be.revertedWithCustomError(
contractsRegistry,
"OwnableUnauthorizedAccount",
);
await expect(contractsRegistry.connect(SECOND).injectDependencies(""))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).injectDependenciesWithData("", "0x"),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).injectDependenciesWithData("", "0x"))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).upgradeContract("", ethers.ZeroAddress),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).upgradeContract("", ethers.ZeroAddress))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).upgradeContractAndCall("", ethers.ZeroAddress, "0x"),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).upgradeContractAndCall("", ethers.ZeroAddress, "0x"))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(contractsRegistry.connect(SECOND).addContract("", ethers.ZeroAddress)).to.be.revertedWithCustomError(
contractsRegistry,
"OwnableUnauthorizedAccount",
);
await expect(contractsRegistry.connect(SECOND).addContract("", ethers.ZeroAddress))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).addProxyContract("", ethers.ZeroAddress),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).addProxyContract("", ethers.ZeroAddress))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).addProxyContractAndCall("", ethers.ZeroAddress, "0x"),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).addProxyContractAndCall("", ethers.ZeroAddress, "0x"))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(
contractsRegistry.connect(SECOND).justAddProxyContract("", ethers.ZeroAddress),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(contractsRegistry.connect(SECOND).justAddProxyContract("", ethers.ZeroAddress))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(contractsRegistry.connect(SECOND).removeContract("")).to.be.revertedWithCustomError(
contractsRegistry,
"OwnableUnauthorizedAccount",
);
await expect(contractsRegistry.connect(SECOND).removeContract(""))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);
});
});

Expand Down
39 changes: 18 additions & 21 deletions test/contracts-registry/pools/PoolContractsRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ describe("PoolContractsRegistry", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(poolContractsRegistry.__OwnablePoolContractsRegistry_init()).to.be.revertedWithCustomError(
poolContractsRegistry,
"InvalidInitialization",
);

await expect(poolContractsRegistry.mockInit()).to.be.revertedWithCustomError(
poolContractsRegistry,
"NotInitializing",
);
await expect(poolContractsRegistry.__OwnablePoolContractsRegistry_init())
.to.be.revertedWithCustomError(poolContractsRegistry, "InvalidInitialization")
.withArgs();

await expect(poolContractsRegistry.mockInit())
.to.be.revertedWithCustomError(poolContractsRegistry, "NotInitializing")
.withArgs();
});

it("should not set dependencies from non dependant", async () => {
Expand All @@ -81,18 +79,17 @@ describe("PoolContractsRegistry", () => {
});

it("only owner should call these functions", async () => {
await expect(poolContractsRegistry.connect(SECOND).setNewImplementations([], [])).to.be.revertedWithCustomError(
contractsRegistry,
"OwnableUnauthorizedAccount",
);

await expect(
poolContractsRegistry.connect(SECOND).injectDependenciesToExistingPools("", 0, 0),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");

await expect(
poolContractsRegistry.connect(SECOND).injectDependenciesToExistingPoolsWithData("", "0x", 0, 0),
).to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount");
await expect(poolContractsRegistry.connect(SECOND).setNewImplementations([], []))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(poolContractsRegistry.connect(SECOND).injectDependenciesToExistingPools("", 0, 0))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(poolContractsRegistry.connect(SECOND).injectDependenciesToExistingPoolsWithData("", "0x", 0, 0))
.to.be.revertedWithCustomError(contractsRegistry, "OwnableUnauthorizedAccount")
.withArgs(SECOND);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ describe("MultiOwnableContractsRegistry", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(contractsRegistry.__MultiOwnableContractsRegistry_init()).to.be.revertedWithCustomError(
contractsRegistry,
"InvalidInitialization",
);
await expect(contractsRegistry.__MultiOwnableContractsRegistry_init())
.to.be.revertedWithCustomError(contractsRegistry, "InvalidInitialization")
.withArgs();
});

it("only owner should call these functions", async () => {
Expand Down
14 changes: 6 additions & 8 deletions test/diamond/DiamondERC721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,15 @@ describe("DiamondERC721 and InitializableStorage", () => {

describe("access", () => {
it("should initialize only once", async () => {
await expect(erc721.__DiamondERC721Mock_init("Mock Token", "MT")).to.be.revertedWithCustomError(
erc721,
"AlreadyInitialized",
);
await expect(erc721.__DiamondERC721Mock_init("Mock Token", "MT"))
.to.be.revertedWithCustomError(erc721, "AlreadyInitialized")
.withArgs();
});

it("should initialize only by top level contract", async () => {
await expect(erc721.__DiamondERC721Direct_init("Mock Token", "MT")).to.be.revertedWithCustomError(
erc721,
"NotInitializing",
);
await expect(erc721.__DiamondERC721Direct_init("Mock Token", "MT"))
.to.be.revertedWithCustomError(erc721, "NotInitializing")
.withArgs();
});

it("should disable implementation initialization", async () => {
Expand Down
21 changes: 9 additions & 12 deletions test/finance/compound-rate-keeper/CompoundRateKeeper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ describe("CompoundRateKeeper", () => {
describe("access", () => {
it("should not initialize twice", async () => {
await expect(keeper.mockInit(precision(1), 31536000)).to.be.revertedWithCustomError(keeper, "NotInitializing");
await expect(keeper.__OwnableCompoundRateKeeper_init(precision(1), 31536000)).to.be.revertedWithCustomError(
keeper,
"InvalidInitialization",
);
await expect(keeper.__OwnableCompoundRateKeeper_init(precision(1), 31536000))
.to.be.revertedWithCustomError(keeper, "InvalidInitialization")
.withArgs();
});

it("only owner should call these functions", async () => {
await expect(keeper.connect(SECOND).setCapitalizationRate(precision(1))).to.be.revertedWithCustomError(
keeper,
"OwnableUnauthorizedAccount",
);
await expect(keeper.connect(SECOND).setCapitalizationRate(precision(1)))
.to.be.revertedWithCustomError(keeper, "OwnableUnauthorizedAccount")
.withArgs(SECOND);

await expect(keeper.connect(SECOND).setCapitalizationPeriod(31536000)).to.be.revertedWithCustomError(
keeper,
"OwnableUnauthorizedAccount",
);
await expect(keeper.connect(SECOND).setCapitalizationPeriod(31536000))
.to.be.revertedWithCustomError(keeper, "OwnableUnauthorizedAccount")
.withArgs(SECOND);
});
});

Expand Down
13 changes: 7 additions & 6 deletions test/finance/staking/AbstractStaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ describe("AbstractStaking", () => {

describe("AbstractStaking initialization", () => {
it("should not initialize twice", async () => {
await expect(
abstractStaking.mockInit(sharesToken, rewardsToken, rate, stakingStartTime),
).to.be.revertedWithCustomError(abstractStaking, "NotInitializing");
await expect(
abstractStaking.__AbstractStakingMock_init(sharesToken, rewardsToken, rate, stakingStartTime),
).to.be.revertedWithCustomError(abstractStaking, "InvalidInitialization");
await expect(abstractStaking.mockInit(sharesToken, rewardsToken, rate, stakingStartTime))
.to.be.revertedWithCustomError(abstractStaking, "NotInitializing")
.withArgs();

await expect(abstractStaking.__AbstractStakingMock_init(sharesToken, rewardsToken, rate, stakingStartTime))
.to.be.revertedWithCustomError(abstractStaking, "InvalidInitialization")
.withArgs();
});

it("should set the initial values correctly", async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/finance/vesting/Vesting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ describe("Vesting", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(vesting.__VestingMock_init()).to.be.revertedWithCustomError(vesting, "InvalidInitialization");
await expect(vesting.vestingInit()).to.be.revertedWithCustomError(vesting, "NotInitializing");
await expect(vesting.__VestingMock_init())
.to.be.revertedWithCustomError(vesting, "InvalidInitialization")
.withArgs();
await expect(vesting.vestingInit()).to.be.revertedWithCustomError(vesting, "NotInitializing").withArgs();
});
});

Expand Down
13 changes: 7 additions & 6 deletions test/oracles/UniswapV2Oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ describe("UniswapV2Oracle", () => {
});

it("should not initialize twice", async () => {
await expect(
oracle.mockInit(await uniswapV2Factory.getAddress(), ORACLE_TIME_WINDOW),
).to.be.revertedWithCustomError(oracle, "NotInitializing");
await expect(
oracle.__OracleV2Mock_init(await uniswapV2Factory.getAddress(), ORACLE_TIME_WINDOW),
).to.be.revertedWithCustomError(oracle, "InvalidInitialization");
await expect(oracle.mockInit(await uniswapV2Factory.getAddress(), ORACLE_TIME_WINDOW))
.to.be.revertedWithCustomError(oracle, "NotInitializing")
.withArgs();

await expect(oracle.__OracleV2Mock_init(await uniswapV2Factory.getAddress(), ORACLE_TIME_WINDOW))
.to.be.revertedWithCustomError(oracle, "InvalidInitialization")
.withArgs();
});
});

Expand Down
7 changes: 3 additions & 4 deletions test/proxy/transparent/TransparentUpgradeableProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ describe("SolarityTransparentProxy", () => {
const AMOUNT = 10;

it("proxy admin cannot call delegated functions", async () => {
await expect(tokenProxy.connect(PROXY_UPGRADER).mint(OWNER.address, AMOUNT)).to.be.revertedWithCustomError(
proxy,
"ProxyDeniedAdminAccess",
);
await expect(tokenProxy.connect(PROXY_UPGRADER).mint(OWNER.address, AMOUNT))
.to.be.revertedWithCustomError(proxy, "ProxyDeniedAdminAccess")
.withArgs();
});

it("everyone except proxy admin can call delegated functions", async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/token/SBT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ describe("SBT", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(sbt.__SBTMock_init(name, symbol)).to.be.revertedWithCustomError(sbt, "InvalidInitialization");
await expect(sbt.mockInit(name, symbol)).to.be.revertedWithCustomError(sbt, "NotInitializing");
await expect(sbt.__SBTMock_init(name, symbol))
.to.be.revertedWithCustomError(sbt, "InvalidInitialization")
.withArgs();
await expect(sbt.mockInit(name, symbol)).to.be.revertedWithCustomError(sbt, "NotInitializing").withArgs();
});
});

Expand Down

0 comments on commit a2fb96f

Please sign in to comment.