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 contract/dependencies conflict checker #1600

Merged
merged 2 commits into from
May 16, 2024
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
45 changes: 21 additions & 24 deletions internal/dependencymanager/dependencyinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ func (f *dependencyManagerFlagsCollection) AddToCommand(cmd *cobra.Command) {
}

type DependencyInstaller struct {
Gateways map[string]gateway.Gateway
Logger output.Logger
State *flowkit.State
SkipDeployments bool
SkipAlias bool
logs categorizedLogs
initialContractsState config.Contracts
dependencies map[string]config.Dependency
Gateways map[string]gateway.Gateway
Logger output.Logger
State *flowkit.State
SkipDeployments bool
SkipAlias bool
logs categorizedLogs
dependencies map[string]config.Dependency
}

// NewDependencyInstaller creates a new instance of DependencyInstaller
Expand All @@ -137,13 +136,12 @@ func NewDependencyInstaller(logger output.Logger, state *flowkit.State, flags de
}

return &DependencyInstaller{
Gateways: gateways,
Logger: logger,
State: state,
SkipDeployments: flags.skipDeployments,
SkipAlias: flags.skipAlias,
initialContractsState: *state.Contracts(), // Copy at this point in time
dependencies: make(map[string]config.Dependency),
Gateways: gateways,
Logger: logger,
State: state,
SkipDeployments: flags.skipDeployments,
SkipAlias: flags.skipAlias,
dependencies: make(map[string]config.Dependency),
}, nil
}

Expand Down Expand Up @@ -207,25 +205,24 @@ func (di *DependencyInstaller) Add(depSource, customName string) error {
}

func (di *DependencyInstaller) addDependency(dep config.Dependency) error {
if _, exists := di.dependencies[dep.Source.Address.String()]; exists {
sourceString := fmt.Sprintf("%s://%s.%s", dep.Source.NetworkName, dep.Source.Address.String(), dep.Source.ContractName)

if _, exists := di.dependencies[sourceString]; exists {
return nil
}

di.dependencies[dep.Source.Address.String()] = dep
di.dependencies[sourceString] = dep

return nil

}

// checkForConflictingContracts checks if any of the dependencies conflict with contracts already in the state
func (di *DependencyInstaller) checkForConflictingContracts() {
for _, dependency := range di.dependencies {
_, err := di.initialContractsState.ByName(dependency.Name)
if err != nil {
if !isCoreContract(dependency.Name) {
msg := util.MessageWithEmojiPrefix("❌", fmt.Sprintf("Contract named %s already exists in flow.json", dependency.Name))
di.logs.issues = append(di.logs.issues, msg)
}
foundContract, _ := di.State.Contracts().ByName(dependency.Name)
if foundContract != nil && !foundContract.IsDependency {
msg := util.MessageWithEmojiPrefix("❌", fmt.Sprintf("Contract named %s already exists in flow.json", dependency.Name))
di.logs.issues = append(di.logs.issues, msg)
}
}
}
Expand Down
Loading