Commit e3e5390a by Hadrien Croubois

use a latest release as a reference

parent ef12bdef
...@@ -31,6 +31,5 @@ jobs: ...@@ -31,6 +31,5 @@ jobs:
FORCE_COLOR: 1 FORCE_COLOR: 1
ENABLE_GAS_REPORT: true ENABLE_GAS_REPORT: true
- run: npm run test:inheritance - run: npm run test:inheritance
- run: npm run layout:test
- name: Print gas report - name: Print gas report
run: cat gas-report.txt run: cat gas-report.txt
...@@ -33,4 +33,5 @@ jobs: ...@@ -33,4 +33,5 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
- run: bash scripts/upgradeable/git-user-config.sh - 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/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 }} - run: git push origin ${{ steps.branch.outputs.name }}
...@@ -11,6 +11,10 @@ const path = require('path'); ...@@ -11,6 +11,10 @@ const path = require('path');
const argv = require('yargs/yargs')() const argv = require('yargs/yargs')()
.env('') .env('')
.options({ .options({
root: {
type: 'string',
default: '.',
},
ci: { ci: {
type: 'boolean', type: 'boolean',
default: false, default: false,
...@@ -58,6 +62,9 @@ const withOptimizations = argv.enableGasReport || argv.compileMode === 'producti ...@@ -58,6 +62,9 @@ const withOptimizations = argv.enableGasReport || argv.compileMode === 'producti
* @type import('hardhat/config').HardhatUserConfig * @type import('hardhat/config').HardhatUserConfig
*/ */
module.exports = { module.exports = {
paths: {
root: argv.root,
},
solidity: { solidity: {
version: argv.compiler, version: argv.compiler,
settings: { settings: {
......
...@@ -31,9 +31,7 @@ ...@@ -31,9 +31,7 @@
"test": "hardhat test", "test": "hardhat test",
"test:inheritance": "node scripts/inheritanceOrdering artifacts/build-info/*", "test:inheritance": "node scripts/inheritanceOrdering artifacts/build-info/*",
"gas-report": "env ENABLE_GAS_REPORT=true npm run test", "gas-report": "env ENABLE_GAS_REPORT=true npm run test",
"slither": "npm run clean && slither . --detect reentrancy-eth,reentrancy-no-eth,reentrancy-unlimited-gas", "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"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
......
...@@ -2,23 +2,17 @@ const fs = require('fs'); ...@@ -2,23 +2,17 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const { findAll } = require('solidity-ast/utils'); const { findAll } = require('solidity-ast/utils');
const { const { astDereferencer } = require('@openzeppelin/upgrades-core/dist/ast-dereferencer');
astDereferencer, const { solcInputOutputDecoder } = require('@openzeppelin/upgrades-core/dist/src-decoder');
} = require('@openzeppelin/upgrades-core/dist/ast-dereferencer'); 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 { const { ref, head } = require('yargs').argv;
solcInputOutputDecoder,
extractStorageLayout,
StorageLayoutComparator,
LayoutCompatibilityReport,
} = require('@openzeppelin/upgrades-core');
const { build, check, _: artifacts } = require('yargs').argv; function extractLayouts(file) {
const layout = {};
// build layout for current version of the code const { input, output } = require(file);
const layout = {};
for (const artifact of artifacts) {
const { input, output } = require(path.resolve(__dirname, '../..', artifact));
const decoder = solcInputOutputDecoder(input, output); const decoder = solcInputOutputDecoder(input, output);
const deref = astDereferencer(output); const deref = astDereferencer(output);
...@@ -41,29 +35,28 @@ for (const artifact of artifacts) { ...@@ -41,29 +35,28 @@ for (const artifact of artifacts) {
).storage; ).storage;
} }
} }
return layout;
} }
// if the --check option is set, check compatibility of the current layout against the cache const oldLayout = extractLayouts(ref);
if (check) { const newLayout = extractLayouts(head);
const cache = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../..', check)));
for (const id in cache) { for (const id in oldLayout) {
if (id in newLayout) {
const comparator = new StorageLayoutComparator(); const comparator = new StorageLayoutComparator();
const report = new LayoutCompatibilityReport(comparator.layoutLevenshtein( const report = new LayoutCompatibilityReport(comparator.layoutLevenshtein(
cache[id], oldLayout[id],
layout[id], newLayout[id],
{ allowAppend: false }, { allowAppend: false },
)); ));
if (report.ok) {
if (!report.ok) { console.log(`INFO: ${id} is storage compliant`);
console.log(`Storage incompatibility in ${id}`); } else {
console.log(`ERROR: Storage incompatibility in ${id}`);
console.log(report.explain()); console.log(report.explain());
process.exitCode = 1; process.exitCode = 1;
} }
} else {
console.log(`WARNING: ${id} is missing from the current branch`);
} }
} }
\ No newline at end of file
// if the --build option is set, write the layout results
if (build) {
fs.writeFileSync(path.resolve(__dirname, '../..', build), JSON.stringify(layout));
}
#!/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