package transactions_test

import (
	"dejo_node/internal/transactions"
	"testing"
)

func TestCreateBlock(t *testing.T) {
	tx1 := &transactions.Transaction{
		From:  "A",
		To:    "B",
		Value: 10,
		Nonce: 1,
		Gas:   1,
		Signature: "sig1",
	}

tx2 := &transactions.Transaction{
		From:  "B",
		To:    "C",
		Value: 5,
		Nonce: 1,
		Gas:   1,
		Signature: "sig2",
	}

	block := transactions.CreateBlock("prevhash", []*transactions.Transaction{tx1, tx2}, 2)

	if block.Hash == "" {
		t.Error("hash do bloco não pode ser vazio")
	}
	if block.Index != 2 {
		t.Errorf("esperava índice 2, obteve %d", block.Index)
	}
	if block.PrevHash != "prevhash" {
		t.Errorf("hash anterior incorreto")
	}
	if len(block.Txns) != 2 {
		t.Errorf("esperava 2 transações no bloco, obteve %d", len(block.Txns))
	}
}