Skip to content

Commit

Permalink
Improve migration
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jul 13, 2023
1 parent 1d7f7f1 commit 45f8a4f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions scripts/migrations/migrate_2.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/upgrade/01_generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function getGenericContext(
let protocolContractStateAfterUpgradeAndActions;

before(async function () {
console.log("POPULATING AFTER THE UPGRADE");
postUpgradeEntities = await populateProtocolContract(
deployer,
protocolDiamondAddress,
Expand Down
3 changes: 2 additions & 1 deletion test/upgrade/2.2.1-2.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions test/util/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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+$/, ""));
});
}

Expand Down Expand Up @@ -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, []]);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);

Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions test/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 45f8a4f

Please sign in to comment.