From 4df5d370c5a7cd008a89116a3dfee1f74dcb3d10 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 11 Nov 2021 20:00:40 +0300 Subject: [PATCH] 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. --- pkg/neotest/account.go | 3 ++- pkg/neotest/basic.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/neotest/account.go b/pkg/neotest/account.go index 00c95a7a0..d03db8d33 100644 --- a/pkg/neotest/account.go +++ b/pkg/neotest/account.go @@ -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 } diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 67c0ac87b..a572fab53 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -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(),