Skip to content

Commit 51efd60

Browse files
authored
add all mainnet configs as default (#4572)
* add all mainnet configs as default * fix unit tests * address comments
1 parent 7510ace commit 51efd60

File tree

64 files changed

+459
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+459
-329
lines changed

action/protocol/account/protocol_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestProtocol_Initialize(t *testing.T) {
131131
return 0, nil
132132
}).AnyTimes()
133133

134-
ge := genesis.Default
134+
ge := genesis.TestDefault()
135135
ge.Account.InitBalanceMap = map[string]string{
136136
identityset.Address(0).String(): "100",
137137
}

action/protocol/account/transfer_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestProtocol_ValidateTransfer(t *testing.T) {
3535
t.Run("invalid transfer", func(t *testing.T) {
3636
tsf := action.NewTransfer(big.NewInt(1), "2", make([]byte, 32683))
3737
tsf1 := action.NewTransfer(big.NewInt(1), "2", nil)
38-
g := genesis.Default
38+
g := genesis.TestDefault()
3939
ctx := protocol.WithFeatureCtx(genesis.WithGenesisContext(protocol.WithBlockCtx(context.Background(), protocol.BlockCtx{
4040
BlockHeight: g.NewfoundlandBlockHeight,
4141
}), g))
@@ -61,12 +61,13 @@ func TestProtocol_HandleTransfer(t *testing.T) {
6161

6262
// set-up protocol and genesis states
6363
p := NewProtocol(rewarding.DepositGas)
64-
reward := rewarding.NewProtocol(genesis.Default.Rewarding)
64+
g := genesis.TestDefault()
65+
reward := rewarding.NewProtocol(g.Rewarding)
6566
registry := protocol.NewRegistry()
6667
require.NoError(reward.Register(registry))
6768
chainCtx := genesis.WithGenesisContext(
6869
protocol.WithRegistry(context.Background(), registry),
69-
genesis.Default,
70+
g,
7071
)
7172
ctx := protocol.WithBlockCtx(chainCtx, protocol.BlockCtx{})
7273
ctx = protocol.WithFeatureCtx(ctx)

action/protocol/eip1559_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestCalcBaseFee(t *testing.T) {
2727
{action.InitialBaseFee, 24000000, 1000000000000}, // usage below target but capped to default
2828
{action.InitialBaseFee, 26000000, 1005000000000}, // usage above target
2929
}
30-
g := genesis.Default.Blockchain
30+
g := genesis.TestDefault().Blockchain
3131
for _, test := range tests {
3232
parent := &TipInfo{
3333
Height: g.VanuatuBlockHeight,

action/protocol/execution/evm/evm_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestExecuteContractFailure(t *testing.T) {
4747
Producer: identityset.Address(27),
4848
GasLimit: testutil.TestGasLimit,
4949
})
50-
ctx = genesis.WithGenesisContext(ctx, genesis.Default)
50+
ctx = genesis.WithGenesisContext(ctx, genesis.TestDefault())
5151

5252
ctx = protocol.WithBlockchainCtx(protocol.WithFeatureCtx(ctx), protocol.BlockchainCtx{
5353
ChainID: 1,
@@ -81,7 +81,7 @@ func TestConstantinople(t *testing.T) {
8181
})
8282

8383
evmNetworkID := uint32(100)
84-
g := genesis.Default
84+
g := genesis.TestDefault()
8585
ctx = protocol.WithBlockchainCtx(genesis.WithGenesisContext(ctx, g), protocol.BlockchainCtx{
8686
ChainID: 1,
8787
EvmNetworkID: evmNetworkID,
@@ -377,7 +377,7 @@ func TestConstantinople(t *testing.T) {
377377

378378
func TestEvmError(t *testing.T) {
379379
r := require.New(t)
380-
g := genesis.Default.Blockchain
380+
g := genesis.TestDefault().Blockchain
381381

382382
beringTests := []struct {
383383
evmError error
@@ -442,7 +442,7 @@ func TestGasEstimate(t *testing.T) {
442442
for _, v := range []struct {
443443
gas, consume, refund, size uint64
444444
}{
445-
{genesis.Default.BlockGasLimit, 8200300, 1000000, 20000},
445+
{genesis.TestDefault().BlockGasLimit, 8200300, 1000000, 20000},
446446
{1000000, 245600, 100000, 5600},
447447
{500000, 21000, 10000, 36},
448448
} {

action/protocol/execution/evm/evmstatedbadapter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ func TestReadContractStorage(t *testing.T) {
235235
stateDB.CommitContracts()
236236

237237
ctx := protocol.WithBlockchainCtx(protocol.WithFeatureCtx(protocol.WithBlockCtx(
238-
genesis.WithGenesisContext(context.Background(), genesis.Default),
239-
protocol.BlockCtx{BlockHeight: genesis.Default.MidwayBlockHeight})),
238+
genesis.WithGenesisContext(context.Background(), genesis.TestDefault()),
239+
protocol.BlockCtx{BlockHeight: genesis.TestDefault().MidwayBlockHeight})),
240240
protocol.BlockchainCtx{})
241241
for k, v := range kvs {
242242
b, err := ReadContractStorage(ctx, sm, addr, k[:])

action/protocol/execution/protocol_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type (
110110
)
111111

112112
var (
113-
fixedTime = time.Unix(genesis.Default.Timestamp, 0)
113+
fixedTime = time.Unix(genesis.TestDefault().Timestamp, 0)
114114
)
115115

116116
func (eb *ExpectedBalance) Balance() *big.Int {
@@ -546,7 +546,9 @@ func (sct *SmartContractTest) deployContracts(
546546
func (sct *SmartContractTest) run(r *require.Assertions) {
547547
// prepare blockchain
548548
ctx := context.Background()
549-
cfg := deepcopy.Copy(config.Default).(config.Config)
549+
defaultCfg := config.Default
550+
defaultCfg.Genesis = genesis.TestDefault()
551+
cfg := deepcopy.Copy(defaultCfg).(config.Config)
550552
cfg.Chain.ProducerPrivKey = identityset.PrivateKey(28).HexString()
551553
cfg.Chain.EnableTrielessStateDB = false
552554
bc, sf, dao, ap := sct.prepareBlockchain(ctx, cfg, r)
@@ -639,6 +641,7 @@ func TestProtocol_Validate(t *testing.T) {
639641
p := execution.NewProtocol(func(uint64) (hash.Hash256, error) {
640642
return hash.ZeroHash256, nil
641643
}, rewarding.DepositGas, getBlockTimeForTest)
644+
g := genesis.TestDefault()
642645

643646
cases := []struct {
644647
name string
@@ -648,16 +651,16 @@ func TestProtocol_Validate(t *testing.T) {
648651
}{
649652
{"limit 32KB", 0, 32683, nil},
650653
{"exceed 32KB", 0, 32684, action.ErrOversizedData},
651-
{"limit 48KB", genesis.Default.SumatraBlockHeight, uint64(48 * 1024), nil},
652-
{"exceed 48KB", genesis.Default.SumatraBlockHeight, uint64(48*1024) + 1, action.ErrOversizedData},
654+
{"limit 48KB", g.SumatraBlockHeight, uint64(48 * 1024), nil},
655+
{"exceed 48KB", g.SumatraBlockHeight, uint64(48*1024) + 1, action.ErrOversizedData},
653656
}
654657

655658
builder := action.EnvelopeBuilder{}
656659
for i := range cases {
657660
t.Run(cases[i].name, func(t *testing.T) {
658661
ex := action.NewExecution("2", big.NewInt(0), make([]byte, cases[i].size))
659662
elp := builder.SetNonce(1).SetAction(ex).Build()
660-
ctx := genesis.WithGenesisContext(context.Background(), config.Default.Genesis)
663+
ctx := genesis.WithGenesisContext(context.Background(), g)
661664
ctx = protocol.WithBlockCtx(ctx, protocol.BlockCtx{
662665
BlockHeight: cases[i].height,
663666
})
@@ -696,6 +699,7 @@ func TestProtocol_Handle(t *testing.T) {
696699
cfg.Chain.EnableAsyncIndexWrite = false
697700
cfg.Genesis.EnableGravityChainVoting = false
698701
cfg.ActPool.MinGasPriceStr = "0"
702+
cfg.Genesis = genesis.TestDefault()
699703
cfg.Genesis.InitBalanceMap[identityset.Address(27).String()] = unit.ConvertIotxToRau(1000000000).String()
700704
ctx := genesis.WithGenesisContext(context.Background(), cfg.Genesis)
701705

@@ -1357,6 +1361,7 @@ func benchmarkHotContractWithFactory(b *testing.B, async bool) {
13571361
r := require.New(b)
13581362
ctx := context.Background()
13591363
cfg := config.Default
1364+
cfg.Genesis = genesis.TestDefault()
13601365
cfg.Genesis.NumSubEpochs = uint64(b.N)
13611366
cfg.Chain.EnableTrielessStateDB = false
13621367
if async {
@@ -1435,6 +1440,7 @@ func benchmarkHotContractWithStateDB(b *testing.B, cachedStateDBOption bool) {
14351440
r := require.New(b)
14361441
ctx := context.Background()
14371442
cfg := config.Default
1443+
cfg.Genesis = genesis.TestDefault()
14381444
cfg.Genesis.NumSubEpochs = uint64(b.N)
14391445
if cachedStateDBOption {
14401446
cfg.Chain.EnableStateDBCaching = true

action/protocol/generic_validator_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@ func TestActionProtoAndGenericValidator(t *testing.T) {
4646
Caller: caller,
4747
})
4848

49+
g := genesis.TestDefault()
4950
ctx = WithBlockchainCtx(
5051
ctx,
5152
BlockchainCtx{
5253
Tip: TipInfo{
5354
Height: 0,
54-
Hash: genesis.Default.Hash(),
55-
Timestamp: time.Unix(genesis.Default.Timestamp, 0),
55+
Hash: g.Hash(),
56+
Timestamp: time.Unix(g.Timestamp, 0),
5657
},
5758
},
5859
)
5960

60-
ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, genesis.Default))
61+
ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, genesis.TestDefault()))
6162

6263
valid := NewGenericValidator(nil, func(_ context.Context, sr StateReader, addr address.Address) (*state.Account, error) {
6364
pk := identityset.PrivateKey(27).PublicKey()

action/protocol/poll/governance_protocol_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func initConstruct(ctrl *gomock.Controller) (Protocol, context.Context, protocol
3838
Genesis genesis.Genesis
3939
Chain blockchain.Config
4040
}{
41-
Genesis: genesis.Default,
41+
Genesis: genesis.TestDefault(),
4242
Chain: blockchain.DefaultConfig,
4343
}
4444
cfg.Genesis.EasterBlockHeight = 1 // set up testing after Easter Height

action/protocol/poll/lifelong_protocol_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Context, protocol.StateManager, error) {
25-
genesisConfig := genesis.Default
25+
genesisConfig := genesis.TestDefault()
2626
delegates := genesisConfig.Delegates
2727
p := NewLifeLongDelegatesProtocol(delegates)
2828
registry := protocol.NewRegistry()
@@ -32,7 +32,7 @@ func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Co
3232
}
3333
ctx := genesis.WithGenesisContext(
3434
protocol.WithRegistry(context.Background(), registry),
35-
genesis.Default,
35+
genesisConfig,
3636
)
3737
ctx = protocol.WithActionCtx(
3838
ctx,

action/protocol/poll/protocol_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func TestNewProtocol(t *testing.T) {
2525
require := require.New(t)
2626
ctrl := gomock.NewController(t)
2727
committee := mock_committee.NewMockCommittee(ctrl)
28-
g := genesis.Default
28+
g := genesis.TestDefault()
29+
g.EnableGravityChainVoting = true
2930
g.ScoreThreshold = "1200000"
3031
p, err := NewProtocol(
3132
_rollDPoSScheme,

0 commit comments

Comments
 (0)