Skip to content

Commit

Permalink
Merge branch 'master' into test/t.TempDir
Browse files Browse the repository at this point in the history
  • Loading branch information
huof6829 authored Jul 6, 2022
2 parents fbe19eb + 2a70177 commit 41be5b2
Show file tree
Hide file tree
Showing 35 changed files with 344 additions and 316 deletions.
3 changes: 1 addition & 2 deletions action/protocol/account/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestProtocol_Initialize(t *testing.T) {
return 0, nil
}).AnyTimes()

ge := config.Default.Genesis
ge := genesis.Default
ge.Account.InitBalanceMap = map[string]string{
identityset.Address(0).String(): "100",
}
Expand Down
5 changes: 2 additions & 3 deletions action/protocol/account/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/testutil"
Expand Down Expand Up @@ -63,12 +62,12 @@ func TestProtocol_HandleTransfer(t *testing.T) {

// set-up protocol and genesis states
p := NewProtocol(rewarding.DepositGas)
reward := rewarding.NewProtocol(config.Default.Genesis.Rewarding)
reward := rewarding.NewProtocol(genesis.Default.Rewarding)
registry := protocol.NewRegistry()
require.NoError(reward.Register(registry))
chainCtx := genesis.WithGenesisContext(
protocol.WithRegistry(context.Background(), registry),
config.Default.Genesis,
genesis.Default,
)
ctx := protocol.WithBlockCtx(chainCtx, protocol.BlockCtx{})
ctx = protocol.WithFeatureCtx(ctx)
Expand Down
7 changes: 3 additions & 4 deletions action/protocol/generic_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
)
Expand Down Expand Up @@ -53,13 +52,13 @@ func TestActionProtoAndGenericValidator(t *testing.T) {
BlockchainCtx{
Tip: TipInfo{
Height: 0,
Hash: config.Default.Genesis.Hash(),
Timestamp: time.Unix(config.Default.Genesis.Timestamp, 0),
Hash: genesis.Default.Hash(),
Timestamp: time.Unix(genesis.Default.Timestamp, 0),
},
},
)

ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, config.Default.Genesis))
ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, genesis.Default))

valid := NewGenericValidator(nil, func(_ context.Context, sr StateReader, addr address.Address) (*state.Account, error) {
pk := identityset.PrivateKey(27).PublicKey()
Expand Down
5 changes: 2 additions & 3 deletions action/protocol/poll/lifelong_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import (
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/mock/mock_chainmanager"
)

func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Context, protocol.StateManager, error) {
genesisConfig := config.Default.Genesis
genesisConfig := genesis.Default
delegates := genesisConfig.Delegates
p := NewLifeLongDelegatesProtocol(delegates)
registry := protocol.NewRegistry()
Expand All @@ -33,7 +32,7 @@ func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Co
}
ctx := genesis.WithGenesisContext(
protocol.WithRegistry(context.Background(), registry),
config.Default.Genesis,
genesis.Default,
)
ctx = protocol.WithActionCtx(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/poll/staking_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initConstructStakingCommittee(ctrl *gomock.Controller) (Protocol, context.C
}
ctx = genesis.WithGenesisContext(
protocol.WithRegistry(ctx, registry),
config.Default.Genesis,
genesis.Default,
)
ctx = protocol.WithBlockchainCtx(ctx, protocol.BlockchainCtx{})
ctx = protocol.WithActionCtx(
Expand Down
9 changes: 4 additions & 5 deletions action/protocol/rewarding/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/iotexproject/iotex-core/action/protocol/poll"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/pkg/unit"
"github.com/iotexproject/iotex-core/state"
Expand All @@ -38,7 +37,7 @@ import (
func TestValidateExtension(t *testing.T) {
r := require.New(t)

g := config.Default.Genesis.Rewarding
g := genesis.Default.Rewarding
r.NoError(validateFoundationBonusExtension(g))

last := g.FoundationBonusP2StartEpoch
Expand All @@ -58,7 +57,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
registry := protocol.NewRegistry()
sm := testdb.NewMockStateManager(ctrl)

g := config.Default.Genesis
g := genesis.Default
// Create a test account with 1000 token
g.InitBalanceMap[identityset.Address(28).String()] = "1000"
g.Rewarding.InitBalanceStr = "0"
Expand Down Expand Up @@ -220,7 +219,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
}

func TestProtocol_Validate(t *testing.T) {
g := config.Default.Genesis
g := genesis.Default
g.NewfoundlandBlockHeight = 0
p := NewProtocol(g.Rewarding)
act := createGrantRewardAction(0, uint64(0)).Action()
Expand Down Expand Up @@ -274,7 +273,7 @@ func TestProtocol_Validate(t *testing.T) {
func TestProtocol_Handle(t *testing.T) {
ctrl := gomock.NewController(t)

g := config.Default.Genesis
g := genesis.Default
registry := protocol.NewRegistry()
sm := mock_chainmanager.NewMockStateManager(ctrl)
cb := batch.NewCachedBatch()
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/rewarding/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
}).AnyTimes()
sm.EXPECT().Height().Return(uint64(1), nil).AnyTimes()

ge := config.Default.Genesis
ge := genesis.Default
ge.Rewarding.InitBalanceStr = "0"
ge.Rewarding.BlockRewardStr = "10"
ge.Rewarding.EpochRewardStr = "100"
Expand Down
3 changes: 3 additions & 0 deletions api/serverV2_integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ func createServerV2(cfg config.Config, needActPool bool) (*ServerV2, blockchain.
opts := []Option{WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error {
return nil
})}
cfg.API.GRPCPort = testutil.RandomPort()
cfg.API.HTTPPort = 0
cfg.API.WebSocketPort = 0
svr, err := NewServerV2(cfg.API, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, opts...)
if err != nil {
return nil, nil, nil, nil, nil, nil, "", err
Expand Down
3 changes: 1 addition & 2 deletions blockchain/block/genesis_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/pkg/version"
)

func TestGenesisBlock(t *testing.T) {
r := require.New(t)

g := config.Default.Genesis
g := genesis.Default
genesis.SetGenesisTimestamp(g.Timestamp)
blk := GenesisBlock()
r.EqualValues(version.ProtocolVersion, blk.Version())
Expand Down
8 changes: 4 additions & 4 deletions blockchain/blockdao/blockdao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestBlockDAO(t *testing.T) {

testBlockDao := func(dao BlockDAO, t *testing.T) {
ctx := protocol.WithBlockchainCtx(
genesis.WithGenesisContext(context.Background(), config.Default.Genesis),
genesis.WithGenesisContext(context.Background(), genesis.Default),
protocol.BlockchainCtx{
ChainID: config.Default.Chain.ID,
})
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestBlockDAO(t *testing.T) {

testDeleteDao := func(dao BlockDAO, t *testing.T) {
ctx := protocol.WithBlockchainCtx(
genesis.WithGenesisContext(context.Background(), config.Default.Genesis),
genesis.WithGenesisContext(context.Background(), genesis.Default),
protocol.BlockchainCtx{
ChainID: config.Default.Chain.ID,
})
Expand Down Expand Up @@ -414,8 +414,8 @@ func TestBlockDAO(t *testing.T) {

cfg := db.DefaultConfig
cfg.DbPath = testPath
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)
for _, v := range daoList {
testutil.CleanupPath(testPath)
dao, err := createTestBlockDAO(v.inMemory, v.legacy, v.compressBlock, cfg)
Expand Down
4 changes: 2 additions & 2 deletions blockchain/filedao/filedao_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func TestFileDAOLegacy_PutBlock(t *testing.T) {

cfg := db.DefaultConfig
cfg.DbPath = testPath
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)
for _, compress := range []bool{false, true} {
cfg.CompressLegacy = compress
t.Run("test fileDAOLegacy interface", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions blockchain/filedao/filedao_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ func TestNewFdInterface(t *testing.T) {
deser := block.NewDeserializer(config.Default.Chain.EVMNetworkID)
_, err = newFileDAOv2(0, cfg, deser)
r.Equal(ErrNotSupported, err)
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)

for _, compress := range []string{"", compress.Snappy} {
for _, start := range []uint64{1, 5, _blockStoreBatchSize + 1, 4 * _blockStoreBatchSize} {
Expand Down
3 changes: 2 additions & 1 deletion blockchain/filedao/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/db/batch"
Expand Down Expand Up @@ -223,7 +224,7 @@ func testVerifyChainDB(t *testing.T, fd FileDAO, start, end uint64) {
}

func createTestingBlock(builder *block.TestingBuilder, height uint64, h hash.Hash256) *block.Block {
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)
r := &action.Receipt{
Status: 1,
BlockHeight: height,
Expand Down
3 changes: 2 additions & 1 deletion blockchain/integrity/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/blockindex"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
Expand Down Expand Up @@ -220,7 +221,7 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
cfg.Chain.IndexDBPath = testIndexPath
cfg.Chain.EnableArchiveMode = true
cfg.Consensus.Scheme = config.RollDPoSScheme
cfg.Genesis.BlockGasLimit = config.Default.Genesis.BlockGasLimit * 100
cfg.Genesis.BlockGasLimit = genesis.Default.BlockGasLimit * 100
cfg.ActPool.MinGasPriceStr = "0"
cfg.ActPool.MaxNumActsPerAcct = 1000000000
cfg.Genesis.EnableGravityChainVoting = false
Expand Down
4 changes: 2 additions & 2 deletions blockchain/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestGetBlockHash(t *testing.T) {
cfg.Genesis.MidwayBlockHeight = 9
cfg.ActPool.MinGasPriceStr = "0"
genesis.SetGenesisTimestamp(cfg.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)
// create chain
registry := protocol.NewRegistry()
acc := account.NewProtocol(rewarding.DepositGas)
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func TestLoadBlockchainfromDB(t *testing.T) {
cfg.Genesis.EnableGravityChainVoting = false
cfg.ActPool.MinGasPriceStr = "0"
genesis.SetGenesisTimestamp(cfg.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)

t.Run("load blockchain from DB w/o explorer", func(t *testing.T) {
testValidateBlockchain(cfg, t)
Expand Down
Loading

0 comments on commit 41be5b2

Please sign in to comment.