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.
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.MPT = nil
systemInterop := bc.newInteropContext(trigger.Application, d, nil, tx)
systemInterop := bc.newInteropContext(trigger.Application, d, b, tx)
vm := systemInterop.SpawnVM()
vm.SetPriceGetter(getPrice)
return vm

View file

@ -50,7 +50,7 @@ type Blockchainer interface {
GetStateRoot(height uint32) (*state.MPTRootState, error)
GetStorageItem(id int32, key []byte) *state.StorageItem
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)
mempool.Feer // fee interface
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 {
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")
}
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, acc.SignTx(tx))
require.NoError(t, chain.VerifyTx(tx))
v := chain.GetTestVM(tx)
v := chain.GetTestVM(tx, nil)
v.LoadScriptWithFlags(tx.Script, smartcontract.All)
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
// result.
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.LoadScriptWithFlags(script, smartcontract.All)
err := vm.Run()