Skip to content

Commit

Permalink
Continue remediation
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 20, 2023
1 parent 52781ee commit 9288716
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 314 deletions.
2 changes: 1 addition & 1 deletion scripts/domain/AuthToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AuthToken {

return AuthToken.fromObject({
tokenId: tokenId.toString(),
tokenType: tokenType,
tokenType: Number(tokenType),
});
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/domain/Dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Dispute {
return Dispute.fromObject({
exchangeId: exchangeId.toString(),
buyerPercent: buyerPercent.toString(),
state,
state: Number(state),
});
}

Expand Down
12 changes: 4 additions & 8 deletions scripts/util/deploy-mock-tokens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const hre = require("hardhat");
const { expect } = require("chai");
const environments = require("../../environments");
const ethers = hre.ethers;
const { getContractFactory, provider, ZeroAddress, getAddress } = hre.ethers;
const network = hre.network.name;
const confirmations = hre.network.name == "hardhat" ? 1 : environments.confirmations;

Expand All @@ -20,7 +20,7 @@ async function deployMockTokens(tokens = ["BosonToken", "Foreign721", "Foreign11
let token = tokens.shift();
let TokenContractFactory = await getContractFactory(token);
const tokenContract = await TokenContractFactory.deploy();
await tokenContract.deployed();
await tokenContract.waitForDeployment();
deployedTokens.push(tokenContract);
}

Expand Down Expand Up @@ -72,13 +72,9 @@ async function deployAndMintMockNFTAuthTokens() {
tx1 = await lensTokenContract.mint(to, BigInt(lensTokenId));
tx2 = await ensTokenContract.mint(to, BigInt(ensTokenId));

await expect(tx1)
.to.emit(lensTokenContract, "Transfer")
.withArgs(ZeroAddress, getAddress(to), lensTokenId);
await expect(tx1).to.emit(lensTokenContract, "Transfer").withArgs(ZeroAddress, getAddress(to), lensTokenId);

await expect(tx2)
.to.emit(ensTokenContract, "Transfer")
.withArgs(ZeroAddress, getAddress(to), ensTokenId);
await expect(tx2).to.emit(ensTokenContract, "Transfer").withArgs(ZeroAddress, getAddress(to), ensTokenId);

let lensOwner = await lensTokenContract.ownerOf(BigInt(lensTokenId));
let ensOwner = await ensTokenContract.ownerOf(BigInt(ensTokenId));
Expand Down
2 changes: 1 addition & 1 deletion test/protocol/AgentHandlerTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const hre = require("hardhat");
const ethers = hre.ethers;
const { ZeroAddress } = hre.ethers;
const { expect } = require("chai");

const Agent = require("../../scripts/domain/Agent");
Expand Down
33 changes: 25 additions & 8 deletions test/protocol/BundleHandlerTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ethers } = require("hardhat");
const { MaxUnit256, getContractAt } = ethers;
const { ZeroAddress, getContractFactory, MaxUint256 } = ethers;
const { expect, assert } = require("chai");

const Bundle = require("../../scripts/domain/Bundle");
Expand Down Expand Up @@ -131,7 +131,12 @@ describe("IBosonBundleHandler", function () {
agentId = "0"; // agent id is optional while creating an offer

// Create a valid seller, then set fields in tests directly
seller = mockSeller(await assistant.getAddress(), await admin.getAddress(), await clerk.getAddress(), await treasury.getAddress());
seller = mockSeller(
await assistant.getAddress(),
await admin.getAddress(),
clerk.address,
await treasury.getAddress()
);
expect(seller.isValid()).is.true;

// VoucherInitValues
Expand All @@ -148,7 +153,7 @@ describe("IBosonBundleHandler", function () {
disputeResolver = mockDisputeResolver(
await assistantDR.getAddress(),
await adminDR.getAddress(),
await clerkDR.getAddress(),
clerkDR.address,
await treasuryDR.getAddress(),
true
);
Expand Down Expand Up @@ -295,7 +300,7 @@ describe("IBosonBundleHandler", function () {
it("If sum of offers' quantities is more than maxUint256, total quantity is maxUint256", async function () {
// create two offers with close to unlimited supply
const newOffer = offer.clone();
newOffer.quantityAvailable = MaxUint256/10*9;
newOffer.quantityAvailable = ((MaxUint256 / 10n) * 9n).toString();
const newOffer2 = newOffer.clone();
const newOfferId = "6";
const newOfferId2 = "7";
Expand All @@ -310,7 +315,7 @@ describe("IBosonBundleHandler", function () {

// create a twin with almost unlimited supply
twin = mockTwin(await bosonToken.getAddress());
twin.supplyAvailable = MaxUint256-1;
twin.supplyAvailable = MaxUint256 - 1n;
expect(twin.isValid()).is.true;

// Approving the twinHandler contract to transfer seller's tokens
Expand Down Expand Up @@ -387,7 +392,12 @@ describe("IBosonBundleHandler", function () {
it("Caller is not the seller of all offers", async function () {
// create another seller and an offer
let expectedNewOfferId = "6";
seller = mockSeller(await rando.getAddress(), await rando.getAddress(), ZeroAddress, await rando.getAddress());
seller = mockSeller(
await rando.getAddress(),
await rando.getAddress(),
ZeroAddress,
await rando.getAddress()
);

await accountHandler.connect(rando).createSeller(seller, emptyAuthToken, voucherInitValues);
const tx = await offerHandler
Expand Down Expand Up @@ -427,7 +437,12 @@ describe("IBosonBundleHandler", function () {
it("Caller is not the seller of all twins", async function () {
// create another seller and a twin
let expectedNewTwinId = "6";
seller = mockSeller(await rando.getAddress(), await rando.getAddress(), ZeroAddress, await rando.getAddress());
seller = mockSeller(
await rando.getAddress(),
await rando.getAddress(),
ZeroAddress,
await rando.getAddress()
);

await accountHandler.connect(rando).createSeller(seller, emptyAuthToken, voucherInitValues);
await bosonToken.connect(rando).approve(await twinHandler.getAddress(), 1); // approving the twin handler
Expand Down Expand Up @@ -524,7 +539,9 @@ describe("IBosonBundleHandler", function () {

// Commit to an offer
let offerIdToCommit = bundle.offerIds[0];
await exchangeHandler.connect(buyer).commitToOffer(await buyer.getAddress(), offerIdToCommit, { value: price });
await exchangeHandler
.connect(buyer)
.commitToOffer(await buyer.getAddress(), offerIdToCommit, { value: price });

// Attempt to Create a bundle, expecting revert
await expect(bundleHandler.connect(assistant).createBundle(bundle)).to.revertedWith(
Expand Down
11 changes: 6 additions & 5 deletions test/protocol/BuyerHandlerTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { ZeroAddress, getContractAt } = require("hardhat");
const { ethers } = require("hardhat");
const { getContractAt, ZeroAddress } = ethers;
const { expect } = require("chai");

const Buyer = require("../../scripts/domain/Buyer");
Expand Down Expand Up @@ -315,7 +316,7 @@ describe("BuyerHandler", function () {
await expect(accountHandler.connect(other1).updateBuyer(buyer)).to.revertedWith(RevertReasons.NOT_BUYER_WALLET);
});

context("💔 Revert Reasons", async function () {
context.only("💔 Revert Reasons", async function () {
beforeEach(async function () {
// Initial ids for all the things
id = await accountHandler.connect(rando).getNextAccountId();
Expand All @@ -326,7 +327,7 @@ describe("BuyerHandler", function () {
seller = mockSeller(
await assistant.getAddress(),
await admin.getAddress(),
await clerk.getAddress(),
clerk.address,
await treasury.getAddress()
);
seller.id = id.toString();
Expand All @@ -350,11 +351,11 @@ describe("BuyerHandler", function () {
disputeResolver = mockDisputeResolver(
await assistant.getAddress(),
await admin.getAddress(),
await clerk.getAddress(),
clerk.address,
await treasury.getAddress(),
true
);
disputeResolver.id = (id + 1).toString();
disputeResolver.id = id + 1n;
expect(disputeResolver.isValid()).is.true;

//Create DisputeResolverFee array
Expand Down
66 changes: 41 additions & 25 deletions test/protocol/ConfigHandlerTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { ethers } = require("hardhat");
const { getSigners, getContractAt, ZeroAddress, parseUnits } = ethers;
const { expect } = require("chai");

const Role = require("../../scripts/domain/Role");
Expand Down Expand Up @@ -554,9 +555,9 @@ describe("IBosonConfigHandler", function () {

it("treasury address is the zero address", async function () {
// Attempt to set new treasury address, expecting revert
await expect(
configHandler.connect(deployer).setTreasuryAddress(ZeroAddress)
).to.revertedWith(RevertReasons.INVALID_ADDRESS);
await expect(configHandler.connect(deployer).setTreasuryAddress(ZeroAddress)).to.revertedWith(
RevertReasons.INVALID_ADDRESS
);
});
});
});
Expand Down Expand Up @@ -586,16 +587,16 @@ describe("IBosonConfigHandler", function () {
context("💔 Revert Reasons", async function () {
it("caller is not the admin", async function () {
// Attempt to set new beacon address, expecting revert
await expect(configHandler.connect(rando).setVoucherBeaconAddress(await beacon.getAddress())).to.revertedWith(
RevertReasons.ACCESS_DENIED
);
await expect(
configHandler.connect(rando).setVoucherBeaconAddress(await beacon.getAddress())
).to.revertedWith(RevertReasons.ACCESS_DENIED);
});

it("voucher beacon address is the zero address", async function () {
// Attempt to set new beacon address, expecting revert
await expect(
configHandler.connect(deployer).setVoucherBeaconAddress(ZeroAddress)
).to.revertedWith(RevertReasons.INVALID_ADDRESS);
await expect(configHandler.connect(deployer).setVoucherBeaconAddress(ZeroAddress)).to.revertedWith(
RevertReasons.INVALID_ADDRESS
);
});
});
});
Expand Down Expand Up @@ -632,9 +633,9 @@ describe("IBosonConfigHandler", function () {

it("beacon proxy address is the zero address", async function () {
// Attempt to set new proxy address, expecting revert
await expect(
configHandler.connect(deployer).setBeaconProxyAddress(ZeroAddress)
).to.revertedWith(RevertReasons.INVALID_ADDRESS);
await expect(configHandler.connect(deployer).setBeaconProxyAddress(ZeroAddress)).to.revertedWith(
RevertReasons.INVALID_ADDRESS
);
});
});
});
Expand Down Expand Up @@ -794,7 +795,7 @@ describe("IBosonConfigHandler", function () {
let maxEscalationResponsePeriod;
beforeEach(async function () {
// set new value
maxEscalationResponsePeriod = BigInt(oneMonth)+oneWeek;
maxEscalationResponsePeriod = oneMonth + oneWeek;
});

it("should emit a MaxEscalationResponsePeriodChanged event", async function () {
Expand Down Expand Up @@ -1013,15 +1014,19 @@ describe("IBosonConfigHandler", function () {
it("should emit an AuthTokenContractChanged event", async function () {
// Set new auth token contract, testing for the event
await expect(
configHandler.connect(deployer).setAuthTokenContract(AuthTokenType.Lens, await authTokenContract.getAddress())
configHandler
.connect(deployer)
.setAuthTokenContract(AuthTokenType.Lens, await authTokenContract.getAddress())
)
.to.emit(configHandler, "AuthTokenContractChanged")
.withArgs(AuthTokenType.Lens, await authTokenContract.getAddress(), await deployer.getAddress());
});

it("should update state", async function () {
// Set new auth token contract,
await configHandler.connect(deployer).setAuthTokenContract(AuthTokenType.ENS, await authTokenContract.getAddress());
await configHandler
.connect(deployer)
.setAuthTokenContract(AuthTokenType.ENS, await authTokenContract.getAddress());

// Verify that new value is stored
expect(await configHandler.connect(rando).getAuthTokenContract(AuthTokenType.ENS)).to.equal(
Expand All @@ -1040,14 +1045,18 @@ describe("IBosonConfigHandler", function () {
it("_authTokenType is None", async function () {
// Attempt to set new auth token contract, expecting revert
await expect(
configHandler.connect(deployer).setAuthTokenContract(AuthTokenType.None, await authTokenContract.getAddress())
configHandler
.connect(deployer)
.setAuthTokenContract(AuthTokenType.None, await authTokenContract.getAddress())
).to.revertedWith(RevertReasons.INVALID_AUTH_TOKEN_TYPE);
});

it("_authTokenType is Custom", async function () {
// Attempt to set new auth token contract, expecting revert
await expect(
configHandler.connect(deployer).setAuthTokenContract(AuthTokenType.Custom, await authTokenContract.getAddress())
configHandler
.connect(deployer)
.setAuthTokenContract(AuthTokenType.Custom, await authTokenContract.getAddress())
).to.revertedWith(RevertReasons.INVALID_AUTH_TOKEN_TYPE);
});

Expand Down Expand Up @@ -1103,7 +1112,7 @@ describe("IBosonConfigHandler", function () {
let maxResolutionPeriod;
beforeEach(async function () {
// set new value
maxResolutionPeriod = BigInt(oneMonth)+oneWeek;
maxResolutionPeriod = oneMonth + oneWeek;
});

it("should emit a MaxResolutionPeriodChanged event", async function () {
Expand Down Expand Up @@ -1142,7 +1151,7 @@ describe("IBosonConfigHandler", function () {
let minDisputePeriod;
beforeEach(async function () {
// set new value
minDisputePeriod = BigInt(oneMonth)-oneWeek;
minDisputePeriod = oneMonth - oneWeek;
});

it("should emit a MinDisputePeriodChanged event", async function () {
Expand Down Expand Up @@ -1225,7 +1234,9 @@ describe("IBosonConfigHandler", function () {

it("should emit an AccessControllerAddressChanged event", async function () {
// Set new access controller address
await expect(configHandler.connect(deployer).setAccessControllerAddress(await newAccessController.getAddress()))
await expect(
configHandler.connect(deployer).setAccessControllerAddress(await newAccessController.getAddress())
)
.to.emit(configHandler, "AccessControllerAddressChanged")
.withArgs(await newAccessController.getAddress(), await deployer.getAddress());
});
Expand All @@ -1235,7 +1246,9 @@ describe("IBosonConfigHandler", function () {
await configHandler.connect(deployer).setAccessControllerAddress(await newAccessController.getAddress());

// Verify that new value is stored
expect(await configHandler.connect(rando).getAccessControllerAddress()).to.equal(await newAccessController.getAddress());
expect(await configHandler.connect(rando).getAccessControllerAddress()).to.equal(
await newAccessController.getAddress()
);
});

context("💔 Revert Reasons", async function () {
Expand All @@ -1248,9 +1261,9 @@ describe("IBosonConfigHandler", function () {

it("_accessControllerAddress is the zero address", async function () {
// Attempt to set new value, expecting revert
await expect(
configHandler.connect(deployer).setAccessControllerAddress(ZeroAddress)
).to.revertedWith(RevertReasons.INVALID_ADDRESS);
await expect(configHandler.connect(deployer).setAccessControllerAddress(ZeroAddress)).to.revertedWith(
RevertReasons.INVALID_ADDRESS
);
});
});
});
Expand All @@ -1266,7 +1279,10 @@ describe("IBosonConfigHandler", function () {
await treasury.getAddress(),
"Invalid treasury address"
);
expect(await configHandler.connect(rando).getTokenAddress()).to.equal(await token.getAddress(), "Invalid token address");
expect(await configHandler.connect(rando).getTokenAddress()).to.equal(
await token.getAddress(),
"Invalid token address"
);
expect(await configHandler.connect(rando).getVoucherBeaconAddress()).to.equal(
await beacon.getAddress(),
"Invalid voucher address"
Expand Down
Loading

0 comments on commit 9288716

Please sign in to comment.