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

Commit 798f548

Browse files
authored
Add volume filter tests for non-nil quote and ignore mode (#614)
* vf-testing-strategy * Revert "vf-testing-strategy" This reverts commit d0a9e4f. * Initial commit
1 parent d811d40 commit 798f548

1 file changed

Lines changed: 182 additions & 0 deletions

File tree

plugins/volumeFilter_test.go

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,188 @@ func TestVolumeFilterFn_BaseCap_Ignore(t *testing.T) {
348348
}
349349
}
350350

351+
func TestVolumeFilterFn_QuoteCap_Ignore(t *testing.T) {
352+
// We want to test the following 4 valid combinations of OTB and TBB values:
353+
// otb = 0
354+
// tbb = 0
355+
// otb = 0 && tbb = 0
356+
// otb > 0 && tbb > 0
357+
// 12 cases here; 4 combinations of tbb/otb values from bullet points above x 3 combinations of cap relationship to projected (<, =, >)
358+
testCases := []volumeFilterFnTestCase{
359+
{
360+
name: "1. otb = 0; projected < cap",
361+
cap: 10.0,
362+
otb: 0,
363+
tbb: 5,
364+
inputPrice: 2.0,
365+
inputAmount: 2.49,
366+
wantPrice: pointy.Float64(2.0),
367+
wantAmount: pointy.Float64(2.49),
368+
wantTbbBase: 2.49,
369+
wantTbbQuote: 9.98,
370+
},
371+
{
372+
name: "2. otb = 0; projected = cap",
373+
cap: 10.0,
374+
otb: 0,
375+
tbb: 5,
376+
inputPrice: 2.0,
377+
inputAmount: 2.5,
378+
wantPrice: pointy.Float64(2.0),
379+
wantAmount: pointy.Float64(2.5),
380+
wantTbbBase: 2.5,
381+
wantTbbQuote: 10,
382+
},
383+
{
384+
name: "3. otb = 0; projected > cap",
385+
cap: 10.0,
386+
otb: 0,
387+
tbb: 5,
388+
inputPrice: 2.0,
389+
inputAmount: 5.01,
390+
wantPrice: nil,
391+
wantAmount: nil,
392+
wantTbbBase: 0,
393+
wantTbbQuote: 5,
394+
},
395+
{
396+
name: "4. tbb = 0; projected < cap",
397+
cap: 10.0,
398+
otb: 5,
399+
tbb: 0,
400+
inputPrice: 2.0,
401+
inputAmount: 2.49,
402+
wantPrice: pointy.Float64(2.0),
403+
wantAmount: pointy.Float64(2.49),
404+
wantTbbBase: 2.49,
405+
wantTbbQuote: 4.98,
406+
},
407+
{
408+
name: "5. tbb = 0; projected = cap",
409+
cap: 10.0,
410+
otb: 5,
411+
tbb: 0,
412+
inputPrice: 2.0,
413+
inputAmount: 2.5,
414+
wantPrice: pointy.Float64(2.0),
415+
wantAmount: pointy.Float64(2.5),
416+
wantTbbBase: 2.5,
417+
wantTbbQuote: 5,
418+
},
419+
{
420+
name: "6. tbb = 0; projected > cap",
421+
cap: 10.0,
422+
otb: 5,
423+
tbb: 0,
424+
inputPrice: 2.0,
425+
inputAmount: 6.0,
426+
wantPrice: nil,
427+
wantAmount: nil,
428+
wantTbbBase: 0,
429+
wantTbbQuote: 0,
430+
},
431+
{
432+
name: "7. otb = 0 && tbb = 0; projected < cap",
433+
cap: 10.0,
434+
otb: 0,
435+
tbb: 0,
436+
inputPrice: 2.0,
437+
inputAmount: 2.5,
438+
wantPrice: pointy.Float64(2.0),
439+
wantAmount: pointy.Float64(2.5),
440+
wantTbbBase: 2.5,
441+
wantTbbQuote: 5,
442+
},
443+
{
444+
name: "8. otb = 0 && tbb = 0; projected = cap",
445+
cap: 10.0,
446+
otb: 0,
447+
tbb: 0,
448+
inputPrice: 2.0,
449+
inputAmount: 5.0,
450+
wantPrice: pointy.Float64(2.0),
451+
wantAmount: pointy.Float64(5.0),
452+
wantTbbBase: 5,
453+
wantTbbQuote: 10,
454+
},
455+
{
456+
name: "9. otb = 0 && tbb = 0; projected > cap",
457+
cap: 10.0,
458+
otb: 0,
459+
tbb: 0,
460+
inputPrice: 2.0,
461+
inputAmount: 15.0,
462+
wantPrice: nil,
463+
wantAmount: nil,
464+
wantTbbBase: 0,
465+
wantTbbQuote: 0,
466+
},
467+
{
468+
name: "10. otb > 0 && tbb > 0; projected < cap",
469+
cap: 10.0,
470+
otb: 1,
471+
tbb: 1,
472+
inputPrice: 2.0,
473+
inputAmount: 2.5,
474+
wantPrice: pointy.Float64(2.0),
475+
wantAmount: pointy.Float64(2.5),
476+
wantTbbBase: 2.5,
477+
wantTbbQuote: 6,
478+
},
479+
{
480+
name: "11. otb > 0 && tbb > 0; projected = cap",
481+
cap: 10.0,
482+
otb: 2,
483+
tbb: 2,
484+
inputPrice: 2.0,
485+
inputAmount: 3.0,
486+
wantPrice: pointy.Float64(2.0),
487+
wantAmount: pointy.Float64(3.0),
488+
wantTbbBase: 3,
489+
wantTbbQuote: 8,
490+
},
491+
{
492+
name: "12. otb > 0 && tbb > 0; projected > cap",
493+
cap: 10.0,
494+
otb: 2,
495+
tbb: 2,
496+
inputPrice: 2.0,
497+
inputAmount: 7.0,
498+
wantPrice: nil,
499+
wantAmount: nil,
500+
wantTbbBase: 0,
501+
wantTbbQuote: 2,
502+
},
503+
}
504+
for _, k := range testCases {
505+
// convert to common format accepted by runTestVolumeFilterFn
506+
// doing this explicitly here is easier to read rather than if we were to add "logic" to convert it to a standard format
507+
inputOp := makeSellOpAmtPrice(k.inputAmount, k.inputPrice)
508+
509+
var wantOp *txnbuild.ManageSellOffer
510+
if k.wantPrice != nil && k.wantAmount != nil {
511+
wantOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice)
512+
}
513+
514+
runTestVolumeFilterFn(
515+
t,
516+
k.name,
517+
volumeFilterModeIgnore,
518+
queries.DailyVolumeActionSell,
519+
nil, // base cap nil because this test is for the QuoteCap
520+
pointy.Float64(k.cap), // quote cap
521+
nil, // baseOTB nil because this test is for the BaseCap
522+
pointy.Float64(k.otb), // quoteOTB
523+
pointy.Float64(0), // baseTBB (non-nil since it accumulates)
524+
pointy.Float64(k.tbb), // quoteTBB
525+
inputOp,
526+
wantOp,
527+
pointy.Float64(k.wantTbbBase),
528+
pointy.Float64(k.wantTbbQuote),
529+
)
530+
}
531+
}
532+
351533
func runTestVolumeFilterFn(
352534
t *testing.T,
353535
name string,

0 commit comments

Comments
 (0)