github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/consensus/block_test.go (about)

     1  package consensus
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/nspcc-dev/dbft"
     7  	"github.com/nspcc-dev/neo-go/pkg/core/transaction"
     8  	"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
     9  	"github.com/nspcc-dev/neo-go/pkg/util"
    10  	"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestNeoBlock_Sign(t *testing.T) {
    15  	b := new(neoBlock)
    16  	priv, _ := keys.NewPrivateKey()
    17  
    18  	require.NoError(t, b.Sign(&privateKey{PrivateKey: priv}))
    19  	require.NoError(t, b.Verify(&publicKey{PublicKey: priv.PublicKey()}, b.Signature()))
    20  }
    21  
    22  func TestNeoBlock_Setters(t *testing.T) {
    23  	b := new(neoBlock)
    24  
    25  	b.Block.Index = 12
    26  	require.EqualValues(t, 12, b.Index())
    27  
    28  	b.Block.Timestamp = 777
    29  	// 777ms -> 777000000ns
    30  	require.EqualValues(t, 777000000, b.Timestamp())
    31  
    32  	b.Block.MerkleRoot = util.Uint256{1, 2, 3, 4}
    33  	require.Equal(t, util.Uint256{1, 2, 3, 4}, b.MerkleRoot())
    34  
    35  	b.Block.PrevHash = util.Uint256{9, 8, 7}
    36  	require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
    37  
    38  	txx := []dbft.Transaction[util.Uint256]{transaction.New([]byte{byte(opcode.PUSH1)}, 1)}
    39  	b.SetTransactions(txx)
    40  	require.Equal(t, txx, b.Transactions())
    41  }