Skip to content

Commit

Permalink
Merge pull request #64 from provable-things/upgrade-checks
Browse files Browse the repository at this point in the history
feat(upgrades): <- adds tool to check compatibility for those
  • Loading branch information
gskapka authored Dec 5, 2022
2 parents cd57776 + bf91e7b commit 0186697
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "ptokens-erc777-smart-contract",
"version": "3.9.1",
"version": "3.10.0",
"description": "The pToken ERC777 smart-contract & CLI",
"main": "cli.js",
"scripts": {
"compile": "npx hardhat compile",
"compile": "ENDPOINT=0.0.0.0 npx hardhat compile",
"tests": "ENDPOINT=http://localhost:8545 npx hardhat test",
"test": "npm run tests",
"lint": "npx eslint ./"
"lint": "npx eslint ./",
"checkStorageCompatibility": "npm run compile && ENDPOINT=0.0.0.0 node ./scripts/check-storage-compatibility"
},
"repository": {
"type": "git",
Expand Down
42 changes: 42 additions & 0 deletions scripts/check-storage-compatibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable-next-line no-shadow */
const { ethers, upgrades } = require('hardhat')

const getContractNameFromCliArgs = _ =>
new Promise((resolve, reject) => {
if (process.argv.length <= 2) {
return reject(new Error('Could not find env arg for contract name!'))
} else {
const contractName = process.argv[2]
console.info(`✔ Finding contract called '${contractName}'...`)
return resolve(contractName)
}
})

// NOTE: This script accepts a contract name (which contract MUST exist in the `./contracts/` dir!)
// passed in via a command line arg. The script then compares that contract to the latest version of
// the pToken contract in this repo to check for storage incompatibilities.
//
// USAGE:
// `npm run checkStorageCompatibility <contractNameWithNoFileTypeExtension>`

const main = _ =>
getContractNameFromCliArgs()
.then(_previousContract =>
Promise.all([
ethers.getContractFactory(_previousContract),
ethers.getContractFactory('PToken')
])
)
.then(([ a, b ]) => {
console.info('✔ Contracts retreived! Checking compatibility...')
return upgrades.validateUpgrade(a, b)
})
.then(_ => console.info('✔ Storage IS compatible!'))
.catch(_err => {
if (_err.message.includes('HH700')) {
console.info('✘ Could not find contract! Make sure it exists in the `./contracts` dir!')
}
return Promise.reject(_err)
})

main().catch(console.error)

0 comments on commit 0186697

Please sign in to comment.