aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie
diff options
context:
space:
mode:
Diffstat (limited to 'utils/merkletrie')
-rw-r--r--utils/merkletrie/iter.go4
-rw-r--r--utils/merkletrie/iter_test.go11
2 files changed, 13 insertions, 2 deletions
diff --git a/utils/merkletrie/iter.go b/utils/merkletrie/iter.go
index c84f6fc..e3f3055 100644
--- a/utils/merkletrie/iter.go
+++ b/utils/merkletrie/iter.go
@@ -83,6 +83,10 @@ func newIter(root noder.Noder, base noder.Path) (*Iter, error) {
base: base,
}
+ if root == nil {
+ return ret, nil
+ }
+
frame, err := frame.New(root)
if err != nil {
return nil, err
diff --git a/utils/merkletrie/iter_test.go b/utils/merkletrie/iter_test.go
index 7e8c302..b334cf1 100644
--- a/utils/merkletrie/iter_test.go
+++ b/utils/merkletrie/iter_test.go
@@ -19,13 +19,13 @@ var _ = Suite(&IterSuite{})
// A test is a list of operations we want to perform on an iterator and
// their expected results.
//
-// The operations are expresed as a sequence of `n` and `s`,
+// The operations are expressed as a sequence of `n` and `s`,
// representing the amount of next and step operations we want to call
// on the iterator and their order. For example, an operations value of
// "nns" means: call a `n`ext, then another `n`ext and finish with a
// `s`tep.
//
-// The expeced is the full path of the noders returned by the
+// The expected is the full path of the noders returned by the
// operations, separated by spaces.
//
// For instance:
@@ -446,6 +446,13 @@ func (e *errorNoder) Children() ([]noder.Noder, error) {
return nil, fmt.Errorf("mock error")
}
+func (s *IterSuite) TestNewIterNil(c *C) {
+ i, err := merkletrie.NewIter(nil)
+ c.Assert(err, IsNil)
+ _, err = i.Next()
+ c.Assert(err, Equals, io.EOF)
+}
+
func (s *IterSuite) TestNewIterFailsOnChildrenErrors(c *C) {
_, err := merkletrie.NewIter(&errorNoder{})
c.Assert(err, ErrorMatches, "mock error")