neo-go/pkg/consensus/block_test.go
Anna Shaleva 65503aa9b4 core: add nonce field to transaction
1. Closes #840: added Nonce field to transaction.Transaction and
removed Nonce field from transaction.MinerTx

2. Added following methods to different tx types:
  - NewMinerTx()
  - NewMinerTxWithNonce(...)
  - NewEnrollmentTx(...)
  - NewIssueTx()
  - NewPublishTx(...)
  - NewRegisterTx(...)
  - NewStateTx(...)
in order to avoid code duplication when new transaction is created.

3. Commented out test cases where binary transaction/block are used.
These test cases marked with `TODO NEO3.0: Update binary` and need to be
updated.

4. Updated other tests

5. Added constant Nonce to GoveringTockenTx, UtilityTokenTx and genesis
block to avoid data variability. Also marked with TODO.
2020-04-14 16:19:41 +03:00

49 lines
1.2 KiB
Go

package consensus
import (
"crypto/rand"
"testing"
"github.com/nspcc-dev/dbft/block"
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require"
)
func TestNeoBlock_Sign(t *testing.T) {
b := new(neoBlock)
priv, pub := crypto.Generate(rand.Reader)
require.NoError(t, b.Sign(priv))
require.NoError(t, b.Verify(pub, b.Signature()))
}
func TestNeoBlock_Setters(t *testing.T) {
b := new(neoBlock)
b.SetVersion(1)
require.EqualValues(t, 1, b.Version())
b.SetIndex(12)
require.EqualValues(t, 12, b.Index())
b.SetTimestamp(777)
require.EqualValues(t, 777, b.Timestamp())
b.SetConsensusData(456)
require.EqualValues(t, 456, b.ConsensusData())
b.SetMerkleRoot(util.Uint256{1, 2, 3, 4})
require.Equal(t, util.Uint256{1, 2, 3, 4}, b.MerkleRoot())
b.SetNextConsensus(util.Uint160{9, 2})
require.Equal(t, util.Uint160{9, 2}, b.NextConsensus())
b.SetPrevHash(util.Uint256{9, 8, 7})
require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
txx := []block.Transaction{transaction.NewMinerTX()}
b.SetTransactions(txx)
require.Equal(t, txx, b.Transactions())
}