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

fix: looser is_local_representation #1815

Merged
merged 4 commits into from
Apr 18, 2024
Merged

fix: looser is_local_representation #1815

merged 4 commits into from
Apr 18, 2024

Conversation

wischli
Copy link
Contributor

@wischli wischli commented Apr 17, 2024

Description

Fixes issue which blocks FRAX <> USDC order fulfilments on Demo.

The current implementation of is_local_representation is too strict such that it throws an error if the checked CurrencyId has not configured a local representation. Instead, it should return Ok(false). This function has not been tested directly.

To the best of my knowledge, this does not affect production for now as it only affects checking currencies which don't have a configured local asset, e.g. FRAX.

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@wischli wischli added the I2-bug The code fails to follow expected behaviour. label Apr 17, 2024
@wischli wischli self-assigned this Apr 17, 2024
lemunozm
lemunozm previously approved these changes Apr 17, 2024
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Thanks for researching this @wischli, and for adding related tests

Ok(self == &local)
Ok(self == &local.into())
} else {
Ok(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice found!

#[test]
fn is_local_happy_paths() {
new_test_ext().execute_with(|| {
assert_eq!(<CurrencyId as HasLocalAssetRepresentation<MockRegistry>>::is_local_representation_of(&USDC_LOCAL, &USDC_1), Ok(true));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious,

CurrencyId::is_local_representation_of()

Does not compile? Does the compiler force you to specify the trait?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, the AssetInspect parameter type cannot be inferred. Tried different variants but none of the shortcuts worked.

mustermeiszer
mustermeiszer previously approved these changes Apr 17, 2024
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Thanks for the hustle! Nice found!

wischli and others added 2 commits April 18, 2024 09:22
* add tests that fail and shouldn't

* add fix

* add extra tests
@wischli wischli dismissed stale reviews from mustermeiszer and lemunozm via 1446db2 April 18, 2024 07:23
@wischli wischli enabled auto-merge (squash) April 18, 2024 07:36
@wischli wischli merged commit 430fbe9 into main Apr 18, 2024
10 checks passed
@wischli wischli deleted the fix/local-representation branch May 16, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The code fails to follow expected behaviour.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants