|
1 | 1 | package subtree |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/bsv-blockchain/go-bt/v2/chainhash" |
@@ -119,6 +120,62 @@ func TestGetParentVoutsAtIndex(t *testing.T) { |
119 | 120 | }) |
120 | 121 | } |
121 | 122 |
|
| 123 | +func TestString(t *testing.T) { |
| 124 | + p, err := NewTxInpointsFromTx(tx) |
| 125 | + require.NoError(t, err) |
| 126 | + |
| 127 | + // Test String method |
| 128 | + str := p.String() |
| 129 | + assert.NotEmpty(t, str) |
| 130 | + assert.Contains(t, str, "TxInpoints") |
| 131 | + assert.Contains(t, str, "ParentTxHashes") |
| 132 | + assert.Contains(t, str, "Idxs") |
| 133 | +} |
| 134 | + |
| 135 | +func TestLen32(t *testing.T) { |
| 136 | + t.Run("nil slice", func(t *testing.T) { |
| 137 | + var nilSlice []int |
| 138 | + result := len32(nilSlice) |
| 139 | + assert.Equal(t, uint32(0), result) |
| 140 | + }) |
| 141 | + |
| 142 | + t.Run("normal slice", func(t *testing.T) { |
| 143 | + normalSlice := []int{1, 2, 3, 4, 5} |
| 144 | + result := len32(normalSlice) |
| 145 | + assert.Equal(t, uint32(5), result) |
| 146 | + }) |
| 147 | + |
| 148 | + t.Run("empty slice", func(t *testing.T) { |
| 149 | + emptySlice := make([]int, 0) |
| 150 | + result := len32(emptySlice) |
| 151 | + assert.Equal(t, uint32(0), result) |
| 152 | + }) |
| 153 | +} |
| 154 | + |
| 155 | +func TestNewTxInpointsFromBytesError(t *testing.T) { |
| 156 | + t.Run("invalid bytes", func(t *testing.T) { |
| 157 | + invalidBytes := []byte{0x01, 0x02, 0x03} |
| 158 | + _, err := NewTxInpointsFromBytes(invalidBytes) |
| 159 | + require.Error(t, err) |
| 160 | + }) |
| 161 | + |
| 162 | + t.Run("empty bytes", func(t *testing.T) { |
| 163 | + emptyBytes := make([]byte, 4) |
| 164 | + // This creates bytes representing 0 parent inpoints |
| 165 | + p, err := NewTxInpointsFromBytes(emptyBytes) |
| 166 | + require.NoError(t, err) |
| 167 | + assert.Empty(t, p.ParentTxHashes) |
| 168 | + }) |
| 169 | +} |
| 170 | + |
| 171 | +func TestNewTxInpointsFromReaderError(t *testing.T) { |
| 172 | + t.Run("invalid reader", func(t *testing.T) { |
| 173 | + invalidBytes := []byte{0x01, 0x02, 0x03} |
| 174 | + _, err := NewTxInpointsFromReader(bytes.NewReader(invalidBytes)) |
| 175 | + require.Error(t, err) |
| 176 | + }) |
| 177 | +} |
| 178 | + |
122 | 179 | func BenchmarkNewTxInpoints(b *testing.B) { |
123 | 180 | for i := 0; i < b.N; i++ { |
124 | 181 | _, err := NewTxInpointsFromTx(tx) |
|
0 commit comments