mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-16 21:16:30 +00:00
neotest: bind AddSystemFee and TestInvoke to Executor
These methods need Executor's context to properly process coverage, thus these methods are not independent anymore. Ref. https://github.com/nspcc-dev/neo-go/pull/3462#pullrequestreview-2219332436. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
ffcbe6a10d
commit
5799397034
3 changed files with 10 additions and 10 deletions
|
@ -67,7 +67,7 @@ func TestCryptoLib_KoblitzVerificationScript(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
neotest.AddNetworkFee(t, e.Chain, tx)
|
neotest.AddNetworkFee(t, e.Chain, tx)
|
||||||
neotest.AddSystemFee(e.Chain, tx, -1)
|
e.AddSystemFee(tx, -1)
|
||||||
|
|
||||||
// Add some more network fee to pay for the witness verification. This value may be calculated precisely,
|
// Add some more network fee to pay for the witness verification. This value may be calculated precisely,
|
||||||
// but let's keep some inaccurate value for the test.
|
// but let's keep some inaccurate value for the test.
|
||||||
|
@ -631,7 +631,7 @@ func TestCryptoLib_KoblitzMultisigVerificationScript(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
neotest.AddNetworkFee(t, e.Chain, tx)
|
neotest.AddNetworkFee(t, e.Chain, tx)
|
||||||
neotest.AddSystemFee(e.Chain, tx, -1)
|
e.AddSystemFee(tx, -1)
|
||||||
|
|
||||||
// Add some more network fee to pay for the witness verification. This value may be calculated precisely,
|
// Add some more network fee to pay for the witness verification. This value may be calculated precisely,
|
||||||
// but let's keep some inaccurate value for the test.
|
// but let's keep some inaccurate value for the test.
|
||||||
|
|
|
@ -227,7 +227,7 @@ func TestLedger_GetTransactionSignersInteropAPI(t *testing.T) {
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
neotest.AddNetworkFee(t, e.Chain, tx, c.Committee)
|
neotest.AddNetworkFee(t, e.Chain, tx, c.Committee)
|
||||||
neotest.AddSystemFee(e.Chain, tx, -1)
|
e.AddSystemFee(tx, -1)
|
||||||
require.NoError(t, c.Committee.SignTx(e.Chain.GetConfig().Magic, tx))
|
require.NoError(t, c.Committee.SignTx(e.Chain.GetConfig().Magic, tx))
|
||||||
c.AddNewBlock(t, tx)
|
c.AddNewBlock(t, tx)
|
||||||
c.CheckHalt(t, tx.Hash(), stackitem.Make(e.Chain.BlockHeight()-1))
|
c.CheckHalt(t, tx.Hash(), stackitem.Make(e.Chain.BlockHeight()-1))
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (e *Executor) SignTx(t testing.TB, tx *transaction.Transaction, sysFee int6
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
AddNetworkFee(t, e.Chain, tx, signers...)
|
AddNetworkFee(t, e.Chain, tx, signers...)
|
||||||
AddSystemFee(e.Chain, tx, sysFee)
|
e.AddSystemFee(tx, sysFee)
|
||||||
|
|
||||||
for _, acc := range signers {
|
for _, acc := range signers {
|
||||||
require.NoError(t, acc.SignTx(e.Chain.GetConfig().Magic, tx))
|
require.NoError(t, acc.SignTx(e.Chain.GetConfig().Magic, tx))
|
||||||
|
@ -287,12 +287,12 @@ func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract
|
||||||
|
|
||||||
// AddSystemFee adds system fee to the transaction. If negative value specified,
|
// AddSystemFee adds system fee to the transaction. If negative value specified,
|
||||||
// then system fee is defined by test invocation.
|
// then system fee is defined by test invocation.
|
||||||
func AddSystemFee(bc *core.Blockchain, tx *transaction.Transaction, sysFee int64) {
|
func (e *Executor) AddSystemFee(tx *transaction.Transaction, sysFee int64) {
|
||||||
if sysFee >= 0 {
|
if sysFee >= 0 {
|
||||||
tx.SystemFee = sysFee
|
tx.SystemFee = sysFee
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v, _ := TestInvoke(bc, tx) // ignore error to support failing transactions
|
v, _ := e.TestInvoke(tx) // ignore error to support failing transactions
|
||||||
tx.SystemFee = v.GasConsumed()
|
tx.SystemFee = v.GasConsumed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,14 +384,14 @@ func (e *Executor) AddBlockCheckHalt(t testing.TB, txs ...*transaction.Transacti
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestInvoke creates a test VM with a dummy block and executes a transaction in it.
|
// TestInvoke creates a test VM with a dummy block and executes a transaction in it.
|
||||||
func TestInvoke(bc *core.Blockchain, tx *transaction.Transaction) (*vm.VM, error) {
|
func (e *Executor) TestInvoke(tx *transaction.Transaction) (*vm.VM, error) {
|
||||||
lastBlock, err := bc.GetBlock(bc.GetHeaderHash(bc.BlockHeight()))
|
lastBlock, err := e.Chain.GetBlock(e.Chain.GetHeaderHash(e.Chain.BlockHeight()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b := &block.Block{
|
b := &block.Block{
|
||||||
Header: block.Header{
|
Header: block.Header{
|
||||||
Index: bc.BlockHeight() + 1,
|
Index: e.Chain.BlockHeight() + 1,
|
||||||
Timestamp: lastBlock.Timestamp + 1,
|
Timestamp: lastBlock.Timestamp + 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ func TestInvoke(bc *core.Blockchain, tx *transaction.Transaction) (*vm.VM, error
|
||||||
// `GetTestVM` as well as `Run` can use a transaction hash which will set a cached value.
|
// `GetTestVM` as well as `Run` can use a transaction hash which will set a cached value.
|
||||||
// This is unwanted behavior, so we explicitly copy the transaction to perform execution.
|
// This is unwanted behavior, so we explicitly copy the transaction to perform execution.
|
||||||
ttx := *tx
|
ttx := *tx
|
||||||
ic, _ := bc.GetTestVM(trigger.Application, &ttx, b)
|
ic, _ := e.Chain.GetTestVM(trigger.Application, &ttx, b)
|
||||||
|
|
||||||
defer ic.Finalize()
|
defer ic.Finalize()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue