Skip to content

Commit

Permalink
Fixing benchmarks and removing cargo order
Browse files Browse the repository at this point in the history
  • Loading branch information
hbulgarini committed Aug 16, 2023
1 parent d2186a5 commit 1056198
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ jobs:
- uses: actions/checkout@v1
- run: >
cargo fmt --all -- --check
&& cargo install cargo-sort
&& cargo sort --workspace --check --grouped
&& cargo clippy --workspace --tests -- -Dwarnings
&& cargo test --workspace --features runtime-benchmarks
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ frame-system = { default-features = false, git = "https://github.com/paritytech/

pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }


[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
Expand All @@ -33,8 +34,8 @@ default = ["std"]
std = [
"codec/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"sp-std/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
Expand Down
2 changes: 1 addition & 1 deletion rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }

pallet-dex = { version = "0.0.2", default-features = false, path = "../.." }
pallet-dex = { version = "0.0.1", default-features = false, path = "../.." }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

Expand Down
14 changes: 7 additions & 7 deletions src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const LIQ_TOKEN_B: u32 = 12;

fn prepare_exchange<T>(asset_id: u32, liquidity_token_id: u32) -> DispatchResult
where
T: frame_system::Config<BlockNumber = u32>,
frame_system::pallet_prelude::BlockNumberFor<T>: From<u32>,
T: Config<AssetId = u32, AssetBalance = u128>,
T::Currency: Currency<AccountIdOf<T>, Balance = u128>,
T::Assets: Create<AccountIdOf<T>> + Mutate<AccountIdOf<T>>,
Expand All @@ -38,7 +38,7 @@ where
benchmarks! {
where_clause {
where
T: frame_system::Config<BlockNumber = u32>,
frame_system::pallet_prelude::BlockNumberFor<T>: From<u32>,
T: Config<AssetId = u32, AssetBalance = u128>,
T::Currency: Currency<AccountIdOf<T>, Balance = u128>,
T::Assets: Create<AccountIdOf<T>> + Mutate<AccountIdOf<T>>,
Expand All @@ -58,7 +58,7 @@ benchmarks! {
prepare_exchange::<T>(ASSET_A, LIQ_TOKEN_A)?;
let caller: T::AccountId = whitelisted_caller();
// Token amount is 2, not 1 because of the `+1` in liquidity added formula
}: _(RawOrigin::Signed(caller), ASSET_A, 1, 1, 2, 1)
}: _(RawOrigin::Signed(caller), ASSET_A, 1, 1, 2, 1.into())
verify {
let exchange = Pallet::<T>::exchanges(ASSET_A).unwrap();
assert_eq!(exchange.currency_reserve, INIT_LIQUIDITY + 1);
Expand All @@ -68,7 +68,7 @@ benchmarks! {
remove_liquidity {
prepare_exchange::<T>(ASSET_A, LIQ_TOKEN_A)?;
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), ASSET_A, 1, 1, 1, 1)
}: _(RawOrigin::Signed(caller), ASSET_A, 1, 1, 1, 1.into())
verify {
let exchange = Pallet::<T>::exchanges(ASSET_A).unwrap();
assert_eq!(exchange.currency_reserve, INIT_LIQUIDITY - 1);
Expand All @@ -80,7 +80,7 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
let input_amount = 500;
let min_output = 498; // sold amount (500) - provider fee (0.3%) should be ~498
}: _(RawOrigin::Signed(caller), ASSET_A, TradeAmount::FixedInput{input_amount, min_output}, 1, None)
}: _(RawOrigin::Signed(caller), ASSET_A, TradeAmount::FixedInput{input_amount, min_output}, 1.into(), None)
verify {
let exchange = Pallet::<T>::exchanges(ASSET_A).unwrap();
assert_eq!(exchange.currency_reserve, INIT_LIQUIDITY + input_amount);
Expand All @@ -92,7 +92,7 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
let input_amount = 500;
let min_output = 498; // sold amount (500) - provider fee (0.3%) should be ~498
}: _(RawOrigin::Signed(caller), ASSET_A, TradeAmount::FixedInput{input_amount, min_output}, 1, None)
}: _(RawOrigin::Signed(caller), ASSET_A, TradeAmount::FixedInput{input_amount, min_output}, 1.into(), None)
verify {
let exchange = Pallet::<T>::exchanges(ASSET_A).unwrap();
assert_eq!(exchange.currency_reserve, INIT_LIQUIDITY - min_output);
Expand All @@ -106,7 +106,7 @@ benchmarks! {
let input_amount = 500;
let currency_amount = 498; // sold amount (500) - provider fee (0.3%) should be ~498
let min_output = 496; // currency amount (498) - provider fee (0.3%) should be ~496
}: _(RawOrigin::Signed(caller), ASSET_A, ASSET_B, TradeAmount::FixedInput{input_amount, min_output}, 1, None)
}: _(RawOrigin::Signed(caller), ASSET_A, ASSET_B, TradeAmount::FixedInput{input_amount, min_output}, 1.into(), None)
verify {
let exchange_a = Pallet::<T>::exchanges(ASSET_A).unwrap();
assert_eq!(exchange_a.currency_reserve, INIT_LIQUIDITY - currency_amount);
Expand Down

0 comments on commit 1056198

Please sign in to comment.