Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Nov 3, 2023
1 parent 535abf8 commit b8b6ed6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
20 changes: 13 additions & 7 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ func TestExecuteContractFailure(t *testing.T) {
ChainID: 1,
EvmNetworkID: 100,
})
retval, receipt, err := ExecuteContract(ctx, sm, e,
func(uint64) (hash.Hash256, error) {
ctx = WithHelperCtx(ctx, HelperContext{
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) {
DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) {
return nil, nil
}, nil)
},
Sgd: nil,
})
retval, receipt, err := ExecuteContract(ctx, sm, e)
require.Nil(t, retval)
require.Nil(t, receipt)
require.Error(t, err)
Expand Down Expand Up @@ -255,11 +258,14 @@ func TestConstantinople(t *testing.T) {
GasLimit: testutil.TestGasLimit,
BlockHeight: e.height,
}))
fCtx = WithHelperCtx(fCtx, HelperContext{
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
})
stateDB, err := prepareStateDB(fCtx, sm)
require.NoError(err)
ps, err := newParams(fCtx, ex, stateDB, func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
})
ps, err := newParams(fCtx, ex, stateDB)
require.NoError(err)

var evmConfig vm.Config
Expand Down
6 changes: 4 additions & 2 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ func readExecution(
if err != nil {
return nil, nil, err
}

return sf.SimulateExecution(ctx, addr, exec, dao.GetBlockHash)
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
})
return sf.SimulateExecution(ctx, addr, exec)
}

func runExecutions(
Expand Down
6 changes: 5 additions & 1 deletion e2etest/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/execution/evm"
"github.com/iotexproject/iotex-core/action/protocol/poll"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
Expand Down Expand Up @@ -121,7 +122,10 @@ func TestStakingContract(t *testing.T) {
return nil, err
}

data, _, err := sf.SimulateExecution(ctx, addr, ex, dao.GetBlockHash)
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
})
data, _, err := sf.SimulateExecution(ctx, addr, ex)

return data, err
})
Expand Down
8 changes: 6 additions & 2 deletions state/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/account"
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
"github.com/iotexproject/iotex-core/action/protocol/execution/evm"
"github.com/iotexproject/iotex-core/action/protocol/poll"
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
Expand Down Expand Up @@ -1223,9 +1224,12 @@ func testSimulateExecution(ctx context.Context, sf Factory, t *testing.T) {
addr, err := address.FromString(address.ZeroAddress)
require.NoError(err)

_, _, err = sf.SimulateExecution(ctx, addr, ex, func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
},
})
_, _, err = sf.SimulateExecution(ctx, addr, ex)
require.NoError(err)
}

Expand Down
9 changes: 4 additions & 5 deletions test/mock/mock_factory/mock_factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8b6ed6

Please sign in to comment.