mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-22 21:17:35 +00:00
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:
parent
5799397034
commit
72d1427109
2 changed files with 11 additions and 11 deletions
|
@ -127,7 +127,7 @@ func TestManagement_CallInTheSameBlock(t *testing.T) {
|
||||||
m.Name = "another contract"
|
m.Name = "another contract"
|
||||||
h := state.CreateContractHash(e.Validator.ScriptHash(), ne.Checksum, m.Name)
|
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)
|
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.
|
txCall := e.NewUnsignedTx(t, h, "main") // Test invocation doesn't give true GAS cost before deployment.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"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/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
"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/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"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`.
|
// data is an optional argument to `_deploy`.
|
||||||
// It returns the hash of the deploy transaction.
|
// It returns the hash of the deploy transaction.
|
||||||
func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, data any) util.Uint256 {
|
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.AddNewBlock(t, tx)
|
||||||
e.CheckHalt(t, tx.Hash())
|
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
|
// DeployContractCheckFAULT compiles and deploys a contract to the bc using the validator
|
||||||
// account. It checks that the deploy transaction FAULTed with the specified error.
|
// 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) {
|
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.AddNewBlock(t, tx)
|
||||||
e.CheckFault(t, tx.Hash(), errMessage)
|
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.
|
// 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 {
|
func (e *Executor) NewDeployTx(t testing.TB, c *Contract, data any) *transaction.Transaction {
|
||||||
return NewDeployTxBy(t, bc, e.Validator, c, data)
|
return e.NewDeployTxBy(t, e.Validator, c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeployTxBy returns a new deployment tx for the contract signed by the specified signer.
|
// 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)
|
rawManifest, err := json.Marshal(c.Manifest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
neb, err := c.NEF.Bytes()
|
neb, err := c.NEF.Bytes()
|
||||||
require.NoError(t, err)
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tx := transaction.New(script, 100*native.GASFactor)
|
tx := transaction.New(script, 0)
|
||||||
tx.Nonce = Nonce()
|
tx.Nonce = Nonce()
|
||||||
tx.ValidUntilBlock = bc.BlockHeight() + 1
|
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
|
||||||
tx.Signers = []transaction.Signer{{
|
tx.Signers = []transaction.Signer{{
|
||||||
Account: signer.ScriptHash(),
|
Account: signer.ScriptHash(),
|
||||||
Scopes: transaction.Global,
|
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))
|
require.NoError(t, signer.SignTx(netmode.UnitTestNet, tx))
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue