Commit 95c0463c authored by Mark Tyneway's avatar Mark Tyneway Committed by Kelvin Fichter

l2geth: fix various tests

The tests were not running in CI on the experimental
branch which was an oversight and allowed for various
tests to fail. Now that experimental has been renamed
to regenesis/0.5.0, the tests are running in CI again.
This commit fixes all tests that were broken while
development happened on experimental.

It removes a config option `--rollup.minl2gaslimit`
that is no longer required post regenesis.

It also adds the ability to populate a genesis account
with value in the sync service tests.
parent 4f805355
---
'@eth-optimism/l2geth': patch
---
Fix various geth tests
......@@ -161,7 +161,6 @@ var (
utils.RollupMaxCalldataSizeFlag,
utils.RollupBackendFlag,
utils.RollupEnforceFeesFlag,
utils.RollupMinL2GasLimitFlag,
utils.RollupFeeThresholdDownFlag,
utils.RollupFeeThresholdUpFlag,
}
......
......@@ -75,7 +75,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.RollupMaxCalldataSizeFlag,
utils.RollupBackendFlag,
utils.RollupEnforceFeesFlag,
utils.RollupMinL2GasLimitFlag,
utils.RollupFeeThresholdDownFlag,
utils.RollupFeeThresholdUpFlag,
},
......
......@@ -851,11 +851,6 @@ var (
Usage: "Disable transactions with 0 gas price",
EnvVar: "ROLLUP_ENFORCE_FEES",
}
RollupMinL2GasLimitFlag = cli.Uint64Flag{
Name: "rollup.minl2gaslimit",
Usage: "Minimum accepted L2 gas limit",
EnvVar: "ROLLUP_MIN_L2_GAS_LIMIT",
}
RollupFeeThresholdDownFlag = cli.Float64Flag{
Name: "rollup.feethresholddown",
Usage: "Allow txs with fees below the current fee up to this amount, must be < 1",
......@@ -1134,10 +1129,6 @@ func setRollup(ctx *cli.Context, cfg *rollup.Config) {
if ctx.GlobalIsSet(RollupEnforceFeesFlag.Name) {
cfg.EnforceFees = true
}
if ctx.GlobalIsSet(RollupMinL2GasLimitFlag.Name) {
val := ctx.GlobalUint64(RollupMinL2GasLimitFlag.Name)
cfg.MinL2GasLimit = new(big.Int).SetUint64(val)
}
if ctx.GlobalIsSet(RollupFeeThresholdDownFlag.Name) {
val := ctx.GlobalFloat64(RollupFeeThresholdDownFlag.Name)
cfg.FeeThresholdDown = new(big.Float).SetFloat64(val)
......
......@@ -40,6 +40,7 @@ func skipWithoutSolc(t *testing.T) {
}
func TestSolidityCompiler(t *testing.T) {
t.Skip("Not required for optimism")
skipWithoutSolc(t)
contracts, err := CompileSolidityString("", testSource)
......
......@@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}, common.Address{}, common.Address{}, common.Address{}, "", nil, 12000000),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Miner: miner.Config{
Etherbase: common.HexToAddress(testAddress),
},
......
......@@ -198,6 +198,11 @@ type ReceiptForStorage Receipt
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
// into an RLP stream.
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
feeScalar := ""
if r.FeeScalar != nil {
feeScalar = r.FeeScalar.String()
}
enc := &storedReceiptRLP{
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
CumulativeGasUsed: r.CumulativeGasUsed,
......@@ -205,7 +210,7 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
L1GasUsed: r.L1GasUsed,
L1GasPrice: r.L1GasPrice,
L1Fee: r.L1Fee,
FeeScalar: r.FeeScalar.String(),
FeeScalar: feeScalar,
}
for i, log := range r.Logs {
enc.Logs[i] = (*LogForStorage)(log)
......@@ -227,6 +232,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
if err := decodeStoredReceiptRLP(r, blob); err == nil {
return nil
}
if err := decodeV3StoredReceiptRLP(r, blob); err == nil {
return nil
}
......@@ -249,9 +255,13 @@ func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
// UsingOVM
scalar, ok := new(big.Float).SetString(stored.FeeScalar)
if !ok {
return errors.New("cannot parse fee scalar")
scalar := new(big.Float)
if stored.FeeScalar != "" {
var ok bool
scalar, ok = scalar.SetString(stored.FeeScalar)
if !ok {
return errors.New("cannot parse fee scalar")
}
}
r.L1GasUsed = stored.L1GasUsed
r.L1GasPrice = stored.L1GasPrice
......
......@@ -128,7 +128,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
from := statedb.GetOrNewStateObject(bankAddr)
from.SetBalance(math.MaxBig256)
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, nil, 0, types.QueueOriginSequencer)}
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, 0, types.QueueOriginSequencer)}
context := core.NewEVMContext(msg, header, bc, nil)
vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
......@@ -142,7 +142,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
header := lc.GetHeaderByHash(bhash)
state := light.NewState(ctx, header, lc.Odr())
state.SetBalance(bankAddr, math.MaxBig256)
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, nil, 0, types.QueueOriginSequencer)}
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, 0, types.QueueOriginSequencer)}
context := core.NewEVMContext(msg, header, lc, nil)
vmenv := vm.NewEVM(context, state, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64)
......
......@@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
// Perform read-only call.
st.SetBalance(testBankAddress, math.MaxBig256)
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, nil, nil, 0, types.QueueOriginSequencer)}
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, nil, 0, types.QueueOriginSequencer)}
context := core.NewEVMContext(msg, header, chain, nil)
vmenv := vm.NewEVM(context, st, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64)
......
......@@ -32,10 +32,6 @@ type Config struct {
Backend Backend
// Only accept transactions with fees
EnforceFees bool
// Prevent transactions with a L2 gas limit lower than this value
// The L2 gas limit is parsed from the `tx.gasPrice`, see the
// `rollup/fees` package for more information
MinL2GasLimit *big.Int
// Allow fees within a buffer upwards or downwards
// to take fee volatility into account between being
// quoted and the transaction being executed
......
......@@ -111,6 +111,9 @@ func TestCalculateFee(t *testing.T) {
msg, _ := tx.AsMessage(signer)
l1MsgFee, err := fees.CalculateL1MsgFee(msg, state, &addr)
if err != nil {
t.Fatal(err)
}
if l1MsgFee.Cmp(expectL1Fee) != 0 {
t.Fatal("l1 msg fee not computed correctly")
}
......
......@@ -66,7 +66,6 @@ type SyncService struct {
gasPriceOracleOwnerAddressLock *sync.RWMutex
enforceFees bool
signer types.Signer
minL2GasLimit *big.Int
feeThresholdUp *big.Float
feeThresholdDown *big.Float
}
......@@ -123,11 +122,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
cfg.FeeThresholdUp)
}
}
if cfg.MinL2GasLimit == nil {
value := new(big.Int)
log.Info("Sanitizing minimum L2 gas limit", "value", value)
cfg.MinL2GasLimit = value
}
service := SyncService{
ctx: ctx,
......@@ -147,7 +141,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
gasPriceOracleOwnerAddressLock: new(sync.RWMutex),
enforceFees: cfg.EnforceFees,
signer: types.NewEIP155Signer(chainID),
minL2GasLimit: cfg.MinL2GasLimit,
feeThresholdDown: cfg.FeeThresholdDown,
feeThresholdUp: cfg.FeeThresholdUp,
}
......
......@@ -22,12 +22,11 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/fees"
"github.com/ethereum/go-ethereum/rollup/rcfg"
)
func setupLatestEthContextTest() (*SyncService, *EthContext) {
service, _, _, _ := newTestSyncService(false)
service, _, _, _ := newTestSyncService(false, nil)
resp := &EthContext{
BlockNumber: uint64(10),
BlockHash: common.Hash{},
......@@ -98,7 +97,7 @@ func TestSyncServiceContextUpdated(t *testing.T) {
// after the transaction enqueued event is emitted. Set `false` as
// the argument to start as a sequencer
func TestSyncServiceTransactionEnqueued(t *testing.T) {
service, txCh, _, err := newTestSyncService(false)
service, txCh, _, err := newTestSyncService(false, nil)
if err != nil {
t.Fatal(err)
}
......@@ -160,7 +159,7 @@ func TestSyncServiceTransactionEnqueued(t *testing.T) {
}
func TestTransactionToTipNoIndex(t *testing.T) {
service, txCh, _, err := newTestSyncService(false)
service, txCh, _, err := newTestSyncService(false, nil)
if err != nil {
t.Fatal(err)
}
......@@ -211,7 +210,7 @@ func TestTransactionToTipNoIndex(t *testing.T) {
}
func TestTransactionToTipTimestamps(t *testing.T) {
service, txCh, _, err := newTestSyncService(false)
service, txCh, _, err := newTestSyncService(false, nil)
if err != nil {
t.Fatal(err)
}
......@@ -275,7 +274,7 @@ func TestTransactionToTipTimestamps(t *testing.T) {
}
func TestApplyIndexedTransaction(t *testing.T) {
service, txCh, _, err := newTestSyncService(true)
service, txCh, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -318,7 +317,7 @@ func TestApplyIndexedTransaction(t *testing.T) {
}
func TestApplyBatchedTransaction(t *testing.T) {
service, txCh, _, err := newTestSyncService(true)
service, txCh, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -355,7 +354,7 @@ func TestApplyBatchedTransaction(t *testing.T) {
}
func TestIsAtTip(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -428,7 +427,7 @@ func TestIsAtTip(t *testing.T) {
}
func TestSyncQueue(t *testing.T) {
service, txCh, _, err := newTestSyncService(true)
service, txCh, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -485,7 +484,7 @@ func TestSyncQueue(t *testing.T) {
}
func TestSyncServiceL1GasPrice(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
setupMockClient(service, map[string]interface{}{})
if err != nil {
......@@ -523,7 +522,7 @@ func TestSyncServiceL1GasPrice(t *testing.T) {
}
func TestSyncServiceL2GasPrice(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -557,40 +556,8 @@ func TestSyncServiceL2GasPrice(t *testing.T) {
}
}
func TestSyncServiceMinL2GasPrice(t *testing.T) {
service, _, _, err := newTestSyncService(true)
if err != nil {
t.Fatal(err)
}
service.minL2GasLimit = new(big.Int).SetUint64(10_000_000)
signer := types.NewEIP155Signer(big.NewInt(420))
// Generate a key
key, _ := crypto.GenerateKey()
// Create a transaction
gasLimit := uint64(100)
tx := types.NewTransaction(0, common.Address{}, big.NewInt(0), gasLimit, big.NewInt(15000000), []byte{})
// Make sure the gas limit is set correctly
if tx.Gas() != gasLimit {
t.Fatal("gas limit not set correctly")
}
// Sign the dummy tx with the owner key
signedTx, err := types.SignTx(tx, signer, key)
if err != nil {
t.Fatal(err)
}
// Sanity check the L2 gas limit
if tx.L2Gas() > service.minL2GasLimit.Uint64() {
t.Fatal("L2 gas limit expected to be smaller than min accepted by sequencer")
}
// Verify the fee of the signed tx, ensure it does not error
err = service.verifyFee(signedTx)
if !errors.Is(err, fees.ErrL2GasLimitTooLow) {
t.Fatal(err)
}
}
func TestSyncServiceGasPriceOracleOwnerAddress(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -624,7 +591,7 @@ func TestSyncServiceGasPriceOracleOwnerAddress(t *testing.T) {
// Only the gas price oracle owner can send 0 gas price txs
// when fees are enforced
func TestFeeGasPriceOracleOwnerTransactions(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -680,7 +647,7 @@ func TestFeeGasPriceOracleOwnerTransactions(t *testing.T) {
// Pass true to set as a verifier
func TestSyncServiceSync(t *testing.T) {
service, txCh, sub, err := newTestSyncService(true)
service, txCh, sub, err := newTestSyncService(true, nil)
defer sub.Unsubscribe()
if err != nil {
t.Fatal(err)
......@@ -732,7 +699,7 @@ func TestSyncServiceSync(t *testing.T) {
}
func TestInitializeL1ContextPostGenesis(t *testing.T) {
service, _, _, err := newTestSyncService(true)
service, _, _, err := newTestSyncService(true, nil)
if err != nil {
t.Fatal(err)
}
......@@ -798,7 +765,7 @@ func TestInitializeL1ContextPostGenesis(t *testing.T) {
func TestBadFeeThresholds(t *testing.T) {
// Create the deps for the sync service
cfg, txPool, chain, db, err := newTestSyncServiceDeps(false)
cfg, txPool, chain, db, err := newTestSyncServiceDeps(false, nil)
if err != nil {
t.Fatal(err)
}
......@@ -843,14 +810,21 @@ func TestBadFeeThresholds(t *testing.T) {
}
}
func newTestSyncServiceDeps(isVerifier bool) (Config, *core.TxPool, *core.BlockChain, ethdb.Database, error) {
func newTestSyncServiceDeps(isVerifier bool, alloc *common.Address) (Config, *core.TxPool, *core.BlockChain, ethdb.Database, error) {
chainCfg := params.AllEthashProtocolChanges
chainID := big.NewInt(420)
chainCfg.ChainID = chainID
engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase()
_ = new(core.Genesis).MustCommit(db)
genesis := new(core.Genesis)
if alloc != nil {
genesis.Alloc = make(core.GenesisAlloc)
genesis.Alloc[*alloc] = core.GenesisAccount{
Balance: new(big.Int).SetUint64(100000000000000),
}
}
_ = genesis.MustCommit(db)
chain, err := core.NewBlockChain(db, nil, chainCfg, engine, vm.Config{}, nil)
if err != nil {
return Config{}, nil, nil, nil, fmt.Errorf("Cannot initialize blockchain: %w", err)
......@@ -869,8 +843,8 @@ func newTestSyncServiceDeps(isVerifier bool) (Config, *core.TxPool, *core.BlockC
return cfg, txPool, chain, db, nil
}
func newTestSyncService(isVerifier bool) (*SyncService, chan core.NewTxsEvent, event.Subscription, error) {
cfg, txPool, chain, db, err := newTestSyncServiceDeps(isVerifier)
func newTestSyncService(isVerifier bool, alloc *common.Address) (*SyncService, chan core.NewTxsEvent, event.Subscription, error) {
cfg, txPool, chain, db, err := newTestSyncServiceDeps(isVerifier, alloc)
if err != nil {
return nil, nil, nil, fmt.Errorf("Cannot initialize syncservice: %w", err)
}
......
......@@ -279,7 +279,7 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
return nil, fmt.Errorf("invalid tx data %q", dataHex)
}
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil, nil, 0, types.QueueOriginSequencer)
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil, 0, types.QueueOriginSequencer)
return msg, nil
}
......
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