Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 30, 2023
1 parent ba46cc9 commit 781ccaa
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions scripts/util/diamond-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ const hre = require("hardhat");
const { keccak256, toUtf8Bytes, getContractAt, ZeroAddress, Interface, getContractFactory, encodeBytes32String } =
hre.ethers;
const environments = "../../environments.js";

const confirmations = hre.network.name === "hardhat" ? 1 : environments.confirmations;
const FacetCutAction = require("../domain/FacetCutAction");
const { interfacesWithMultipleArtifacts } = require("./constants");
const { getFees } = require("./utils");

/**
* Utilities for testing and interacting with Diamond
*
* @author Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)
*/
Expand Down Expand Up @@ -233,6 +238,10 @@ async function cutDiamond(
return transactionResponse;
}

function toHexString(bigNumber, { startPad }) {
return "0x" + (startPad ? bigNumber.toString(16).padStart(startPad, "0") : bigNumber.toString(16));
}

exports.getSelectors = getSelectors;
exports.FacetCutAction = FacetCutAction;
exports.remove = remove;
Expand Down
8 changes: 4 additions & 4 deletions scripts/util/estimate-limits.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ setupEnvironment["maxExchangesPerBatch"] = async function (exchangesCount = 10)
// Set time forward to run out the dispute period
const blockNumber = await provider.getBlockNumber();
const block = await provider.getBlock(blockNumber);
const newTime = BigInt(block.timestamp).add(offerDurations.disputePeriod).add(1).toNumber();
const newTime = Number(BigInt(block.timestamp) + BigInt(offerDurations.disputePeriod) + 1n);
await setNextBlockTimestamp(newTime);

const exchangeIds = [...Array(exchangesCount + 1).keys()].slice(1);
Expand Down Expand Up @@ -645,7 +645,7 @@ setupEnvironment["maxDisputesPerBatch"] = async function (exchangesCount = 10) {
// Set time forward to run out the dispute period
const blockNumber = await provider.getBlockNumber();
const block = await provider.getBlock(blockNumber);
const newTime = BigInt(block.timestamp).add(offerDurations.resolutionPeriod).add(1).toNumber();
const newTime = Number(BigInt(block.timestamp) + BigInt(offerDurations.resolutionPeriod) + 1n);
await setNextBlockTimestamp(newTime);

const exchangeIds = [...Array(exchangesCount + 1).keys()].slice(1);
Expand Down Expand Up @@ -874,8 +874,8 @@ async function estimateLimit(limit, inputs, safeGasLimitPercent) {
const gasEstimate = await handlers[handler]
.connect(methodInputs.account)
.estimateGas[method](...adjustedArgs, { gasLimit });
console.log("Length:", arrayLength, "Gas:", gasEstimate.toNumber());
gasEstimates.push([gasEstimate.toNumber(), arrayLength]);
console.log("Length:", arrayLength, "Gas:", Number(gasEstimate));
gasEstimates.push([Number(gasEstimate), arrayLength]);
} catch (e) {
// console.log(e)
console.log("Block gas limit already hit");
Expand Down
5 changes: 0 additions & 5 deletions test/domain/OfferDatesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ describe("OfferDates", function () {
offerDates.voucherRedeemableUntil = "126";
expect(offerDates.voucherRedeemableUntilIsValid()).is.true;
expect(offerDates.isValid()).is.true;

// Invalid field value
offerDates.voucherRedeemableUntil = new Date();
expect(offerDates.voucherRedeemableUntilIsValid()).is.false;
expect(offerDates.isValid()).is.false;
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/integration/seaport/seaport-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ describe("[@skip-on-coverage] Seaport integration", function () {

({ isValidated, totalFilled } = await seaport.getOrderStatus(orderHash));
assert(isValidated, "Order is not validated");
assert.equal(totalFilled.toNumber(), 0);
assert.equal(totalFilled, 0n);

const tx = await seaport.connect(buyer).fulfillOrder(order, ZeroHash, { value });
const receipt = await tx.wait();

const event = getEvent(receipt, seaport, "OrderFulfilled");

({ totalFilled } = await seaport.getOrderStatus(orderHash));
assert.equal(totalFilled.toNumber(), 1);
assert.equal(totalFilled, 1n);

assert.equal(orderHash, event[0]);
});
Expand Down
42 changes: 21 additions & 21 deletions test/util/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async function populateProtocolContract(
}

// create offers - first seller has 5 offers, second 4, third 3 etc
let offerId = (await offerHandler.getNextOfferId()).toNumber();
let offerId = Number(await offerHandler.getNextOfferId());
for (let i = 0; i < sellers.length; i++) {
for (let j = i; j >= 0; j--) {
// Mock offer, offerDates and offerDurations
Expand Down Expand Up @@ -521,7 +521,7 @@ async function populateProtocolContract(
}

// group some offers
let groupId = (await groupHandler.getNextGroupId()).toNumber();
let groupId = Number(await groupHandler.getNextGroupId());
for (let i = 0; i < sellers.length; i = i + 2) {
const seller = sellers[i];
const group = new Group(groupId, seller.seller.id, seller.offerIds); // group all seller's offers
Expand All @@ -537,8 +537,8 @@ async function populateProtocolContract(
}

// create some twins and bundles
let twinId = (await twinHandler.getNextTwinId()).toNumber();
let bundleId = (await bundleHandler.getNextBundleId()).toNumber();
let twinId = Number(await twinHandler.getNextTwinId());
let bundleId = Number(await bundleHandler.getNextBundleId());
for (let i = 1; i < sellers.length; i = i + 2) {
const seller = sellers[i];
const sellerId = seller.id;
Expand Down Expand Up @@ -618,7 +618,7 @@ async function populateProtocolContract(

// commit to some offers: first buyer commit to 1 offer, second to 2, third to 3 etc
await setNextBlockTimestamp(Number(offers[offers.length - 1].offerDates.validFrom)); // When latest offer is valid, also other offers are valid
let exchangeId = (await exchangeHandler.getNextExchangeId()).toNumber();
let exchangeId = Number(await exchangeHandler.getNextExchangeId());
for (let i = 0; i < buyers.length; i++) {
for (let j = i; j < buyers.length; j++) {
const offer = offers[i + j].offer; // some offers will be picked multiple times, some never.
Expand Down Expand Up @@ -1233,10 +1233,10 @@ async function getProtocolLookupsPrivateContractState(
const id = Number(offer.offer.id);
// exchangeIdsByOffer
let exchangeIdsByOffer = [];
const arraySlot = BigInt.from(getMappingStoragePosition(protocolLookupsSlotNumber + 0n, id, paddingType.START));
const arrayLength = BigInt(await getStorageAt(protocolDiamondAddress, arraySlot)).toNumber();
const arrayStart = BigInt(keccak256(arraySlot));
for (let i = 0; i < arrayLength; i++) {
const arraySlot = BigInt(getMappingStoragePosition(protocolLookupsSlotNumber + 0n, id, paddingType.START));
const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot);
const arrayStart = keccak256(arraySlot);
for (let i = 0n; i < arrayLength; i++) {
exchangeIdsByOffer.push(await getStorageAt(protocolDiamondAddress, arrayStart + i));
}
exchangeIdsByOfferState.push(exchangeIdsByOffer);
Expand Down Expand Up @@ -1363,13 +1363,13 @@ async function getProtocolLookupsPrivateContractState(
await mockTwin.getAddress(),
paddingType.START
);
const arrayLength = BigInt(await getStorageAt(protocolDiamondAddress, arraySlot)).toNumber();
const arrayStart = BigInt(keccak256(arraySlot));
for (let i = 0; i < arrayLength * 2; i = i + 2) {
const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot);
const arrayStart = keccak256(arraySlot);
for (let i = 0; i < arrayLength * 2n; i = i + 2n) {
// each BosonTypes.TokenRange has length 2
ranges[await mockTwin.getAddress()].push({
start: await getStorageAt(protocolDiamondAddress, arrayStart + i),
end: await getStorageAt(protocolDiamondAddress, arrayStart + i + 1),
end: await getStorageAt(protocolDiamondAddress, arrayStart + i + 1n),
});
}
}
Expand All @@ -1390,8 +1390,8 @@ async function getProtocolLookupsPrivateContractState(
await mockTwin.getAddress(),
paddingType.START
);
const arrayLength = BigInt(await getStorageAt(protocolDiamondAddress, arraySlot)).toNumber();
const arrayStart = BigInt(keccak256(arraySlot));
const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot);
const arrayStart = keccak256(arraySlot);
for (let i = 0; i < arrayLength; i++) {
twinIds[await mockTwin.getAddress()].push(await getStorageAt(protocolDiamondAddress, arrayStart + i));
}
Expand Down Expand Up @@ -1445,7 +1445,7 @@ async function getProtocolLookupsPrivateContractState(
// pendingAddressUpdatesBySeller
let structStorageSlot = BigInt(getMappingStoragePosition(protocolLookupsSlotNumber + 29n, id, paddingType.START));
let structFields = [];
for (let i = 0; i < 5; i++) {
for (let i = 0n; i < 5n; i++) {
// BosonTypes.Seller has 6 fields, but last bool is packed in one slot with previous field
structFields.push(await getStorageAt(protocolDiamondAddress, structStorageSlot + i));
}
Expand All @@ -1454,7 +1454,7 @@ async function getProtocolLookupsPrivateContractState(
// pendingAuthTokenUpdatesBySeller
structStorageSlot = BigInt(getMappingStoragePosition(protocolLookupsSlotNumber + 30n, id, paddingType.START));
structFields = [];
for (let i = 0; i < 2; i++) {
for (let i = 0n; i < 2n; i++) {
// BosonTypes.AuthToken has 2 fields
structFields.push(await getStorageAt(protocolDiamondAddress, structStorageSlot + i));
}
Expand All @@ -1463,11 +1463,11 @@ async function getProtocolLookupsPrivateContractState(
// pendingAddressUpdatesByDisputeResolver
structStorageSlot = BigInt(getMappingStoragePosition(protocolLookupsSlotNumber + 31n, id, paddingType.START));
structFields = [];
for (let i = 0; i < 8; i++) {
for (let i = 0n; i < 8n; i++) {
// BosonTypes.DisputeResolver has 8 fields
structFields.push(await getStorageAt(protocolDiamondAddress, structStorageSlot + i));
}
structFields[6] = await getStorageAt(protocolDiamondAddress, keccak256(structStorageSlot + 6)); // represents field string metadataUri. Technically this value represents the length of the string, but since it should be 0, we don't do further decoding
structFields[6] = await getStorageAt(protocolDiamondAddress, keccak256(structStorageSlot + 6n)); // represents field string metadataUri. Technically this value represents the length of the string, but since it should be 0, we don't do further decoding
pendingAddressUpdatesByDisputeResolver.push(structFields);
}

Expand Down Expand Up @@ -1671,7 +1671,7 @@ async function populateVoucherContract(
}

// create offers - first seller has 5 offers, second 4, third 3 etc
let offerId = (await offerHandler.getNextOfferId()).toNumber();
let offerId = Number(await offerHandler.getNextOfferId());
for (let i = 0; i < sellers.length; i++) {
for (let j = i; j >= 0; j--) {
// Mock offer, offerDates and offerDurations
Expand Down Expand Up @@ -1725,7 +1725,7 @@ async function populateVoucherContract(

// commit to some offers: first buyer commit to 1 offer, second to 2, third to 3 etc
await setNextBlockTimestamp(Number(offers[offers.length - 1].offerDates.validFrom)); // When latest offer is valid, also other offers are valid
let exchangeId = (await exchangeHandler.getNextExchangeId()).toNumber();
let exchangeId = Number(await exchangeHandler.getNextExchangeId());
for (let i = 0; i < buyers.length; i++) {
for (let j = i; j < buyers.length; j++) {
const offer = offers[i + j].offer; // some offers will be picked multiple times, some never.
Expand Down

0 comments on commit 781ccaa

Please sign in to comment.