Skip to content

Commit

Permalink
Unify backend environment for Unit & Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Sep 11, 2023
1 parent d0d3d6f commit 71c3a0a
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 144 deletions.
3 changes: 2 additions & 1 deletion test/emulator_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func newSystemClock() *systemClock {
type deployedContractConstructorInvocation struct {
ConstructorArguments []interpreter.Value
ArgumentTypes []sema.Type
Address common.Address
}

var contractInvocations = make(
Expand Down Expand Up @@ -515,6 +516,7 @@ func (e *EmulatorBackend) DeployContract(
contractInvocations[name] = deployedContractConstructorInvocation{
ConstructorArguments: args,
ArgumentTypes: argTypes,
Address: account.Address,
}

return e.CommitBlock()
Expand Down Expand Up @@ -572,7 +574,6 @@ func (e *EmulatorBackend) replaceImports(code string) string {

sb := strings.Builder{}
importDeclEnd := 0

for _, importDeclaration := range program.ImportDeclarations() {
prevImportDeclEnd := importDeclEnd
importDeclEnd = importDeclaration.EndPos.Offset + 1
Expand Down
22 changes: 16 additions & 6 deletions test/test_framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type TestFrameworkProvider struct {
stdlibHandler stdlib.StandardLibraryHandler

coverageReport *runtime.CoverageReport

emulatorBackend *EmulatorBackend
}

func (tf *TestFrameworkProvider) ReadFile(path string) (string, error) {
Expand Down Expand Up @@ -61,21 +63,29 @@ func (tf *TestFrameworkProvider) ReadFile(path string) (string, error) {
}

func (tf *TestFrameworkProvider) NewEmulatorBackend() stdlib.Blockchain {
return NewEmulatorBackend(
tf.fileResolver,
tf.stdlibHandler,
tf.coverageReport,
)
return tf.emulatorBackend
// return NewEmulatorBackend(
// tf.fileResolver,
// tf.stdlibHandler,
// tf.coverageReport,
// )
}

func NewTestFrameworkProvider(
fileResolver FileResolver,
stdlibHandler stdlib.StandardLibraryHandler,
coverageReport *runtime.CoverageReport,
) stdlib.TestFramework {
return &TestFrameworkProvider{
provider := &TestFrameworkProvider{
fileResolver: fileResolver,
stdlibHandler: stdlibHandler,
coverageReport: coverageReport,
}
provider.emulatorBackend = NewEmulatorBackend(
fileResolver,
stdlibHandler,
coverageReport,
)

return provider
}
Loading

0 comments on commit 71c3a0a

Please sign in to comment.