pool/order/supplyunit_test.go
2022-03-28 15:22:41 +02:00

34 lines
780 B
Go

package order_test
import (
"math/rand"
"reflect"
"testing"
"testing/quick"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/pool/order"
"github.com/stretchr/testify/require"
)
// TestRoundToNextSupplyUnit runs a quick check scenario to ensure the
// correctness of RoundToNextSupplyUnit.
func TestRoundToNextSupplyUnit(t *testing.T) {
t.Parallel()
f := func(sats btcutil.Amount) bool {
units := order.RoundToNextSupplyUnit(sats)
if sats%order.BaseSupplyUnit == 0 {
return units == order.NewSupplyFromSats(sats)
}
return units == order.NewSupplyFromSats(sats)+1
}
cfg := &quick.Config{
Values: func(v []reflect.Value, r *rand.Rand) {
v[0] = reflect.ValueOf(btcutil.Amount(r.Int63()))
},
}
require.NoError(t, quick.Check(f, cfg))
}