Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test precompiles per ArbOS version #2126

Merged
merged 3 commits into from
Feb 6, 2024
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
48 changes: 32 additions & 16 deletions precompiles/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Loading