Skip to content
Merged
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
31 changes: 3 additions & 28 deletions internal/migrate/staging_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ func (v *stagingValidator) ValidateContractUpdate(
interpreterProgram,
v.elaborations,
)

// Set the user defined type change checker
chainId, ok := chainIdMap[v.flow.Network().Name]
if !ok {
return fmt.Errorf("unsupported network: %s", v.flow.Network().Name)
}
validator.WithUserDefinedTypeChangeChecker(newUserDefinedTypeChangeCheckerFunc(chainId))
validator.WithUserDefinedTypeChangeChecker(migrations.NewUserDefinedTypeChangeCheckerFunc(chainId))

err = validator.Validate()
if err != nil {
Expand Down Expand Up @@ -443,30 +445,3 @@ 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
}
}