Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

chore: stop the periodic commit when the test EVM chain is stopped #123

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion testing/evm_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ const DefaultPeriodicCommitDelay = time.Nanosecond
// PeriodicCommit periodically run `commit()` on the simulated network to mine
// the hanging blocks.
// If there are no hanging transactions, the chain will not advance.
// Make sure to cancel the context to stop the periodic commit.
func (e *EVMChain) PeriodicCommit(ctx context.Context, delay time.Duration) {
defer func() {
if r := recover(); r != nil {
// we want to exit when the simulated blockchain has stopped instead of panic.
err, ok := r.(error)
if !ok || err.Error() != "blockchain is stopped" {
panic(r)
}
}
}()
ticker := time.NewTicker(delay)
for {
select {
Expand Down