From a5914f89fa62c240a1d0ea454892899097df6617 Mon Sep 17 00:00:00 2001
From: Evgenii Stratonikov <evgeniy@nspcc.ru>
Date: Sat, 21 Nov 2020 15:19:23 +0300
Subject: [PATCH] core: allow to provide block in `GetTestVM()`

Sometimes amount of GAS consumed depends on block height.
---
 pkg/core/blockchain.go                | 4 ++--
 pkg/core/blockchainer/blockchainer.go | 2 +-
 pkg/network/helper_test.go            | 2 +-
 pkg/rpc/server/client_test.go         | 2 +-
 pkg/rpc/server/server.go              | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go
index cbfea1725..689874354 100644
--- a/pkg/core/blockchain.go
+++ b/pkg/core/blockchain.go
@@ -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
diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go
index 451b7941c..ce9ea4c5c 100644
--- a/pkg/core/blockchainer/blockchainer.go
+++ b/pkg/core/blockchainer/blockchainer.go
@@ -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
diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go
index 1c9169ead..962073c4a 100644
--- a/pkg/network/helper_test.go
+++ b/pkg/network/helper_test.go
@@ -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) {
diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go
index 4fe350bc1..711db62a5 100644
--- a/pkg/rpc/server/client_test.go
+++ b/pkg/rpc/server/client_test.go
@@ -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())
 }
diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go
index f17412ba3..382e28079 100644
--- a/pkg/rpc/server/server.go
+++ b/pkg/rpc/server/server.go
@@ -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()