(t *testing.T)
| 101 | } |
| 102 | |
| 103 | func TestMerkleTree(t *testing.T) { |
| 104 | tests := []struct { |
| 105 | name string |
| 106 | detail string |
| 107 | items [][]byte |
| 108 | expectedRoot []byte |
| 109 | expectedTree [][]byte |
| 110 | }{ |
| 111 | { |
| 112 | name: "empty input", |
| 113 | detail: "there are no items", |
| 114 | items: nil, |
| 115 | expectedRoot: []byte{}, |
| 116 | expectedTree: [][]byte{}, |
| 117 | }, |
| 118 | { |
| 119 | name: "one item", |
| 120 | detail: "there's one entry in the tree", |
| 121 | items: [][]byte{[]byte("a")}, |
| 122 | expectedRoot: crypto.Hash([]byte("a")), |
| 123 | expectedTree: [][]byte{ |
| 124 | crypto.Hash([]byte("a")), |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | name: "multi-item", |
| 129 | detail: "there are multiple items added", |
| 130 | items: [][]byte{ |
| 131 | []byte("a"), |
| 132 | []byte("b"), |
| 133 | []byte("c"), |
| 134 | []byte("d"), |
| 135 | }, |
| 136 | expectedTree: [][]byte{ |
| 137 | crypto.Hash([]byte("a")), |
| 138 | crypto.Hash([]byte("b")), |
| 139 | crypto.Hash([]byte("c")), |
| 140 | crypto.Hash([]byte("d")), |
| 141 | crypto.Hash(append(crypto.Hash([]byte("a")), crypto.Hash([]byte("b"))...)), |
| 142 | crypto.Hash(append(crypto.Hash([]byte("c")), crypto.Hash([]byte("d"))...)), |
| 143 | crypto.Hash(append( |
| 144 | crypto.Hash(append(crypto.Hash([]byte("a")), crypto.Hash([]byte("b"))...)), |
| 145 | crypto.Hash(append(crypto.Hash([]byte("c")), crypto.Hash([]byte("d"))...))..., |
| 146 | )), |
| 147 | }, |
| 148 | expectedRoot: crypto.Hash( |
| 149 | append( |
| 150 | crypto.Hash(append(crypto.Hash([]byte("a")), crypto.Hash([]byte("b"))...)), |
| 151 | crypto.Hash(append(crypto.Hash([]byte("c")), crypto.Hash([]byte("d"))...))..., |
| 152 | ), |
| 153 | ), |
| 154 | }, |
| 155 | { |
| 156 | name: "'non power of two' multi-item", |
| 157 | detail: "there are multiple items, but not enough for a perfect po2 tree", |
| 158 | items: [][]byte{ |
| 159 | []byte("a"), |
| 160 | []byte("b"), |
nothing calls this directly
no test coverage detected