diff --git a/flowkit/config/json/account.go b/flowkit/config/json/account.go index 6a6b0d178..7708ee35a 100644 --- a/flowkit/config/json/account.go +++ b/flowkit/config/json/account.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "regexp" "strings" @@ -224,7 +225,7 @@ func transformAdvancedToConfig(accountName string, a advancedAccount) (*config.A if a.Key.Location == "" { return nil, fmt.Errorf("missing location to a file containing the private key value for the account %s", accountName) } - key.Location = a.Key.Location + key.Location = filepath.FromSlash(a.Key.Location) } return &config.Account{ @@ -326,7 +327,7 @@ func transformAdvancedKeyToJSON(key config.AccountKey) advanceKey { case config.KeyTypeGoogleKMS: advancedKey.ResourceID = key.ResourceID case config.KeyTypeFile: - advancedKey.Location = key.Location + advancedKey.Location = filepath.ToSlash(key.Location) } return advancedKey diff --git a/flowkit/config/json/account_test.go b/flowkit/config/json/account_test.go index 21eb6a1ef..0cb836828 100644 --- a/flowkit/config/json/account_test.go +++ b/flowkit/config/json/account_test.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "testing" "github.com/onflow/flow-go-sdk" @@ -114,7 +115,7 @@ func Test_ConfigAccountKeysAdvancedFile(t *testing.T) { assert.Equal(t, "f8d6e0586b0a20c7", account.Address.String()) assert.Equal(t, "SHA3_256", key.HashAlgo.String()) assert.Equal(t, "ECDSA_P256", key.SigAlgo.String()) - assert.Equal(t, "./test.pkey", key.Location) + assert.Equal(t, filepath.FromSlash("./test.pkey"), key.Location) assert.Equal(t, "", key.ResourceID) jsonAccs := transformAccountsToJSON(accounts) diff --git a/flowkit/config/json/contract.go b/flowkit/config/json/contract.go index 39a400f63..b1a12b6b1 100644 --- a/flowkit/config/json/contract.go +++ b/flowkit/config/json/contract.go @@ -21,6 +21,7 @@ package json import ( "encoding/json" "fmt" + "path/filepath" "github.com/invopop/jsonschema" "github.com/onflow/flow-go-sdk" @@ -70,7 +71,7 @@ func transformContractsToJSON(contracts config.Contracts) jsonContracts { // if simple case if !c.IsAliased() { jsonContracts[c.Name] = jsonContract{ - Simple: c.Location, + Simple: filepath.ToSlash(c.Location), } } else { // if advanced config // check if we already created for this name then add or create @@ -81,7 +82,7 @@ func transformContractsToJSON(contracts config.Contracts) jsonContracts { jsonContracts[c.Name] = jsonContract{ Advanced: jsonContractAdvanced{ - Source: c.Location, + Source: filepath.ToSlash(c.Location), Aliases: aliases, }, } @@ -110,7 +111,7 @@ func (j *jsonContract) UnmarshalJSON(b []byte) error { // simple err := json.Unmarshal(b, &source) if err == nil { - j.Simple = source + j.Simple = filepath.FromSlash(source) return nil } @@ -118,6 +119,7 @@ func (j *jsonContract) UnmarshalJSON(b []byte) error { err = json.Unmarshal(b, &advancedFormat) if err == nil { j.Advanced = advancedFormat + j.Advanced.Source = filepath.FromSlash(j.Advanced.Source) } else { return err } diff --git a/flowkit/config/json/contract_test.go b/flowkit/config/json/contract_test.go index 0ddb2d28a..bd9ab0800 100644 --- a/flowkit/config/json/contract_test.go +++ b/flowkit/config/json/contract_test.go @@ -19,6 +19,7 @@ package json import ( "encoding/json" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -43,8 +44,8 @@ func Test_ConfigContractsSimple(t *testing.T) { marketContract, _ := contracts.ByName("KittyItemsMarket") assert.NotNil(t, marketContract) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItems.cdc", contract.Location) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItemsMarket.cdc", marketContract.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItems.cdc"), contract.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItemsMarket.cdc"), marketContract.Location) } func Test_ConfigContractsComplex(t *testing.T) { @@ -73,8 +74,8 @@ func Test_ConfigContractsComplex(t *testing.T) { kittyItemsMarket, _ := contracts.ByName("KittyItemsMarket") assert.NotNil(t, kittyItemsMarket) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItems.cdc", kittyItems.Location) - assert.Equal(t, "./cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc", kittyItemsMarket.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItems.cdc"), kittyItems.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc"), kittyItemsMarket.Location) assert.True(t, kittyItemsMarket.Aliases.ByNetwork("emulator") == nil) @@ -115,19 +116,19 @@ func Test_ConfigContractsAliases(t *testing.T) { assert.NotNil(t, fungibleToken) assert.True(t, fungibleToken.IsAliased()) assert.Equal(t, "e5a8b7f23e8b548f", fungibleToken.Aliases.ByNetwork("emulator").Address.String()) - assert.Equal(t, "../hungry-kitties/cadence/contracts/FungibleToken.cdc", fungibleToken.Location) + assert.Equal(t, filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc"), fungibleToken.Location) kibble, _ := contracts.ByName("Kibble") assert.NotNil(t, kibble) assert.True(t, kibble.IsAliased()) - assert.Equal(t, "../hungry-kitties/cadence/contracts/Kibble.cdc", kibble.Location) + assert.Equal(t, filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc"), kibble.Location) assert.Equal(t, "ead892083b3e2c6c", kibble.Aliases.ByNetwork("testnet").Address.String()) assert.Equal(t, "f8d6e0586b0a20c7", kibble.Aliases.ByNetwork("emulator").Address.String()) nft, _ := contracts.ByName("NonFungibleToken") assert.NotNil(t, nft) assert.False(t, nft.IsAliased()) - assert.Equal(t, nft.Location, "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") + assert.Equal(t, nft.Location, filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) } func Test_TransformContractToJSON(t *testing.T) { diff --git a/flowkit/config/loader_test.go b/flowkit/config/loader_test.go index 85a36b8b9..d77a74e54 100644 --- a/flowkit/config/loader_test.go +++ b/flowkit/config/loader_test.go @@ -20,6 +20,7 @@ package config_test import ( "fmt" "os" + "path/filepath" "testing" "github.com/onflow/flow-cli/flowkit/config" @@ -459,5 +460,5 @@ func Test_LoadAccountFileType(t *testing.T) { assert.NoError(t, err) assert.Len(t, conf.Accounts, 1) - assert.Equal(t, "./test.pkey", acc.Key.Location) + assert.Equal(t, filepath.FromSlash("./test.pkey"), acc.Key.Location) } diff --git a/flowkit/project/deployment.go b/flowkit/project/deployment.go index 6f97afd86..f8b4f1431 100644 --- a/flowkit/project/deployment.go +++ b/flowkit/project/deployment.go @@ -20,6 +20,7 @@ package project import ( "fmt" + "path/filepath" "gonum.org/v1/gonum/graph" "gonum.org/v1/gonum/graph/simple" @@ -86,7 +87,7 @@ func (d *Deployment) add(contract *Contract) error { } d.contracts = append(d.contracts, c) - d.contractsByLocation[c.Location()] = c + d.contractsByLocation[filepath.Clean(c.Location())] = c d.contractsByName[c.Name] = c return nil diff --git a/flowkit/project/deployment_test.go b/flowkit/project/deployment_test.go index e22c87c8b..f5916ea7c 100644 --- a/flowkit/project/deployment_test.go +++ b/flowkit/project/deployment_test.go @@ -38,7 +38,7 @@ type testContract struct { var addresses = test.AddressGenerator() var testContractA = testContract{ - location: "ContractA.cdc", + location: "foobar/ContractA.cdc", code: []byte(`pub contract ContractA {}`), accountAddress: addresses.New(), } @@ -50,7 +50,7 @@ var testContractB = testContract{ } var testContractC = testContract{ - location: "ContractC.cdc", + location: "foobar/ContractC.cdc", code: []byte(` import ContractA from "ContractA.cdc" @@ -62,7 +62,7 @@ var testContractC = testContract{ var testContractD = testContract{ location: "ContractD.cdc", code: []byte(` - import ContractC from "ContractC.cdc" + import ContractC from "foobar/ContractC.cdc" pub contract ContractD {} `), @@ -91,7 +91,7 @@ var testContractF = testContract{ var testContractG = testContract{ location: "ContractG.cdc", code: []byte(` - import ContractA from "ContractA.cdc" + import ContractA from "foobar/ContractA.cdc" import ContractB from "ContractB.cdc" pub contract ContractG {} diff --git a/flowkit/project/imports.go b/flowkit/project/imports.go index 07f57206b..268b0e86e 100644 --- a/flowkit/project/imports.go +++ b/flowkit/project/imports.go @@ -20,7 +20,7 @@ package project import ( "fmt" - "path" + "path/filepath" "github.com/onflow/flow-go-sdk" ) @@ -49,7 +49,7 @@ func (i *ImportReplacer) Replace(program *Program) (*Program, error) { for _, imp := range imports { // check if import by path exists (e.g. import X from ["./X.cdc"]) - importLocation := path.Clean(absolutePath(program.Location(), imp)) + importLocation := filepath.Clean(absolutePath(program.Location(), imp)) address, isPath := contractsLocations[importLocation] if isPath { program.replaceImport(imp, address) @@ -72,18 +72,18 @@ func (i *ImportReplacer) Replace(program *Program) (*Program, error) { func (i *ImportReplacer) getContractsLocations() map[string]string { locationAddress := make(map[string]string) for _, contract := range i.contracts { - locationAddress[path.Clean(contract.Location())] = contract.AccountAddress.String() + locationAddress[filepath.Clean(contract.Location())] = contract.AccountAddress.String() // add also by name since we might use the new import schema locationAddress[contract.Name] = contract.AccountAddress.String() } for source, target := range i.aliases { - locationAddress[path.Clean(source)] = flow.HexToAddress(target).String() + locationAddress[filepath.Clean(source)] = flow.HexToAddress(target).String() } return locationAddress } func absolutePath(basePath, relativePath string) string { - return path.Join(path.Dir(basePath), relativePath) + return filepath.Join(filepath.Dir(basePath), relativePath) } diff --git a/flowkit/state.go b/flowkit/state.go index 96d2c8d99..1fc05c517 100644 --- a/flowkit/state.go +++ b/flowkit/state.go @@ -21,7 +21,6 @@ package flowkit import ( "fmt" "os" - "path" "path/filepath" "github.com/onflow/flow-go-sdk/crypto" @@ -173,7 +172,7 @@ func (p *State) DeploymentContractsByNetwork(network config.Network) ([]*project contract := project.NewContract( c.Name, - path.Clean(location), + filepath.Clean(location), code, account.Address, account.Name, @@ -213,7 +212,7 @@ func (p *State) AliasesForNetwork(network config.Network) project.LocationAliase for _, contract := range p.conf.Contracts { if contract.IsAliased() && contract.Aliases.ByNetwork(network.Name) != nil { alias := contract.Aliases.ByNetwork(network.Name).Address.String() - aliases[path.Clean(contract.Location)] = alias // alias for import by file location + aliases[filepath.Clean(contract.Location)] = alias // alias for import by file location aliases[contract.Name] = alias // alias for import by name } } diff --git a/flowkit/state_test.go b/flowkit/state_test.go index a7b2a9b6c..af39e923b 100644 --- a/flowkit/state_test.go +++ b/flowkit/state_test.go @@ -21,6 +21,7 @@ package flowkit import ( "fmt" "os" + "path/filepath" "sort" "testing" @@ -343,7 +344,7 @@ func generateAliasesComplexProject() State { func Test_GetContractsByNameSimple(t *testing.T) { p := generateSimpleProject() - path := "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc" + path := filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") af.WriteFile(path, []byte("pub contract{}"), os.ModePerm) contracts, err := p.DeploymentContractsByNetwork(config.EmulatorNetwork) @@ -399,21 +400,22 @@ func Test_GetContractsByNameComplex(t *testing.T) { require.NoError(t, err) require.Equal(t, 7, len(contracts)) - //sort names so tests are deterministic + //sort contracts by name so tests are deterministic + sort.Slice(contracts, func(i, j int) bool { + return contracts[i].Name < contracts[j].Name + }) + contractNames := funk.Map(contracts, func(c *project.Contract) string { return c.Name }).([]string) - sort.Strings(contractNames) sources := funk.Map(contracts, func(c *project.Contract) string { return c.Location() }).([]string) - sort.Strings(sources) targets := funk.Map(contracts, func(c *project.Contract) string { return c.AccountAddress.String() }).([]string) - sort.Strings(targets) assert.Equal(t, contractNames[0], "FungibleToken") assert.Equal(t, contractNames[1], "Kibble") @@ -423,21 +425,21 @@ func Test_GetContractsByNameComplex(t *testing.T) { assert.Equal(t, contractNames[5], "KittyItemsMarket") assert.Equal(t, contractNames[6], "NonFungibleToken") - assert.Equal(t, sources[0], "../hungry-kitties/cadence/contracts/FungibleToken.cdc") - assert.Equal(t, sources[1], "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") - assert.Equal(t, sources[2], "cadence/kibble/contracts/Kibble.cdc") - assert.Equal(t, sources[3], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[4], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[5], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") - assert.Equal(t, sources[6], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") + assert.Equal(t, sources[0], filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")) + assert.Equal(t, sources[1], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc")) + assert.Equal(t, sources[2], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[3], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) + assert.Equal(t, sources[5], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) + assert.Equal(t, sources[6], filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) assert.Equal(t, targets[0], "f8d6e0586b0a20c1") assert.Equal(t, targets[1], "f8d6e0586b0a20c1") - assert.Equal(t, targets[2], "f8d6e0586b0a20c1") + assert.Equal(t, targets[2], "f8d6e0586b0a20c7") assert.Equal(t, targets[3], "f8d6e0586b0a20c1") - assert.Equal(t, targets[4], "f8d6e0586b0a20c1") - assert.Equal(t, targets[5], "f8d6e0586b0a20c7") - assert.Equal(t, targets[6], "f8d6e0586b0a20c7") + assert.Equal(t, targets[4], "f8d6e0586b0a20c7") + assert.Equal(t, targets[5], "f8d6e0586b0a20c1") + assert.Equal(t, targets[6], "f8d6e0586b0a20c1") } func Test_EmulatorConfigComplex(t *testing.T) { @@ -485,7 +487,7 @@ func Test_GetAliases(t *testing.T) { contracts, _ := p.DeploymentContractsByNetwork(config.EmulatorNetwork) assert.Len(t, aliases, 2) - assert.Equal(t, aliases["../hungry-kitties/cadence/contracts/FungibleToken.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aliases[filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")], "ee82856bf20e2aa6") assert.Len(t, contracts, 1) assert.Equal(t, contracts[0].Name, "NonFungibleToken") } @@ -503,11 +505,11 @@ func Test_GetAliasesComplex(t *testing.T) { assert.Equal(t, cEmulator[0].Name, "NonFungibleToken") assert.Len(t, aEmulator, 4) - assert.Equal(t, aEmulator["../hungry-kitties/cadence/contracts/FungibleToken.cdc"], "ee82856bf20e2aa6") - assert.Equal(t, aEmulator["../hungry-kitties/cadence/contracts/Kibble.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aEmulator[filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")], "ee82856bf20e2aa6") + assert.Equal(t, aEmulator[filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc")], "ee82856bf20e2aa6") assert.Len(t, aTestnet, 2) - assert.Equal(t, aTestnet["../hungry-kitties/cadence/contracts/Kibble.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aTestnet[filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc")], "ee82856bf20e2aa6") assert.Len(t, cTestnet, 2) assert.Equal(t, cTestnet[0].Name, "NonFungibleToken") diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 1ccb73536..d611123ac 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -22,7 +22,7 @@ import ( "errors" "fmt" "os" - "path" + "path/filepath" "github.com/spf13/viper" ) @@ -51,7 +51,7 @@ func FileDir() string { if err != nil { dir = "." } - return path.Join(dir, settingsDir) + return filepath.Join(dir, settingsDir) } // Set updates settings file with new value for provided key diff --git a/internal/super/files.go b/internal/super/files.go index c86437fe6..d1388bfa2 100644 --- a/internal/super/files.go +++ b/internal/super/files.go @@ -22,7 +22,6 @@ import ( "fmt" "io/fs" "os" - "path" "path/filepath" "time" @@ -58,7 +57,7 @@ type contractChange struct { func newProjectFiles(projectPath string) *projectFiles { return &projectFiles{ - cadencePath: path.Join(projectPath, cadenceDir), + cadencePath: filepath.Join(projectPath, cadenceDir), watcher: watcher.New(), } } @@ -121,7 +120,7 @@ func (f *projectFiles) transactions() ([]string, error) { // This function returns two channels, accountChange which reports any changes on the accounts folders and // contractChange which reports any changes to the contract files. func (f *projectFiles) watch() (<-chan accountChange, <-chan contractChange, error) { - err := f.watcher.AddRecursive(path.Join(f.cadencePath, contractDir)) + err := f.watcher.AddRecursive(filepath.Join(f.cadencePath, contractDir)) if err != nil { return nil, nil, errors.Wrap(err, "add recursive files failed") } @@ -193,7 +192,7 @@ func (f *projectFiles) watch() (<-chan accountChange, <-chan contractChange, err // getFilePaths returns a list of only Cadence files that are inside the provided directory. func (f *projectFiles) getCadenceFilepaths(dir string) ([]string, error) { - dir = path.Join(f.cadencePath, dir) + dir = filepath.Join(f.cadencePath, dir) paths := make([]string, 0) err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if path == dir || d.IsDir() || filepath.Ext(path) != cadenceExt { // we only want to get .cdc files in the dir @@ -218,7 +217,7 @@ func (f *projectFiles) getCadenceFilepaths(dir string) ([]string, error) { // relProjectPath gets a filepath relative to the project directory including the base cadence directory. // eg. a path /Users/Mike/Dev/project/cadence/contracts/foo.cdc will become cadence/contracts/foo.cdc func (f *projectFiles) relProjectPath(file string) (string, error) { - rel, err := filepath.Rel(path.Dir(f.cadencePath), file) + rel, err := filepath.Rel(filepath.Dir(f.cadencePath), file) if err != nil { return "", errors.Wrap(err, "failed getting project relative path") } diff --git a/internal/super/files_test.go b/internal/super/files_test.go index 08358e615..9f9888017 100644 --- a/internal/super/files_test.go +++ b/internal/super/files_test.go @@ -20,7 +20,7 @@ package super import ( "fmt" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -36,7 +36,7 @@ func Test_AccountFromPath(t *testing.T) { } for i, test := range paths { - name, ok := accountFromPath(test[0]) + name, ok := accountFromPath(filepath.FromSlash(test[0])) assert.Equal(t, test[1] != "", ok) // if we don't provide a name we mean it shouldn't be returned assert.Equal(t, test[1], name, fmt.Sprintf("failed test %d", i)) } @@ -45,10 +45,10 @@ func Test_AccountFromPath(t *testing.T) { func Test_RelativeProjectPath(t *testing.T) { cdcDir := "/Users/Mike/Dev/my-project/cadence" paths := [][]string{ - {path.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, - {path.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, - {path.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, - {path.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, + {filepath.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, + {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, + {filepath.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, + {filepath.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, } f := &projectFiles{ @@ -56,8 +56,8 @@ func Test_RelativeProjectPath(t *testing.T) { } for i, test := range paths { - rel, err := f.relProjectPath(test[0]) + rel, err := f.relProjectPath(filepath.FromSlash(test[0])) assert.NoError(t, err) - assert.Equal(t, test[1], rel, fmt.Sprintf("test %d failed", i)) + assert.Equal(t, filepath.FromSlash(test[1]), rel, fmt.Sprintf("test %d failed", i)) } } diff --git a/internal/super/setup.go b/internal/super/setup.go index 2b54703bd..96168a7f8 100644 --- a/internal/super/setup.go +++ b/internal/super/setup.go @@ -25,7 +25,6 @@ import ( "io" "net/http" "os" - "path" "path/filepath" "time" @@ -123,7 +122,7 @@ func getTargetDirectory(directory string) (string, error) { return "", err } - target := path.Join(pwd, directory) + target := filepath.Join(pwd, directory) info, err := os.Stat(target) if !os.IsNotExist(err) { if !info.IsDir() { diff --git a/internal/test/test.go b/internal/test/test.go index 12772902b..32098beaa 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -23,7 +23,7 @@ import ( "encoding/json" "fmt" "os" - "path" + "path/filepath" "strings" cdcTests "github.com/onflow/cadence-tools/test" @@ -100,7 +100,7 @@ func run( var file []byte var err error - ext := path.Ext(testFlags.CoverProfile) + ext := filepath.Ext(testFlags.CoverProfile) if ext == ".json" { file, err = json.MarshalIndent(coverageReport, "", " ") } else if ext == ".lcov" { @@ -223,11 +223,11 @@ func fileResolver(scriptPath string, state *flowkit.State) cdcTests.FileResolver } func absolutePath(basePath, filePath string) string { - if path.IsAbs(filePath) { + if filepath.IsAbs(filePath) { return filePath } - return path.Join(path.Dir(basePath), filePath) + return filepath.Join(filepath.Dir(basePath), filePath) } type result struct { diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index ad9e799c8..ef49d676a 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -20,6 +20,7 @@ package transactions import ( "encoding/json" + "fmt" "strings" "testing" @@ -31,6 +32,7 @@ import ( "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/accounts" "github.com/onflow/flow-cli/flowkit/config" + "github.com/onflow/flow-cli/flowkit/output" "github.com/onflow/flow-cli/flowkit/tests" "github.com/onflow/flow-cli/flowkit/transactions" "github.com/onflow/flow-cli/internal/command" @@ -344,10 +346,10 @@ Payload (hidden, use --include payload)`, "\n"), result.String()) t.Run("Success with result", func(t *testing.T) { result := transactionResult{tx: tx, result: txResult} - assert.Equal(t, strings.TrimPrefix(` + expectedString := strings.TrimPrefix(fmt.Sprintf(` Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537 Block Height 1 -Status ✅ SEALED +Status %s SEALED ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f Payer 0000000000000002 Authorizers [] @@ -372,7 +374,9 @@ Events: Code (hidden, use --include code) -Payload (hidden, use --include payload)`, "\n"), result.String()) +Payload (hidden, use --include payload)`, output.OkEmoji()), "\n") + + assert.Equal(t, expectedString, result.String()) assert.Equal(t, map[string]any{ "authorizers": "[]", diff --git a/internal/util/prompt.go b/internal/util/prompt.go index 5c721ed07..deb194d73 100644 --- a/internal/util/prompt.go +++ b/internal/util/prompt.go @@ -21,7 +21,7 @@ package util import ( "fmt" "os" - "path" + "path/filepath" "strconv" "strings" @@ -685,7 +685,7 @@ func InstallPathPrompt(defaultPath string) string { os.Exit(-1) } - return path.Clean(install) + return filepath.Clean(install) } type ScaffoldItem struct { diff --git a/internal/util/util.go b/internal/util/util.go index c47c62cbd..f928ded19 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -23,7 +23,7 @@ import ( "encoding/hex" "fmt" "os" - "path" + "path/filepath" "strings" "text/tabwriter" @@ -46,7 +46,7 @@ func AddToGitIgnore(filename string, loader flowkit.ReaderWriter) error { if err != nil { return err } - gitIgnorePath := path.Join(currentWd, ".gitignore") + gitIgnorePath := filepath.Join(currentWd, ".gitignore") gitIgnoreFiles := "" filePermissions := os.FileMode(0644)