-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate contract updates #593
Conversation
…onflow/cadence into supun/validate-contract-updates
…/validate-contract-updates
23e1d2e
to
d09944b
Compare
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.
Nice work! Code looks overall great, just a few comments on re-using existing code and code organization.
runtime/runtime.go
Outdated
if isUpdate { | ||
validator := NewContractUpdateValidator(existingCode, program.Program) | ||
err := validator.Validate() |
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.
👏
@@ -6122,3 +6122,643 @@ func TestPanics(t *testing.T) { | |||
) | |||
assert.Error(t, err) | |||
} | |||
|
|||
func TestContractUpdateValidation(t *testing.T) { |
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.
Great tests! 👏
11ccdd3
to
6b8414f
Compare
6b8414f
to
4862f89
Compare
95e208f
to
c814b79
Compare
c814b79
to
11dba10
Compare
@turbolent Thanks for the suggestions! Added the required changes. |
e5fb27f
to
a255035
Compare
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.
Great refactor! Just a couple last comments and after that it should be ready to go
@@ -26,4 +26,5 @@ type Declaration interface { | |||
DeclarationIdentifier() *Identifier | |||
DeclarationKind() common.DeclarationKind | |||
DeclarationAccess() Access | |||
DeclarationMembers() *Members |
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.
👍
oldFields := oldDeclaration.DeclarationMembers().FieldsByIdentifier() | ||
newFields := newDeclaration.DeclarationMembers().Fields() | ||
|
||
// Updated contract has to have at-most the same number of field as the old contract. |
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.
👍
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.
Very nice! 👏
Work towards #588
Description
This PR introduces a validation step before updating a contract, to avoid any data inconsistencies.
✔️ This validate and prevents:
contract
->contract-interface
->contract
, that may again cause field type incompatibility (i.e: indirect update to an incompatible state)✔️ Things that are allowed:
For contributor use:
master
branchFiles changed
in the Github PR explorer