Skip to content

Commit

Permalink
fix pallet balances test
Browse files Browse the repository at this point in the history
  • Loading branch information
haerdib committed Sep 11, 2024
1 parent 78f40a2 commit 34c180a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 97 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ jobs:
jsonrpsee_tests,
keystore_tests,
pallet_balances_tests,
pallet_contract_tests,
pallet_transaction_payment_tests,
runtime_api_tests,
tungstenite_client_test,
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/config/asset_runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! https://github.com/paritytech/subxt/blob/ce0a82e3227efb0eae131f025da5f839d9623e15/subxt/src/config/substrate.rs
use crate::{
config::WithExtrinsicParams, Config, DefaultRuntimeConfig, GenericExtrinsicParams, PlainTip,
config::WithExtrinsicParams, AssetTip, Config, DefaultRuntimeConfig, GenericExtrinsicParams,
};
/// Standard runtime config for Substrate and Polkadot nodes that use the asset pallet.
pub type AssetRuntimeConfig =
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ mod tests {
let nonce = 6;
let retrieved_params = api.extrinsic_params(nonce);

let expected_params = GenericExtrinsicParams::<AssetRuntimeConfig, PlainTip<u128>>::new(
let expected_params = GenericExtrinsicParams::<DefaultRuntimeConfig, PlainTip<u128>>::new(
runtime_version.spec_version,
runtime_version.transaction_version,
nonce,
Expand Down
38 changes: 33 additions & 5 deletions testing/async/examples/pallet_balances_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

//! Tests for the pallet balances interface functions.
use codec::Encode;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_primitives::WestendRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api,
GetAccountInformation, GetBalance, SubmitAndWatch, XtStatus,
GetAccountInformation, GetBalance, GetTransactionPayment, SubmitAndWatch, XtStatus,
};

#[tokio::main]
Expand All @@ -41,29 +42,56 @@ async fn main() {
println!("[+] Bob's Free Balance is {}\n", balance_of_bob);

// Rough estimate of fees for three transactions
let fee_estimate = 3 * 2000000000000;
let dummy_xt = api
.balance_transfer_keep_alive(bob.clone().into(), balance_of_alice)
.await
.unwrap()
.encode();
let transaction_fee =
api.get_fee_details(&dummy_xt.into(), None).await.unwrap().unwrap().final_fee();
println!("[+] Transaction Fee is {}\n", transaction_fee);

let xt = api
.balance_transfer_keep_alive(bob.clone().into(), balance_of_alice / 2 - fee_estimate)
.balance_transfer_keep_alive(
bob.clone().into(),
balance_of_alice / 2 - (3 * transaction_fee),
)
.await
.unwrap();
let report = api.submit_and_watch_extrinsic_until(xt, XtStatus::Finalized).await;
// This call should succeed as alice has enough money
assert!(report.is_ok());

// Alice now has half of her balance plus two transaction fees left
// (one has been deducted by the transaction above).
let estimated_balance_of_alice = balance_of_alice / 2 + 2 * transaction_fee;

let balance_of_alice = api.get_account_data(&alice).await.unwrap().unwrap().free;
println!("[+] Alice's Free Balance is {}\n", balance_of_alice);
assert_eq!(balance_of_alice, estimated_balance_of_alice);

let xt = api
.balance_transfer_keep_alive(bob.clone().into(), balance_of_alice - fee_estimate)
.balance_transfer_keep_alive(bob.clone().into(), balance_of_alice - transaction_fee - 1)
.await
.unwrap();

let report = api.submit_and_watch_extrinsic_until(xt, XtStatus::Finalized).await;
// This call should fail as alice would fall below the existential deposit
assert!(report.is_err());

let balance_of_alice = api.get_account_data(&alice).await.unwrap().unwrap().free;
println!("[+] Alice's Free Balance is {}\n", balance_of_alice);

let dummy_xt = api
.balance_transfer_allow_death(bob.clone().into(), balance_of_alice)
.await
.unwrap()
.encode();
let transaction_fee =
api.get_fee_details(&dummy_xt.into(), None).await.unwrap().unwrap().final_fee();

let xt = api
.balance_transfer_allow_death(bob.clone().into(), balance_of_alice - fee_estimate)
.balance_transfer_allow_death(bob.clone().into(), balance_of_alice - transaction_fee - 1)
.await
.unwrap();
let result = api.submit_and_watch_extrinsic_until(xt, XtStatus::Finalized).await;
Expand Down
83 changes: 0 additions & 83 deletions testing/async/examples/pallet_contract_tests.rs

This file was deleted.

4 changes: 2 additions & 2 deletions testing/async/examples/runtime_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ async fn main() {
// let _session_keys =
// runtime_api.decode_session_keys(encoded_session_keys, None).unwrap().unwrap();

// Staking
let _quota = runtime_api.nominations_quota(100000000, None).await.unwrap();
// Staking not available
// let _quota = runtime_api.nominations_quota(100000000, None).await.unwrap();

// Transaction Payment
let extrinsic = api.balance_transfer_allow_death(bob.clone().into(), 1000).await.unwrap();
Expand Down
6 changes: 2 additions & 4 deletions testing/async/examples/state_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ async fn main() {
assert_eq!(storage_keys.len() as u32, 14);

let max_keys = 20;
let storage_keys = api
.get_storage_keys_paged_limited(None, max_keys.clone(), None, None)
.await
.unwrap();
let storage_keys =
api.get_storage_keys_paged_limited(None, max_keys, None, None).await.unwrap();
assert_eq!(storage_keys.len() as u32, max_keys);

let storage_keys = api.get_storage_keys_paged(None, max_keys, None, None).await.unwrap();
Expand Down

0 comments on commit 34c180a

Please sign in to comment.