Skip to content

Commit

Permalink
adapt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Dec 16, 2024
1 parent 49e055f commit 1d0a582
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 6 additions & 2 deletions share/shwap/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r Row) MarshalJSON() ([]byte, error) {
Shares []libshare.Share `json:"shares"`
Side string `json:"side"`
}{
Shares: r.halfShares,
Shares: r.shares,
Side: r.side.String(),
}
return json.Marshal(&jsonRow)
Expand All @@ -194,7 +194,7 @@ func (r *Row) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
r.halfShares = jsonRow.Shares
r.shares = jsonRow.Shares
r.side = toRowSide(jsonRow.Side)
return nil
}
Expand All @@ -221,6 +221,8 @@ func (s RowSide) String() string {
return "LEFT"
case Right:
return "RIGHT"
case Both:
return "BOTH"
default:
panic("invalid row side")
}
Expand All @@ -232,6 +234,8 @@ func toRowSide(s string) RowSide {
return Left
case "RIGHT":
return Right
case "BOTH":
return Both
default:
panic("invalid row side")
}
Expand Down
20 changes: 14 additions & 6 deletions share/shwap/row_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func TestRowShares(t *testing.T) {
row, err := RowFromEDS(eds, rowIdx, side)
require.NoError(t, err)
require.Equal(t, side, row.side)

extended, err := row.Shares()
require.NoError(t, err)
require.Len(t, extended, odsSize*2)
require.Equal(t, Both, row.side)
}
}
}
Expand All @@ -30,21 +35,24 @@ func TestRowMarshal(t *testing.T) {
eds := edstest.RandEDS(t, odsSize)
for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ {
for _, side := range []RowSide{Left, Right} {
shrs := eds.Row(uint(rowIdx))
shares, err := libshare.FromBytes(shrs)
row, err := RowFromEDS(eds, rowIdx, side)
require.NoError(t, err)

row := RowFromShares(shares, side)
rowData, err := json.Marshal(row)
require.NoError(t, err)

decodedRow := &Row{}
err = json.Unmarshal(rowData, decodedRow)
require.NoError(t, err)
extended, err := row.Shares()
require.NoError(t, err)

require.Equal(t, side, decodedRow.side)
extended, err := decodedRow.Shares()
require.NoError(t, err)

shares, err := row.Shares()
require.NoError(t, err)

require.Equal(t, shares, extended)
require.Equal(t, row.side, decodedRow.side)
}
}
}
Expand Down

0 comments on commit 1d0a582

Please sign in to comment.