grid2: fix tests

This commit is contained in:
c9s 2022-11-25 15:42:45 +08:00
parent 622fe75ed3
commit 1629a25beb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -16,18 +16,6 @@ func TestStrategy_checkRequiredInvestmentByQuantity(t *testing.T) {
},
}
t.Run("basic base balance check", func(t *testing.T) {
_, _, err := s.checkRequiredInvestmentByQuantity(number(1.0), number(10_000.0), number(0.1), number(19000.0), []Pin{})
assert.Error(t, err)
assert.EqualError(t, err, "baseInvestment setup 2.000000 is greater than the total base balance 1.000000")
})
t.Run("basic quote balance check", func(t *testing.T) {
_, _, err := s.checkRequiredInvestmentByQuantity(number(1.0), number(100.0), number(0.1), number(19_000.0), []Pin{})
assert.Error(t, err)
assert.EqualError(t, err, "quoteInvestment setup 10000.000000 is greater than the total quote balance 100.000000")
})
t.Run("quote to base balance conversion check", func(t *testing.T) {
_, requiredQuote, err := s.checkRequiredInvestmentByQuantity(number(0.0), number(10_000.0), number(0.1), number(13_500.0), []Pin{
Pin(number(10_000.0)), // 0.1 * 10_000 = 1000 USD (buy)
@ -64,7 +52,7 @@ func TestStrategy_checkRequiredInvestmentByAmount(t *testing.T) {
}
t.Run("quote to base balance conversion", func(t *testing.T) {
_, requiredQuote, err := s.checkRequiredInvestmentByAmount(number(0.0), number(3_000.0),
_, requiredQuote, err := s.checkRequiredInvestmentByAmount(
number(0.0), number(3_000.0),
number(1000.0),
number(13_500.0), []Pin{
@ -76,6 +64,6 @@ func TestStrategy_checkRequiredInvestmentByAmount(t *testing.T) {
Pin(number(15_000.0)),
})
assert.EqualError(t, err, "quote balance (3000.000000 USDT) is not enough, required = quote 4999.999890")
assert.Equal(t, number(4999.99989), requiredQuote)
assert.InDelta(t, 4999.99989, requiredQuote.Float64(), number(0.001).Float64())
})
}