|
1 | 1 | package bc
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "math" |
4 | 5 | "testing"
|
5 | 6 |
|
6 | 7 | "github.com/libsv/go-p2p/chaincfg/chainhash"
|
@@ -168,3 +169,27 @@ func TestTxids(t *testing.T) {
|
168 | 169 | txids := bump.Txids()
|
169 | 170 | require.Equal(t, []string{testnetBlockExample[0]}, txids)
|
170 | 171 | }
|
| 172 | + |
| 173 | +func TestOnlySpecifiedPathsStored(t *testing.T) { |
| 174 | + chainHashBlock := make([]*chainhash.Hash, 0) |
| 175 | + for _, txid := range blockTxExample { |
| 176 | + hash, err := chainhash.NewHashFromStr(txid) |
| 177 | + require.NoError(t, err) |
| 178 | + chainHashBlock = append(chainHashBlock, hash) |
| 179 | + } |
| 180 | + merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock) |
| 181 | + require.NoError(t, err) |
| 182 | + |
| 183 | + for idx := range blockTxExample { |
| 184 | + bump, err := NewBUMPFromMerkleTreeAndIndex(1575794, merkles, uint64(idx)) |
| 185 | + require.NoError(t, err) |
| 186 | + totalHashes := 0 |
| 187 | + for _, level := range bump.Path { |
| 188 | + totalHashes += len(level) |
| 189 | + } |
| 190 | + // number of levels plus the txid itself. |
| 191 | + l := int(math.Log2(float64(len(blockTxExample)))) + 1 |
| 192 | + require.Equal(t, l, totalHashes) |
| 193 | + } |
| 194 | + |
| 195 | +} |
0 commit comments