This repository was archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
Add tests for volume filter for non-nil base and exact mode #615
Merged
nikhilsaraf
merged 10 commits into
stellar-deprecated:master
from
debnil:vf-tests-base-exact
Dec 11, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0a9e4f
vf-testing-strategy
debnil 52af4ac
Revert "vf-testing-strategy"
debnil 669089b
Merge remote-tracking branch 'upstream/master'
debnil a1344a9
Initial commit - cp ignore, failing
debnil 719c970
Add remaining test cases
debnil 3dc39f0
Clarify number of test cases
debnil 7ce04d5
Merge branch 'master' into vf-tests-base-exact
debnil 5f4dc28
Clean up transition to last set of tests
debnil 7fec57f
Merge branch 'vf-tests-base-exact' of github.com:debnil/kelp into vf-…
debnil d0a5876
fix name for case 15
nikhilsaraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,278 @@ type volumeFilterFnTestCase struct { | |
| wantTbbQuote float64 | ||
| } | ||
|
|
||
| func TestVolumeFilterFn_BaseCap_Exact(t *testing.T) { | ||
| // We want to test the following 4 valid combinations of OTB and TBB values: | ||
| // otb = 0 | ||
| // tbb = 0 | ||
| // otb = 0 && tbb = 0 | ||
| // otb > 0 && tbb > 0 | ||
| // We also want to test 3 combinations of cap relationship to projected (<, =, >) | ||
| // Finally, if projected > cap, we want to test 3 possible values of newAmount (+, 0, -) | ||
| // The above gives 4 * (2 + 1*3) = 20. | ||
| // One generated case is impossible in the code: otb = 0 && tbb = 0, newAmount < 0 | ||
| // so we have 19 cases | ||
| testCases := []volumeFilterFnTestCase{ | ||
| { | ||
| name: "1. otb = 0; projected < cap", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 5, | ||
| inputPrice: 2.0, | ||
| inputAmount: 4.99, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(4.99), | ||
| wantTbbBase: 9.99, | ||
| wantTbbQuote: 9.98, | ||
| }, | ||
| { | ||
| name: "2. otb = 0; projected = cap", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 5, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5), | ||
| wantTbbBase: 10, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "3. otb = 0; projected > cap, newAmount > 0", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 5, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.01, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5.0), | ||
| wantTbbBase: 10, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "4. otb = 0; projected > cap, newAmount = 0", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 10, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.01, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 10, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| { | ||
| name: "5. otb = 0; projected > cap, newAmount < 0", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 11, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.01, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 11, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| { | ||
| name: "6. tbb = 0; projected < cap", | ||
| cap: 10.0, | ||
| otb: 5, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 4.99, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(4.99), | ||
| wantTbbBase: 4.99, | ||
| wantTbbQuote: 9.98, | ||
| }, | ||
| { | ||
| name: "7. tbb = 0; projected = cap", | ||
| cap: 10.0, | ||
| otb: 5, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5.0), | ||
| wantTbbBase: 5, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "8. tbb = 0; projected > cap, newAmount > 0", | ||
| cap: 10.0, | ||
| otb: 5, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 6.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5.0), | ||
| wantTbbBase: 5, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "9. tbb = 0; projected > cap, newAmount = 0", | ||
| cap: 10.0, | ||
| otb: 10, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 6.0, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 0, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| { | ||
| name: "10. tbb = 0; projected > cap, newAmount < 0", | ||
| cap: 10.0, | ||
| otb: 11, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 6.0, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 0, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| { | ||
| name: "11. otb = 0 && tbb = 0; projected < cap", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5.0), | ||
| wantTbbBase: 5, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "12. otb = 0 && tbb = 0; projected = cap", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 10.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(10.0), | ||
| wantTbbBase: 10, | ||
| wantTbbQuote: 20, | ||
| }, | ||
| { | ||
| // note that in this case, newAmount >= 0, since newAmount = cap - otb - tbb | ||
| name: "13. otb = 0 && tbb = 0; projected > cap, newAmount > 0", | ||
| cap: 10.0, | ||
| otb: 0, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 15.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(10.0), | ||
| wantTbbBase: 10, | ||
| wantTbbQuote: 20, | ||
| }, | ||
| { | ||
| name: "14. otb = 0 && tbb = 0; projected > cap, newAmount = 0", | ||
| cap: 0.0, | ||
| otb: 0, | ||
| tbb: 0, | ||
| inputPrice: 2.0, | ||
| inputAmount: 15.0, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 0, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| // it is not possible for otb = 0 && tbb = 0 and newAmount < 0, so skipping that case | ||
| { | ||
| name: "15. otb > 0 && tbb > 0; projected < cap", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @debnil this case is the |
||
| cap: 10.0, | ||
| otb: 1, | ||
| tbb: 1, | ||
| inputPrice: 2.0, | ||
| inputAmount: 5.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(5.0), | ||
| wantTbbBase: 6, | ||
| wantTbbQuote: 10, | ||
| }, | ||
| { | ||
| name: "16. otb > 0 && tbb > 0; projected = cap", | ||
| cap: 10.0, | ||
| otb: 2, | ||
| tbb: 2, | ||
| inputPrice: 2.0, | ||
| inputAmount: 6.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(6.0), | ||
| wantTbbBase: 8, | ||
| wantTbbQuote: 12, | ||
| }, | ||
| { | ||
| name: "17. otb > 0 && tbb > 0; projected > cap, newAmount > 0", | ||
| cap: 10.0, | ||
| otb: 2, | ||
| tbb: 2, | ||
| inputPrice: 2.0, | ||
| inputAmount: 7.0, | ||
| wantPrice: pointy.Float64(2.0), | ||
| wantAmount: pointy.Float64(6.0), | ||
| wantTbbBase: 8, | ||
| wantTbbQuote: 12, | ||
| }, | ||
| { | ||
| name: "18. otb > 0 && tbb > 0; projected > cap, newAmount = 0", | ||
| cap: 10.0, | ||
| otb: 5, | ||
| tbb: 5, | ||
| inputPrice: 2.0, | ||
| inputAmount: 7.0, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 5, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| { | ||
| name: "19. otb > 0 && tbb > 0; projected > cap, newAmount < 0", | ||
| cap: 10.0, | ||
| otb: 5, | ||
| tbb: 5.1, | ||
| inputPrice: 2.0, | ||
| inputAmount: 7.0, | ||
| wantPrice: nil, | ||
| wantAmount: nil, | ||
| wantTbbBase: 5.1, | ||
| wantTbbQuote: 0, | ||
| }, | ||
| } | ||
| 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 | ||
| if k.wantPrice != nil && k.wantAmount != nil { | ||
| wantOp = makeSellOpAmtPrice(*k.wantAmount, *k.wantPrice) | ||
| } | ||
|
|
||
| runTestVolumeFilterFn( | ||
| t, | ||
| k.name, | ||
| volumeFilterModeExact, | ||
| queries.DailyVolumeActionSell, | ||
| 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) | ||
| inputOp, | ||
| wantOp, | ||
| pointy.Float64(k.wantTbbBase), | ||
| pointy.Float64(k.wantTbbQuote), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| func TestVolumeFilterFn_BaseCap_Ignore(t *testing.T) { | ||
| // We want to test the following 4 valid combinations of OTB and TBB values: | ||
| // otb = 0 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.