Skip to content

Commit

Permalink
Remove backend field from TestRunner and restructure tests for blockc…
Browse files Browse the repository at this point in the history
…hain logs
  • Loading branch information
m-Peter committed May 29, 2023
1 parent 76657ef commit e963a7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
32 changes: 17 additions & 15 deletions test/test_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,19 @@ func TestRetrieveLogsFromIntegrationTests(t *testing.T) {
let result = blockchain.executeTransaction(tx)
assert(result.status == Test.ResultStatus.succeeded)
}
pub fun tearDown() {
let expectedLogs = [
"init successful",
"getIntegerTrait works",
"specialNumbers updated",
"addSpecialNumber works"
]
for log in blockchain.logs() {
Test.assert(expectedLogs.contains(log))
}
}
`

const transactionCode = `
Expand Down Expand Up @@ -3152,18 +3165,6 @@ func TestRetrieveLogsFromIntegrationTests(t *testing.T) {

_, err := runner.RunTests(testCode)
require.NoError(t, err)

logs := runner.backend.Logs()
assert.ElementsMatch(
t,
[]string{
"init successful",
"getIntegerTrait works",
"specialNumbers updated",
"addSpecialNumber works",
},
logs,
)
}

func TestRetrieveEmptyLogsFromIntegrationTests(t *testing.T) {
Expand Down Expand Up @@ -3251,6 +3252,10 @@ func TestRetrieveEmptyLogsFromIntegrationTests(t *testing.T) {
let result = blockchain.executeTransaction(tx)
assert(result.status == Test.ResultStatus.succeeded)
}
pub fun tearDown() {
Test.assert(blockchain.logs() == [])
}
`

const transactionCode = `
Expand Down Expand Up @@ -3286,7 +3291,4 @@ func TestRetrieveEmptyLogsFromIntegrationTests(t *testing.T) {

_, err := runner.RunTests(testCode)
require.NoError(t, err)

logs := runner.backend.Logs()
assert.Equal(t, []string{}, logs)
}
6 changes: 2 additions & 4 deletions test/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ type TestRunner struct {
// the script environment, in order to aggregate and expose
// log messages from test cases and contracts.
logCollection *LogCollectionHook

backend *EmulatorBackend
}

func NewTestRunner() *TestRunner {
Expand Down Expand Up @@ -427,14 +425,14 @@ func (r *TestRunner) interpreterContractValueHandler(
return contract

case stdlib.TestContractLocation:
r.backend = NewEmulatorBackend(
testFramework := NewEmulatorBackend(
r.fileResolver,
stdlibHandler,
r.coverageReport,
)
contract, err := stdlib.NewTestContract(
inter,
r.backend,
testFramework,
constructorGenerator(common.Address{}),
invocationRange,
)
Expand Down

0 comments on commit e963a7f

Please sign in to comment.