2019-11-15 10:32:40 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-02 14:25:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
2020-03-27 07:14:40 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/random"
|
2020-10-02 14:25:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-11-15 10:32:40 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPrepareRequest_Setters(t *testing.T) {
|
|
|
|
var p prepareRequest
|
|
|
|
|
|
|
|
p.SetTimestamp(123)
|
2020-04-24 09:49:17 +00:00
|
|
|
// 123ns -> 0ms -> 0ns
|
|
|
|
require.EqualValues(t, 0, p.Timestamp())
|
|
|
|
|
|
|
|
p.SetTimestamp(1230000)
|
|
|
|
// 1230000ns -> 1ms -> 1000000ns
|
|
|
|
require.EqualValues(t, 1000000, p.Timestamp())
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
p.SetNextConsensus(util.Uint160{5, 6, 7})
|
2020-07-11 09:32:53 +00:00
|
|
|
require.Equal(t, util.Uint160{}, p.NextConsensus())
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
p.SetNonce(8765)
|
|
|
|
require.EqualValues(t, 8765, p.Nonce())
|
|
|
|
|
2020-03-27 07:14:40 +00:00
|
|
|
hashes := [2]util.Uint256{random.Uint256(), random.Uint256()}
|
2019-11-15 10:32:40 +00:00
|
|
|
|
|
|
|
p.SetTransactionHashes(hashes[:])
|
|
|
|
require.Equal(t, hashes[:], p.TransactionHashes())
|
|
|
|
}
|
2020-10-02 14:25:55 +00:00
|
|
|
|
|
|
|
func TestPrepareRequest_EncodeDecodeBinary(t *testing.T) {
|
|
|
|
t.Run("positive", func(t *testing.T) {
|
|
|
|
expected := &prepareRequest{
|
|
|
|
timestamp: 112,
|
|
|
|
nonce: 1325,
|
|
|
|
transactionHashes: []util.Uint256{
|
|
|
|
random.Uint256(),
|
|
|
|
random.Uint256(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testserdes.EncodeDecodeBinary(t, expected, new(prepareRequest))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("bad hashes count", func(t *testing.T) {
|
|
|
|
hashes := make([]util.Uint256, block.MaxTransactionsPerBlock+1)
|
|
|
|
for i := range hashes {
|
|
|
|
hashes[i] = random.Uint256()
|
|
|
|
}
|
|
|
|
expected := &prepareRequest{
|
|
|
|
timestamp: 112,
|
|
|
|
nonce: 1325,
|
|
|
|
transactionHashes: hashes,
|
|
|
|
}
|
|
|
|
data, err := testserdes.EncodeBinary(expected)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Error(t, testserdes.DecodeBinary(data, new(prepareRequest)))
|
|
|
|
})
|
|
|
|
}
|