Skip to content

Commit

Permalink
Merge pull request #2126 from OffchainLabs/test-precompiles-per-version
Browse files Browse the repository at this point in the history
Test precompiles per ArbOS version
  • Loading branch information
PlasmaPower authored Feb 6, 2024
2 parents 142b089 + ae10772 commit 4c2dd22
Showing 1 changed file with 32 additions and 16 deletions.
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
}

0 comments on commit 4c2dd22

Please sign in to comment.