Skip to content

Commit f4cf3df

Browse files
authoredApr 4, 2022
Merge pull request celestiaorg#671 from vgonkivs/add_tree_method_to_nmt
2 parents 0d0baeb + 2e49751 commit f4cf3df

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
 

‎CELESTIA_CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased Changes
44
- Add .github/workflows/pending-changelog-checker.yml to enforce updating this file (`CELESTIA_CHANGELOG.md`) on commits to `master` branch.
55
- [proto: moves proto files to](https://github.com/celestiaorg/celestia-core/pull/608) [spec](https://github.com/celestiaorg/spec) @sweexordious
6+
- [nmt_wrapper: extend nmt wrapper with tree method](https://github.com/celestiaorg/celestia-core/pull/671) @vgonkivs
67

78
## v0.1
89

‎pkg/wrapper/nmt_wrapper.go

+5
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ func (w *ErasuredNamespacedMerkleTree) Push(data []byte, idx rsmt2d.SquareIndex)
7272
func (w *ErasuredNamespacedMerkleTree) Root() []byte {
7373
return w.tree.Root()
7474
}
75+
76+
// Tree returns the underlying NamespacedMerkleTree
77+
func (w *ErasuredNamespacedMerkleTree) Tree() *nmt.NamespacedMerkleTree {
78+
return w.tree
79+
}

‎pkg/wrapper/nmt_wrapper_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ func TestExtendedDataSquare(t *testing.T) {
108108
assert.NoError(t, err)
109109
}
110110

111+
func TestErasuredNamespacedMerkleTree(t *testing.T) {
112+
// check that the Tree() returns exact underlying nmt tree
113+
size := 8
114+
data := generateRandNamespacedRawData(size, consts.NamespaceSize, consts.MsgShareSize)
115+
n := NewErasuredNamespacedMerkleTree(uint64(size))
116+
tree := n.Constructor()
117+
118+
for i, d := range data {
119+
tree.Push(d, rsmt2d.SquareIndex{Axis: uint(0), Cell: uint(i)})
120+
}
121+
122+
assert.Equal(t, n.Tree(), n.tree)
123+
assert.Equal(t, n.Tree().Root(), n.tree.Root())
124+
}
125+
111126
// generateErasuredData produces a slice that is twice as long as it erasures
112127
// the data
113128
func generateErasuredData(t *testing.T, numLeaves int, codec rsmt2d.Codec) [][]byte {

0 commit comments

Comments
 (0)