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

Add all buy-side tests for volume filter #629

Merged
merged 3 commits into from
Dec 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

@nikhilsaraf nikhilsaraf Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this comment was fixed to say QuoteCap instead of BaseCap. great catch!

It's sometimes easer to review these minor changes and not skip over them if they are highlighted in the PR with a comment, esp. since it breaks from the general pattern of the rest of the PR. regardless, thanks for fixing! :)

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