Skip to content

Commit

Permalink
v2.3.0 migration script and upgrade test (#680)
Browse files Browse the repository at this point in the history
* Modify contract change detection

* generic tests

* return zero DR clerk

* always return zero DR clerk

* Clerk related tests

* unpause regions

* minimal resolution period related

* correctly clear pending updates

* limit twin gas transfer

* commit at expiry

* twin related tests

* token gating

* multiple collections

* get*Funds, getTokenList*

* protocol limits are not enforced anymore

* get pending update metadataUri

* Fix import

* package.json

* Continue work on upgrade tests

* Improve migration

* Remediate hardhat listAccounts bug

* minor changes

* Continue work on upgrade tests

* Add exchange handler to migration upgrade

* Add upgrade BV to migration

* Continue

* Make twin creation opt

* Adding BosonVoucher and PauseHandler tests

* Fix new collection tests

* Fix rest of failling tests

* Migrations improvements

* Adding subgraph call to fetch seller creators

* adding dry-run env

* Adding and removing selectors from metaTx handler

* Adding and removing selectors from metaTx handler

* Make subgraph call respect chain

* Make subgraph call respect chain

* removing logs

* fixing bug on migration

* Tidy

* Fix offer collectionIndex script

* Removing logs

* Add create2 test

* Fix configHandler storage validation

* Populate sellerCreators when is upgrade test env

* Remove upgrade tests from coverage

* Make generic tests compatible with v2.3.0

* WIP: review changes

* Continue review changes

* Add generic tests for vouchers

* Fix wrong proxy address [skip ci]

* Fix generic voucher tests

* WIP update tests to rc.2

* Adapt tests to v2.3.0-rc.2

---------

Co-authored-by: Ana Julia <anajuliabit@gmail.com>
  • Loading branch information
zajck and anajuliabit committed Sep 1, 2023
1 parent 7c144ef commit 48285f2
Show file tree
Hide file tree
Showing 26 changed files with 2,313 additions and 353 deletions.
1 change: 1 addition & 0 deletions contracts/protocol/facets/DisputeResolverHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ contract DisputeResolverHandlerFacet is IBosonAccountEvents, ProtocolBase {
{
(exists, disputeResolver, disputeResolverFees) = fetchDisputeResolver(_disputeResolverId);
if (exists) {
disputeResolver.clerk = address(0);
sellerAllowList = protocolLookups().allowedSellers[_disputeResolverId];
}
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/protocol/facets/ExchangeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,6 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase {
// Token transfer order is descending
twinM.tokenId += twinM.supplyAvailable;
}

// ERC-721 style transfer
data = abi.encodeWithSignature(
"safeTransferFrom(address,address,uint256,bytes)",
Expand All @@ -890,7 +889,6 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase {
""
);
}

// Make call only if there is enough gas and code at address exists.
// If not, skip the call and mark the transfer as failed
twinM.tokenAddress = twinS.tokenAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ contract ProtocolInitializationHandlerFacet is IBosonProtocolInitializationHandl
function initV2_3_0(bytes calldata _initializationData) internal {
// Current version must be 2.2.1
require(protocolStatus().version == bytes32("2.2.1"), WRONG_CURRENT_VERSION);

require(protocolCounters().nextTwinId == 1, TWINS_ALREADY_EXIST);

// Decode initialization data
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/facets/SellerHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ contract SellerHandlerFacet is SellerBase {

(exists, sellerId) = getSellerIdByAuthToken(_associatedAuthToken);
if (exists) {
return fetchSeller(sellerId);
return fetchSellerWithoutClerk(sellerId);
}
}

Expand Down
9 changes: 5 additions & 4 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ task(
task("upgrade-facets", "Upgrade existing facets, add new facets or remove existing facets")
.addParam("newVersion", "The version of the protocol to upgrade to")
.addParam("env", "The deployment environment")
.addParam("functionNamesToSelector", "JSON list of function names to selectors")
.addOptionalParam("facetConfig", "JSON list of facets to upgrade")
.setAction(async ({ env, facetConfig, newVersion }) => {
.setAction(async ({ env, facetConfig, newVersion, functionNamesToSelector }) => {
const { upgradeFacets } = await lazyImport("./scripts/upgrade-facets.js");

await upgradeFacets(env, facetConfig, newVersion);
await upgradeFacets(env, facetConfig, newVersion, functionNamesToSelector);
});

task("upgrade-clients", "Upgrade existing clients")
Expand Down Expand Up @@ -115,9 +116,9 @@ task("migrate", "Migrates the protocol to a new version")

if (dryRun) {
const balanceAfter = await getBalance();
const etherSpent = balanceBefore.sub(balanceAfter);
const etherSpent = balanceBefore - balanceAfter;

const formatUnits = require("ethers").utils.formatUnits;
const formatUnits = require("ethers").formatUnits;
console.log("Ether spent: ", formatUnits(etherSpent, "ether"));
}
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tidy:contracts": "solhint --fix contracts/**/*.sol && prettier --write contracts/**",
"tidy:scripts": "eslint --fix test/** scripts/** '*.js' && prettier --write test/** scripts/** '*.js'",
"size": "npx hardhat size-contracts",
"coverage": "npx hardhat clean && npx hardhat coverage",
"coverage": "npx hardhat clean && npx hardhat coverage --testfiles '{test/access/*.js,test/protocol/*.js,test/protocol/clients/*.js}'",
"deploy-suite:hardhat": "npx hardhat clean && npx hardhat compile && npx hardhat deploy-suite --network hardhat",
"deploy-suite:local": "npx hardhat clean && npx hardhat compile && npx hardhat deploy-suite --network localhost",
"deploy-suite:test": "npx hardhat clean && npx hardhat compile && npx hardhat deploy-suite --network test --env test >> logs/test.deploy.contracts.txt",
Expand All @@ -52,6 +52,7 @@
"upgrade-facets:polygon:mumbai-test": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-facets --network mumbai --env test >> logs/mumbai-test.upgrade.contracts.txt",
"upgrade-facets:polygon:mumbai-staging": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-facets --network mumbai --env staging >> logs/mumbai-staging.upgrade.contracts.txt",
"upgrade-facets:polygon:mainnet": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-facets --network polygon --env prod >> logs/polygon.upgrade.contracts.txt",
"migrate": "npx hardhat clean && npx hardhat compile && npx hardhat migrate >> logs/${npm_config_env}-migrate.contracts.txt",
"upgrade-clients:local": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-clients --network localhost --env ''",
"upgrade-clients:test": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-clients --network test --env test >> logs/test.upgrade.contracts.txt",
"upgrade-clients:ethereum:mainnet": "npx hardhat clean && npx hardhat compile && npx hardhat upgrade-clients --network mainnet --env prod >> logs/mainnet.upgrade.contracts.txt",
Expand Down
3 changes: 3 additions & 0 deletions scripts/domain/Offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class Offer {
voided,
collectionIndex,
] = struct;
if (!collectionIndex) {
collectionIndex = 0;
}

return Offer.fromObject({
id: id.toString(),
Expand Down
4 changes: 2 additions & 2 deletions scripts/manage-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const hre = require("hardhat");
const { getContractAt, provider } = hre.ethers;
const network = hre.network.name;
const { RoleAssignments } = require("./config/role-assignments");
const { readContracts } = require("./util/utils");
const { readContracts, listAccounts } = require("./util/utils");
const environments = require("../environments");
const Role = require("./domain/Role");

Expand Down Expand Up @@ -39,7 +39,7 @@ async function main(env) {
console.log(`⛓ Network: ${hre.network.name}\n📅 ${new Date()}`);

// Get the accounts
const accounts = await provider.listAccounts();
const accounts = await listAccounts();
const admin = accounts[0];
console.log("🔱 Admin account: ", admin ? admin : "not found" && process.exit());
console.log(divider);
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrations/dry-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function setupDryRun(env) {

await hre.changeNetwork("hardhat");

env = "upgrade-test";
env = `${env}-dry-run`;

const { chainId } = await ethers.provider.getNetwork();
if (chainId != "31337") process.exit(1); // make sure network is hardhat
Expand Down
1 change: 1 addition & 0 deletions scripts/migrations/migrate_2.2.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function migrate(env) {

console.log("Compiling old contracts");
await hre.run("clean");

await hre.run("compile");

const { chainId } = await provider.getNetwork();
Expand Down
Loading

0 comments on commit 48285f2

Please sign in to comment.