neotest: export nonce() method

Sometimes user needs to construct transaction by itself, so it's better
to unify nonce sources for auto-generated and manually-generated
transactions to avoid nonce collisions in tests.
This commit is contained in:
Anna Shaleva 2021-11-11 20:00:40 +03:00
parent 0a7f8afcea
commit 4df5d370c5
2 changed files with 4 additions and 3 deletions

View file

@ -2,7 +2,8 @@ package neotest
var _nonce uint32
func nonce() uint32 {
// Nonce returns unique number that can be used as nonce for new transactions.
func Nonce() uint32 {
_nonce++
return _nonce
}

View file

@ -69,7 +69,7 @@ func (e *Executor) NewUnsignedTx(t *testing.T, hash util.Uint160, method string,
script := w.Bytes()
tx := transaction.New(script, 0)
tx.Nonce = nonce()
tx.Nonce = Nonce()
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
return tx
}
@ -157,7 +157,7 @@ func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Co
require.NoError(t, buf.Err)
tx := transaction.New(buf.Bytes(), 100*native.GASFactor)
tx.Nonce = nonce()
tx.Nonce = Nonce()
tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.Signers = []transaction.Signer{{
Account: e.Committee.ScriptHash(),