From 45f8a4f8dba9dfb7bf8ce2fb786bce9f106d89b8 Mon Sep 17 00:00:00 2001 From: Ana Julia Date: Thu, 13 Jul 2023 15:00:53 -0300 Subject: [PATCH] Improve migration --- scripts/migrations/migrate_2.3.0.js | 8 ++++---- test/upgrade/01_generic.js | 1 - test/upgrade/2.2.1-2.3.0.js | 3 ++- test/util/upgrade.js | 32 ++++++++++++++--------------- test/util/utils.js | 1 + 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/scripts/migrations/migrate_2.3.0.js b/scripts/migrations/migrate_2.3.0.js index 0f1747ad1..1a39ccea4 100644 --- a/scripts/migrations/migrate_2.3.0.js +++ b/scripts/migrations/migrate_2.3.0.js @@ -35,15 +35,15 @@ async function migrate(env) { console.log("Removing any local changes before upgrading"); shell.exec(`git reset @{u}`); const statusOutput = shell.exec("git status -s -uno scripts"); + console.log(statusOutput); + shell.exec(`cat package.json`); if (statusOutput.stdout) { throw new Error("Local changes found. Please stash them before upgrading"); } - if (env != "upgrade-test") { - console.log("Installing dependencies"); - shell.exec(`npm install`); - } + console.log("Installing dependencies"); + shell.exec(`npm install`); const { chainId } = await ethers.provider.getNetwork(); const contractsFile = readContracts(chainId, network, env); diff --git a/test/upgrade/01_generic.js b/test/upgrade/01_generic.js index a9ca45449..2f219bf18 100644 --- a/test/upgrade/01_generic.js +++ b/test/upgrade/01_generic.js @@ -67,7 +67,6 @@ function getGenericContext( let protocolContractStateAfterUpgradeAndActions; before(async function () { - console.log("POPULATING AFTER THE UPGRADE"); postUpgradeEntities = await populateProtocolContract( deployer, protocolDiamondAddress, diff --git a/test/upgrade/2.2.1-2.3.0.js b/test/upgrade/2.2.1-2.3.0.js index 5ed75b58c..2ec7c652f 100644 --- a/test/upgrade/2.2.1-2.3.0.js +++ b/test/upgrade/2.2.1-2.3.0.js @@ -143,7 +143,8 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation "PauseHandlerFacet", "GroupHandlerFacet", "OfferHandlerFacet", - "OrchestrationHandlerFacet", + "OrchestrationHandlerFacet1", + "OrchestrationHandlerFacet2", ], undefined, ["setMinResolutionPeriod", "unpause", "createGroup", "createSellerAnd", "createOffer", "createPremintedOffer"] //ToDo: revise diff --git a/test/util/upgrade.js b/test/util/upgrade.js index 67cee6cc9..986031375 100644 --- a/test/util/upgrade.js +++ b/test/util/upgrade.js @@ -4,8 +4,9 @@ const { getStorageAt } = require("@nomicfoundation/hardhat-network-helpers"); const hre = require("hardhat"); const decache = require("decache"); const { + id: ethersId, keccak256, - formatBytes32String, + encodeBytes32String, ZeroAddress, getContractAt, Wallet, @@ -77,7 +78,7 @@ function getVersionsBeforeTarget(versions, targetVersion) { return versionsBefore.map((version) => { // Remove "v" prefix and "-rc.${number}" suffix - return formatBytes32String(version.replace(/^v/, "").replace(/-rc\.\d+$/, "")); + return encodeBytes32String(version.replace(/^v/, "").replace(/-rc\.\d+$/, "")); }); } @@ -777,7 +778,7 @@ async function getAccountContractState(accountHandler, { DRs, sellers, buyers, a } agentsState.push(await getAgent(accountHandlerRando, id)); buyersState.push(await getBuyer(accountHandlerRando, id)); - if (versionsBelowV2_3.includes(isBefore ? versionTags.oldVersion : versionTags.newVersion)) { + if (!versionsBelowV2_3.includes(isBefore ? versionTags.oldVersion : versionTags.newVersion)) { sellersCollections.push(await accountHandlerRando.getSellersCollections(id)); } else { sellersCollections.push([ZeroAddress, []]); @@ -915,7 +916,6 @@ async function getBundleContractState(bundleHandler, bundles) { async function getConfigContractState(configHandler, isBefore = false) { const configHandlerRando = configHandler.connect(rando); - console.log("ana", versionsBelowV2_3.includes(isBefore ? versionTags.oldVersion : versionTags.newVersion)); const [ tokenAddress, treasuryAddress, @@ -1132,7 +1132,7 @@ async function getMetaTxPrivateContractState(protocolDiamondAddress) { // get also hashFunction hashInfoState.push({ typeHash: await getStorageAt(protocolDiamondAddress, storageSlot), - functionPointer: await getStorageAt(protocolDiamondAddress, BigInt(storageSlot) + 1), + functionPointer: await getStorageAt(protocolDiamondAddress, BigInt(storageSlot) + 1n), }); } const isAllowlistedState = {}; @@ -1273,7 +1273,7 @@ async function getProtocolLookupsPrivateContractState( const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot); const arrayStart = keccak256(arraySlot); for (let i = 0n; i < arrayLength; i++) { - exchangeIdsByOffer.push(await getStorageAt(protocolDiamondAddress, arrayStart + i)); + exchangeIdsByOffer.push(await getStorageAt(protocolDiamondAddress, BigInt(arrayStart) + i)); } exchangeIdsByOfferState.push(exchangeIdsByOffer); @@ -1294,7 +1294,7 @@ async function getProtocolLookupsPrivateContractState( const accounts = [...sellers, ...DRs, ...agents, ...buyers]; for (const account of accounts) { - const accountAddress = account.wallet; + const accountAddress = account.wallet.address; // buyerIdByWallet buyerIdByWallet.push( @@ -1399,9 +1399,9 @@ async function getProtocolLookupsPrivateContractState( await mockTwin.getAddress(), paddingType.START ); - const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot); - const arrayStart = keccak256(arraySlot); - for (let i = 0; i < arrayLength * 2n; i = i + 2n) { + const arrayLength = BigInt(await getStorageAt(protocolDiamondAddress, arraySlot)); + const arrayStart = BigInt(keccak256(arraySlot)); + for (let i = 0n; i < arrayLength * 2n; i = i + 2n) { // each BosonTypes.TokenRange has length 2 ranges[await mockTwin.getAddress()].push({ start: await getStorageAt(protocolDiamondAddress, arrayStart + i), @@ -1427,8 +1427,8 @@ async function getProtocolLookupsPrivateContractState( paddingType.START ); const arrayLength = await getStorageAt(protocolDiamondAddress, arraySlot); - const arrayStart = keccak256(arraySlot); - for (let i = 0; i < arrayLength; i++) { + const arrayStart = BigInt(keccak256(arraySlot)); + for (let i = 0n; i < arrayLength; i++) { twinIds[await mockTwin.getAddress()].push(await getStorageAt(protocolDiamondAddress, arrayStart + i)); } } @@ -1483,13 +1483,13 @@ async function getProtocolLookupsPrivateContractState( // pendingAddressUpdatesBySeller let structStorageSlot = BigInt(getMappingStoragePosition(protocolLookupsSlotNumber + 29n, id, paddingType.START)); let structFields = []; - for (let i = 0; i < 6n; i++) { + for (let i = 0n; i < 6n; i++) { // BosonTypes.Seller has 7 fields, but `address payable treasury` and `bool active` are packed into one slot structFields.push(await getStorageAt(protocolDiamondAddress, structStorageSlot + i)); } // ToDo: make sure this gets the corrects slots - const metadataUriLength = await getStorageAt(protocolDiamondAddress, structStorageSlot + 6n); - const metadataUriSlot = BigInt(keccak256(structStorageSlot + 6n)); + const metadataUriLength = BigInt(await getStorageAt(protocolDiamondAddress, structStorageSlot + 6n)); + const metadataUriSlot = BigInt(keccak256(ethersId(structStorageSlot + 6n))); const occupiedSlots = metadataUriLength / 32n + 1n; const metadataUri = []; for (let i = 0n; i < occupiedSlots; i++) { @@ -1515,7 +1515,7 @@ async function getProtocolLookupsPrivateContractState( // BosonTypes.DisputeResolver has 8 fields structFields.push(await getStorageAt(protocolDiamondAddress, structStorageSlot + i)); } - 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 + structFields[6] = await getStorageAt(protocolDiamondAddress, keccak256(ethersId(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); } diff --git a/test/util/utils.js b/test/util/utils.js index 82bb14859..e4956cc35 100644 --- a/test/util/utils.js +++ b/test/util/utils.js @@ -295,6 +295,7 @@ const paddingType = { function getMappingStoragePosition(slot, key, padding = paddingType.NONE) { let keyBuffer; + let keyHex = String(key).startsWith("0x") ? String(key) : toHexString(key); switch (padding) {