|
8 | 8 | "testing" |
9 | 9 |
|
10 | 10 | "github.com/ethereum/go-ethereum/common" |
| 11 | + "github.com/ethereum/go-ethereum/crypto" |
11 | 12 | "github.com/stretchr/testify/assert" |
12 | 13 | ) |
13 | 14 |
|
@@ -129,6 +130,51 @@ func TestAppendAndRepeated(t *testing.T) { |
129 | 130 | assert.Equal(t, tree1, tree2) |
130 | 131 | } |
131 | 132 |
|
| 133 | +func TestBuildRootChildren1(t *testing.T) { |
| 134 | + p := Proof{ |
| 135 | + Pos: big.NewInt(1), |
| 136 | + Node: common.HexToHash("0x01"), |
| 137 | + Siblings: []common.Hash{ |
| 138 | + common.HexToHash("0x02"), |
| 139 | + }, |
| 140 | + } |
| 141 | + rootHash := p.BuildRoot() |
| 142 | + lhs, rhs := p.BuildRootChildren() |
| 143 | + |
| 144 | + assert.Equal(t, rootHash, crypto.Keccak256Hash(lhs[:], rhs[:])) |
| 145 | +} |
| 146 | + |
| 147 | +func TestBuildRootChildren2(t *testing.T) { |
| 148 | + p := Proof{ |
| 149 | + Pos: big.NewInt(1), |
| 150 | + Node: common.HexToHash("0x01"), |
| 151 | + Siblings: []common.Hash{ |
| 152 | + common.HexToHash("0x02"), |
| 153 | + common.HexToHash("0x03"), |
| 154 | + }, |
| 155 | + } |
| 156 | + rootHash := p.BuildRoot() |
| 157 | + lhs, rhs := p.BuildRootChildren() |
| 158 | + |
| 159 | + assert.Equal(t, rootHash, crypto.Keccak256Hash(lhs[:], rhs[:])) |
| 160 | +} |
| 161 | + |
| 162 | +func TestBuildRootChildren3(t *testing.T) { |
| 163 | + p := Proof{ |
| 164 | + Pos: big.NewInt(1), |
| 165 | + Node: common.HexToHash("0x01"), |
| 166 | + Siblings: []common.Hash{ |
| 167 | + common.HexToHash("0x02"), |
| 168 | + common.HexToHash("0x03"), |
| 169 | + common.HexToHash("0x04"), |
| 170 | + }, |
| 171 | + } |
| 172 | + rootHash := p.BuildRoot() |
| 173 | + lhs, rhs := p.BuildRootChildren() |
| 174 | + |
| 175 | + assert.Equal(t, rootHash, crypto.Keccak256Hash(lhs[:], rhs[:])) |
| 176 | +} |
| 177 | + |
132 | 178 | // repanicked |
133 | 179 | //func TestBuildNotPow2(t *testing.T) { |
134 | 180 | // defer recover() |
|
0 commit comments