package consensus

import (
	"testing"

	"git.marketally.com/tutus-one/tutus-consensus"
	"git.marketally.com/tutus-one/tutus-chain/pkg/core/transaction"
	"git.marketally.com/tutus-one/tutus-chain/pkg/crypto/keys"
	"git.marketally.com/tutus-one/tutus-chain/pkg/util"
	"git.marketally.com/tutus-one/tutus-chain/pkg/vm/opcode"
	"github.com/stretchr/testify/require"
)

func TestNeoBlock_Sign(t *testing.T) {
	b := new(neoBlock)
	priv, _ := keys.NewPrivateKey()

	require.NoError(t, b.Sign(priv))
	require.NoError(t, b.Verify(priv.PublicKey(), b.Signature()))
}

func TestNeoBlock_Setters(t *testing.T) {
	b := new(neoBlock)

	b.Block.Index = 12
	require.EqualValues(t, 12, b.Index())

	b.Block.Timestamp = 777
	// 777ms -> 777000000ns
	require.EqualValues(t, 777000000, b.Timestamp())

	b.Block.MerkleRoot = util.Uint256{1, 2, 3, 4}
	require.Equal(t, util.Uint256{1, 2, 3, 4}, b.MerkleRoot())

	b.Block.PrevHash = util.Uint256{9, 8, 7}
	require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())

	txx := []dbft.Transaction[util.Uint256]{transaction.New([]byte{byte(opcode.PUSH1)}, 1)}
	b.SetTransactions(txx)
	require.Equal(t, txx, b.Transactions())
}
