diff --git a/plugins/volumeFilter_test.go b/plugins/volumeFilter_test.go index 24c2541d8..ab459ec4f 100644 --- a/plugins/volumeFilter_test.go +++ b/plugins/volumeFilter_test.go @@ -1124,183 +1124,6 @@ func runTestVolumeFilterFn( }) } -func TestVolumeFilterFn(t *testing.T) { - testCases := []struct { - name string - mode volumeFilterMode - baseCapInBase *float64 - baseCapInQuote *float64 - otbBase *float64 - otbQuote *float64 - tbbBase *float64 - tbbQuote *float64 - inputOp *txnbuild.ManageSellOffer - wantOp *txnbuild.ManageSellOffer - wantTbbBase *float64 - wantTbbQuote *float64 - }{ - { - name: "1. selling, base units sell cap, don't keep selling base, exact mode", - mode: volumeFilterModeExact, - baseCapInBase: pointy.Float64(0.0), - baseCapInQuote: nil, - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - { - name: "2. selling, base units sell cap, don't keep selling base, ignore mode", - mode: volumeFilterModeIgnore, - baseCapInBase: pointy.Float64(0.0), - baseCapInQuote: nil, - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - { - name: "3. selling, base units sell cap, keep selling base, exact mode", - mode: volumeFilterModeExact, - baseCapInBase: pointy.Float64(1.0), - baseCapInQuote: nil, - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: makeManageSellOffer("2.0", "1.0000000"), - wantTbbBase: pointy.Float64(1.0), - wantTbbQuote: pointy.Float64(2.0), - }, - { - name: "4. selling, base units sell cap, keep selling base, ignore mode", - mode: volumeFilterModeIgnore, - baseCapInBase: pointy.Float64(1.0), - baseCapInQuote: nil, - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - { - name: "7. selling, quote units sell cap, don't keep selling quote, exact mode", - mode: volumeFilterModeExact, - baseCapInBase: nil, - baseCapInQuote: pointy.Float64(0), - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - { - name: "8. selling, quote units sell cap, don't keep selling quote, ignore mode", - mode: volumeFilterModeIgnore, - baseCapInBase: nil, - baseCapInQuote: pointy.Float64(0), - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - { - name: "9. selling, quote units sell cap, keep selling quote, exact mode", - mode: volumeFilterModeExact, - baseCapInBase: nil, - baseCapInQuote: pointy.Float64(1.0), - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: makeManageSellOffer("2.0", "0.5000000"), - wantTbbBase: pointy.Float64(0.5), - wantTbbQuote: pointy.Float64(1.0), - }, - { - name: "10. selling, quote units sell cap, keep selling quote, ignore mode", - mode: volumeFilterModeIgnore, - baseCapInBase: nil, - baseCapInQuote: pointy.Float64(1.0), - otbBase: pointy.Float64(0.0), - otbQuote: pointy.Float64(0.0), - tbbBase: pointy.Float64(0.0), - tbbQuote: pointy.Float64(0.0), - inputOp: makeManageSellOffer("2.0", "100.0"), - wantOp: nil, - wantTbbBase: pointy.Float64(0.0), - wantTbbQuote: pointy.Float64(0.0), - }, - } - - // we fix the marketIDs and accountIDs, since volumeFilterFn output does not depend on them - marketIDs := []string{} - accountIDs := []string{} - - for _, k := range testCases { - for _, action := range []queries.DailyVolumeAction{queries.DailyVolumeActionSell} { - t.Run(k.name, func(t *testing.T) { - // exactly one of the two cap values must be set - if k.baseCapInBase == nil && k.baseCapInQuote == nil { - assert.Fail(t, "either one of the two cap values must be set") - return - } - - if k.baseCapInBase != nil && k.baseCapInQuote != nil { - assert.Fail(t, "both of the cap values cannot be set") - return - } - - dailyOTB := makeRawVolumeFilterConfig(k.otbBase, k.otbQuote, action, k.mode, marketIDs, accountIDs) - dailyTBBAccumulator := makeRawVolumeFilterConfig(k.tbbBase, k.tbbQuote, action, k.mode, marketIDs, accountIDs) - lp := limitParameters{ - baseAssetCapInBaseUnits: k.baseCapInBase, - baseAssetCapInQuoteUnits: k.baseCapInQuote, - mode: k.mode, - } - - actual, e := volumeFilterFn(dailyOTB, dailyTBBAccumulator, k.inputOp, utils.NativeAsset, utils.NativeAsset, lp) - if !assert.Nil(t, e) { - return - } - assert.Equal(t, k.wantOp, actual) - - wantTBBAccumulator := makeRawVolumeFilterConfig(k.wantTbbBase, k.wantTbbQuote, action, k.mode, marketIDs, accountIDs) - assert.Equal(t, wantTBBAccumulator, dailyTBBAccumulator) - }) - } - } -} - -func makeManageSellOffer(price string, amount string) *txnbuild.ManageSellOffer { - return &txnbuild.ManageSellOffer{ - Buying: txnbuild.NativeAsset{}, - Selling: txnbuild.NativeAsset{}, - Price: price, - Amount: amount, - } -} - func makeSellOpAmtPrice(amount float64, price float64) *txnbuild.ManageSellOffer { return &txnbuild.ManageSellOffer{ Buying: txnbuild.NativeAsset{},