Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add all buy-side tests for volume filter (#629)
Browse files Browse the repository at this point in the history
* Iniitial commit - base, ignore

* Add quote-ignore

* Add quote-exact
  • Loading branch information
debnil authored Dec 23, 2020
1 parent f909f50 commit df4f2fa
Showing 1 changed file with 101 additions and 26 deletions.
127 changes: 101 additions & 26 deletions plugins/volumeFilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,17 @@ func TestVolumeFilterFn_BaseCap_Ignore(t *testing.T) {
}
for _, k := range testCases {
// convert to common format accepted by runTestVolumeFilterFn
// doing this explicitly here is easier to read rather than if we were to add "logic" to convert it to a standard format
inputOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)

var wantOp *txnbuild.ManageSellOffer
// test sell action
sellName := fmt.Sprintf("%s, sell", k.name)
inputSellOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)
var wantSellOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
wantSellOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
k.name,
sellName,
volumeFilterModeIgnore,
queries.DailyVolumeActionSell,
pointy.Float64(k.cap), // base cap
Expand All @@ -641,8 +641,33 @@ func TestVolumeFilterFn_BaseCap_Ignore(t *testing.T) {
nil, // quoteOTB nil because this test is for the BaseCap
pointy.Float64(k.tbb), // baseTBB
pointy.Float64(0), // quoteTBB (non-nil since it accumulates)
inputOp,
wantOp,
inputSellOp,
wantSellOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)

// test buy action
buyName := fmt.Sprintf("%s, buy", k.name)
inputBuyOp := makeBuyOpAmtPrice(k.inputAmount, k.inputPrice)
var wantBuyOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantBuyOp = makeBuyOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
buyName,
volumeFilterModeIgnore,
queries.DailyVolumeActionBuy,
pointy.Float64(k.cap), // base cap
nil, // quote cap nil because this test is for the BaseCap
pointy.Float64(k.otb), // baseOTB
nil, // quoteOTB nil because this test is for the BaseCap
pointy.Float64(k.tbb), // baseTBB
pointy.Float64(0), // quoteTBB (non-nil since it accumulates)
inputBuyOp,
wantBuyOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)
Expand Down Expand Up @@ -804,27 +829,52 @@ func TestVolumeFilterFn_QuoteCap_Ignore(t *testing.T) {
}
for _, k := range testCases {
// convert to common format accepted by runTestVolumeFilterFn
// doing this explicitly here is easier to read rather than if we were to add "logic" to convert it to a standard format
inputOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)

var wantOp *txnbuild.ManageSellOffer
// test sell action
sellName := fmt.Sprintf("%s, sell", k.name)
inputSellOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)
var wantSellOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
wantSellOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
k.name,
sellName,
volumeFilterModeIgnore,
queries.DailyVolumeActionSell,
nil, // base cap nil because this test is for the QuoteCap
pointy.Float64(k.cap), // quote cap
nil, // baseOTB nil because this test is for the BaseCap
nil, // baseOTB nil because this test is for the QuoteCap
pointy.Float64(k.otb), // quoteOTB
pointy.Float64(0), // baseTBB (non-nil since it accumulates)
pointy.Float64(k.tbb), // quoteTBB
inputSellOp,
wantSellOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)

// test buy action
buyName := fmt.Sprintf("%s, buy", k.name)
inputBuyOp := makeBuyOpAmtPrice(k.inputAmount, k.inputPrice)
var wantBuyOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantBuyOp = makeBuyOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
buyName,
volumeFilterModeIgnore,
queries.DailyVolumeActionBuy,
nil, // base cap nil because this test is for the QuoteCap
pointy.Float64(k.cap), // quote cap
nil, // baseOTB nil because this test is for the QuoteCap
pointy.Float64(k.otb), // quoteOTB
pointy.Float64(0), // baseTBB (non-nil since it accumulates)
pointy.Float64(k.tbb), // quoteTBB
inputOp,
wantOp,
inputBuyOp,
wantBuyOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)
Expand Down Expand Up @@ -1076,27 +1126,52 @@ func TestVolumeFilterFn_QuoteCap_Exact(t *testing.T) {
}
for _, k := range testCases {
// convert to common format accepted by runTestVolumeFilterFn
// doing this explicitly here is easier to read rather than if we were to add "logic" to convert it to a standard format
inputOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)

var wantOp *txnbuild.ManageSellOffer
// test sell action
sellName := fmt.Sprintf("%s, sell", k.name)
inputSellOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)
var wantSellOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
wantSellOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
k.name,
sellName,
volumeFilterModeExact,
queries.DailyVolumeActionSell,
nil, // base cap nil because this test is for the QuoteCap
pointy.Float64(k.cap), // quote
pointy.Float64(k.cap), // quote cap
nil, // baseOTB nil because this test is for the QuoteCap
pointy.Float64(k.otb), // quoteOTB
pointy.Float64(0), // baseTBB (non-nil since it accumulates)
pointy.Float64(k.tbb), // quoteTBB
inputSellOp,
wantSellOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)

// test buy action
buyName := fmt.Sprintf("%s, buy", k.name)
inputBuyOp := makeBuyOpAmtPrice(k.inputAmount, k.inputPrice)
var wantBuyOp *txnbuild.ManageSellOffer
if k.wantPrice != nil && k.wantAmount != nil {
wantBuyOp = makeBuyOpAmtPrice(*k.wantAmount, *k.wantPrice)
}

runTestVolumeFilterFn(
t,
buyName,
volumeFilterModeExact,
queries.DailyVolumeActionBuy,
nil, // base cap nil because this test is for the QuoteCap
pointy.Float64(k.cap), // quote cap
nil, // baseOTB nil because this test is for the QuoteCap
pointy.Float64(k.otb), // quoteOTB
pointy.Float64(0), // baseTBB (non-nil since it accumulates)
pointy.Float64(k.tbb), // quoteTBB
inputOp,
wantOp,
inputBuyOp,
wantBuyOp,
pointy.Float64(k.wantTbbBase),
pointy.Float64(k.wantTbbQuote),
)
Expand Down

0 comments on commit df4f2fa

Please sign in to comment.