From 86d02cbf8d7469dc5a2168746a92212c897cb1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 29 Aug 2024 13:08:34 -0700 Subject: [PATCH] fix fetching of dependencies do not parse all contracts in account, only get the requested contract --- .../dependencymanager/dependencyinstaller.go | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) 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 }