Skip to content

Commit

Permalink
Fix staging validator type change bug (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Apr 5, 2024
1 parent 5c0fa11 commit 050b039
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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
}
}

0 comments on commit 050b039

Please sign in to comment.