Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
e3e5390a
Commit
e3e5390a
authored
Mar 12, 2022
by
Hadrien Croubois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use a latest release as a reference
parent
ef12bdef
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
33 deletions
+56
-33
test.yml
.github/workflows/test.yml
+0
-1
transpile.yml
.github/workflows/transpile.yml
+1
-0
hardhat.config.js
hardhat.config.js
+7
-0
package.json
package.json
+1
-3
layout-rebuild-and-compare.js
scripts/upgradeable/layout-rebuild-and-compare.js
+23
-29
layout-test.sh
scripts/upgradeable/layout-test.sh
+24
-0
No files found.
.github/workflows/test.yml
View file @
e3e5390a
...
...
@@ -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
.github/workflows/transpile.yml
View file @
e3e5390a
...
...
@@ -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 }}
hardhat.config.js
View file @
e3e5390a
...
...
@@ -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
:
{
...
...
package.json
View file @
e3e5390a
...
...
@@ -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"
,
...
...
scripts/upgradeable/layout.js
→
scripts/upgradeable/layout
-rebuild-and-compare
.js
View file @
e3e5390a
...
...
@@ -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
],
l
ayout
[
id
],
oldLayout
[
id
],
newL
ayout
[
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`
);
}
}
\ 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
));
}
scripts/upgradeable/layout-test.sh
0 → 100644
View file @
e3e5390a
#!/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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment