types_test.go 1.06 KB
Newer Older
1 2 3 4 5 6 7 8 9
package rollup

import (
	"encoding/json"
	"math/big"
	"math/rand"
	"testing"
	"time"

10 11
	"github.com/stretchr/testify/assert"

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	"github.com/ethereum-optimism/optimism/op-node/eth"
	"github.com/ethereum/go-ethereum/common"
)

func randConfig() *Config {
	randHash := func() (out common.Hash) {
		rand.Read(out[:])
		return
	}
	randAddr := func() (out common.Address) { // we need generics...
		rand.Read(out[:])
		return
	}
	return &Config{
		Genesis: Genesis{
			L1:     eth.BlockID{Hash: randHash(), Number: 424242},
			L2:     eth.BlockID{Hash: randHash(), Number: 1337},
			L2Time: uint64(time.Now().Unix()),
		},
		BlockTime:           2,
		MaxSequencerDrift:   100,
		SeqWindowSize:       2,
		L1ChainID:           big.NewInt(900),
		FeeRecipientAddress: randAddr(),
		BatchInboxAddress:   randAddr(),
		BatchSenderAddress:  randAddr(),
	}
}

func TestConfigJSON(t *testing.T) {
	config := randConfig()
	data, err := json.Marshal(config)
	assert.NoError(t, err)
	var roundTripped Config
	assert.NoError(t, json.Unmarshal(data, &roundTripped))
	assert.Equal(t, &roundTripped, config)
}