github.com/sunrise-zone/sunrise-node@v0.13.1-sr2/share/ipld/nmt_test.go (about)

     1  package ipld
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/celestiaorg/rsmt2d"
    11  	"github.com/sunrise-zone/sunrise-app/pkg/da"
    12  
    13  	"github.com/sunrise-zone/sunrise-node/share/eds/edstest"
    14  )
    15  
    16  // TestNamespaceFromCID checks that deriving the Namespaced hash from
    17  // the given CID works correctly.
    18  func TestNamespaceFromCID(t *testing.T) {
    19  	var tests = []struct {
    20  		eds *rsmt2d.ExtendedDataSquare
    21  	}{
    22  		// note that the number of shares must be a power of two
    23  		{eds: edstest.RandEDS(t, 4)},
    24  		{eds: edstest.RandEDS(t, 16)},
    25  	}
    26  
    27  	for i, tt := range tests {
    28  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    29  			dah, err := da.NewDataAvailabilityHeader(tt.eds)
    30  			require.NoError(t, err)
    31  			// check to make sure NamespacedHash is correctly derived from CID
    32  			for _, row := range dah.RowRoots {
    33  				c, err := CidFromNamespacedSha256(row)
    34  				require.NoError(t, err)
    35  
    36  				got := NamespacedSha256FromCID(c)
    37  				assert.Equal(t, row, got)
    38  			}
    39  		})
    40  	}
    41  }