Commit e3e5390a by Hadrien Croubois

use a latest release as a reference

parent ef12bdef
......@@ -31,6 +31,5 @@ jobs:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: true
- run: npm run test:inheritance
- run: npm run layout:test
- name: Print gas report
run: cat gas-report.txt
......@@ -33,4 +33,5 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
- run: bash scripts/upgradeable/git-user-config.sh
- run: bash scripts/upgradeable/transpile-onto.sh ${{ steps.branch.outputs.name }} origin/${{ steps.branch.outputs.name }}
- run: bash scripts/upgradeable/layout-test.sh
- run: git push origin ${{ steps.branch.outputs.name }}
......@@ -11,6 +11,10 @@ const path = require('path');
const argv = require('yargs/yargs')()
.env('')
.options({
root: {
type: 'string',
default: '.',
},
ci: {
type: 'boolean',
default: false,
......@@ -58,6 +62,9 @@ const withOptimizations = argv.enableGasReport || argv.compileMode === 'producti
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
paths: {
root: argv.root,
},
solidity: {
version: argv.compiler,
settings: {
......
......@@ -31,9 +31,7 @@
"test": "hardhat test",
"test:inheritance": "node scripts/inheritanceOrdering artifacts/build-info/*",
"gas-report": "env ENABLE_GAS_REPORT=true npm run test",
"slither": "npm run clean && slither . --detect reentrancy-eth,reentrancy-no-eth,reentrancy-unlimited-gas",
"layout:build": "node scripts/upgradeable/layout.js artifacts/build-info/* --build storage-layout-cache.json",
"layout:test": "node scripts/upgradeable/layout.js artifacts/build-info/* --check storage-layout-cache.json"
"slither": "npm run clean && slither . --detect reentrancy-eth,reentrancy-no-eth,reentrancy-unlimited-gas"
},
"repository": {
"type": "git",
......
......@@ -2,23 +2,17 @@ const fs = require('fs');
const path = require('path');
const { findAll } = require('solidity-ast/utils');
const {
astDereferencer,
} = require('@openzeppelin/upgrades-core/dist/ast-dereferencer');
const { astDereferencer } = require('@openzeppelin/upgrades-core/dist/ast-dereferencer');
const { solcInputOutputDecoder } = require('@openzeppelin/upgrades-core/dist/src-decoder');
const { extractStorageLayout } = require('@openzeppelin/upgrades-core/dist/storage/extract');
const { StorageLayoutComparator } = require('@openzeppelin/upgrades-core/dist/storage/compare');
const { LayoutCompatibilityReport } = require('@openzeppelin/upgrades-core/dist/storage/report');
const {
solcInputOutputDecoder,
extractStorageLayout,
StorageLayoutComparator,
LayoutCompatibilityReport,
} = require('@openzeppelin/upgrades-core');
const { ref, head } = require('yargs').argv;
const { build, check, _: artifacts } = require('yargs').argv;
// build layout for current version of the code
const layout = {};
for (const artifact of artifacts) {
const { input, output } = require(path.resolve(__dirname, '../..', artifact));
function extractLayouts(file) {
const layout = {};
const { input, output } = require(file);
const decoder = solcInputOutputDecoder(input, output);
const deref = astDereferencer(output);
......@@ -41,29 +35,28 @@ for (const artifact of artifacts) {
).storage;
}
}
return layout;
}
// if the --check option is set, check compatibility of the current layout against the cache
if (check) {
const cache = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../..', check)));
const oldLayout = extractLayouts(ref);
const newLayout = extractLayouts(head);
for (const id in cache) {
for (const id in oldLayout) {
if (id in newLayout) {
const comparator = new StorageLayoutComparator();
const report = new LayoutCompatibilityReport(comparator.layoutLevenshtein(
cache[id],
layout[id],
oldLayout[id],
newLayout[id],
{ allowAppend: false },
));
if (!report.ok) {
console.log(`Storage incompatibility in ${id}`);
if (report.ok) {
console.log(`INFO: ${id} is storage compliant`);
} else {
console.log(`ERROR: Storage incompatibility in ${id}`);
console.log(report.explain());
process.exitCode = 1;
}
} else {
console.log(`WARNING: ${id} is missing from the current branch`);
}
}
// if the --build option is set, write the layout results
if (build) {
fs.writeFileSync(path.resolve(__dirname, '../..', build), JSON.stringify(layout));
}
}
\ No newline at end of file
#!/usr/bin/env bash
set -euo pipefail -x
TMP=`mktemp -d`
# get latest release
npm install --prefix $TMP @openzeppelin/contracts-upgradeable@latest
# preparing environment
mv $TMP/node_modules/@openzeppelin/contracts-upgradeable $TMP/contracts
# compile contracts
ROOT=. npx hardhat compile
ROOT=$TMP npx hardhat compile
# compare the layouts
node scripts/upgradeable/layout-rebuild-and-compare.js \
--ref $TMP/artifacts/build-info/*.json \
--head $PWD/artifacts/build-info/*.json
# TODO: delete even if comparaison fails
rm $TMP
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment