[Test] `Test.Blockchain` struct reuses one single backend implementation
Closed this issue · 0 comments
Problem
Currently, when the Test.newEmulatorBlockchain()
is called, it returns a new Test.Blockchain
struct. However, the underlying backend implementation is the same for all Test.Blockchain
structs that are created in a single test file. This is due to the fact that the ContractValueHandler
injects only once the backend implementation, when it first encounters the Test
contract in a test file.
Steps to Reproduce
import Test
pub let blockchain = Test.newEmulatorBlockchain()
pub let account = blockchain.createAccount()
pub fun testEventRetrieval() {
let evts = blockchain.events()
Test.assert(evts.length == 19)
let blockchain2 = Test.newEmulatorBlockchain()
Test.assert(blockchain2.events().length == 19)
}
Acceptance Criteria
Either returns a newly-created backend implementation for every call of Test.newEmulatorBlockchain()
, or maybe move towards making the Test.Blockchain
a singleton. Creating many backend implementations should add some overhead when running tests, and right now, it is possible to call Reset()
on a Test.Blockchain
value. See discussion in #138.