Skip to content

Commit

Permalink
fix: Fix hardhat tests after removal of CheckContract
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Jul 28, 2024
1 parent cd2a347 commit e456c4e
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions contracts/test/OwnershipTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,9 @@ contract("All Liquity functions with onlyOwner modifier", async (accounts) => {
borrowerOperations = contracts.borrowerOperations;
});

const testZeroAddress = async (contract, params, method = "setAddresses", skip = 0) => {
await testWrongAddress(contract, params, th.ZERO_ADDRESS, method, skip, "Account cannot be zero address");
};
const testNonContractAddress = async (contract, params, method = "setAddresses", skip = 0) => {
await testWrongAddress(contract, params, bob, method, skip, "Account code size cannot be zero");
};
const testWrongAddress = async (contract, params, address, method, skip, message) => {
for (let i = skip; i < params.length; i++) {
const newParams = [...params];
newParams[i] = address;
await th.assertRevert(contract[method](...newParams, { from: owner }), message);
}
};

const testDeploymentSetter = async (
contract,
numberOfAddresses,
checkContract = true,
twice = true,
method = "setAddresses",
) => {
Expand All @@ -64,13 +49,6 @@ contract("All Liquity functions with onlyOwner modifier", async (accounts) => {
// Attempt call from alice
await th.assertRevert(contract[method](...params, { from: alice }));

if (checkContract) {
// Attempt to use zero address
await testZeroAddress(contract, params, method);
// Attempt to use non contract
await testNonContractAddress(contract, params, method);
}

// Owner can successfully set any address
const txOwner = await contract[method](...params, { from: owner });
assert.isTrue(txOwner.receipt.status);
Expand All @@ -82,25 +60,25 @@ contract("All Liquity functions with onlyOwner modifier", async (accounts) => {

describe("BoldToken", async (accounts) => {
it("setBranchAddresses(): reverts when called by non-owner, with wrong addresses", async () => {
await testDeploymentSetter(boldToken, 4, false, false, "setBranchAddresses");
await testDeploymentSetter(boldToken, 4, false, "setBranchAddresses");
});
it("setCollateralRegistry(): reverts when called by non-owner, with wrong address, or twice", async () => {
await testDeploymentSetter(boldToken, 1, false, true, "setCollateralRegistry");
await testDeploymentSetter(boldToken, 1, true, "setCollateralRegistry");
});
});

describe("TroveManager", async (accounts) => {
it("setAddresses(): reverts when called by non-owner, with wrong addresses", async () => {
await testDeploymentSetter(troveManager, 9, false, false);
await testDeploymentSetter(troveManager, 9, false);
});
it("setCollateralRegistry(): reverts when called by non-owner, with wrong address, or twice", async () => {
await testDeploymentSetter(troveManager, 1, false, true, "setCollateralRegistry");
await testDeploymentSetter(troveManager, 1, true, "setCollateralRegistry");
});
});

describe("BorrowerOperations", async (accounts) => {
it("setAddresses(): reverts when called by non-owner, with wrong addresses, or twice", async () => {
await testDeploymentSetter(borrowerOperations, 7, false);
await testDeploymentSetter(borrowerOperations, 7);
});
});

Expand All @@ -112,7 +90,7 @@ contract("All Liquity functions with onlyOwner modifier", async (accounts) => {

describe("StabilityPool", async (accounts) => {
it("setAddresses(): reverts when called by non-owner, with wrong addresses, or twice", async () => {
await testDeploymentSetter(stabilityPool, 6, false);
await testDeploymentSetter(stabilityPool, 6);
});
});

Expand All @@ -130,11 +108,6 @@ contract("All Liquity functions with onlyOwner modifier", async (accounts) => {
// Attempt call from alice
await th.assertRevert(sortedTroves.setAddresses(...params, { from: alice }));

// Attempt to use zero address
await testZeroAddress(sortedTroves, params, "setAddresses", 1);
// Attempt to use non contract
await testNonContractAddress(sortedTroves, params, "setAddresses", 1);

// Owner can successfully set params
const txOwner = await sortedTroves.setAddresses(...params, { from: owner });
assert.isTrue(txOwner.receipt.status);
Expand Down

0 comments on commit e456c4e

Please sign in to comment.