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

+1-1
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

+4-3
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

+1-1
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

+4-4
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

+2-2
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

+11-5
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

+4-3
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

+1-1
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

+2-2
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

+2-1
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,

action/protocol/poll/staking_committee_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func initConstructStakingCommittee(ctrl *gomock.Controller) (Protocol, context.C
3939
Genesis genesis.Genesis
4040
Chain blockchain.Config
4141
}{
42-
Genesis: genesis.Default,
42+
Genesis: genesis.TestDefault(),
4343
Chain: blockchain.DefaultConfig,
4444
}
4545
cfg.Genesis.NativeStakingContractAddress = "io1xpq62aw85uqzrccg9y5hnryv8ld2nkpycc3gza"
@@ -58,7 +58,7 @@ func initConstructStakingCommittee(ctrl *gomock.Controller) (Protocol, context.C
5858
}
5959
ctx = genesis.WithGenesisContext(
6060
protocol.WithRegistry(ctx, registry),
61-
genesis.Default,
61+
genesis.TestDefault(),
6262
)
6363
ctx = protocol.WithBlockchainCtx(ctx, protocol.BlockchainCtx{})
6464
ctx = protocol.WithActionCtx(

action/protocol/rewarding/admin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestAdminPb(t *testing.T) {
2727
a := admin{}
2828
r.NoError(a.Deserialize(b))
2929

30-
g := genesis.Default
30+
g := genesis.TestDefault()
3131
r.Equal(a.blockReward.String(), g.DardanellesBlockRewardStr)
3232
r.Equal(a.epochReward.String(), g.AleutianEpochRewardStr)
3333
r.Equal(a.numDelegatesForEpochReward, g.NumDelegatesForEpochReward)

action/protocol/rewarding/protocol_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
func TestValidateExtension(t *testing.T) {
3737
r := require.New(t)
3838

39-
g := genesis.Default.Rewarding
39+
g := genesis.TestDefault().Rewarding
4040
r.NoError(validateFoundationBonusExtension(g))
4141

4242
last := g.FoundationBonusP2StartEpoch
@@ -56,7 +56,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
5656
registry := protocol.NewRegistry()
5757
sm := testdb.NewMockStateManager(ctrl)
5858

59-
g := genesis.Default
59+
g := genesis.TestDefault()
6060
// Create a test account with 1000 token
6161
g.InitBalanceMap[identityset.Address(28).String()] = "1000"
6262
g.Rewarding.InitBalanceStr = "0"
@@ -173,7 +173,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
173173
ctx = protocol.WithBlockCtx(
174174
ctx, protocol.BlockCtx{
175175
Producer: identityset.Address(27),
176-
BlockHeight: genesis.Default.NumDelegates * genesis.Default.NumSubEpochs,
176+
BlockHeight: g.NumDelegates * g.NumSubEpochs,
177177
},
178178
)
179179
ctx = protocol.WithActionCtx(
@@ -218,15 +218,15 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
218218
}
219219

220220
func TestProtocol_Validate(t *testing.T) {
221-
g := genesis.Default
221+
g := genesis.TestDefault()
222222
g.NewfoundlandBlockHeight = 0
223223
p := NewProtocol(g.Rewarding)
224224
act := createGrantRewardAction(0, uint64(0))
225225
ctx := protocol.WithBlockCtx(
226226
context.Background(),
227227
protocol.BlockCtx{
228228
Producer: identityset.Address(0),
229-
BlockHeight: genesis.Default.NumDelegates * genesis.Default.NumSubEpochs,
229+
BlockHeight: g.NumDelegates * g.NumSubEpochs,
230230
},
231231
)
232232
ctx = genesis.WithGenesisContext(
@@ -272,7 +272,7 @@ func TestProtocol_Validate(t *testing.T) {
272272
func TestProtocol_Handle(t *testing.T) {
273273
ctrl := gomock.NewController(t)
274274

275-
g := genesis.Default
275+
g := genesis.TestDefault()
276276
registry := protocol.NewRegistry()
277277
sm := mock_chainmanager.NewMockStateManager(ctrl)
278278
cb := batch.NewCachedBatch()
@@ -357,7 +357,7 @@ func TestProtocol_Handle(t *testing.T) {
357357
ctx,
358358
protocol.BlockCtx{
359359
Producer: identityset.Address(0),
360-
BlockHeight: genesis.Default.NumDelegates * genesis.Default.NumSubEpochs,
360+
BlockHeight: g.NumDelegates * g.NumSubEpochs,
361361
},
362362
)
363363
ctx = protocol.WithActionCtx(
@@ -506,7 +506,7 @@ func TestStateCheckLegacy(t *testing.T) {
506506

507507
ctrl := gomock.NewController(t)
508508
sm := testdb.NewMockStateManager(ctrl)
509-
p := NewProtocol(genesis.Default.Rewarding)
509+
p := NewProtocol(genesis.TestDefault().Rewarding)
510510
chainCtx := genesis.WithGenesisContext(
511511
context.Background(),
512512
genesis.Genesis{
@@ -601,7 +601,7 @@ func TestMigrateValue(t *testing.T) {
601601
e1 := exempt{
602602
[]address.Address{identityset.Address(31)},
603603
}
604-
g := genesis.Default
604+
g := genesis.TestDefault()
605605

606606
testProtocol(t, func(t *testing.T, ctx context.Context, sm protocol.StateManager, p *Protocol) {
607607
// verify v1 state

action/protocol/rewarding/reward_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestProtocol_GrantBlockReward(t *testing.T) {
7373

7474
// Grant with priority fee after VanuatuBlockHeight
7575
blkCtx.AccumulatedTips = *big.NewInt(5)
76-
blkCtx.BlockHeight = genesis.Default.VanuatuBlockHeight
76+
blkCtx.BlockHeight = genesis.TestDefault().VanuatuBlockHeight
7777
ctx = protocol.WithFeatureCtx(protocol.WithBlockCtx(ctx, blkCtx))
7878
rewardLog, err = p.GrantBlockReward(ctx, sm)
7979
require.NoError(t, err)
@@ -344,7 +344,7 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
344344
}).AnyTimes()
345345
sm.EXPECT().Height().Return(uint64(1), nil).AnyTimes()
346346

347-
ge := genesis.Default
347+
ge := genesis.TestDefault()
348348
ge.Rewarding.InitBalanceStr = "0"
349349
ge.Rewarding.BlockRewardStr = "10"
350350
ge.Rewarding.EpochRewardStr = "100"
@@ -362,9 +362,9 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
362362

363363
p := NewProtocol(ge.Rewarding)
364364
rp := rolldpos.NewProtocol(
365-
genesis.Default.NumCandidateDelegates,
366-
genesis.Default.NumDelegates,
367-
genesis.Default.NumSubEpochs,
365+
ge.NumCandidateDelegates,
366+
ge.NumDelegates,
367+
ge.NumSubEpochs,
368368
)
369369
abps := []*state.Candidate{
370370
{
@@ -378,7 +378,7 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
378378
RewardAddress: identityset.Address(1).String(),
379379
},
380380
}
381-
g := genesis.Default
381+
g := genesis.TestDefault()
382382
committee := mock_committee.NewMockCommittee(ctrl)
383383
slasher, err := poll.NewSlasher(
384384
func(uint64, uint64) (map[string]uint64, error) {
@@ -443,7 +443,7 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
443443
ctx,
444444
protocol.BlockCtx{
445445
Producer: identityset.Address(0),
446-
BlockHeight: genesis.Default.NumDelegates * genesis.Default.NumSubEpochs,
446+
BlockHeight: g.NumDelegates * g.NumSubEpochs,
447447
},
448448
)
449449
ctx = protocol.WithActionCtx(

action/protocol/staking/bucket_pool_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestBucketPool(t *testing.T) {
119119
r.Equal(count, pool.Count())
120120

121121
var testGreenland bool
122-
ctx := protocol.WithFeatureWithHeightCtx(genesis.WithGenesisContext(context.Background(), genesis.Default))
122+
ctx := protocol.WithFeatureWithHeightCtx(genesis.WithGenesisContext(context.Background(), genesis.TestDefault()))
123123
for _, v := range tests {
124124
csm, err = NewCandidateStateManager(sm, v.postGreenland && testGreenland)
125125
r.NoError(err)

0 commit comments

Comments
 (0)