diff --git a/package-lock.json b/package-lock.json index ed6f01ac2..5f4836a54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9440,7 +9440,6 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.5.tgz", "integrity": "sha512-HTm14iMQKK2FjFLRTM5lAVcyaUzOnqbPtesFIvREgXpJHdQm8bWS+GkQgIkfaBYRHuCnea7w8UVNfwiAQhlr9A==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" @@ -9798,7 +9797,6 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz", "integrity": "sha512-vLt1O5Pp+flcArHGIyKEQq883nBt8nN8tVBcoL0qUXj2XT1n7p70yGIq2VK98I5FdZ1YHc0wk/koOnHjnXWk1Q==", "dev": true, - "hasInstallScript": true, "optional": true, "dependencies": { "node-gyp-build": "^4.3.0" diff --git a/scripts/util/diamond-utils.js b/scripts/util/diamond-utils.js index efcc7da04..aaf50b5d5 100644 --- a/scripts/util/diamond-utils.js +++ b/scripts/util/diamond-utils.js @@ -2,6 +2,7 @@ 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"); @@ -9,6 +10,10 @@ const { getFees } = require("./utils"); /** * Utilities for testing and interacting with Diamond + + + + * * @author Nick Mudge (https://twitter.com/mudgen) */ @@ -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; diff --git a/scripts/util/estimate-limits.js b/scripts/util/estimate-limits.js index 4a2bbe0af..5ec712ad7 100644 --- a/scripts/util/estimate-limits.js +++ b/scripts/util/estimate-limits.js @@ -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); @@ -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); @@ -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"); diff --git a/test/domain/OfferDatesTest.js b/test/domain/OfferDatesTest.js index 83ea11ef4..5cd5baead 100644 --- a/test/domain/OfferDatesTest.js +++ b/test/domain/OfferDatesTest.js @@ -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; }); }); diff --git a/test/integration/seaport/seaport-integration.js b/test/integration/seaport/seaport-integration.js index 2fc2e0f20..86d4181c6 100644 --- a/test/integration/seaport/seaport-integration.js +++ b/test/integration/seaport/seaport-integration.js @@ -125,7 +125,7 @@ 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(); @@ -133,7 +133,7 @@ describe("[@skip-on-coverage] Seaport integration", function () { 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]); }); diff --git a/test/util/upgrade.js b/test/util/upgrade.js index 57be5dfab..a33dfa45e 100644 --- a/test/util/upgrade.js +++ b/test/util/upgrade.js @@ -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 @@ -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 @@ -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; @@ -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. @@ -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); @@ -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), }); } } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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); } @@ -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 @@ -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.