core: allow to provide block in GetTestVM()

Sometimes amount of GAS consumed depends on block height.
This commit is contained in:
Evgenii Stratonikov 2020-11-21 15:19:23 +03:00
parent 42ae226f9e
commit a5914f89fa
5 changed files with 6 additions and 6 deletions

View file

@ -1557,10 +1557,10 @@ func (bc *Blockchain) GetEnrollments() ([]state.Validator, error) {
} }
// GetTestVM returns a VM and a Store setup for a test run of some sort of code. // GetTestVM returns a VM and a Store setup for a test run of some sort of code.
func (bc *Blockchain) GetTestVM(tx *transaction.Transaction) *vm.VM { func (bc *Blockchain) GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM {
d := bc.dao.GetWrapped().(*dao.Simple) d := bc.dao.GetWrapped().(*dao.Simple)
d.MPT = nil d.MPT = nil
systemInterop := bc.newInteropContext(trigger.Application, d, nil, tx) systemInterop := bc.newInteropContext(trigger.Application, d, b, tx)
vm := systemInterop.SpawnVM() vm := systemInterop.SpawnVM()
vm.SetPriceGetter(getPrice) vm.SetPriceGetter(getPrice)
return vm return vm

View file

@ -50,7 +50,7 @@ type Blockchainer interface {
GetStateRoot(height uint32) (*state.MPTRootState, error) GetStateRoot(height uint32) (*state.MPTRootState, error)
GetStorageItem(id int32, key []byte) *state.StorageItem GetStorageItem(id int32, key []byte) *state.StorageItem
GetStorageItems(id int32) (map[string]*state.StorageItem, error) GetStorageItems(id int32) (map[string]*state.StorageItem, error)
GetTestVM(tx *transaction.Transaction) *vm.VM GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
mempool.Feer // fee interface mempool.Feer // fee interface
GetMaxBlockSize() uint32 GetMaxBlockSize() uint32

View file

@ -130,7 +130,7 @@ func (chain testChain) GetStateRoot(height uint32) (*state.MPTRootState, error)
func (chain testChain) GetStorageItem(id int32, key []byte) *state.StorageItem { func (chain testChain) GetStorageItem(id int32, key []byte) *state.StorageItem {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetTestVM(tx *transaction.Transaction) *vm.VM { func (chain testChain) GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetStorageItems(id int32) (map[string]*state.StorageItem, error) { func (chain testChain) GetStorageItems(id int32) (map[string]*state.StorageItem, error) {

View file

@ -284,7 +284,7 @@ func TestCreateNEP5TransferTx(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, acc.SignTx(tx)) require.NoError(t, acc.SignTx(tx))
require.NoError(t, chain.VerifyTx(tx)) require.NoError(t, chain.VerifyTx(tx))
v := chain.GetTestVM(tx) v := chain.GetTestVM(tx, nil)
v.LoadScriptWithFlags(tx.Script, smartcontract.All) v.LoadScriptWithFlags(tx.Script, smartcontract.All)
require.NoError(t, v.Run()) require.NoError(t, v.Run())
} }

View file

@ -1127,7 +1127,7 @@ func (s *Server) invokescript(reqParams request.Params) (interface{}, *response.
// runScriptInVM runs given script in a new test VM and returns the invocation // runScriptInVM runs given script in a new test VM and returns the invocation
// result. // result.
func (s *Server) runScriptInVM(script []byte, tx *transaction.Transaction) *result.Invoke { func (s *Server) runScriptInVM(script []byte, tx *transaction.Transaction) *result.Invoke {
vm := s.chain.GetTestVM(tx) vm := s.chain.GetTestVM(tx, nil)
vm.GasLimit = int64(s.config.MaxGasInvoke) vm.GasLimit = int64(s.config.MaxGasInvoke)
vm.LoadScriptWithFlags(script, smartcontract.All) vm.LoadScriptWithFlags(script, smartcontract.All)
err := vm.Run() err := vm.Run()