Skip to content

Commit

Permalink
Merge pull request #245 from bluesign/testting_helpers
Browse files Browse the repository at this point in the history
Move blockchain helper to separate package
  • Loading branch information
turbolent authored Nov 11, 2023
2 parents 6b85ff8 + aa98085 commit 305558d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

package test
package helpers

import (
_ "embed"
Expand All @@ -32,6 +32,8 @@ import (
//go:embed blockchain_helpers.cdc
var BlockchainHelpers []byte

const BlockchainHelpersLocation = common.IdentifierLocation("BlockchainHelpers")

func BlockchainHelpersChecker() *sema.Checker {
program, err := parser.ParseProgram(
nil,
Expand Down Expand Up @@ -73,8 +75,8 @@ func BlockchainHelpersChecker() *sema.Checker {
BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation {
return activation
},
AccessCheckMode: sema.AccessCheckModeStrict,
ImportHandler: importHandler,
AccessCheckMode: sema.AccessCheckModeStrict,
ImportHandler: importHandler,
},
)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion test/test_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"fmt"
"testing"

"github.com/onflow/cadence-tools/test/helpers"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -4762,7 +4764,7 @@ func TestBlockchainReset(t *testing.T) {
func TestBlockchainHelpersChecker(t *testing.T) {
t.Parallel()

checker := BlockchainHelpersChecker()
checker := helpers.BlockchainHelpersChecker()
err := checker.Check()
assert.NoError(t, err)
}
Expand Down
13 changes: 6 additions & 7 deletions test/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/onflow/flow-go/model/flow"

"github.com/onflow/cadence-tools/test/helpers"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
Expand Down Expand Up @@ -59,8 +60,6 @@ const afterEachFunctionName = "afterEach"

var testScriptLocation = common.NewScriptLocation(nil, []byte("test"))

const BlockchainHelpersLocation = common.IdentifierLocation("BlockchainHelpers")

var quotedLog = regexp.MustCompile("\"(.*)\"")

type Results []Result
Expand Down Expand Up @@ -454,7 +453,7 @@ func (r *TestRunner) initializeEnvironment() (
if r.coverageReport != nil {
r.coverageReport.ExcludeLocation(stdlib.CryptoCheckerLocation)
r.coverageReport.ExcludeLocation(stdlib.TestContractLocation)
r.coverageReport.ExcludeLocation(BlockchainHelpersLocation)
r.coverageReport.ExcludeLocation(helpers.BlockchainHelpersLocation)
r.coverageReport.ExcludeLocation(testScriptLocation)
ctx.CoverageReport = r.coverageReport
}
Expand Down Expand Up @@ -497,8 +496,8 @@ func (r *TestRunner) checkerImportHandler(ctx runtime.Context) sema.ImportHandle
testChecker := stdlib.GetTestContractType().Checker
elaboration = testChecker.Elaboration

case BlockchainHelpersLocation:
helpersChecker := BlockchainHelpersChecker()
case helpers.BlockchainHelpersLocation:
helpersChecker := helpers.BlockchainHelpersChecker()
elaboration = helpersChecker.Elaboration

default:
Expand Down Expand Up @@ -628,8 +627,8 @@ func (r *TestRunner) interpreterImportHandler(ctx runtime.Context) interpreter.I
testChecker := stdlib.GetTestContractType().Checker
program = interpreter.ProgramFromChecker(testChecker)

case BlockchainHelpersLocation:
helpersChecker := BlockchainHelpersChecker()
case helpers.BlockchainHelpersLocation:
helpersChecker := helpers.BlockchainHelpersChecker()
program = interpreter.ProgramFromChecker(helpersChecker)

default:
Expand Down

0 comments on commit 305558d

Please sign in to comment.