-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
- Loading branch information
1 parent
f4a8651
commit 0a2003b
Showing
64 changed files
with
25,693 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package accounting | ||
|
||
import ( | ||
"github.com/nspcc-dev/neofs-sdk-go/internal/proto" | ||
) | ||
|
||
const ( | ||
_ = iota | ||
fieldDecimalValue | ||
fieldDecimalPrecision | ||
) | ||
|
||
func (x *Decimal) MarshaledSize() int { | ||
var sz int | ||
if x != nil { | ||
sz = proto.SizeVarint(fieldDecimalValue, x.Value) + | ||
proto.SizeVarint(fieldDecimalPrecision, x.Precision) | ||
} | ||
return sz | ||
} | ||
|
||
func (x *Decimal) MarshalStable(b []byte) { | ||
if x != nil { | ||
off := proto.MarshalVarint(b, fieldDecimalValue, x.Value) | ||
proto.MarshalVarint(b[off:], fieldDecimalPrecision, x.Precision) | ||
} | ||
} | ||
|
||
const ( | ||
_ = iota | ||
fieldBalanceReqOwner | ||
) | ||
|
||
func (x *BalanceRequest_Body) MarshaledSize() int { | ||
var sz int | ||
if x != nil { | ||
sz = proto.SizeNested(fieldBalanceReqOwner, x.OwnerId) | ||
} | ||
return sz | ||
} | ||
|
||
func (x *BalanceRequest_Body) MarshalStable(b []byte) { | ||
if x != nil { | ||
proto.MarshalNested(b, fieldBalanceReqOwner, x.OwnerId) | ||
} | ||
} | ||
|
||
const ( | ||
_ = iota | ||
fieldBalanceRespBalance | ||
) | ||
|
||
func (x *BalanceResponse_Body) MarshaledSize() int { | ||
var sz int | ||
if x != nil { | ||
sz = proto.SizeNested(fieldBalanceRespBalance, x.Balance) | ||
} | ||
return sz | ||
} | ||
|
||
func (x *BalanceResponse_Body) MarshalStable(b []byte) { | ||
if x != nil { | ||
proto.MarshalNested(b, fieldBalanceRespBalance, x.Balance) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package accounting_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-sdk-go/api/accounting" | ||
"github.com/nspcc-dev/neofs-sdk-go/api/refs" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func TestBalanceRequest_Body(t *testing.T) { | ||
v := &accounting.BalanceRequest_Body{ | ||
OwnerId: &refs.OwnerID{ | ||
Value: []byte("any_owner"), | ||
}, | ||
} | ||
|
||
sz := v.MarshaledSize() | ||
b := make([]byte, sz) | ||
v.MarshalStable(b) | ||
|
||
var res accounting.BalanceRequest_Body | ||
err := proto.Unmarshal(b, &res) | ||
require.NoError(t, err) | ||
require.Empty(t, res.ProtoReflect().GetUnknown()) | ||
require.Equal(t, v.OwnerId, res.OwnerId) | ||
// TODO: test field order. Pretty challenging in general, but can be simplified | ||
// for NeoFS specifics (forbid group types, maps, etc.). | ||
} | ||
|
||
func TestBalanceResponse_Body(t *testing.T) { | ||
v := &accounting.BalanceResponse_Body{ | ||
Balance: &accounting.Decimal{ | ||
Value: 12, | ||
Precision: 34, | ||
}, | ||
} | ||
|
||
sz := v.MarshaledSize() | ||
b := make([]byte, sz) | ||
v.MarshalStable(b) | ||
|
||
var res accounting.BalanceResponse_Body | ||
err := proto.Unmarshal(b, &res) | ||
require.NoError(t, err) | ||
require.Empty(t, res.ProtoReflect().GetUnknown()) | ||
require.Equal(t, v.Balance, res.Balance) | ||
} |
Oops, something went wrong.