-
Notifications
You must be signed in to change notification settings - Fork 2
/
batchedExchange_test.go
50 lines (44 loc) · 1.46 KB
/
batchedExchange_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package plugins
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stellar/go/txnbuild"
"github.com/stellar/kelp/model"
"github.com/stellar/kelp/support/utils"
)
func TestManageOffer2Order(t *testing.T) {
testCases := []struct {
op *txnbuild.ManageSellOffer
oc *model.OrderConstraints
wantAction model.OrderAction
wantAmount float64
wantPrice float64
}{
{
op: makeSellOpAmtPrice(0.0018, 50500.0),
oc: model.MakeOrderConstraints(2, 4, 0.001),
wantAction: model.OrderActionSell,
wantAmount: 0.0018,
wantPrice: 50500.0,
}, {
op: makeBuyOpAmtPrice(0.0018, 50500.0),
oc: model.MakeOrderConstraints(2, 4, 0.001),
wantAction: model.OrderActionBuy,
wantAmount: 0.0018,
// 1/50500.0 = 0.000019801980198, we need to reduce it to 7 decimals precision because of sdex op, giving 0.0000198 which when inverted is 50505.05 at price precision = 2
wantPrice: 50505.05,
},
}
for _, k := range testCases {
baseAsset := utils.Asset2Asset2(testBaseAsset)
quoteAsset := utils.Asset2Asset2(testQuoteAsset)
order, e := manageOffer2Order(k.op, baseAsset, quoteAsset, k.oc)
if !assert.NoError(t, e) {
return
}
assert.Equal(t, k.wantAction, order.OrderAction, fmt.Sprintf("expected '%s' but got '%s'", k.wantAction.String(), order.OrderAction.String()))
assert.Equal(t, k.wantPrice, order.Price.AsFloat())
assert.Equal(t, k.wantAmount, order.Volume.AsFloat())
}
}