celestiaorg / nmt

Namespaced Merkle Tree
Apache License 2.0
112 stars 39 forks source link

test: ExampleNamespacedMerkleTree #203

Closed rootulp closed 1 year ago

rootulp commented 1 year ago

Previously the function ExampleNamespacedMerkleTree existed in nmt_test.go. AFAIK Go only runs unit tests for functions with the name Test* so I wouldn't expect ExampleNamespacedMerkleTree to run by the Go test runner. But it is run and fails here.

This PR converts the example into a test. Defer to @staheri14 if it should be deleted instead.

codecov[bot] commented 1 year ago

Codecov Report

Merging #203 (13c3278) into master (9efc9bf) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #203   +/-   ##
=======================================
  Coverage   95.40%   95.40%           
=======================================
  Files           5        5           
  Lines         566      566           
=======================================
  Hits          540      540           
  Misses         15       15           
  Partials       11       11           
rootulp commented 1 year ago

[question] What changes made the test pass? why it was failing?

The example started failing in https://github.com/celestiaorg/nmt/actions/runs/5092193098/jobs/9153228914?pr=202#step:7:551 because the text output for the Example*s is slightly different from the new output.

The example wanted this text output:

https://github.com/celestiaorg/nmt/blob/9efc9bff0ac35eed215de67c11f00e8ccf5a2137/nmt_test.go#L107-L110

and instead it got:

    // Output:
    // Min namespace: 00
    // Max namespace: 01
    // Successfully verified namespace: 3030

The changes in this PR make the example a test which use explicit asserts.