package track1

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestHandleBlockDetailRejectsInvalidBlockNumber(t *testing.T) {
	server := &Server{}
	req := httptest.NewRequest(http.MethodGet, "/api/v1/track1/block/not-a-number", nil)
	w := httptest.NewRecorder()

	server.HandleBlockDetail(w, req)

	if w.Code != http.StatusBadRequest {
		t.Fatalf("expected 400 for invalid block number, got %d", w.Code)
	}
}

func TestHandleTransactionDetailRejectsInvalidHash(t *testing.T) {
	server := &Server{}
	req := httptest.NewRequest(http.MethodGet, "/api/v1/track1/tx/not-a-hash", nil)
	w := httptest.NewRecorder()

	server.HandleTransactionDetail(w, req)

	if w.Code != http.StatusBadRequest {
		t.Fatalf("expected 400 for invalid tx hash, got %d", w.Code)
	}
}

func TestHandleAddressBalanceRejectsInvalidAddress(t *testing.T) {
	server := &Server{}
	req := httptest.NewRequest(http.MethodGet, "/api/v1/track1/address/not-an-address/balance", nil)
	w := httptest.NewRecorder()

	server.HandleAddressBalance(w, req)

	if w.Code != http.StatusBadRequest {
		t.Fatalf("expected 400 for invalid address, got %d", w.Code)
	}
}
