Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Nov 15, 2023
1 parent fa59762 commit 93ffc32
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 20 deletions.
7 changes: 7 additions & 0 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/core/vm"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -64,6 +65,9 @@ func TestExecuteContractFailure(t *testing.T) {
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
GetBlockTime: func(uint64) (time.Time, error) {
return time.Time{}, nil
},
DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) {
return nil, nil
},
Expand Down Expand Up @@ -262,6 +266,9 @@ func TestConstantinople(t *testing.T) {
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
GetBlockTime: func(uint64) (time.Time, error) {
return time.Time{}, nil
},
})
stateDB, err := prepareStateDB(fCtx, sm)
require.NoError(err)
Expand Down
12 changes: 9 additions & 3 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"math/big"
"os"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -285,6 +286,9 @@ func readExecution(
}
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: func(uint64) (time.Time, error) {
return time.Time{}, nil
},
})
return sf.SimulateExecution(ctx, addr, exec)
}
Expand Down Expand Up @@ -457,7 +461,7 @@ func (sct *SmartContractTest) prepareBlockchain(
r.NoError(reward.Register(registry))

r.NotNil(bc)
execution := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
execution := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
r.NoError(execution.Register(registry))
r.NoError(bc.Start(ctx))

Expand Down Expand Up @@ -607,7 +611,9 @@ func TestProtocol_Validate(t *testing.T) {
require := require.New(t)
p := NewProtocol(func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
}, rewarding.DepositGasWithSGD, nil)
}, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) {
return time.Time{}, nil
})

ex, err := action.NewExecution("2", uint64(1), big.NewInt(0), uint64(0), big.NewInt(0), make([]byte, 32684))
require.NoError(err)
Expand Down Expand Up @@ -677,7 +683,7 @@ func TestProtocol_Handle(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
exeProtocol := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
exeProtocol := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
require.NoError(exeProtocol.Register(registry))
require.NoError(bc.Start(ctx))
require.NotNil(bc)
Expand Down
3 changes: 3 additions & 0 deletions action/protocol/poll/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestNewProtocol(t *testing.T) {
func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
func(u uint64) (time.Time, error) {
return time.Time{}, nil
},
)
require.NoError(err)
require.NotNil(p)
Expand Down
3 changes: 2 additions & 1 deletion api/coreservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math/big"
"strconv"
"testing"
"time"

"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -174,7 +175,7 @@ func setupTestCoreService() (CoreService, blockchain.Blockchain, blockdao.BlockD
opts := []Option{WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error {
return nil
})}
svr, err := newCoreService(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, opts...)
svr, err := newCoreService(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, func(u uint64) (time.Time, error) { return time.Time{}, nil }, opts...)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions api/serverV2_integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func setupChain(cfg testConfig) (blockchain.Blockchain, blockdao.BlockDAO, block
}()

acc := account.NewProtocol(rewarding.DepositGas)
evm := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
evm := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
p := poll.NewLifeLongDelegatesProtocol(cfg.genesis.Delegates)
rolldposProtocol := rolldpos.NewProtocol(
genesis.Default.NumCandidateDelegates,
Expand Down Expand Up @@ -452,7 +452,7 @@ func createServerV2(cfg testConfig, needActPool bool) (*ServerV2, blockchain.Blo
opts := []Option{WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error {
return nil
})}
svr, err := NewServerV2(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, opts...)
svr, err := NewServerV2(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, func(u uint64) (time.Time, error) { return time.Time{}, nil }, opts...)
if err != nil {
return nil, nil, nil, nil, nil, nil, "", err
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/integrity/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
if bc == nil {
return nil, nil, errors.New("pointer is nil")
}
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
if err = ep.Register(registry); err != nil {
return nil, nil, err
}
Expand Down
18 changes: 11 additions & 7 deletions blockchain/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ var (
_postGrPostStore *big.Int
)

func fakeGetBlockTime(height uint64) (time.Time, error) {
return time.Time{}, nil
}

func addTestingConstantinopleBlocks(bc blockchain.Blockchain, dao blockdao.BlockDAO, sf factory.Factory, ap actpool.ActPool) error {
// Add block 1
priKey0 := identityset.PrivateKey(27)
Expand Down Expand Up @@ -494,7 +498,7 @@ func TestCreateBlockchain(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -547,7 +551,7 @@ func TestGetBlockHash(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -710,7 +714,7 @@ func TestBlockchain_MintNewBlock(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(t, ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(t, rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -786,7 +790,7 @@ func TestBlockchain_MintNewBlock_PopAccount(t *testing.T) {
)
rp := rolldpos.NewProtocol(cfg.Genesis.NumCandidateDelegates, cfg.Genesis.NumDelegates, cfg.Genesis.NumSubEpochs)
require.NoError(t, rp.Register(registry))
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(t, ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(t, rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -885,7 +889,7 @@ func TestConstantinople(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -1135,7 +1139,7 @@ func TestLoadBlockchainfromDB(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(ep.Register(registry))
require.NoError(bc.Start(ctx))

Expand Down Expand Up @@ -1989,7 +1993,7 @@ func newChain(t *testing.T, stateTX bool) (blockchain.Blockchain, factory.Factor
)),
)
require.NotNil(bc)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
require.NoError(ep.Register(registry))
require.NoError(bc.Start(context.Background()))

Expand Down
5 changes: 4 additions & 1 deletion e2etest/bigint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"math/big"
"testing"
"time"

"github.com/iotexproject/go-pkgs/crypto"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -39,6 +40,8 @@ const (
_executorPriKey = "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1"
)

func fakeGetBlockTime(uint64) (time.Time, error) { return time.Time{}, nil }

func TestTransfer_Negative(t *testing.T) {
r := require.New(t)
ctx := context.Background()
Expand Down Expand Up @@ -110,7 +113,7 @@ func prepareBlockchain(ctx context.Context, _executor string, r *require.Asserti
reward := rewarding.NewProtocol(cfg.Genesis.Rewarding)
r.NoError(reward.Register(registry))

ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
r.NoError(ep.Register(registry))
r.NoError(bc.Start(ctx))
ctx = genesis.WithGenesisContext(ctx, cfg.Genesis)
Expand Down
2 changes: 1 addition & 1 deletion e2etest/contract_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ func prepareContractStakingBlockchain(ctx context.Context, cfg config.Config, r
// r.NoError(reward.Register(registry))

r.NotNil(bc)
execution := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
execution := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
r.NoError(execution.Register(registry))
r.NoError(bc.Start(ctx))

Expand Down
2 changes: 1 addition & 1 deletion e2etest/sgd_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestSGDRegistry(t *testing.T) {
reward := rewarding.NewProtocol(cfg.Genesis.Rewarding)
r.NoError(reward.Register(registry))

ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, fakeGetBlockTime)
r.NoError(ep.Register(registry))
r.NoError(bc.Start(ctx))
ctx = genesis.WithGenesisContext(ctx, cfg.Genesis)
Expand Down
3 changes: 3 additions & 0 deletions e2etest/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func TestStakingContract(t *testing.T) {

ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: func(u uint64) (time.Time, error) {
return time.Time{}, nil
},
})
data, _, err := sf.SimulateExecution(ctx, addr, ex)

Expand Down
5 changes: 3 additions & 2 deletions gasstation/gasstattion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"math/big"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -81,7 +82,7 @@ func TestSuggestGasPriceForUserAction(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(blkMemDao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(blkMemDao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
require.NoError(t, ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(t, rewardingProtocol.Register(registry))
Expand Down Expand Up @@ -157,7 +158,7 @@ func TestSuggestGasPriceForSystemAction(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
ep := execution.NewProtocol(blkMemDao.GetBlockHash, rewarding.DepositGasWithSGD, nil)
ep := execution.NewProtocol(blkMemDao.GetBlockHash, rewarding.DepositGasWithSGD, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil })
require.NoError(t, ep.Register(registry))
rewardingProtocol := rewarding.NewProtocol(cfg.Genesis.Rewarding)
require.NoError(t, rewardingProtocol.Register(registry))
Expand Down
3 changes: 3 additions & 0 deletions state/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,9 @@ func testSimulateExecution(ctx context.Context, sf Factory, t *testing.T) {
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
GetBlockTime: func(u uint64) (time.Time, error) {
return time.Time{}, nil
},
})
_, _, err = sf.SimulateExecution(ctx, addr, ex)
require.NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion tools/actioninjector.v2/internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestClient(t *testing.T) {
require.NoError(err)
bfIndexer, err := blockindex.NewBloomfilterIndexer(db.NewMemKVStore(), cfg.Indexer)
require.NoError(err)
apiServer, err := api.NewServerV2(cfg.API, bc, nil, sf, nil, indexer, bfIndexer, ap, nil, newOption)
apiServer, err := api.NewServerV2(cfg.API, bc, nil, sf, nil, indexer, bfIndexer, ap, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil }, newOption)
require.NoError(err)
require.NoError(apiServer.Start(ctx))
// test New()
Expand Down

0 comments on commit 93ffc32

Please sign in to comment.