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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ endif
.PHONY: ci
ci: generate test coverage

.PHONY: $(BINARY)
$(BINARY):
CGO_ENABLED=1 \
CGO_CFLAGS="-O2 -D__BLST_PORTABLE__ -std=gnu11" \
Expand Down
48 changes: 16 additions & 32 deletions internal/cadence/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("lints file with no issues", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "NoError.cdc")
require.NoError(t, err)
Expand All @@ -67,9 +66,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("lints file with import", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "foo/WithImports.cdc")
require.NoError(t, err)
Expand All @@ -90,9 +88,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("lints multiple files", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "NoError.cdc", "foo/WithImports.cdc")
require.NoError(t, err)
Expand All @@ -116,9 +113,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("lints file with warning", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "LintWarning.cdc")
require.NoError(t, err)
Expand Down Expand Up @@ -148,9 +144,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("lints file with error", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "LintError.cdc")
require.NoError(t, err)
Expand Down Expand Up @@ -190,9 +185,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("generates synthetic replacement for replacement category diagnostics", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "ReplacementHint.cdc")
require.NoError(t, err)
Expand All @@ -217,9 +211,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("linter resolves imports from flowkit state", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "WithFlowkitImport.cdc")
require.NoError(t, err)
Expand All @@ -239,9 +232,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("resolves stdlib imports contracts", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "StdlibImportsContract.cdc")
require.NoError(t, err)
Expand Down Expand Up @@ -273,9 +265,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("resolves stdlib imports transactions", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "StdlibImportsTransaction.cdc")
require.NoError(t, err)
Expand Down Expand Up @@ -307,9 +298,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("resolves stdlib imports scripts", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "StdlibImportsScript.cdc")
require.NoError(t, err)
Expand All @@ -329,9 +319,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("resolves stdlib imports Crypto", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "StdlibImportsCrypto.cdc")
require.NoError(t, err)
Expand All @@ -351,9 +340,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("resolves nested imports when contract imported by name", func(t *testing.T) {
t.Parallel()

state := setupMockState(t)
t.Parallel()

results, err := lintFiles(state, "TransactionImportingContractWithNestedImports.cdc")
require.NoError(t, err)
Expand All @@ -373,9 +361,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("allows access(account) when contracts on same account", func(t *testing.T) {
t.Parallel()

state := setupMockStateWithAccountAccess(t)
t.Parallel()

results, err := lintFiles(state, "ContractA.cdc")
require.NoError(t, err)
Expand All @@ -396,9 +383,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("denies access(account) when contracts on different accounts", func(t *testing.T) {
t.Parallel()

state := setupMockStateWithAccountAccess(t)
t.Parallel()

results, err := lintFiles(state, "ContractC.cdc")
require.NoError(t, err)
Expand All @@ -412,9 +398,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("allows access(account) when dependencies on same account (peak-money repro)", func(t *testing.T) {
t.Parallel()

state := setupMockStateWithDependencies(t)
t.Parallel()

results, err := lintFiles(state, "imports/testaddr/DepA.cdc")
require.NoError(t, err)
Expand All @@ -435,9 +420,8 @@ func Test_Lint(t *testing.T) {
})

t.Run("allows access(account) when dependencies have Source but no Aliases", func(t *testing.T) {
t.Parallel()

state := setupMockStateWithSourceOnly(t)
t.Parallel()

// Verify that AddDependencyAsContract automatically adds Source to Aliases
sourceAContract, _ := state.Contracts().ByName("SourceA")
Expand Down
56 changes: 56 additions & 0 deletions internal/test/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Flow CLI
*
* Copyright Flow Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test

import (
"fmt"
"testing"

"github.com/onflow/flow-go-sdk/crypto"
"github.com/onflow/flowkit/v2"
"github.com/onflow/flowkit/v2/accounts"
"github.com/onflow/flowkit/v2/tests"
)

func buildTestFiles(n int) map[string][]byte {
script := tests.TestScriptSimple
files := make(map[string][]byte, n)
for i := range n {
files[fmt.Sprintf("test_%02d_%s", i, script.Filename)] = script.Source
}
return files
}

func BenchmarkTestCode_NFiles(b *testing.B) {
rw, _ := tests.ReaderWriter()
state, err := flowkit.Init(rw)
if err != nil {
b.Fatal(err)
}
emulatorAccount, _ := accounts.NewEmulatorAccount(rw, crypto.ECDSA_P256, crypto.SHA3_256, "")
state.Accounts().AddOrUpdate(emulatorAccount)
testFiles := buildTestFiles(10)

for b.Loop() {
_, err := testCode(testFiles, state, flagsTests{})
if err != nil {
b.Fatal(err)
}
}
}
Loading
Loading