Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions internal/util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func AbsolutePath(basePath, relativePath string) string {
return filepath.Join(filepath.Dir(basePath), relativePath)
}

// IsPathLocation returns true if the location is a file path (contains .cdc)
// IsPathLocation returns true if the location names a Cadence source file.
func IsPathLocation(location common.Location) bool {
stringLocation, ok := location.(common.StringLocation)
if !ok {
return false
}
return strings.Contains(stringLocation.String(), ".cdc")
return filepath.Ext(stringLocation.String()) == ".cdc"
}

// NormalizePathLocation normalizes a relative path import against a base location
Expand Down
17 changes: 17 additions & 0 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@ import (
"strings"
"testing"

"github.com/onflow/cadence/common"
"github.com/onflow/flow-go-sdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIsPathLocation(t *testing.T) {
for _, tc := range []struct {
name string
want bool
}{
{"contracts/Example.cdc", true},
{"contracts/Example.cdc.backup", false},
{"contracts.cdc/Example", false},
{"Example", false},
} {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, IsPathLocation(common.StringLocation(tc.name)))
})
}
}

func TestIsAddressValidForNetwork(t *testing.T) {
testnetAddr := flow.HexToAddress("8efde57e98c557fa") // Valid testnet address
emulatorAddr := flow.HexToAddress("f8d6e0586b0a20c7") // Valid emulator address
Expand Down
Loading