-
Notifications
You must be signed in to change notification settings - Fork 199
Conversation
Let's please create some issues for the pending items |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job! Congrats @spalladino 👏
Left really minor comments :)
@@ -192,12 +192,13 @@ export default class ZosNetworkFile { | |||
this.setDependency(name, fn(this.getDependency(name))); | |||
} | |||
|
|||
addContract(alias, instance) { | |||
addContract(alias, instance, extraData = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using object arguments when those are kind of irrelevant to the rest of the parameters and if they are some type of configuration for the function being called. In this case, note that that extraData
has the same importance as the rest of the parameters, we are deconstructing it as is, and it is impossible for the reader to know what data is actually being handled here. It forces the reader to look up for calls to this function to understand how it should be called. It is definitely not a blocker, but it is one of the things we should decide and standardize for the whole codebase.
const [begin, count] = src.split(':'); | ||
return sourceCode.substr(begin, count); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move all this logic outside the controller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely!
DELETION_COST = 2; | ||
|
||
export function compareStorageLayouts(original, updated) { | ||
// TODO: Check cases with empty storage (both for original and updated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move this TODO
to an issue please
} | ||
|
||
// Adapted from https://gist.github.com/andrei-m/982927 by Andrei Mackenzie | ||
function levenshtein(originalStorage, updatedStorage, areEqualFn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
const originalType = originalTypes[originalVar.type], | ||
updatedType = updatedTypes[updatedVar.type]; | ||
|
||
// TODO: Compare complex types (structs and enums) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, let's create another issue for that
? this.getValueTypeInfo(node.valueType) | ||
: this.getTypeInfo(node) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍
kind: 'elementary', | ||
label: 'function' | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we move this one and the one above to constants?
4098342
to
9d69946
Compare
@facuspagnuolo I implemented the suggested changes, and added issues #112, #113, and #114 to cover for the missing pieces (all in Backlog for now). The only thing I'm wondering is whether we may want to add a feature toggle to disable these warnings until those issues are finished, though I think we can do that later if we find out that we can't get them ready by the next release. |
When running zos-push, validate that the storage layout is compatible with the previous version of the contract, and abort push otherwise. All warnings are displayed to the user, eg:
Storage layout is extracted from the contract's AST by the Storage class in lib, and is stored along with other contract data (such as bytecode hash) in the zos.network.json file. It is then retrieved for comparison on the next zos push. The format is a tuple
(storage, types)
, similar to the format discussed in ethereum/solidity#4017, wherestorage
contains the array of variables, with references to thetypes
dictionary with detailed info on each type.Comparison is handled by the Layout class in lib, and uses a modified levenshtein algorithm for calculating the minimum change between both storages. Changes are identified as additions (either at the end or mid-contract, with additions at the end computed at zero cost for the algorithm), deletions (end or mid-contract), or substitutions (renames, typechanges, or both).
Fixes #37
Pending: