2019-11-15 10:32:40 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-03-21 19:49:39 +00:00
|
|
|
"github.com/nspcc-dev/dbft"
|
2020-04-10 10:41:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2021-03-25 18:46:52 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-06-05 09:28:36 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
2019-11-15 10:32:40 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNeoBlock_Sign(t *testing.T) {
|
|
|
|
b := new(neoBlock)
|
2021-03-25 18:46:52 +00:00
|
|
|
priv, _ := keys.NewPrivateKey()
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2021-03-25 18:46:52 +00:00
|
|
|
require.NoError(t, b.Sign(&privateKey{PrivateKey: priv}))
|
|
|
|
require.NoError(t, b.Verify(&publicKey{PublicKey: priv.PublicKey()}, b.Signature()))
|
2019-11-15 10:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNeoBlock_Setters(t *testing.T) {
|
|
|
|
b := new(neoBlock)
|
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.Version = 1
|
2019-11-15 10:32:40 +00:00
|
|
|
require.EqualValues(t, 1, b.Version())
|
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.Index = 12
|
2019-11-15 10:32:40 +00:00
|
|
|
require.EqualValues(t, 12, b.Index())
|
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.Timestamp = 777
|
|
|
|
// 777ms -> 777000000ns
|
|
|
|
require.EqualValues(t, 777000000, b.Timestamp())
|
2020-04-24 09:49:17 +00:00
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.MerkleRoot = util.Uint256{1, 2, 3, 4}
|
2019-11-15 10:32:40 +00:00
|
|
|
require.Equal(t, util.Uint256{1, 2, 3, 4}, b.MerkleRoot())
|
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.NextConsensus = util.Uint160{9, 2}
|
2019-11-15 10:32:40 +00:00
|
|
|
require.Equal(t, util.Uint160{9, 2}, b.NextConsensus())
|
|
|
|
|
2020-04-24 16:33:45 +00:00
|
|
|
b.Block.PrevHash = util.Uint256{9, 8, 7}
|
2019-11-15 10:32:40 +00:00
|
|
|
require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
|
|
|
|
|
2024-03-21 19:49:39 +00:00
|
|
|
txx := []dbft.Transaction[util.Uint256]{transaction.New([]byte{byte(opcode.PUSH1)}, 1)}
|
2019-11-15 10:32:40 +00:00
|
|
|
b.SetTransactions(txx)
|
|
|
|
require.Equal(t, txx, b.Transactions())
|
|
|
|
}
|