Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Sep 12, 2023
1 parent 6d35468 commit 193ff50
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
42 changes: 28 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
COVER_PROFILE := coverage.txt
# Disable go sum database lookup for private repos
GOPRIVATE := github.com/dapperlabs/*

# Ensure go bin path is in path (Especially for CI)
GOPATH ?= $(HOME)/go
PATH := $(PATH):$(GOPATH)/bin
# OS
UNAME := $(shell uname)
ifeq ($(OS),Windows_NT)
GOPATH ?= $(USERPROFILE)\go
PATH := $(PATH);$(GOPATH)\bin
else
GOPATH ?= $(HOME)/go
PATH := $(PATH):$(GOPATH)/bin
endif

# Set MKDIR variable based on OS
ifeq ($(OS),Windows_NT)
MKDIR := mkdir
else
MKDIR := mkdir -p
endif

MIXPANEL_PROJECT_TOKEN := 3fae49de272be1ceb8cf34119f747073
ACCOUNT_TOKEN := lilico:sF60s3wughJBmNh2
Expand All @@ -24,17 +35,20 @@ binary: $(BINARY)

.PHONY: install-tools
install-tools:
cd ${GOPATH}; \
mkdir -p ${GOPATH}; \
GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \
GO111MODULE=on go install github.com/matm/gocov-html@latest; \
GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \
GO111MODULE=on go install github.com/vektra/mockery/v2@latest;
$(MKDIR) ${GOPATH} && \
go env -w GO111MODULE=on && \
go install github.com/axw/gocov/gocov@latest && \
go install github.com/matm/gocov-html@latest && \
go install github.com/sanderhahn/gozip/cmd/gozip@latest && \
go install github.com/vektra/mockery/v2@latest;

.PHONY: test
test:
GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./...
cd flowkit; GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./...
go env -w GO111MODULE=on && \
go env -w CGO_ENABLED=0 && \
go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... && \
cd flowkit && \
go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./...

.PHONY: test-e2e-emulator
test-e2e-emulator:
Expand Down Expand Up @@ -104,13 +118,13 @@ check-schema:
.PHONY: check-tidy
check-tidy:
go mod tidy
cd flowkit; go mod tidy
cd flowkit && go mod tidy

.PHONY: generate-schema
generate-schema:
cd flowkit && go run ./cmd/flow-schema/flow-schema.go ./schema.json

.PHONY: generate
generate: install-tools
cd flowkit; \
cd flowkit && \
go generate ./...
17 changes: 9 additions & 8 deletions flowkit/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package flowkit
import (
"fmt"
"os"
"path/filepath"
"sort"
"testing"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -423,13 +424,13 @@ 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("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc"))
assert.Equal(t, sources[2], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc"))
assert.Equal(t, sources[3], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc"))
assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc"))
assert.Equal(t, sources[5], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc"))
assert.Equal(t, sources[6], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc"))

assert.Equal(t, targets[0], "f8d6e0586b0a20c1")
assert.Equal(t, targets[1], "f8d6e0586b0a20c1")
Expand Down
18 changes: 9 additions & 9 deletions internal/super/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (

func Test_AccountFromPath(t *testing.T) {
paths := [][]string{ // first is path, second is account name
{"cadence/contracts/alice/foo.cdc", "alice"},
{"cadence/contracts/alice", "alice"},
{"cadence/contracts/alice/boo/foo.cdc", ""},
{"cadence/contracts/foo.cdc", ""},
{"cadence/contracts/foo/bar/goo/foo", ""},
{filepath.FromSlash("cadence/contracts/alice/foo.cdc"), "alice"},
{filepath.FromSlash("cadence/contracts/alice"), "alice"},
{filepath.FromSlash("cadence/contracts/alice/boo/foo.cdc"), ""},
{filepath.FromSlash("cadence/contracts/foo.cdc"), ""},
{filepath.FromSlash("cadence/contracts/foo/bar/goo/foo"), ""},
}

for i, test := range paths {
Expand All @@ -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{
{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"},
{filepath.Join(cdcDir, "/contracts/foo.cdc"), filepath.FromSlash("cadence/contracts/foo.cdc")},
{filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), filepath.FromSlash("cadence/contracts/alice/foo.cdc")},
{filepath.Join(cdcDir, "/scripts/bar.cdc"), filepath.FromSlash("cadence/scripts/bar.cdc")},
{filepath.Join(cdcDir, "/bar.cdc"), filepath.FromSlash("cadence/bar.cdc")},
}

f := &projectFiles{
Expand Down
10 changes: 7 additions & 3 deletions internal/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package transactions

import (
"encoding/json"
"fmt"
"strings"
"testing"

Expand All @@ -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"
Expand Down Expand Up @@ -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 []
Expand All @@ -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": "[]",
Expand Down

0 comments on commit 193ff50

Please sign in to comment.