From f16bc040a326b0a766044a23015cb7b7f2c20a9b Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Fri, 2 Feb 2024 11:46:11 -0700 Subject: [PATCH] Test precompiles per ArbOS version --- precompiles/precompile_test.go | 48 ++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/precompiles/precompile_test.go b/precompiles/precompile_test.go index 02d962f0b4..975856bced 100644 --- a/precompiles/precompile_test.go +++ b/precompiles/precompile_test.go @@ -4,10 +4,13 @@ package precompiles import ( + "fmt" "math/big" + "os" "testing" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -176,22 +179,35 @@ func TestEventCosts(t *testing.T) { } } -type FatalBurner struct { - t *testing.T - count uint64 - gasLeft uint64 -} - -func NewFatalBurner(t *testing.T, limit uint64) FatalBurner { - return FatalBurner{t, 0, limit} -} +func TestPrecompilesPerArbosVersion(t *testing.T) { + // Set up a logger in case log.Crit is called by Precompiles() + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) + glogger.Verbosity(log.LvlWarn) + log.Root().SetHandler(glogger) + + expectedNewMethodsPerArbosVersion := map[uint64]int{ + 0: 89, + 5: 3, + 10: 2, + 11: 4, + 20: 8, + } + + precompiles := Precompiles() + newMethodsPerArbosVersion := make(map[uint64]int) + for _, precompile := range precompiles { + for _, method := range precompile.Precompile().methods { + newMethodsPerArbosVersion[method.arbosVersion]++ + } + } -func (burner FatalBurner) Burn(amount uint64) error { - burner.t.Helper() - burner.count += 1 - if burner.gasLeft < amount { - Fail(burner.t, "out of gas after", burner.count, "burns") + if len(expectedNewMethodsPerArbosVersion) != len(newMethodsPerArbosVersion) { + t.Errorf("expected %v ArbOS versions with new precompile methods but got %v", len(expectedNewMethodsPerArbosVersion), len(newMethodsPerArbosVersion)) + } + for version, count := range newMethodsPerArbosVersion { + fmt.Printf("got %v version count %v\n", version, count) + if expectedNewMethodsPerArbosVersion[version] != count { + t.Errorf("expected %v new precompile methods for ArbOS version %v but got %v", expectedNewMethodsPerArbosVersion[version], version, count) + } } - burner.gasLeft -= amount - return nil }