celestiaorg / rsmt2d

Go implementation of two dimensional Reed-Solomon merkle tree data availability scheme.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`TestMarshalJSON` doesn't test the function it describes

rootulp opened this issue · comments

Context

func TestMarshalJSON(t *testing.T) {
codec := NewLeoRSCodec()
result, err := ComputeExtendedDataSquare([][]byte{
ones, twos,
threes, fours,
}, codec, NewDefaultTree)
if err != nil {
panic(err)
}
edsBytes, err := json.Marshal(result)
if err != nil {
t.Errorf("failed to marshal EDS: %v", err)
}
var eds ExtendedDataSquare
err = json.Unmarshal(edsBytes, &eds)
if err != nil {
t.Errorf("failed to marshal EDS: %v", err)
}
if !reflect.DeepEqual(result.squareRow, eds.squareRow) {
t.Errorf("eds not equal after json marshal/unmarshal")
}
}

Problem

This test should be testing the behavior of MarshalJSON but it never invokes MarshalJSON.

Proposal

Update the test to invoke the function MarshalJSON

func (eds *ExtendedDataSquare) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
DataSquare [][]byte `json:"data_square"`
Codec string `json:"codec"`
Tree string `json:"tree"`
}{
DataSquare: eds.dataSquare.Flattened(),
Codec: eds.codec.Name(),
Tree: eds.treeName,
})
}