Skip to content
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
e8f4765
extract and store struct and enum members
frangio Dec 12, 2020
3f03499
implement type id parsing
frangio Dec 15, 2020
2e88710
expand storage layouts before comparing
frangio Dec 15, 2020
8c60e39
add assertion to type id parsing
frangio Dec 15, 2020
eb0b3ab
lay foundation to compare storage fields recursively
frangio Dec 16, 2020
994ecf5
compare struct members recursively
frangio Dec 16, 2020
dd64a36
test type id parser with unknown mapping key from oz cli migration
frangio Dec 16, 2020
aee06bc
implement type compatibility check
frangio Dec 16, 2020
5fe1b8e
explain parameter Type
frangio Dec 16, 2020
4f2968f
add comment explaining ASTDereferencer
frangio Dec 17, 2020
a847daa
typo
frangio Dec 17, 2020
5a4c06b
add note about UserDefinedTypes
frangio Dec 17, 2020
c3890fc
explain implementation decisions and add todo about recursive types
frangio Dec 17, 2020
97126ff
remove unsafeAllowCustomTypes flag
frangio Dec 17, 2020
45e29f9
Merge branch 'master' into extract-structs
frangio Dec 17, 2020
d5c1d9d
fix error message expected in test
frangio Dec 17, 2020
e6b9c05
add note about generic function
frangio Dec 17, 2020
5ea5c09
improve comment
frangio Dec 17, 2020
aeb6414
add documentation for parse-type-id
frangio Dec 17, 2020
09e9b64
remove unused argument to matchStorageField
frangio Dec 17, 2020
22e48e5
rename canGrow -> allowAppend
frangio Dec 17, 2020
8de6555
add more tests for parse-type-id
frangio Dec 17, 2020
9fd620f
grammar
frangio Dec 17, 2020
e99ed1c
limit enum members to 256
frangio Dec 17, 2020
4eec9ae
detect and fail with recursive types
frangio Dec 18, 2020
90f6c56
validate compatibility of array member type
frangio Dec 18, 2020
2eab1cf
add more tests comparing upgraded types
frangio Dec 18, 2020
4898422
improve storage layout tests
frangio Dec 21, 2020
7b19889
add initial support for complex storage layout error reporting
frangio Dec 21, 2020
fb35da6
cache results of comparing two types
frangio Dec 21, 2020
07af28b
return StorageMatchResult instances from compatibleTypes
frangio Dec 21, 2020
4dda814
rename message -> errorMessage
frangio Dec 23, 2020
4ef2b3e
fix regex
frangio Dec 23, 2020
277f271
make ErrorDescriptor.hint a function
frangio Dec 23, 2020
ff629d4
remove unused default value
frangio Dec 23, 2020
7b8a49d
rename operation kinds to past tense
frangio Dec 23, 2020
8be7b72
remove unused default value
frangio Dec 23, 2020
cfa3e26
improve enum incompatibility error message
frangio Dec 24, 2020
036fac6
simplify error message
frangio Dec 24, 2020
20f603e
break up storage.ts into separate files
frangio Dec 24, 2020
935ed03
fix tests
frangio Dec 29, 2020
f944834
use t.like for levenshtein tests
frangio Dec 29, 2020
f70bedf
refactor levenshtein
frangio Dec 29, 2020
a66e07b
add Manifest.loadAll to load all manifests
frangio Dec 31, 2020
7312b91
reorganize validate module
frangio Jan 2, 2021
33d9363
rename RunValidation -> ValidationRunData
frangio Jan 2, 2021
db023c8
define new validation data version
frangio Jan 2, 2021
949d587
add DeepArray utils
frangio Jan 3, 2021
710c051
add a migration of all manifests as a first step
frangio Jan 5, 2021
1689918
improve handling of outdated validations in hardhat
frangio Jan 5, 2021
15007cf
Merge remote-tracking branch 'origin/master' into extract-structs
frangio Jan 5, 2021
cd7e576
fix validations cache errors on hardhat
frangio Jan 5, 2021
a0d7da9
stabilize test snapshot
frangio Jan 5, 2021
02852be
fix Manifest.loadAll
frangio Jan 5, 2021
a98b83f
fix manifest-migrate tests
frangio Jan 5, 2021
096f3fc
fix findVersionWithoutMetadataMatches
frangio Jan 5, 2021
fe53519
refactor storage comparison reporting
frangio Jan 10, 2021
b4f361a
stop extracting struct and enum errors
frangio Jan 10, 2021
415c959
remove unsafeAllowCustomTypes flag tests
frangio Jan 10, 2021
4a4f72d
use unsafeAllowCustomTypes when there are missing members
frangio Jan 10, 2021
3454497
remove more old tests
frangio Jan 10, 2021
55c37bf
rename 'different kinds' error to 'obvious mismatch'
frangio Jan 10, 2021
ed483db
add tests for obvious mismatch errors
frangio Jan 10, 2021
10244d1
add test for changed inner struct member
frangio Jan 10, 2021
8a6a2d5
Merge remote-tracking branch 'origin/master' into extract-structs
frangio Jan 10, 2021
8ce0ded
migrate manifest version earlier in hardhat
frangio Jan 10, 2021
f93c856
fix manifest-migrate validating manifest version before migration
frangio Jan 10, 2021
98bc695
migrate manifest version earlier in truffle
frangio Jan 11, 2021
f729466
add tests for storage layout error reporting and fix found bugs
frangio Jan 11, 2021
9cdd007
pass missing option to approve missing members and add tests
frangio Jan 11, 2021
39ad18f
shorten warning
frangio Jan 11, 2021
e03e40b
add more detail to expected data in test
frangio Jan 11, 2021
2fa7173
improve plugin tests involving structs and enums
frangio Jan 11, 2021
7a97e4f
remove redundant type change detail in struct change description
frangio Jan 11, 2021
3f4888e
add backwards compatible interface for storage module
frangio Jan 19, 2021
dc8972a
simplify deepEqual
frangio Jan 19, 2021
bb563c6
add function to get or update storage layout in manifest
frangio Jan 19, 2021
42f63e9
remove migrateAllManifests
frangio Jan 19, 2021
72f386e
rename manifest-migrate -> manifest-storage-layout
frangio Jan 19, 2021
d10dd2c
revert breaking change to assertStorageUpgradeSafe arguments
frangio Jan 19, 2021
5977eb6
disable color in tests
frangio Jan 19, 2021
cdd906b
Merge remote-tracking branch 'origin/master' into extract-structs
frangio Jan 22, 2021
065d242
tweak wording for storage error
frangio Jan 22, 2021
20ea4a0
print a note when unsafeAllowCustomTypes is not needed
frangio Jan 22, 2021
b9b19e6
lint
frangio Jan 22, 2021
7f10362
detect when dependencies should be updated and notify
frangio Jan 22, 2021
42dbf3e
clean up whitespace around warnings
frangio Jan 22, 2021
a5e180a
update FAQ entry about structs and enums
frangio Jan 22, 2021
84999a7
fix error from merge
frangio Jan 22, 2021
106aecf
update api docs
frangio Jan 22, 2021
6ad37ae
update faq
frangio Jan 22, 2021
335bc1d
improve messaging and formatting of storage layout report
frangio Jan 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions packages/core/contracts/test/ManifestMigrate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.8;

contract ManifestMigrateLayout {
struct T {
bool b;
}

struct S {
uint x;
string s;
T t;
}

enum E {
E1,
E2
}

uint x1;
T t1;
S s1;
string s2;
bool b1;
E e1;
}

contract ManifestMigrateUnique is ManifestMigrateLayout {
function useAll() external {
x1 = 5;
t1 = T({ b: true });
s1 = S({ x: 6, s: "ok", t: t1 });
s2 = "no";
b1 = false;
e1 = E.E2;
}
}

contract ManifestMigrateUnambiguous0 is ManifestMigrateLayout {
function useAll() external {
x1 = 10;
t1 = T({ b: false });
s1 = S({ x: 6, s: "string", t: t1 });
s2 = "ok";
b1 = false;
e1 = E.E1;
}
}

// These two are expected to have the same bytecode modulo metadata.
contract ManifestMigrateUnambiguous1 is ManifestMigrateUnambiguous0 { }
contract ManifestMigrateUnambiguous2 is ManifestMigrateUnambiguous0 { }

// These two are expected to have the same bytecode modulo metadata and similar
// layout, but different types (see struct D members);
contract ManifestMigrateAmbiguous1 is ManifestMigrateUnique {
struct D {
uint w;
}
D d1;
function test() external {
d1.w += 1;
}
}
contract ManifestMigrateAmbiguous2 is ManifestMigrateUnique {
struct D {
uint z;
}
D d1;
function test() external {
d1.z += 1;
}
}
231 changes: 231 additions & 0 deletions packages/core/contracts/test/Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,234 @@ contract StorageUpgrade_Delete_V1 {
contract StorageUpgrade_Delete_V2 {
address x2;
}

contract StorageUpgrade_Struct_V1 {
struct StructInner {
uint y;
}
struct Struct1 {
uint x;
string s1;
string s2;
StructInner inner;
}
Struct1 data1;
Struct1 data2;
mapping (uint => Struct1) m;
Struct1[10] a1;
Struct1[10] a2;
Struct1 data3;
}

contract StorageUpgrade_Struct_V2_Ok {
struct StructInner {
uint y;
}
struct Struct2 {
uint x;
string s1;
string s2;
StructInner inner;
}
struct Struct2Plus {
uint x;
string s1;
string s2;
StructInner inner;
uint z;
}
Struct2 data1;
Struct2 data2;
mapping (uint => Struct2Plus) m;
Struct2[10] a1;
Struct2[10] a2;
Struct2 data3;
}

contract StorageUpgrade_Struct_V2_Bad {
struct StructInner {
uint y;
}
struct StructInnerPlus {
uint y;
uint z;
}
struct Struct2Minus {
uint x;
string s2;
StructInner inner;
}
struct Struct2Plus {
uint x;
string s1;
string s2;
StructInner inner;
uint z;
}
struct Struct2Changed {
string x;
uint s1;
string s2;
StructInnerPlus inner;
}
Struct2Minus data1;
Struct2Plus data2;
mapping (uint => Struct2Minus) m;
Struct2Minus[10] a1;
Struct2Plus[10] a2;
Struct2Changed data3;
}

contract StorageUpgrade_Enum_V1 {
enum Enum1 {
A,
B
}
Enum1 data1;
Enum1 data2;
Enum1 data3;
Enum1 data4;
}

contract StorageUpgrade_Enum_V2_Ok {
enum Enum2 {
A,
B
}
enum Enum2Larger {
A,
B,
C
}
Enum2Larger data1;
Enum2 data2;
Enum2 data3;
Enum2 data4;
}

contract StorageUpgrade_Enum_V2_Bad {
enum Enum2Delete {
A
}
enum Enum2Replace {
A,
X
}
enum Enum2Insert {
X,
A,
B
}
Enum2Delete data1;
Enum2Replace data2;
Enum2Insert data3;

enum Enum2TooLarge {
A,
B,
V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54, V55, V56, V57, V58, V59, V60, V61, V62, V63, V64, V65, V66, V67, V68, V69, V70, V71, V72, V73, V74, V75, V76, V77, V78, V79, V80, V81, V82, V83, V84, V85, V86, V87, V88, V89, V90, V91, V92, V93, V94, V95, V96, V97, V98, V99, V100, V101, V102, V103, V104, V105, V106, V107, V108, V109, V110, V111, V112, V113, V114, V115, V116, V117, V118, V119, V120, V121, V122, V123, V124, V125, V126, V127, V128, V129, V130, V131, V132, V133, V134, V135, V136, V137, V138, V139, V140, V141, V142, V143, V144, V145, V146, V147, V148, V149, V150, V151, V152, V153, V154, V155, V156, V157, V158, V159, V160, V161, V162, V163, V164, V165, V166, V167, V168, V169, V170, V171, V172, V173, V174, V175, V176, V177, V178, V179, V180, V181, V182, V183, V184, V185, V186, V187, V188, V189, V190, V191, V192, V193, V194, V195, V196, V197, V198, V199, V200, V201, V202, V203, V204, V205, V206, V207, V208, V209, V210, V211, V212, V213, V214, V215, V216, V217, V218, V219, V220, V221, V222, V223, V224, V225, V226, V227, V228, V229, V230, V231, V232, V233, V234, V235, V236, V237, V238, V239, V240, V241, V242, V243, V244, V245, V246, V247, V248, V249, V250, V251, V252, V253, V254, V255, V256,
OneTooMany
}
Enum2TooLarge data4;
}

contract StorageUpgrade_Recursive_V1 {
struct Recursive {
mapping (uint => Recursive) s;
}
Recursive data;
}

contract StorageUpgrade_Recursive_V2 {
struct Recursive {
mapping (uint => Recursive) s;
}
Recursive data;
}

contract StorageUpgrade_Rename_V1 {
uint x1;
uint x2;
uint x3;
}

contract StorageUpgrade_Rename_V2 {
uint x1;
uint renamed;
uint x3;
}

contract StorageUpgrade_Replace_V1 {
uint x1;
uint x2;
uint x3;
}

contract StorageUpgrade_Replace_V2 {
uint x1;
string renamed;
uint x3;
}

contract StorageUpgrade_ObviousMismatch_V1 {
struct S {
uint m;
}

uint x1;
S s1;
uint[] a1;
}

contract StorageUpgrade_ObviousMismatch_V2_Bad {
string x1;
uint s1;
mapping (uint => uint) a1;
}

contract StorageUpgrade_Contract_V1 {
StorageUpgrade_Contract_V1 data;
}

contract StorageUpgrade_Contract_V2 {
StorageUpgrade_Contract_V2 data;
}

contract StorageUpgrade_Array_V1 {
uint[20] x1;
uint[20] x2;
uint[20] x3;
uint[] x4;
mapping (uint => uint[20]) m;
}

contract StorageUpgrade_Array_V2_Ok {
uint[20] x1;
uint[20] x2;
uint[20] x3;
uint[] x4;
mapping (uint => uint[25]) m;
}

contract StorageUpgrade_Array_V2_Bad {
uint[15] x1;
uint[25] x2;
uint[] x3;
uint[20] x4;
mapping (uint => uint[15]) m;
}

contract StorageUpgrade_Mapping_V1 {
mapping (uint => uint[10]) m1;
mapping (string => uint) m2;
}

contract StorageUpgrade_Mapping_V2_Ok {
mapping (uint => uint[10]) m1;
mapping (string => uint) m2;
}

contract StorageUpgrade_Mapping_V2_Bad {
mapping (uint => uint) m1;
mapping (bool => uint) m2;
}
54 changes: 0 additions & 54 deletions packages/core/contracts/test/Validations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,60 +55,6 @@ import './ValidationsImport.sol';
contract ImportedParentHasStateVariableAssignment is ImportedHasStateVariableAssignment {
}

contract HasStruct {
struct Foo {
bool bar;
}

Foo foo;
}

contract HasEnum {
enum Foo { BAR }
}

contract ParentHasStruct is HasStruct {}
contract ParentHasEnum is HasEnum {}

library LibraryWithEnum {
enum Animal { DOG, CAT }

function isCat(Animal animal) internal pure returns (bool) {
return animal == Animal.CAT;
}
}

library LibraryWithStruct {
struct Animal {
string kind;
uint age;
}

function getAge(Animal memory animal) internal pure returns (uint) {
return animal.age;
}
}

contract UsesLibraryWithStruct {
using LibraryWithStruct for LibraryWithStruct.Animal;

LibraryWithStruct.Animal animal;

function getAge() public view returns (uint) {
return animal.getAge();
}
}

contract UsesLibraryWithEnum {
using LibraryWithEnum for LibraryWithEnum.Animal;

LibraryWithEnum.Animal animal;

function isCat() public view returns (bool) {
return animal.isCat();
}
}

// For each of 3 dimensions, libraries usage can be
// 1. implicit or explicit (_use for_ directive or not)
// 2. upgrade safe or unsafe
Expand Down
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prepare:contracts": "hardhat compile",
"prepublishOnly": "bash scripts/copy-artifacts.sh",
"test": "tsc -b && hardhat compile --force && ava",
"test:watch": "hardhat compile --force && fgbg 'ava --watch' 'tsc -b --watch'",
"test:watch": "hardhat compile --force && fgbg 'ava --watch' 'tsc -b --watch' --",
"version": "node ../../scripts/bump-changelog.js"
},
"devDependencies": {
Expand Down Expand Up @@ -50,7 +50,8 @@
"ethereumjs-util": "^7.0.3",
"fp-ts": "^2.7.1",
"io-ts": "^2.2.9",
"promise.allsettled": "^1.0.2",
"proper-lockfile": "^4.1.1",
"solidity-ast": "^0.4.4"
"solidity-ast": "^0.4.15"
}
}
Loading