2021-10-26 10:31:31 +00:00
|
|
|
package accounting_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
v2accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
2021-10-26 10:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
2023-01-31 07:51:49 +00:00
|
|
|
accountingtest "github.com/nspcc-dev/neofs-sdk-go/accounting/test"
|
2021-10-26 10:31:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
func TestDecimalData(t *testing.T) {
|
2021-10-26 10:31:31 +00:00
|
|
|
const v, p = 4, 2
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
var d accounting.Decimal
|
|
|
|
|
|
|
|
require.Zero(t, d.Value())
|
|
|
|
require.Zero(t, d.Precision())
|
|
|
|
|
2021-10-26 10:31:31 +00:00
|
|
|
d.SetValue(v)
|
|
|
|
d.SetPrecision(p)
|
|
|
|
|
|
|
|
require.EqualValues(t, v, d.Value())
|
|
|
|
require.EqualValues(t, p, d.Precision())
|
|
|
|
}
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
func TestDecimalMessageV2(t *testing.T) {
|
|
|
|
var (
|
|
|
|
d accounting.Decimal
|
|
|
|
m v2accounting.Decimal
|
|
|
|
)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
m.SetValue(7)
|
|
|
|
m.SetPrecision(8)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-07-07 10:51:05 +00:00
|
|
|
require.NoError(t, d.ReadFromV2(m))
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
require.EqualValues(t, m.GetValue(), d.Value())
|
|
|
|
require.EqualValues(t, m.GetPrecision(), d.Precision())
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
var m2 v2accounting.Decimal
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-17 13:45:26 +00:00
|
|
|
d.WriteToV2(&m2)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
require.EqualValues(t, d.Value(), m2.GetValue())
|
|
|
|
require.EqualValues(t, d.Precision(), m2.GetPrecision())
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
2023-01-31 07:51:49 +00:00
|
|
|
|
|
|
|
func TestDecimal_Marshal(t *testing.T) {
|
|
|
|
d := *accountingtest.Decimal()
|
|
|
|
|
|
|
|
var d2 accounting.Decimal
|
|
|
|
require.NoError(t, d2.Unmarshal(d.Marshal()))
|
|
|
|
|
|
|
|
require.Equal(t, d, d2)
|
|
|
|
}
|