Commit 372d13b8 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #8410 from ethereum-optimism/feat/e2e-cleanups

op-e2e: Minor cleanups
parents 9216562e d4ed6b06
package e2eutils
import (
"fmt"
"os"
"strings"
"testing"
"unicode"
"unicode/utf8"
"github.com/stretchr/testify/require"
)
func TempDir(t *testing.T) string {
// Drop unusual characters (such as path separators or
// characters interacting with globs) from the directory name to
// avoid surprising os.MkdirTemp behavior.
// Taken from the t.TempDir() implementation in the standard library.
mapper := func(r rune) rune {
if r < utf8.RuneSelf {
const allowed = "!#$%&()+,-.=@^_{}~ "
if '0' <= r && r <= '9' ||
'a' <= r && r <= 'z' ||
'A' <= r && r <= 'Z' {
return r
}
if strings.ContainsRune(allowed, r) {
return r
}
} else if unicode.IsLetter(r) || unicode.IsNumber(r) {
return r
}
return -1
}
dir, err := os.MkdirTemp("", strings.Map(mapper, fmt.Sprintf("op-e2e-%s", t.Name())))
require.NoError(t, err)
t.Cleanup(func() {
err := os.RemoveAll(dir)
if err != nil {
t.Logf("Error removing temp dir %s: %s", dir, err)
}
})
return dir
}
......@@ -47,6 +47,7 @@ type OpGeth struct {
L1Head eth.BlockInfo
L2Head *eth.ExecutionPayload
sequenceNum uint64
lgr log.Logger
}
func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, error) {
......@@ -117,11 +118,14 @@ func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, e
L2ChainConfig: l2Genesis.Config,
L1Head: eth.BlockToInfo(l1Block),
L2Head: genesisPayload,
lgr: logger,
}, nil
}
func (d *OpGeth) Close() {
_ = d.node.Close()
if err := d.node.Close(); err != nil {
d.lgr.Error("error closing node", "err", err)
}
d.l2Engine.Close()
d.L2Client.Close()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment