Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed Aug 30, 2023
1 parent 98e1c49 commit a1f32b7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
6 changes: 5 additions & 1 deletion scripts/migrations/migrate_2.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ async function migrate(env) {

console.log("Compiling contracts");
await hre.run("clean");
await hre.run("compile");
// If some contract was removed, compilation succeeds, but afterwards it falsely reports missing artifacts
// This is a workaround to ignore the error
try {
await hre.run("compile");
} catch {}

console.log("Executing upgrade facets script");
await hre.run("upgrade-facets", {
Expand Down
1 change: 1 addition & 0 deletions test/upgrade/00_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const tagsByVersion = {
"2.3.0": {
oldVersion: "v2.2.1",
newVersion: "v2.3.0",
updateDomain: ["Condition"],
},
};

Expand Down
5 changes: 2 additions & 3 deletions test/upgrade/2.2.1-2.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,8 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
await accountHandler.getAddress(),
beaconProxyAddress,
seller.admin,
""
voucherInitValues.collectionSalt,
voucherInitValues.collectionSalt
);

const tx = await accountHandler.connect(assistant).createSeller(seller, emptyAuthToken, voucherInitValues);
Expand Down Expand Up @@ -1504,7 +1505,6 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
await orchestrationHandler.getAddress(),
beaconProxyAddress,
assistant.address,
""
);

let bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress);
Expand Down Expand Up @@ -1580,7 +1580,6 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
await accountHandler.getAddress(),
beaconProxyAddress,
seller.admin,
""
); // default
bosonVoucher = await getContractAt("BosonVoucher", expectedDefaultAddress);
});
Expand Down
33 changes: 22 additions & 11 deletions test/util/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const hre = require("hardhat");
const { ZeroAddress, provider, parseUnits } = hre.ethers;

const decache = require("decache");
const Condition = require("../../scripts/domain/Condition");
let Condition = require("../../scripts/domain/Condition");
const EvaluationMethod = require("../../scripts/domain/EvaluationMethod");
let Offer = require("../../scripts/domain/Offer");
const GatingType = require("../../scripts/domain/GatingType");
Expand Down Expand Up @@ -262,16 +262,27 @@ async function mockReceipt() {
);
}

function mockCondition({
method,
tokenType,
tokenAddress,
gating,
minTokenId,
threshold,
maxCommits,
maxTokenId,
} = {}) {
function mockCondition(
{ method, tokenType, tokenAddress, gating, minTokenId, threshold, maxCommits, maxTokenId } = {},
{ refreshModule, legacyCondition } = {}
) {
if (refreshModule) {
decache("../../scripts/domain/Condition.js");
Condition = require("../../scripts/domain/Condition.js");
}

if (legacyCondition) {
const tokenId = minTokenId;
return new Condition(
method ?? EvaluationMethod.Threshold,
tokenType ?? TokenType.FungibleToken,
tokenAddress ?? ZeroAddress,
tokenId ?? "0",
threshold ?? "1",
maxCommits ?? "1"
);
}

return new Condition(
method ?? EvaluationMethod.Threshold,
tokenType ?? TokenType.FungibleToken,
Expand Down
30 changes: 23 additions & 7 deletions test/util/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DisputeResolver = require("../../scripts/domain/DisputeResolver");
const Agent = require("../../scripts/domain/Agent");
const Buyer = require("../../scripts/domain/Buyer");
const { tagsByVersion } = require("../upgrade/00_config");
const Condition = require("../../scripts/domain/Condition");
let Condition = require("../../scripts/domain/Condition");

// Common vars
const versionsWithActivateDRFunction = ["v2.0.0", "v2.1.0"];
Expand Down Expand Up @@ -85,7 +85,7 @@ async function deploySuite(deployer, newVersion) {
facets = await getFacets();

// checkout old version
const { oldVersion: tag, deployScript: scriptsTag } = versionTags;
const { oldVersion: tag, deployScript: scriptsTag, updateDomain } = versionTags;
console.log(`Fetching tags`);
shell.exec(`git fetch --force --tags origin`);

Expand All @@ -99,6 +99,12 @@ async function deploySuite(deployer, newVersion) {
shell.exec(`git checkout ${scriptsTag} scripts/**`);
}

if (updateDomain) {
console.log(`Updating the domain definitions to ${tag}`);
const filesToUpdate = updateDomain.map((file) => `scripts/domain/${file}.js`).join(" ");
shell.exec(`git checkout ${tag} ${filesToUpdate}`);
}

const isOldOZVersion = ["v2.0", "v2.1", "v2.2"].some((v) => tag.startsWith(v));
if (isOldOZVersion) {
console.log("Installing correct version of OZ");
Expand Down Expand Up @@ -539,10 +545,16 @@ async function populateProtocolContract(
const seller = sellers[i];
const { offerIds } = seller;
const group = new Group(groupId, seller.seller.id, offerIds); // group all seller's offers
const condition = mockCondition({
tokenAddress: await mockConditionalToken.getAddress(),
maxCommits: "10",
});
const condition = mockCondition(
{
tokenAddress: await mockConditionalToken.getAddress(),
maxCommits: "10",
},
{
refreshModule: true,
legacyCondition: versionsBelowV2_3.includes(isBefore ? versionTags.oldVersion : versionTags.newVersion),
}
);
await groupHandler.connect(seller.wallet).createGroup(group, condition);

groups.push(group);
Expand Down Expand Up @@ -662,12 +674,16 @@ async function populateProtocolContract(
if (groupId && isAfterV2_3_0) {
// get condition
let [, , condition] = await groupHandler.getGroup(groupId);
decache("../../scripts/domain/Condition.js");
Condition = require("../../scripts/domain/Condition.js");
condition = Condition.fromStruct(condition);

// commit to conditional offer
await exchangeHandler
.connect(buyerWallet)
.commitToConditionalOffer(await buyerWallet.getAddress(), offer.id, condition.tokenId, { value: msgValue });
.commitToConditionalOffer(await buyerWallet.getAddress(), offer.id, condition.minTokenId, {
value: msgValue,
});
} else {
await exchangeHandler
.connect(buyerWallet)
Expand Down

0 comments on commit a1f32b7

Please sign in to comment.