Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool: adds a test for the bug in question, no weird behaviour allthough I used pretty similar values with what's already present in the live environment #171

Merged
merged 7 commits into from
Dec 7, 2023

Conversation

gangov
Copy link
Collaborator

@gangov gangov commented Dec 3, 2023

No description provided.

…gh I used pretty similar values with what's already present in the live environment
@gangov gangov requested a review from ueco-jb December 3, 2023 20:32
@gangov gangov self-assigned this Dec 3, 2023
@gangov gangov linked an issue Dec 3, 2023 that may be closed by this pull request
@gangov
Copy link
Collaborator Author

gangov commented Dec 3, 2023

bug-issue-169.md
made a small report on the issue at hand: nothing seems bad in the code, the test is working, and I tried to implement it as close as possible to what we already have in test network's requests

In addition to the new test, we already have a couple of other tests that look correct to me and they work.

I'm thinking that we might have bad initial setup for the pool somehow, but I cannot verify that.

Would it make sense for us to keep the initial command that was used to initialize the pool. I know it sounds similar to what we already have in config, but the config can get updated via update_config in pool contract, and we don't keep track of previous states.

Also, I think swap commission is wrong only when doing simulate_swap for XLM/EURC.

My suggestion is to re-deploy everything on testnet and check again.

std::mem::swap(&mut token1, &mut token2);
}

let swap_fees = 1_000i64; // 10% bps
Copy link
Member

Choose a reason for hiding this comment

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

Can you try smaller amounts, 1% and 0.3%?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got the expected results

@ueco-jb ueco-jb marked this pull request as ready for review December 4, 2023 21:20
Copy link
Member

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

I like those tests. Instead of creating a new, specifically named test cases let's close this withing one test_swap_fee_variants or something; use testcase crate and add that fee as parameter to the tests in couple variants, including those 1%, 0.3%.
https://docs.rs/test-case/latest/test_case/

Copy link
Member

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

Good test, just some cleaning required.

contracts/pool/src/tests/swap.rs Outdated Show resolved Hide resolved
contracts/pool/src/tests/swap.rs Outdated Show resolved Hide resolved
Comment on lines 643 to 644
#[test_case(1_000i64, 10, 99102002 ; "when fee is 10%")]
#[test_case(100, 1, 9910200 ; "when fee is 1%")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[test_case(1_000i64, 10, 99102002 ; "when fee is 10%")]
#[test_case(100, 1, 9910200 ; "when fee is 1%")]
#[test_case(1_000i64, 1000, 99102002 ; "when fee is 10%")]
#[test_case(100, 100, 9910200 ; "when fee is 1%")]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

those values suggested to be changed are gone now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only using BPS

@@ -843,12 +706,12 @@ fn bug_issue_169_below_1_percent() {
}
);

// 991020025 is the request, so 0.3% of that should be what's on the left hand side
assert_eq!(2973060, result.commission_amount);
// 991020025 is the request, so 10% of that should be what's on the left hand side
Copy link
Member

@ueco-jb ueco-jb Dec 7, 2023

Choose a reason for hiding this comment

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

Those comments aren't accurate in parametrized test.


let result = pool.simulate_reverse_swap(&token1.address, &(output_amount - fees));
let output_amount = 991020025i128;
let fees = Decimal::bps(30) * output_amount;
// let fees = Decimal::percent(fee_percentage) * output_amount;
Copy link
Member

Choose a reason for hiding this comment

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

Some leftover?

Suggested change
// let fees = Decimal::percent(fee_percentage) * output_amount;

Copy link
Member

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

Good test 👍

@ueco-jb ueco-jb merged commit 43aab8f into main Dec 7, 2023
3 checks passed
@ueco-jb ueco-jb deleted the bug_issue_169 branch December 7, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pool: simulate_swap returns wrong value
2 participants