From 51a54fa2486290b644e158dc6c7d953f791711af Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 8 Apr 2022 12:49:25 +0300 Subject: [PATCH] core: return default BaseExecFee if blockchain height is 0 For (bc *Blockchain).GetBaseExecFee(). --- pkg/core/blockchain.go | 3 +++ pkg/core/blockchain_core_test.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 19045208f..6ffdba4ed 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -2341,6 +2341,9 @@ func (bc *Blockchain) RegisterPostBlock(f func(func(*transaction.Transaction, *m // GetBaseExecFee return execution price for `NOP`. func (bc *Blockchain) GetBaseExecFee() int64 { + if bc.BlockHeight() == 0 { + return interop.DefaultBaseExecFee + } return bc.contracts.Policy.GetExecFeeFactorInternal(bc.dao) } diff --git a/pkg/core/blockchain_core_test.go b/pkg/core/blockchain_core_test.go index 4a68fb16c..fbfe43213 100644 --- a/pkg/core/blockchain_core_test.go +++ b/pkg/core/blockchain_core_test.go @@ -11,10 +11,12 @@ import ( "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/dao" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" @@ -320,3 +322,22 @@ func setSigner(tx *transaction.Transaction, h util.Uint160) { Scopes: transaction.Global, }} } + +// This test checks that value of BaseExecFee returned from corresponding Blockchain's method matches +// the one provided to the constructor of new interop context. +func TestBlockchain_BaseExecFeeBaseStoragePrice_Compat(t *testing.T) { + bc := newTestChain(t) + + check := func(t *testing.T) { + ic := bc.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore(), bc.config.StateRootInHeader, bc.config.P2PSigExtensions), bc.topBlock.Load().(*block.Block), nil) + require.Equal(t, bc.GetBaseExecFee(), ic.BaseExecFee()) + require.Equal(t, bc.GetStoragePrice(), ic.BaseStorageFee()) + } + t.Run("zero block", func(t *testing.T) { + check(t) + }) + t.Run("non-zero block", func(t *testing.T) { + require.NoError(t, bc.AddBlock(bc.newBlock())) + check(t) + }) +}