commit ca1ee631c44693b79e44faa790de1864bb84c4b0
parent 4996d275087ededb25ed8c9c8745bb8cace685f8
Author: Shivakumar <[email protected]>
Date: Wed, 5 Aug 2026 23:53:26 +0530
test(blockchain): add test for GetBlockByTxID
Signed-off-by: Shivakumar <[email protected]>
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/internal/blockchain/blockchain_test.go b/internal/blockchain/blockchain_test.go
@@ -353,6 +353,54 @@ func TestGetBlockByHeight(t *testing.T) {
})
}
+// GetBlockByTxID Unit-tests
+
+func TestGetBlockByTxID(t *testing.T) {
+ t.Parallel()
+
+ bc := mustNewMemoryChain(t)
+ tx := mustTx(t)
+
+ mustAddBlock(t, bc, tx)
+
+ tests := []struct {
+ name string
+ txID []byte
+ wantErr error
+ }{
+ {
+ name: "Ideal Case",
+ txID: tx.TxID,
+ wantErr: nil,
+ },
+ {
+ name: "nil Case",
+ txID: nil,
+ wantErr: ErrInvalidTxID,
+ },
+ {
+ name: "Unanchored TxID",
+ txID: mustTx(t).TxID,
+ wantErr: storage.ErrNotFound,
+ },
+ {
+ name: "malformed TxID",
+ txID: make([]byte, 42),
+ wantErr: ErrInvalidTxID,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+
+ if _, err := bc.GetBlockByTxID(tt.txID); !errors.Is(err, tt.wantErr) {
+ t.Fatalf("Unexpected Error: want = %v, got = %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
// GetTransaction Unit-tests
func TestGetTransaction(t *testing.T) {