neotest: calculate system fee for deployment transactions

1. Bind NewDeployTxBy to Executor to be able to use
   (*Executor).AddSystemFee.
2. Replace pre-defined constant deployment fee by calculated one.

This change is needed to be able to properly collect coverage for
_deploy method of a contract via neotest coverage. Ref.
https://github.com/nspcc-dev/neo-go/pull/3462#pullrequestreview-2229601870.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-08-09 11:55:22 +03:00
parent 5799397034
commit 72d1427109
2 changed files with 11 additions and 11 deletions

View file

@ -127,7 +127,7 @@ func TestManagement_CallInTheSameBlock(t *testing.T) {
m.Name = "another contract"
h := state.CreateContractHash(e.Validator.ScriptHash(), ne.Checksum, m.Name)
txDeploy := e.NewDeployTx(t, e.Chain, &neotest.Contract{Hash: h, NEF: ne, Manifest: m}, nil)
txDeploy := e.NewDeployTx(t, &neotest.Contract{Hash: h, NEF: ne, Manifest: m}, nil)
txHasMethod := e.NewTx(t, []neotest.Signer{e.Validator}, bc.ManagementContractHash(), "hasMethod", h, "main", 0)
txCall := e.NewUnsignedTx(t, h, "main") // Test invocation doesn't give true GAS cost before deployment.

View file

@ -11,7 +11,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/fee"
"github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -146,7 +145,7 @@ func (e *Executor) DeployContract(t testing.TB, c *Contract, data any) util.Uint
// data is an optional argument to `_deploy`.
// It returns the hash of the deploy transaction.
func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, data any) util.Uint256 {
tx := NewDeployTxBy(t, e.Chain, signer, c, data)
tx := e.NewDeployTxBy(t, signer, c, data)
e.AddNewBlock(t, tx)
e.CheckHalt(t, tx.Hash())
@ -165,7 +164,7 @@ func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, da
// DeployContractCheckFAULT compiles and deploys a contract to the bc using the validator
// account. It checks that the deploy transaction FAULTed with the specified error.
func (e *Executor) DeployContractCheckFAULT(t testing.TB, c *Contract, data any, errMessage string) {
tx := e.NewDeployTx(t, e.Chain, c, data)
tx := e.NewDeployTx(t, c, data)
e.AddNewBlock(t, tx)
e.CheckFault(t, tx.Hash(), errMessage)
}
@ -258,29 +257,30 @@ func (e *Executor) EnsureGASBalance(t testing.TB, acc util.Uint160, isOk func(ba
}
// NewDeployTx returns a new deployment tx for the contract signed by the committee.
func (e *Executor) NewDeployTx(t testing.TB, bc *core.Blockchain, c *Contract, data any) *transaction.Transaction {
return NewDeployTxBy(t, bc, e.Validator, c, data)
func (e *Executor) NewDeployTx(t testing.TB, c *Contract, data any) *transaction.Transaction {
return e.NewDeployTxBy(t, e.Validator, c, data)
}
// NewDeployTxBy returns a new deployment tx for the contract signed by the specified signer.
func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract, data any) *transaction.Transaction {
func (e *Executor) NewDeployTxBy(t testing.TB, signer Signer, c *Contract, data any) *transaction.Transaction {
rawManifest, err := json.Marshal(c.Manifest)
require.NoError(t, err)
neb, err := c.NEF.Bytes()
require.NoError(t, err)
script, err := smartcontract.CreateCallScript(bc.ManagementContractHash(), "deploy", neb, rawManifest, data)
script, err := smartcontract.CreateCallScript(e.Chain.ManagementContractHash(), "deploy", neb, rawManifest, data)
require.NoError(t, err)
tx := transaction.New(script, 100*native.GASFactor)
tx := transaction.New(script, 0)
tx.Nonce = Nonce()
tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
tx.Signers = []transaction.Signer{{
Account: signer.ScriptHash(),
Scopes: transaction.Global,
}}
AddNetworkFee(t, bc, tx, signer)
AddNetworkFee(t, e.Chain, tx, signer)
e.AddSystemFee(tx, -1)
require.NoError(t, signer.SignTx(netmode.UnitTestNet, tx))
return tx
}