Skip to content

Commit

Permalink
Merge pull request #801 from bosonprotocol/2.3.0-upgrade-tests
Browse files Browse the repository at this point in the history
2.3.0 upgrade tests
  • Loading branch information
mischat committed Sep 13, 2023
2 parents aab19d9 + ad224ba commit 5321ad8
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 51 deletions.
1 change: 0 additions & 1 deletion test/upgrade/01_generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function getGenericContext(

// Create new protocol entities. Existing data should not be affected
context("📋 New data after the upgrade do not corrupt the data from before the upgrade", async function () {
this.timeout(1000000);
let protocolContractStateAfterUpgradeAndActions;

before(async function () {
Expand Down
137 changes: 106 additions & 31 deletions test/upgrade/2.2.1-2.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
);

const equalCustomTypes = {
"t_struct(Range)12648_storage": "t_struct(Range)14241_storage",
"t_struct(Range)12648_storage": "t_struct(Range)14254_storage",
};

context(
Expand Down Expand Up @@ -412,7 +412,7 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
});
});

context.skip("Protocol limits", async function () {
context("Protocol limits", async function () {
let wallets;
let sellers, DRs, sellerWallet;

Expand Down Expand Up @@ -527,25 +527,31 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
});

it("can create a bundle with more offers than maxOffersPerBundle", async function () {
const { maxOffersPerBundle } = protocolLimits;
const { maxOffersPerBundle, maxOffersPerBatch } = protocolLimits;
const offerCount = Number(maxOffersPerBundle) + 1;
const twinId = await twinHandler.getNextTwinId();
const startingOfferId = await offerHandler.getNextOfferId();
const offerIds = [...Array(offerCount).keys()].map((i) => startingOfferId + BigInt(i));

const { offer, offerDates, offerDurations } = await mockOffer({ refreshModule: true });
const offers = new Array(offerCount).fill(offer);
const offerDatesList = new Array(offerCount).fill(offerDates);
const offerDurationsList = new Array(offerCount).fill(offerDurations);
const disputeResolverIds = new Array(offerCount).fill(DRs[0].id);
const agentIds = new Array(offerCount).fill("0");
const maxOffersPerBatchInt = Number(maxOffersPerBatch);
const offers = new Array(maxOffersPerBatchInt).fill(offer);
const offerDatesList = new Array(maxOffersPerBatchInt).fill(offerDates);
const offerDurationsList = new Array(maxOffersPerBatchInt).fill(offerDurations);
const disputeResolverIds = new Array(maxOffersPerBatchInt).fill(DRs[0].id);
const agentIds = new Array(maxOffersPerBatchInt).fill("0");

// Create offers in batch
let offersToCreate = offerCount;
while (offersToCreate > maxOffersPerBatchInt) {
await offerHandler
.connect(sellerWallet)
.createOfferBatch(offers, offerDatesList, offerDurationsList, disputeResolverIds, agentIds);
offersToCreate -= maxOffersPerBatchInt;
}
await offerHandler
.connect(sellerWallet)
.createOfferBatch(offers, offerDatesList, offerDurationsList, disputeResolverIds, agentIds, {
gasLimit: 100000000, // increase gas limit to avoid out of gas error
});
.createOfferBatch(offers, offerDatesList, offerDurationsList, disputeResolverIds, agentIds);

// At list one twin is needed to create a bundle
const [twinContract] = await deployMockTokens(["Foreign721"]);
Expand All @@ -560,29 +566,40 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
});

it("can add more offers to a group than maxOffersPerGroup", async function () {
const { maxOffersPerBundle } = protocolLimits;
const { maxOffersPerBundle, maxOffersPerBatch } = protocolLimits;
const offerCount = Number(maxOffersPerBundle) + 1;
const startingOfferId = await offerHandler.getNextOfferId();
const offerIds = [...Array(offerCount).keys()].map((i) => startingOfferId + BigInt(i));
const { offer, offerDates, offerDurations } = await mockOffer();
const offers = new Array(offerCount).fill(offer);
const offerDatesList = new Array(offerCount).fill(offerDates);
const offerDurationsList = new Array(offerCount).fill(offerDurations);
const disputeResolverIds = new Array(offerCount).fill(DRs[0].id);
const agentIds = new Array(offerCount).fill("0");
const maxOffersPerBatchInt = Number(maxOffersPerBatch);
const offers = new Array(maxOffersPerBatchInt).fill(offer);
const offerDatesList = new Array(maxOffersPerBatchInt).fill(offerDates);
const offerDurationsList = new Array(maxOffersPerBatchInt).fill(offerDurations);
const disputeResolverIds = new Array(maxOffersPerBatchInt).fill(DRs[0].id);
const agentIds = new Array(maxOffersPerBatchInt).fill("0");

// Create offers in batch
let offersToCreate = offerCount;
while (offersToCreate > maxOffersPerBatchInt) {
await offerHandler
.connect(sellerWallet)
.createOfferBatch(offers, offerDatesList, offerDurationsList, disputeResolverIds, agentIds);
offersToCreate -= maxOffersPerBatchInt;
}
await offerHandler
.connect(sellerWallet)
.createOfferBatch(offers, offerDatesList, offerDurationsList, disputeResolverIds, agentIds);

// Create a group with more offers than maxOffersPerGroup
const group = new Group("1", sellers[0].seller.id, offerIds);
const { mockConditionalToken } = mockContracts;
const condition = mockCondition({
tokenAddress: await mockConditionalToken.getAddress(),
maxCommits: "10",
});
const condition = mockCondition(
{
tokenAddress: await mockConditionalToken.getAddress(),
maxCommits: "10",
},
{ refreshModule: true }
);
await expect(groupHandler.connect(sellerWallet).createGroup(group, condition)).to.not.be.reverted;
});

Expand Down Expand Up @@ -640,14 +657,14 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
const emptyAuthToken = mockAuthToken();
const voucherInitValues = mockVoucherInitValues();

await Promise.all(
wallets.slice(0, sellerCount).map(async (wallet) => {
const walletAddress = await wallet.getAddress();
const seller = mockSeller(walletAddress, walletAddress, ZeroAddress, walletAddress, true);
await provider.send("hardhat_setBalance", [walletAddress, toHexString(parseEther("10"))]);
return accountHandler.connect(wallet).createSeller(seller, emptyAuthToken, voucherInitValues);
})
);
for (const wallet of wallets.slice(0, sellerCount)) {
const walletAddress = await wallet.getAddress();
const seller = mockSeller(walletAddress, walletAddress, ZeroAddress, walletAddress, true, "", {
refreshModule: true,
});
await provider.send("hardhat_setBalance", [walletAddress, toHexString(parseEther("10"))]);
await accountHandler.connect(wallet).createSeller(seller, emptyAuthToken, voucherInitValues);
}

const disputeResolverFees = [new DisputeResolverFee(ZeroAddress, "Native", "0")];
const disputeResolver = mockDisputeResolver(rando.address, rando.address, ZeroAddress, rando.address);
Expand Down Expand Up @@ -922,7 +939,6 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
wallet: sellerWallet,
id: sellerId,
voucherInitValues,
seller,
voucherContractAddress: expectedDefaultAddress,
} = sellers[0];
const externalId = "new-collection";
Expand All @@ -931,7 +947,7 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
const expectedCollectionAddress = calculateCloneAddress(
await accountHandler.getAddress(),
beaconProxyAddress,
seller.admin,
sellerWallet.address,
voucherInitValues.collectionSalt,
voucherInitValues.collectionSalt
);
Expand Down Expand Up @@ -970,6 +986,65 @@ describe("[@skip-on-coverage] After facet upgrade, everything is still operation
});
});

context("Update seller salt", async function () {
let beaconProxyAddress;
before(async function () {
// Get the beacon proxy address
beaconProxyAddress = await calculateBosonProxyAddress(protocolDiamondAddress);
});

it("New seller can update sellers salt", async function () {
const seller = mockSeller(assistant.address, assistant.address, ZeroAddress, assistant.address);
seller.id = await accountHandler.getNextAccountId();
const emptyAuthToken = mockAuthToken();
const voucherInitValues = mockVoucherInitValues();

await accountHandler.connect(assistant).createSeller(seller, emptyAuthToken, voucherInitValues);

const externalId = "new-collection";
voucherInitValues.collectionSalt = encodeBytes32String(externalId);

const newSellerSalt = encodeBytes32String("new-seller-salt");
await accountHandler.connect(assistant).updateSellerSalt(seller.id, newSellerSalt); // assistant is also the admin in this test

const expectedCollectionAddress = calculateCloneAddress(
await accountHandler.getAddress(),
beaconProxyAddress,
seller.admin,
voucherInitValues.collectionSalt,
newSellerSalt
);
const tx = await accountHandler.connect(assistant).createNewCollection(externalId, voucherInitValues);

await expect(tx)
.to.emit(accountHandler, "CollectionCreated")
.withArgs(Number(seller.id), 1, expectedCollectionAddress, externalId, assistant.address);
});

it("old seller can create update seller salt", async function () {
const { sellers } = preUpgradeEntities;
const { wallet: sellerWallet, id: sellerId, voucherInitValues } = sellers[0];

const newSellerSalt = encodeBytes32String("new-seller-salt");
await accountHandler.connect(sellerWallet).updateSellerSalt(sellerId, newSellerSalt);

const externalId = "new-collection";
voucherInitValues.collectionSalt = encodeBytes32String(externalId);
beaconProxyAddress = await calculateBosonProxyAddress(protocolDiamondAddress);
const expectedCollectionAddress = calculateCloneAddress(
await accountHandler.getAddress(),
beaconProxyAddress,
sellerWallet.address,
voucherInitValues.collectionSalt,
newSellerSalt
);

await expect(accountHandler.connect(sellerWallet).createNewCollection(externalId, voucherInitValues))
.to.emit(accountHandler, "CollectionCreated")
.withArgs(sellerId, 1, expectedCollectionAddress, externalId, sellerWallet.address);
});
});

it("New sellers uses create2 to calculate voucher address", async function () {
const seller = mockSeller(assistant.address, assistant.address, ZeroAddress, assistant.address);
seller.id = await accountHandler.getNextAccountId();
Expand Down
Loading

0 comments on commit 5321ad8

Please sign in to comment.