1
2
3
4
5
6
7
8
9
10
11
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
49
50
51
52
53
54
55
56
57
58
package rollup
import (
"encoding/json"
"math/big"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum-optimism/optimism/op-node/eth"
)
func randConfig() *Config {
randHash := func() (out [32]byte) {
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()),
SystemConfig: eth.SystemConfig{
BatcherAddr: randAddr(),
Overhead: randHash(),
Scalar: randHash(),
GasLimit: 1234567,
},
},
BlockTime: 2,
MaxSequencerDrift: 100,
SeqWindowSize: 2,
ChannelTimeout: 123,
L1ChainID: big.NewInt(900),
L2ChainID: big.NewInt(901),
P2PSequencerAddress: randAddr(),
BatchInboxAddress: randAddr(),
DepositContractAddress: randAddr(),
L1SystemConfigAddress: 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)
}