diff --git a/README.md b/README.md index a7f9c1c9c..e6eae1a69 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Done or in progress are: We welcome contributions! Until now, Boson Protocol has been largely worked on by a small dedicated team. However, the ultimate goal is for all of the Boson Protocol repositories to be fully owned by the community and contributors. Issues, pull requests, suggestions, and any sort of involvement are more than welcome. -If you have noticed a bug, please report it via our [Bug Bounty program](https://immunefi.com/bounty/bosonprotocol/). +If you have noticed a bug, please report it via our [Bug Bounty program](https://github.com/bosonprotocol/community/blob/main/BugBountyProgram.md). Questions and feedback are always welcome, we will use them to improve our offering. diff --git a/contracts/interfaces/handlers/IBosonPauseHandler.sol b/contracts/interfaces/handlers/IBosonPauseHandler.sol index ad4b76dbc..6d103db55 100644 --- a/contracts/interfaces/handlers/IBosonPauseHandler.sol +++ b/contracts/interfaces/handlers/IBosonPauseHandler.sol @@ -19,7 +19,6 @@ interface IBosonPauseHandler is IBosonPauseEvents { * * Reverts if: * - Caller does not have PAUSER role - * - A region is specified more than once * * @param _regions - an array of regions to pause. See: {BosonTypes.PausableRegion} */ @@ -33,7 +32,6 @@ interface IBosonPauseHandler is IBosonPauseEvents { * Reverts if: * - Caller does not have PAUSER role * - Protocol is not currently paused - * - A region is specified more than once * * @param _regions - an array of regions to pause. See: {BosonTypes.PausableRegion} */ diff --git a/contracts/protocol/clients/voucher/BosonVoucher.sol b/contracts/protocol/clients/voucher/BosonVoucher.sol index 635710945..5b584974a 100644 --- a/contracts/protocol/clients/voucher/BosonVoucher.sol +++ b/contracts/protocol/clients/voucher/BosonVoucher.sol @@ -73,7 +73,12 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable address _newOwner, VoucherInitValues calldata voucherInitValues ) public initializer { - string memory sellerId = string.concat(Strings.toString(_sellerId), "_", Strings.toString(_collectionIndex)); + string memory sellerId = string.concat( + "S", + Strings.toString(_sellerId), + "_C", + Strings.toString(_collectionIndex) + ); string memory voucherName = string.concat(VOUCHER_NAME, " ", sellerId); string memory voucherSymbol = string.concat(VOUCHER_SYMBOL, "_", sellerId); diff --git a/contracts/protocol/facets/ConfigHandlerFacet.sol b/contracts/protocol/facets/ConfigHandlerFacet.sol index 7f6d531d0..a30dcf2d3 100644 --- a/contracts/protocol/facets/ConfigHandlerFacet.sol +++ b/contracts/protocol/facets/ConfigHandlerFacet.sol @@ -43,8 +43,8 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { setBuyerEscalationDepositPercentage(_fees.buyerEscalationDepositPercentage); setMaxTotalOfferFeePercentage(_limits.maxTotalOfferFeePercentage); setMaxRoyaltyPecentage(_limits.maxRoyaltyPecentage); - setMinResolutionPeriod(_limits.minResolutionPeriod); setMaxResolutionPeriod(_limits.maxResolutionPeriod); + setMinResolutionPeriod(_limits.minResolutionPeriod); setMinDisputePeriod(_limits.minDisputePeriod); // Initialize protocol counters @@ -428,7 +428,13 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { // Make sure _maxResolutionPeriod is greater than 0 checkNonZero(_minResolutionPeriod); - protocolLimits().minResolutionPeriod = _minResolutionPeriod; + // cache protocol limits + ProtocolLib.ProtocolLimits storage limits = protocolLimits(); + + // Make sure _minResolutionPeriod is less than _maxResolutionPeriod + require(_minResolutionPeriod <= limits.maxResolutionPeriod, INVALID_RESOLUTION_PERIOD); + + limits.minResolutionPeriod = _minResolutionPeriod; emit MinResolutionPeriodChanged(_minResolutionPeriod, msgSender()); } @@ -456,7 +462,13 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { // Make sure _maxResolutionPeriod is greater than 0 checkNonZero(_maxResolutionPeriod); - protocolLimits().maxResolutionPeriod = _maxResolutionPeriod; + // cache protocol limits + ProtocolLib.ProtocolLimits storage limits = protocolLimits(); + + // Make sure _maxResolutionPeriod is greater than _minResolutionPeriod + require(_maxResolutionPeriod >= limits.minResolutionPeriod, INVALID_RESOLUTION_PERIOD); + + limits.maxResolutionPeriod = _maxResolutionPeriod; emit MaxResolutionPeriodChanged(_maxResolutionPeriod, msgSender()); } diff --git a/contracts/protocol/facets/ExchangeHandlerFacet.sol b/contracts/protocol/facets/ExchangeHandlerFacet.sol index 01dca6bab..811c2e943 100644 --- a/contracts/protocol/facets/ExchangeHandlerFacet.sol +++ b/contracts/protocol/facets/ExchangeHandlerFacet.sol @@ -989,8 +989,13 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { ProtocolLib.ProtocolLookups storage lookups = protocolLookups(); if (_condition.method == EvaluationMethod.SpecificToken) { + // Cache conditionalCommitsByTokenId mapping for reference + mapping(uint256 => uint256) storage conditionalCommitsByTokenId = lookups.conditionalCommitsByTokenId[ + _tokenId + ]; + // How many times has this token id been used to commit to offers in the group? - uint256 commitCount = lookups.conditionalCommitsByTokenId[_tokenId][_groupId]; + uint256 commitCount = conditionalCommitsByTokenId[_groupId]; require(commitCount < _condition.maxCommits, MAX_COMMITS_TOKEN_REACHED); @@ -998,11 +1003,16 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { if (allow) { // Increment number of commits to the group for this token id if they are allowed to commit - lookups.conditionalCommitsByTokenId[_tokenId][_groupId] = ++commitCount; + conditionalCommitsByTokenId[_groupId] = ++commitCount; } } else if (_condition.method == EvaluationMethod.Threshold) { + // Cache conditionalCommitsByAddress mapping for reference + mapping(uint256 => uint256) storage conditionalCommitsByAddress = lookups.conditionalCommitsByAddress[ + _buyer + ]; + // How many times has this address committed to offers in the group? - uint256 commitCount = lookups.conditionalCommitsByAddress[_buyer][_groupId]; + uint256 commitCount = conditionalCommitsByAddress[_groupId]; require(commitCount < _condition.maxCommits, MAX_COMMITS_ADDRESS_REACHED); @@ -1010,7 +1020,7 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase { if (allow) { // Increment number of commits to the group for this address if they are allowed to commit - lookups.conditionalCommitsByAddress[_buyer][_groupId] = ++commitCount; + conditionalCommitsByAddress[_groupId] = ++commitCount; } } else { allow = true; diff --git a/contracts/protocol/facets/PauseHandlerFacet.sol b/contracts/protocol/facets/PauseHandlerFacet.sol index e116e64e3..207fb113e 100644 --- a/contracts/protocol/facets/PauseHandlerFacet.sol +++ b/contracts/protocol/facets/PauseHandlerFacet.sol @@ -30,7 +30,6 @@ contract PauseHandlerFacet is ProtocolBase, IBosonPauseHandler { * * Reverts if: * - Caller does not have PAUSER role - * - A region is specified more than once * * @param _regions - an array of regions to pause. See: {BosonTypes.PausableRegion} */ @@ -49,7 +48,6 @@ contract PauseHandlerFacet is ProtocolBase, IBosonPauseHandler { * Reverts if: * - Caller does not have PAUSER role * - Protocol is not currently paused - * - A region is specified more than once */ function unpause(BosonTypes.PausableRegion[] calldata _regions) external onlyRole(PAUSER) nonReentrant { // Cache protocol status for reference @@ -105,9 +103,6 @@ contract PauseHandlerFacet is ProtocolBase, IBosonPauseHandler { * * Toggle all regions if none are specified. * - * Reverts if: - * - A region is specified more than once - * * @param _regions - an array of regions to pause/unpause. See: {BosonTypes.PausableRegion} * @param _pause - a boolean indicating whether to pause (true) or unpause (false) */ diff --git a/contracts/protocol/facets/ProtocolInitializationHandlerFacet.sol b/contracts/protocol/facets/ProtocolInitializationHandlerFacet.sol index deacf4746..5196864a1 100644 --- a/contracts/protocol/facets/ProtocolInitializationHandlerFacet.sol +++ b/contracts/protocol/facets/ProtocolInitializationHandlerFacet.sol @@ -48,7 +48,7 @@ contract ProtocolInitializationHandlerFacet is IBosonProtocolInitializationHandl * - For upgrade to v2.2.0: * - If versions is set already * - If _initializationData cannot be decoded to uin256 - * - If _initializationData is represents value 0 + * - If _initializationData is represents value * * @param _version - version of the protocol * @param _addresses - array of facet addresses to call initialize methods @@ -143,10 +143,11 @@ contract ProtocolInitializationHandlerFacet is IBosonProtocolInitializationHandl * Reverts if: * - Current version is not 2.2.1 * - There are already twins. This version adds a new mapping for twins which make it incompatible with previous versions. - * - minResolutionPeriond is not present in _initializationData parameter + * - minResolutionPeriod is not present in _initializationData parameter * - length of seller creators does not match the length of seller ids * - if some of seller creators is zero address * - if some of seller ids does not bellong to a seller + * - if minResolutionPeriod is greater than maxResolutionPeriod * * @param _initializationData - data representing uint256 _minResolutionPeriod, uint256[] memory sellerIds, address[] memory sellerCreators */ @@ -161,9 +162,15 @@ contract ProtocolInitializationHandlerFacet is IBosonProtocolInitializationHandl (uint256, uint256[], address[]) ); + // cache protocol limits + ProtocolLib.ProtocolLimits storage limits = protocolLimits(); + + // make sure _minResolutionPeriod is less than maxResolutionPeriod + require(limits.maxResolutionPeriod >= _minResolutionPeriod, INVALID_RESOLUTION_PERIOD); + // Initialize limits.maxPremintedVouchers (configHandlerFacet initializer) require(_minResolutionPeriod != 0, VALUE_ZERO_NOT_ALLOWED); - protocolLimits().minResolutionPeriod = _minResolutionPeriod; + limits.minResolutionPeriod = _minResolutionPeriod; emit MinResolutionPeriodChanged(_minResolutionPeriod, msgSender()); // Initialize sellerCreators diff --git a/contracts/protocol/facets/SellerHandlerFacet.sol b/contracts/protocol/facets/SellerHandlerFacet.sol index 5ec42b6ac..0ed27c459 100644 --- a/contracts/protocol/facets/SellerHandlerFacet.sol +++ b/contracts/protocol/facets/SellerHandlerFacet.sol @@ -274,9 +274,9 @@ contract SellerHandlerFacet is SellerBase { IBosonVoucher(lookups.cloneAddress[_sellerId]).transferOwnership(sender); // default voucher contract Collection[] storage sellersAdditionalCollections = lookups.additionalCollections[_sellerId]; uint256 collectionCount = sellersAdditionalCollections.length; - for (i = 0; i < collectionCount; i++) { + for (uint256 j = 0; j < collectionCount; j++) { // Additional collections (if they exist) - IBosonVoucher(sellersAdditionalCollections[i].collectionAddress).transferOwnership(sender); + IBosonVoucher(sellersAdditionalCollections[j].collectionAddress).transferOwnership(sender); } // Store new seller id by assistant mapping diff --git a/test/protocol/ConfigHandlerTest.js b/test/protocol/ConfigHandlerTest.js index e2199b0ce..3f1e99030 100644 --- a/test/protocol/ConfigHandlerTest.js +++ b/test/protocol/ConfigHandlerTest.js @@ -1,7 +1,6 @@ const { ethers } = require("hardhat"); const { getSigners, getContractAt, ZeroAddress, parseUnits } = ethers; const { expect } = require("chai"); - const Role = require("../../scripts/domain/Role"); const { getInterfaceIds } = require("../../scripts/config/supported-interfaces.js"); const { RevertReasons } = require("../../scripts/config/revert-reasons.js"); @@ -718,6 +717,55 @@ describe("IBosonConfigHandler", function () { }); }); + context("👉 setMinResolutionPeriod()", async function () { + let minResolutionPeriod; + beforeEach(async function () { + // set new value + minResolutionPeriod = oneWeek; + }); + + it("should emit a MinResolutionPeriodChanged event", async function () { + // Set new resolution period + await expect(configHandler.connect(deployer).setMinResolutionPeriod(minResolutionPeriod)) + .to.emit(configHandler, "MinResolutionPeriodChanged") + .withArgs(minResolutionPeriod, await deployer.getAddress()); + }); + + it("should update state", async function () { + // Set new resolution period + await configHandler.connect(deployer).setMinResolutionPeriod(minResolutionPeriod); + + // Verify that new value is stored + expect(await configHandler.connect(rando).getMinResolutionPeriod()).to.equal(minResolutionPeriod); + }); + + context("💔 Revert Reasons", async function () { + it("caller is not the admin", async function () { + // Attempt to set new value, expecting revert + await expect(configHandler.connect(rando).setMinResolutionPeriod(minResolutionPeriod)).to.revertedWith( + RevertReasons.ACCESS_DENIED + ); + }); + + it("minResolutionPeriod is zero", async function () { + minResolutionPeriod = 0; + await expect(configHandler.connect(deployer).setMinResolutionPeriod(minResolutionPeriod)).to.revertedWith( + RevertReasons.VALUE_ZERO_NOT_ALLOWED + ); + }); + + it("minResolutionPeriod is greater than maxResolutionPeriod", async function () { + const maxResolutionPeriod = oneMonth; + await configHandler.connect(deployer).setMaxResolutionPeriod(maxResolutionPeriod); + + minResolutionPeriod = maxResolutionPeriod + 1n; + await expect(configHandler.connect(deployer).setMinResolutionPeriod(minResolutionPeriod)).to.revertedWith( + RevertReasons.INVALID_RESOLUTION_PERIOD + ); + }); + }); + }); + context("👉 setMaxResolutionPeriod()", async function () { let maxResolutionPeriod; beforeEach(async function () { @@ -754,6 +802,16 @@ describe("IBosonConfigHandler", function () { RevertReasons.VALUE_ZERO_NOT_ALLOWED ); }); + + it("maxResolutionPeriod is less than minResolutionPeriod", async function () { + const minResolutionPeriod = oneWeek; + await configHandler.connect(deployer).setMinResolutionPeriod(minResolutionPeriod); + + const maxResolutionPeriod = minResolutionPeriod - 1n; + await expect(configHandler.connect(deployer).setMaxResolutionPeriod(maxResolutionPeriod)).to.revertedWith( + RevertReasons.INVALID_RESOLUTION_PERIOD + ); + }); }); }); diff --git a/test/protocol/OfferHandlerTest.js b/test/protocol/OfferHandlerTest.js index f913514ad..4eed7e1f0 100644 --- a/test/protocol/OfferHandlerTest.js +++ b/test/protocol/OfferHandlerTest.js @@ -737,6 +737,7 @@ describe("IBosonOfferHandler", function () { }); it("Resolution period is greater than protocol max resolution period", async function () { + await configHandler.setMinResolutionPeriod(oneDay - 1n); // Set max resolution period to 1 day await configHandler.setMaxResolutionPeriod(oneDay); // 24 hours diff --git a/test/protocol/OrchestrationHandlerTest.js b/test/protocol/OrchestrationHandlerTest.js index aa667f85e..f4d8d1a89 100644 --- a/test/protocol/OrchestrationHandlerTest.js +++ b/test/protocol/OrchestrationHandlerTest.js @@ -777,9 +777,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -820,9 +823,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -883,9 +889,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -1396,11 +1405,11 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); expect(await bosonVoucher.name()).to.equal( - VOUCHER_NAME + " " + seller.id + "_0", + VOUCHER_NAME + " S" + seller.id + "_C0", "Wrong voucher client name" ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); const returnedRange = Range.fromStruct(await bosonVoucher.getRangeByOfferId(offer.id)); @@ -5583,9 +5592,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -5626,9 +5638,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -5689,9 +5704,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -6067,11 +6085,11 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); expect(await bosonVoucher.name()).to.equal( - VOUCHER_NAME + " " + seller.id + "_0", + VOUCHER_NAME + " S" + seller.id + "_C0", "Wrong voucher client name" ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); const returnedRange = Range.fromStruct(await bosonVoucher.getRangeByOfferId(offer.id)); @@ -6417,9 +6435,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -6463,9 +6484,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -6529,9 +6553,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -6978,11 +7005,11 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); expect(await bosonVoucher.name()).to.equal( - VOUCHER_NAME + " " + seller.id + "_0", + VOUCHER_NAME + " S" + seller.id + "_C0", "Wrong voucher client name" ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); const returnedRange = Range.fromStruct(await bosonVoucher.getRangeByOfferId(offer.id)); @@ -7397,9 +7424,12 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -7444,9 +7474,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -7511,9 +7544,12 @@ describe("IBosonOrchestrationHandler", function () { // Voucher clone contract bosonVoucher = await ethers.getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -8015,11 +8051,11 @@ describe("IBosonOrchestrationHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); expect(await bosonVoucher.name()).to.equal( - VOUCHER_NAME + " " + seller.id + "_0", + VOUCHER_NAME + " S" + seller.id + "_C0", "Wrong voucher client name" ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); const returnedRange = Range.fromStruct(await bosonVoucher.getRangeByOfferId(offer.id)); diff --git a/test/protocol/ProtocolInitializationHandlerTest.js b/test/protocol/ProtocolInitializationHandlerTest.js index 4a3bfe7a2..4d59a3d3c 100644 --- a/test/protocol/ProtocolInitializationHandlerTest.js +++ b/test/protocol/ProtocolInitializationHandlerTest.js @@ -18,7 +18,7 @@ const { mockTwin, mockSeller, mockAuthToken, mockVoucherInitValues } = require(" const { deployProtocolDiamond } = require("../../scripts/util/deploy-protocol-diamond.js"); const { deployAndCutFacets, deployProtocolFacets } = require("../../scripts/util/deploy-protocol-handler-facets"); const { getInterfaceIds, interfaceImplementers } = require("../../scripts/config/supported-interfaces"); -const { maxPriorityFeePerGas, oneWeek } = require("../util/constants"); +const { maxPriorityFeePerGas, oneWeek, oneMonth } = require("../util/constants"); const { getFees } = require("../../scripts/util/utils"); const { getFacetAddCut, getFacetReplaceCut } = require("../../scripts/util/diamond-utils"); @@ -831,6 +831,27 @@ describe("ProtocolInitializationHandler", async function () { ).to.be.revertedWith(RevertReasons.VALUE_ZERO_NOT_ALLOWED); }); + it("Min resolution period is greater than max resolution period", async function () { + version = "2.3.0"; + console.log("oneMonth", oneMonth); + await configHandler.connect(deployer).setMaxResolutionPeriod(oneMonth); + minResolutionPeriod = oneMonth + 1n; + console.log("minResolutionPeriod", minResolutionPeriod); + initializationData = abiCoder.encode(["uint256", "uint256[]", "address[]"], [minResolutionPeriod, [], []]); + calldataProtocolInitialization = deployedProtocolInitializationHandlerFacet.interface.encodeFunctionData( + "initialize", + [encodeBytes32String(version), [], [], true, initializationData, [], []] + ); + + await expect( + diamondCutFacet.diamondCut( + [facetCut], + deployedProtocolInitializationHandlerFacetAddress, + calldataProtocolInitialization + ) + ).to.be.revertedWith(RevertReasons.INVALID_RESOLUTION_PERIOD); + }); + it("sellerIds and sellerCreators length mismatch", async function () { version = "2.3.0"; initializationData = abiCoder.encode(["uint256", "uint256[]", "address[]"], [minResolutionPeriod, [1], []]); diff --git a/test/protocol/SellerHandlerTest.js b/test/protocol/SellerHandlerTest.js index af1b44ef0..5a20c328c 100644 --- a/test/protocol/SellerHandlerTest.js +++ b/test/protocol/SellerHandlerTest.js @@ -254,9 +254,12 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -271,9 +274,12 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -308,9 +314,12 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); @@ -372,9 +381,12 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCloneAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_0", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C0", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_0", + VOUCHER_SYMBOL + "_S" + seller.id + "_C0", "Wrong voucher client symbol" ); }); @@ -2553,47 +2565,65 @@ describe("SellerHandler", function () { expect(await bosonVoucher.owner()).to.equal(other1.address); }); - it("Transfers ownerships of all additional collections", async function () { - const expectedDefaultAddress = calculateCloneAddress( - await accountHandler.getAddress(), - beaconProxyAddress, - admin.address, - "" - ); // default - bosonVoucher = await getContractAt("OwnableUpgradeable", expectedDefaultAddress); - - const additionalCollections = []; - // create 3 additional collections - for (let i = 0; i < 3; i++) { - const externalId = `Brand${i}`; - voucherInitValues.contractURI = `https://brand${i}.com`; - const expectedCollectionAddress = calculateCloneAddress( + context("Multiple collections", async function () { + let additionalCollections = []; + beforeEach(async function () { + const expectedDefaultAddress = calculateCloneAddress( await accountHandler.getAddress(), beaconProxyAddress, admin.address, - externalId - ); - await accountHandler.connect(assistant).createNewCollection(externalId, voucherInitValues); - additionalCollections.push(await getContractAt("OwnableUpgradeable", expectedCollectionAddress)); - } + "" + ); // default + bosonVoucher = await getContractAt("OwnableUpgradeable", expectedDefaultAddress); + + // create 3 additional collections + for (let i = 0; i < 3; i++) { + const externalId = `Brand${i}`; + voucherInitValues.contractURI = `https://brand${i}.com`; + const expectedCollectionAddress = calculateCloneAddress( + await accountHandler.getAddress(), + beaconProxyAddress, + admin.address, + externalId + ); + await accountHandler.connect(assistant).createNewCollection(externalId, voucherInitValues); + additionalCollections.push(await getContractAt("OwnableUpgradeable", expectedCollectionAddress)); + } + }); - // original voucher and collections contract owner - expect(await bosonVoucher.owner()).to.equal(assistant.address); - for (const collection of additionalCollections) { - expect(await collection.owner()).to.equal(assistant.address); - } + it("Transfers ownerships of all additional collections", async function () { + // original voucher and collections contract owner + expect(await bosonVoucher.owner()).to.equal(assistant.address); + for (const collection of additionalCollections) { + expect(await collection.owner()).to.equal(assistant.address); + } - seller.assistant = other1.address; - sellerStruct = seller.toStruct(); + seller.assistant = other1.address; + sellerStruct = seller.toStruct(); - await accountHandler.connect(admin).updateSeller(seller, emptyAuthToken); - await accountHandler.connect(other1).optInToSellerUpdate(seller.id, [SellerUpdateFields.Assistant]); + await accountHandler.connect(admin).updateSeller(seller, emptyAuthToken); + await accountHandler.connect(other1).optInToSellerUpdate(seller.id, [SellerUpdateFields.Assistant]); - // new voucher and collections contract owner - expect(await bosonVoucher.owner()).to.equal(other1.address); - for (const collection of additionalCollections) { - expect(await collection.owner()).to.equal(other1.address); - } + // new voucher and collections contract owner + expect(await bosonVoucher.owner()).to.equal(other1.address); + for (const collection of additionalCollections) { + expect(await collection.owner()).to.equal(other1.address); + } + }); + + it("Update of other fields work", async function () { + seller.assistant = seller.admin = other1.address; + sellerStruct = seller.toStruct(); + + await accountHandler.connect(admin).updateSeller(seller, emptyAuthToken); + await accountHandler + .connect(other1) + .optInToSellerUpdate(seller.id, [SellerUpdateFields.Assistant, SellerUpdateFields.Admin]); + + const [, returnedSeller] = await accountHandler.getSeller(seller.id); + expect(returnedSeller.assistant).to.equal(seller.assistant); + expect(returnedSeller.admin).to.equal(seller.admin); + }); }); context("💔 Revert Reasons", async function () { @@ -2821,9 +2851,12 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCollectionAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); - expect(await bosonVoucher.name()).to.equal(VOUCHER_NAME + " " + seller.id + "_1", "Wrong voucher client name"); + expect(await bosonVoucher.name()).to.equal( + VOUCHER_NAME + " S" + seller.id + "_C1", + "Wrong voucher client name" + ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_1", + VOUCHER_SYMBOL + "_S" + seller.id + "_C1", "Wrong voucher client symbol" ); }); @@ -2879,11 +2912,11 @@ describe("SellerHandler", function () { bosonVoucher = await getContractAt("IBosonVoucher", expectedCollectionAddress); expect(await bosonVoucher.contractURI()).to.equal(contractURI, "Wrong contract URI"); expect(await bosonVoucher.name()).to.equal( - VOUCHER_NAME + " " + seller.id + "_" + i, + VOUCHER_NAME + " S" + seller.id + "_C" + i, "Wrong voucher client name" ); expect(await bosonVoucher.symbol()).to.equal( - VOUCHER_SYMBOL + "_" + seller.id + "_" + i, + VOUCHER_SYMBOL + "_S" + seller.id + "_C" + i, "Wrong voucher client symbol" ); }