diff --git a/internal/dependencymanager/dependencyinstaller.go b/internal/dependencymanager/dependencyinstaller.go index 997d2ae4c..5fb562bd3 100644 --- a/internal/dependencymanager/dependencyinstaller.go +++ b/internal/dependencymanager/dependencyinstaller.go @@ -316,44 +316,40 @@ func (di *DependencyInstaller) fetchDependencies(networkName string, address flo return fmt.Errorf("contracts are nil for account: %s", address) } - found := false + contract, ok := account.Contracts[contractName] + if !ok { + return fmt.Errorf("contract %s not found at address %s", contractName, address.String()) + } - for _, contract := range account.Contracts { - program, err := project.NewProgram(contract, nil, "") - if err != nil { - return fmt.Errorf("failed to parse program: %w", err) - } + program, err := project.NewProgram(contract, nil, "") + if err != nil { + return fmt.Errorf("failed to parse program: %w", err) + } - parsedContractName, err := program.Name() - if err != nil { - return fmt.Errorf("failed to parse contract name: %w", err) - } + parsedContractName, err := program.Name() + if err != nil { + return fmt.Errorf("failed to parse contract name: %w", err) + } - if parsedContractName == contractName { - found = true + if parsedContractName != contractName { + return fmt.Errorf("contract name mismatch: expected %s, got %s", contractName, parsedContractName) + } - if err := di.handleFoundContract(networkName, address.String(), assignedName, parsedContractName, program); err != nil { - return fmt.Errorf("failed to handle found contract: %w", err) - } + if err := di.handleFoundContract(networkName, address.String(), assignedName, contractName, program); err != nil { + return fmt.Errorf("failed to handle found contract: %w", err) + } - if program.HasAddressImports() { - imports := program.AddressImportDeclarations() - for _, imp := range imports { - contractName := imp.Identifiers[0].String() - err := di.fetchDependencies(networkName, flowsdk.HexToAddress(imp.Location.String()), contractName, contractName) - if err != nil { - return err - } - } + if program.HasAddressImports() { + imports := program.AddressImportDeclarations() + for _, imp := range imports { + contractName := imp.Identifiers[0].String() + err := di.fetchDependencies(networkName, flowsdk.HexToAddress(imp.Location.String()), contractName, contractName) + if err != nil { + return err } } } - if !found { - errMsg := fmt.Sprintf("contract %s not found for account %s on network %s", contractName, address, networkName) - di.Logger.Error(errMsg) - } - return nil }