Skip to content
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

Fix staging validator type change bug #1495

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion internal/migrate/stage_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func stageContract(
}
} else if err != nil {
logger.Error(validator.prettyPrintError(err, common.StringLocation(contract.Location)))
return nil, fmt.Errorf("errors were found while validating the contract code, and your contract HAS NOT been staged, you can use the --skip-validation flag to bypass this check")
return nil, fmt.Errorf("errors were found while attempting to perform preliminary validation of the contract code, and your contract HAS NOT been staged, however you can use the --skip-validation flag to bypass this check & stage the contract anyway")
} else {
logger.Info("No issues found while validating contract code\n")
logger.Info("DISCLAIMER: Pre-staging validation checks are not exhaustive and do not guarantee the contract will work as expected, please monitor the status of your contract using the `flow migrate is-validated` command\n")
Expand Down
32 changes: 32 additions & 0 deletions internal/migrate/staging_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (v *stagingValidator) ValidateContractUpdate(
interpreterProgram,
v.elaborations,
)
chainId, ok := chainIdMap[v.flow.Network().Name]
if !ok {
return fmt.Errorf("unsupported network: %s", v.flow.Network().Name)
}
validator.WithUserDefinedTypeChangeChecker(newUserDefinedTypeChangeCheckerFunc(chainId))

err = validator.Validate()
if err != nil {
Expand Down Expand Up @@ -438,3 +443,30 @@ func (a *accountContractNamesProviderImpl) GetAccountContractNames(
) ([]string, error) {
return a.resolverFunc(address)
}

// TEMPORARY: this is not exported by flow-go and should be removed once it is
// This is for a quick fix to get the validator working
func newUserDefinedTypeChangeCheckerFunc(
chainID flow.ChainID,
) func(oldTypeID common.TypeID, newTypeID common.TypeID) (checked, valid bool) {

typeChangeRules := map[common.TypeID]common.TypeID{}

compositeTypeRules := migrations.NewCompositeTypeConversionRules(chainID)
for typeID, newStaticType := range compositeTypeRules {
typeChangeRules[typeID] = newStaticType.ID()
}

interfaceTypeRules := migrations.NewInterfaceTypeConversionRules(chainID)
for typeID, newStaticType := range interfaceTypeRules {
typeChangeRules[typeID] = newStaticType.ID()
}

return func(oldTypeID common.TypeID, newTypeID common.TypeID) (checked, valid bool) {
expectedNewTypeID, found := typeChangeRules[oldTypeID]
if found {
return true, expectedNewTypeID == newTypeID
}
return false, false
}
}
Loading