attributes_queue_test.go 2.83 KB
Newer Older
1
package derive
2 3 4 5 6 7 8

import (
	"context"
	"math/big"
	"math/rand"
	"testing"

9 10
	"github.com/stretchr/testify/require"

11 12 13
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/log"

14
	"github.com/ethereum-optimism/optimism/op-node/rollup"
15
	"github.com/ethereum-optimism/optimism/op-service/eth"
16
	"github.com/ethereum-optimism/optimism/op-service/predeploys"
17
	"github.com/ethereum-optimism/optimism/op-service/testlog"
Sabnock01's avatar
Sabnock01 committed
18
	"github.com/ethereum-optimism/optimism/op-service/testutils"
19 20
)

21 22 23 24
// TestAttributesQueue checks that it properly uses the PreparePayloadAttributes function
// (which is well tested) and that it properly sets NoTxPool and adds in the candidate
// transactions.
func TestAttributesQueue(t *testing.T) {
25 26 27 28 29 30
	// test config, only init the necessary fields
	cfg := &rollup.Config{
		BlockTime:              2,
		L1ChainID:              big.NewInt(101),
		L2ChainID:              big.NewInt(102),
		DepositContractAddress: common.Address{0xbb},
31
		L1SystemConfigAddress:  common.Address{0xcc},
32 33
	}
	rng := rand.New(rand.NewSource(1234))
34
	l1Info := testutils.RandomBlockInfo(rng)
35 36 37 38 39 40 41 42

	l1Fetcher := &testutils.MockL1Source{}
	defer l1Fetcher.AssertExpectations(t)

	l1Fetcher.ExpectInfoByHash(l1Info.InfoHash, l1Info, nil)

	safeHead := testutils.RandomL2BlockRef(rng)
	safeHead.L1Origin = l1Info.ID()
43
	safeHead.Time = l1Info.InfoTime
44

45
	batch := SingularBatch{
46
		ParentHash:   safeHead.Hash,
47 48
		EpochNum:     rollup.Epoch(l1Info.InfoNum),
		EpochHash:    l1Info.InfoHash,
49
		Timestamp:    safeHead.Time + cfg.BlockTime,
50
		Transactions: []eth.Data{eth.Data("foobar"), eth.Data("example")},
51
	}
52

53 54 55 56
	parentL1Cfg := eth.SystemConfig{
		BatcherAddr: common.Address{42},
		Overhead:    [32]byte{},
		Scalar:      [32]byte{},
57
		GasLimit:    1234,
58 59 60 61 62
	}
	expectedL1Cfg := eth.SystemConfig{
		BatcherAddr: common.Address{42},
		Overhead:    [32]byte{},
		Scalar:      [32]byte{},
63
		GasLimit:    1234,
64 65 66 67 68
	}

	l2Fetcher := &testutils.MockL2Client{}
	l2Fetcher.ExpectSystemConfigByL2Hash(safeHead.Hash, parentL1Cfg, nil)

69 70
	rollupCfg := rollup.Config{}
	l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
71 72 73 74
	require.NoError(t, err)
	attrs := eth.PayloadAttributes{
		Timestamp:             eth.Uint64Quantity(safeHead.Time + cfg.BlockTime),
		PrevRandao:            eth.Bytes32(l1Info.InfoMixDigest),
75
		SuggestedFeeRecipient: predeploys.SequencerFeeVaultAddr,
76 77
		Transactions:          []eth.Data{l1InfoTx, eth.Data("foobar"), eth.Data("example")},
		NoTxPool:              true,
78
		GasLimit:              (*eth.Uint64Quantity)(&expectedL1Cfg.GasLimit),
79
	}
80
	attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l2Fetcher)
81

82
	aq := NewAttributesQueue(testlog.Logger(t, log.LevelError), cfg, attrBuilder, nil)
83

84
	actual, err := aq.createNextAttributes(context.Background(), &batch, safeHead)
85

86
	require.NoError(t, err)
87
	require.Equal(t, attrs, *actual)
88
}