Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
32 changes: 8 additions & 24 deletions internal/cadence/lint_test.go
Comment thread
holyfuchs marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func Test_Lint(t *testing.T) {

t.Run("lints file with no issues", func(t *testing.T) {
t.Parallel()
Comment thread
holyfuchs marked this conversation as resolved.

state := setupMockState(t)

results, err := lintFiles(state, false, "NoError.cdc")
Expand All @@ -68,7 +67,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "foo/WithImports.cdc")
Expand All @@ -91,7 +89,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "NoError.cdc", "foo/WithImports.cdc")
Expand All @@ -117,7 +114,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "LintWarning.cdc")
Expand Down Expand Up @@ -163,7 +159,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "LintError.cdc")
Expand Down Expand Up @@ -205,7 +200,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "ReplacementHint.cdc")
Expand All @@ -232,7 +226,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "WithFlowkitImport.cdc")
Expand All @@ -254,7 +247,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "StdlibImportsContract.cdc")
Expand Down Expand Up @@ -288,7 +280,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "StdlibImportsTransaction.cdc")
Expand Down Expand Up @@ -322,7 +313,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "StdlibImportsScript.cdc")
Expand All @@ -344,7 +334,6 @@ func Test_Lint(t *testing.T) {

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

state := setupMockState(t)

results, err := lintFiles(state, false, "StdlibImportsCrypto.cdc")
Expand All @@ -366,7 +355,6 @@ 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)

results, err := lintFiles(state, false, "TransactionImportingContractWithNestedImports.cdc")
Expand All @@ -388,7 +376,6 @@ 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)

results, err := lintFiles(state, false, "ContractA.cdc")
Expand All @@ -411,7 +398,6 @@ 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)

results, err := lintFiles(state, false, "ContractC.cdc")
Expand All @@ -427,7 +413,6 @@ 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)

results, err := lintFiles(state, false, "imports/testaddr/DepA.cdc")
Expand All @@ -450,7 +435,6 @@ 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)

// Verify that AddDependencyAsContract automatically adds Source to Aliases
Expand Down Expand Up @@ -577,11 +561,11 @@ func setupMockState(t *testing.T) *flowkit.State {
_ = afero.WriteFile(mockFs, "Helper.cdc", []byte(`
access(all) contract Helper {
access(all) let name: String

init() {
self.name = "Helper"
}

access(all) fun greet(): String {
return "Hello from ".concat(self.name)
}
Expand All @@ -590,7 +574,7 @@ func setupMockState(t *testing.T) *flowkit.State {

_ = afero.WriteFile(mockFs, "ContractWithNestedImports.cdc", []byte(`
import Helper from "./Helper.cdc"

access(all) contract ContractWithNestedImports {
access(all) fun test(): String {
return Helper.greet()
Expand All @@ -601,7 +585,7 @@ func setupMockState(t *testing.T) *flowkit.State {

_ = afero.WriteFile(mockFs, "TransactionImportingContractWithNestedImports.cdc", []byte(`
import ContractWithNestedImports from "ContractWithNestedImports"

transaction() {
prepare(signer: auth(Storage) &Account) {
log(ContractWithNestedImports.test())
Expand Down Expand Up @@ -647,7 +631,7 @@ func setupMockStateWithAccountAccess(t *testing.T) *flowkit.State {
// ContractA imports and calls ContractB's account function - should work (same account)
_ = afero.WriteFile(mockFs, "ContractA.cdc", []byte(`
import ContractB from "ContractB"

access(all) contract ContractA {
access(all) fun callB() {
ContractB.accountOnlyFunction()
Expand All @@ -659,7 +643,7 @@ func setupMockStateWithAccountAccess(t *testing.T) *flowkit.State {
// ContractC imports and calls ContractB's account function - should fail (different account)
_ = afero.WriteFile(mockFs, "ContractC.cdc", []byte(`
import ContractB from "ContractB"

access(all) contract ContractC {
access(all) fun callB() {
ContractB.accountOnlyFunction()
Expand Down Expand Up @@ -734,7 +718,7 @@ func setupMockStateWithDependencies(t *testing.T) *flowkit.State {
// DepA imports and calls DepB's account function (like FlowEVMBridgeConfig)
_ = afero.WriteFile(mockFs, "imports/testaddr/DepA.cdc", []byte(`
import DepB from "DepB"

access(all) contract DepA {
access(all) fun callDepB(forType: Type) {
DepB.pauseConfig(forType: forType)
Expand Down Expand Up @@ -833,7 +817,7 @@ func setupMockStateWithSourceOnly(t *testing.T) *flowkit.State {
// SourceA imports and calls SourceB's account function
_ = afero.WriteFile(mockFs, "imports/testaddr/SourceA.cdc", []byte(`
import SourceB from "SourceB"

access(all) contract SourceA {
access(all) fun callSourceB() {
SourceB.sourceOnlyFunction()
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