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

pallet asset-conversion additional quote tests #1371

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Changes from 1 commit
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
95 changes: 95 additions & 0 deletions substrate/frame/asset-conversion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ fn can_quote_price() {
),
Some(60)
);
// including fee so should get less out...
assert_eq!(
AssetConversion::quote_price_exact_tokens_for_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
3000,
true,
),
Some(46)
);
// Check it still gives same price:
// (if the above accidentally exchanged then it would not give same quote as before)
assert_eq!(
Expand All @@ -580,6 +590,16 @@ fn can_quote_price() {
),
Some(60)
);
// including fee so should get less out...
assert_eq!(
AssetConversion::quote_price_exact_tokens_for_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
3000,
true,
),
Some(46)
);

// Check inverse:
assert_eq!(
Expand All @@ -591,6 +611,81 @@ fn can_quote_price() {
),
Some(3000)
);
// including fee so should get less out...
assert_eq!(
AssetConversion::quote_price_exact_tokens_for_tokens(
NativeOrAssetId::Asset(2),
NativeOrAssetId::Native,
60,
true,
),
Some(2302)
);

//
// same tests as above but for quote_price_tokens_for_exact_tokens:
//
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
60,
false,
),
Some(3000)
);
// including fee so should need to put more in...
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
60,
true,
),
Some(4299)
);
// Check it still gives same price:
// (if the above accidentally exchanged then it would not give same quote as before)
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
60,
false,
),
Some(3000)
);
// including fee so should need to put more in...
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Native,
NativeOrAssetId::Asset(2),
60,
true,
),
Some(4299)
);

// Check inverse:
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Asset(2),
NativeOrAssetId::Native,
3000,
false,
),
Some(60)
);
// including fee so should need to put more in...
assert_eq!(
AssetConversion::quote_price_tokens_for_exact_tokens(
NativeOrAssetId::Asset(2),
NativeOrAssetId::Native,
3000,
true,
),
Some(86)
);
});
}

Expand Down