Skip to content

Commit

Permalink
Merge branch 'master' into evm/beta-commands
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
Gregor Gololicic committed Dec 12, 2023
2 parents 045b98e + 9cb8e40 commit 9c2ac8a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 23 deletions.
6 changes: 2 additions & 4 deletions flowkit/gateway/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func NewEmulatorGateway(key *EmulatorKey) *EmulatorGateway {
}

func NewEmulatorGatewayWithOpts(key *EmulatorKey, opts ...func(*EmulatorGateway)) *EmulatorGateway {

noopLogger := zerolog.Nop()
gateway := &EmulatorGateway{
ctx: context.Background(),
Expand All @@ -71,9 +70,8 @@ func NewEmulatorGatewayWithOpts(key *EmulatorKey, opts ...func(*EmulatorGateway)
}

gateway.emulator = newEmulator(key, gateway.emulatorOptions...)
logger := zerolog.Nop()
gateway.adapter = adapters.NewSDKAdapter(&logger, gateway.emulator)
gateway.accessAdapter = adapters.NewAccessAdapter(&logger, gateway.emulator)
gateway.adapter = adapters.NewSDKAdapter(gateway.logger, gateway.emulator)
gateway.accessAdapter = adapters.NewAccessAdapter(gateway.logger, gateway.emulator)
gateway.emulator.EnableAutoMine()
return gateway
}
Expand Down
4 changes: 2 additions & 2 deletions flowkit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/invopop/jsonschema v0.7.0
github.com/lmars/go-slip10 v0.0.0-20190606092855-400ba44fee12
github.com/onflow/cadence v0.42.5
github.com/onflow/flow-emulator v0.57.3
github.com/onflow/flow-go v0.32.4-0.20231111003039-3b479f6b0995
github.com/onflow/flow-emulator v0.58.0
github.com/onflow/flow-go v0.32.4-0.20231115172515-c1ec969fd6f2
github.com/onflow/flow-go-sdk v0.41.16
github.com/onflow/flow-go/crypto v0.24.10
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 4 additions & 0 deletions flowkit/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,14 @@ github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-emulator v0.57.3 h1:YvJIhPVI7LwfO0u61Joir0NjSUc4Lkrlvy3gDRHDSwQ=
github.com/onflow/flow-emulator v0.57.3/go.mod h1:621Xk9Dz/BKr61zfwJeLEFdHKWAU0UBn0SK9bSbT034=
github.com/onflow/flow-emulator v0.58.0 h1:/Zo+qznjqN2jJNOGQu1mFK2lZT3L6c8V18AmAzXLKZ8=
github.com/onflow/flow-emulator v0.58.0/go.mod h1:pi23Sx7kuj65dJRT7OIlio53XRAhLTUUhf3zV9TN3PA=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 h1:B4ll7e3j+MqTJv2122Enq3RtDNzmIGRu9xjV7fo7un0=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13/go.mod h1:kTMFIySzEJJeupk+7EmXs0EJ6CBWY/MV9fv9iYQk+RU=
github.com/onflow/flow-go v0.32.4-0.20231111003039-3b479f6b0995 h1:Q6dcqtPguVl+NcCKMyM2H1wpmdY1pFE6NIOU2jH/F7M=
github.com/onflow/flow-go v0.32.4-0.20231111003039-3b479f6b0995/go.mod h1:bKcX2932bIunkyXBKW9qmw8Z0zXpHol+5xCJCumV/H8=
github.com/onflow/flow-go v0.32.4-0.20231115172515-c1ec969fd6f2 h1:ujrwrJelTX0R3HtX9kSJRoU7bUtcdvf1Pmpvy31yvNQ=
github.com/onflow/flow-go v0.32.4-0.20231115172515-c1ec969fd6f2/go.mod h1:bKcX2932bIunkyXBKW9qmw8Z0zXpHol+5xCJCumV/H8=
github.com/onflow/flow-go-sdk v0.24.0/go.mod h1:IoptMLPyFXWvyd9yYA6/4EmSeeozl6nJoIv4FaEMg74=
github.com/onflow/flow-go-sdk v0.41.16 h1:HsmHwEVmj+iK+GszHbFseHh7Ii5W3PWOIRNAH/En08Q=
github.com/onflow/flow-go-sdk v0.41.16/go.mod h1:bVrVNoJKiwB6vW5Qbm5tFAfJBQ5we4uSQWnn9gNAFhQ=
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ require (
github.com/dukex/mixpanel v1.0.1
github.com/ethereum/go-ethereum v1.12.0
github.com/getsentry/sentry-go v0.25.0
github.com/go-git/go-git/v5 v5.10.0
github.com/go-git/go-git/v5 v5.11.0
github.com/gosuri/uilive v0.0.4
github.com/manifoldco/promptui v0.9.0
github.com/onflow/cadence v0.42.6
github.com/onflow/cadence-tools/languageserver v0.33.3
github.com/onflow/cadence-tools/test v0.14.4
github.com/onflow/cadence-tools/test v0.14.5-0.20231212143648-fb25e9aca2d4
github.com/onflow/fcl-dev-wallet v0.7.4
github.com/onflow/flixkit-go v0.3.1
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
Expand Down Expand Up @@ -195,7 +195,7 @@ require (
github.com/rs/zerolog v1.29.0 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
github.com/sourcegraph/jsonrpc2 v0.1.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ github.com/VictoriaMetrics/fastcache v1.5.3/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
Expand Down Expand Up @@ -345,8 +343,8 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmS
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOjbQ=
github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo=
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -753,8 +751,6 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -1071,8 +1067,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM=
github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/slok/go-http-metrics v0.10.0 h1:rh0LaYEKza5eaYRGDXujKrOln57nHBi4TtVhmNEpbgM=
github.com/slok/go-http-metrics v0.10.0/go.mod h1:lFqdaS4kWMfUKCSukjC47PdCeTk+hXDUVm8kLHRqJ38=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down
35 changes: 30 additions & 5 deletions internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type flagsTests struct {
CoverCode string `default:"all" flag:"covercode" info:"Use the covercode flag to calculate coverage report only for certain types of code. Available values are \"all\" & \"contracts\""`
Random bool `default:"false" flag:"random" info:"Use the random flag to execute test cases randomly"`
Seed int64 `default:"0" flag:"seed" info:"Use the seed flag to manipulate random execution of test cases"`
Name string `default:"" flag:"name" info:"Use the name flag to run only tests that match the given name"`
}

var testFlags = flagsTests{}
Expand Down Expand Up @@ -191,13 +192,32 @@ func testCode(
WithFileResolver(fileResolver(scriptPath, state)).
WithContracts(contracts)

results, err := runner.RunTests(string(code))
if err != nil {
return nil, err
if flags.Name != "" {
testFunctions, err := runner.GetTests(string(code))
if err != nil {
return nil, err
}

for _, testFunction := range testFunctions {
if testFunction != flags.Name {
continue
}

result, err := runner.RunTest(string(code), flags.Name)
if err != nil {
return nil, err
}
testResults[scriptPath] = []cdcTests.Result{*result}
}
} else {
results, err := runner.RunTests(string(code))
if err != nil {
return nil, err
}
testResults[scriptPath] = results
}
testResults[scriptPath] = results

for _, result := range results {
for _, result := range testResults[scriptPath] {
if result.Error != nil {
status = 1
break
Expand Down Expand Up @@ -337,6 +357,11 @@ func (r *result) String() string {
func (r *result) Oneliner() string {
var builder strings.Builder

if len(r.Results) == 0 {
builder.WriteString("No tests found")
return builder.String()
}

for scriptPath, testResult := range r.Results {
builder.WriteString(cdcTests.PrettyPrintResults(testResult, scriptPath))
}
Expand Down
87 changes: 87 additions & 0 deletions internal/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,91 @@ Seed: 1521
string(output),
)
})

t.Run("run specific test case by name", func(t *testing.T) {
t.Parallel()

// Setup
_, state, _ := util.TestMocks(t)

// Execute script
script := tests.TestScriptSimple
testFiles := map[string][]byte{
script.Filename: script.Source,
}
flags := flagsTests{
Name: "testSimple",
}

result, err := testCode(testFiles, state, flags)

assert.NoError(t, err)
assert.Len(t, result.Results, 1)
assert.NoError(t, result.Results[script.Filename][0].Error)

expected := "Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\n"
assert.Equal(
t,
expected,
result.Oneliner(),
)
})

t.Run("run specific test case by name multiple files", func(t *testing.T) {
t.Parallel()

// Setup
_, state, _ := util.TestMocks(t)

scriptPassing := tests.TestScriptSimple
scriptFailing := tests.TestScriptSimpleFailing

// Execute script
testFiles := map[string][]byte{
scriptPassing.Filename: scriptPassing.Source,
scriptFailing.Filename: scriptFailing.Source,
}
flags := flagsTests{
Name: "testSimple",
}

result, err := testCode(testFiles, state, flags)

assert.NoError(t, err)
assert.Len(t, result.Results, 2)
assert.NoError(t, result.Results[scriptPassing.Filename][0].Error)
assert.Error(t, result.Results[scriptFailing.Filename][0].Error)
assert.ErrorAs(t, result.Results[scriptFailing.Filename][0].Error, &stdlib.AssertionError{})
assert.Equal(
t,
"Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\nTest results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\n",
result.Oneliner(),
)
})

t.Run("run specific test case by name will do nothing if not found", func(t *testing.T) {
t.Parallel()

// Setup
_, state, _ := util.TestMocks(t)

// Execute script
script := tests.TestScriptSimple
testFiles := map[string][]byte{
script.Filename: script.Source,
}
flags := flagsTests{
Name: "doesNotExist",
}

result, err := testCode(testFiles, state, flags)

assert.NoError(t, err)
assert.Len(t, result.Results, 0)
assert.Equal(
t,
"No tests found",
result.Oneliner(),
)
})
}
2 changes: 1 addition & 1 deletion scaffolds.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Empty Cadence Project",
"repo": "https://github.com/sideninja/flow-empty-scaffold",
"description": "Empty project containing only basic folder structure and flow.json configuration.",
"commit": "0345c6263b06559eb47cf24fef8da8ea2f9a41ba"
"commit": "598612f4cdc7ee4487752ef203061082527216b4"
},
{
"name": "Simple Cadence Project",
Expand Down

0 comments on commit 9c2ac8a

Please sign in to comment.