Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e22b79
dont use String for creating connections
krzysztofziobro Dec 27, 2022
20aafa6
do not wrap client
krzysztofziobro Dec 27, 2022
1f10b03
wip
krzysztofziobro Dec 28, 2022
2f5cda9
should work as old one
krzysztofziobro Dec 28, 2022
f5b769f
hide connection
krzysztofziobro Dec 28, 2022
44a4e9a
hide the rest
krzysztofziobro Dec 28, 2022
1472fd7
Don not hide clone
krzysztofziobro Dec 28, 2022
40225ca
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 29, 2022
168ce19
bump
krzysztofziobro Dec 29, 2022
0247e81
wip
krzysztofziobro Dec 30, 2022
4c1a6eb
wrap client
krzysztofziobro Dec 30, 2022
e41d124
rename client
krzysztofziobro Dec 30, 2022
7968aea
add Clone
krzysztofziobro Dec 30, 2022
9a979f6
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 30, 2022
50d7071
more general adder
krzysztofziobro Dec 30, 2022
dba9561
Add AsSigned
krzysztofziobro Dec 30, 2022
d700129
add impls for references
krzysztofziobro Dec 30, 2022
e45f361
wip
krzysztofziobro Jan 2, 2023
e6839b8
change TreasurySudoApi
krzysztofziobro Jan 2, 2023
8ec4625
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
3bf05d5
add methods to SignedConnectionApi
krzysztofziobro Jan 2, 2023
6b259b2
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
23d5a58
remove unnecessary casts
krzysztofziobro Jan 2, 2023
5600e11
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
b7ad771
review part 1
krzysztofziobro Jan 2, 2023
d156320
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
ef5625d
review part 2
krzysztofziobro Jan 2, 2023
af4d737
Make AsConnection visible only in crate
krzysztofziobro Jan 3, 2023
d15be1b
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 3, 2023
70db49a
Remove unnecessary dependencies on ConnectionApi
krzysztofziobro Jan 4, 2023
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
Prev Previous commit
Next Next commit
review part 2
  • Loading branch information
krzysztofziobro committed Jan 2, 2023
commit ef5625d7d83e7c510698486b81d5221b1f7fbbcc
3 changes: 1 addition & 2 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pub type BlockHash = H256;
pub(crate) type SubxtClient = OnlineClient<AlephConfig>;

pub use connections::{
AsConnection, AsSigned, Connection, ConnectionApi, RootConnection, SignedConnection,
SignedConnectionApi, SudoCall,
Connection, ConnectionApi, RootConnection, SignedConnection, SignedConnectionApi, SudoCall,
};

#[derive(Copy, Clone)]
Expand Down
8 changes: 4 additions & 4 deletions aleph-client/src/pallets/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub trait TreasureApiExt {

#[async_trait::async_trait]
pub trait TreasurySudoApi {
async fn sudo_approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn sudo_reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -91,13 +91,13 @@ impl<S: SignedConnectionApi> TreasuryUserApi for S {

#[async_trait::async_trait]
impl TreasurySudoApi for RootConnection {
async fn sudo_approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash> {
async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash> {
let call = Treasury(approve_proposal { proposal_id });

self.sudo_unchecked(call, status).await
}

async fn sudo_reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash> {
async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result<BlockHash> {
let call = Treasury(reject_proposal { proposal_id });

self.sudo_unchecked(call, status).await
Expand Down
6 changes: 2 additions & 4 deletions bin/cliain/src/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ pub async fn propose(connection: SignedConnection, amount_in_tokens: u64, benefi

/// Delegates to `aleph_client::approve_treasury_proposal`.
pub async fn approve(connection: RootConnection, proposal_id: u32) {
connection
.sudo_approve(proposal_id, TxStatus::Finalized)
TreasurySudoApi::approve(&connection, proposal_id, TxStatus::Finalized)
.await
.unwrap();
}

/// Delegates to `aleph_client::reject_treasury_proposal`.
pub async fn reject(connection: RootConnection, proposal_id: u32) {
connection
.sudo_reject(proposal_id, TxStatus::Finalized)
TreasurySudoApi::reject(&connection, proposal_id, TxStatus::Finalized)
.await
.unwrap();
}
22 changes: 11 additions & 11 deletions e2e-tests/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use aleph_client::{
primitives::{CommitteeSeats, EraValidators},
utility::BlocksApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, SignedConnection, TxStatus,
AccountId, SignedConnection, SignedConnectionApi, TxStatus,
};
use anyhow::anyhow;
use log::{debug, info};
Expand All @@ -33,8 +33,8 @@ type RewardPoint = u32;

/// Changes session_keys used by a given `controller` to some `zero`/invalid value,
/// making it impossible to create new legal blocks.
pub async fn set_invalid_keys_for_validator(
controller_connection: &SignedConnection,
pub async fn set_invalid_keys_for_validator<S: SignedConnectionApi>(
controller_connection: &S,
) -> anyhow::Result<()> {
let zero_session_keys = [0; 64].to_vec().into();

Expand All @@ -51,8 +51,8 @@ pub async fn set_invalid_keys_for_validator(
}

/// Rotates session_keys of a given `controller`, making it able to rejoin the `consensus`.
pub(super) async fn reset_validator_keys(
controller_connection: &SignedConnection,
pub(super) async fn reset_validator_keys<S: SignedConnectionApi>(
controller_connection: &S,
) -> anyhow::Result<()> {
let validator_keys = controller_connection.author_rotate_keys().await?;
controller_connection
Expand All @@ -68,8 +68,8 @@ pub(super) async fn reset_validator_keys(
Ok(())
}

pub async fn download_exposure(
connection: &SignedConnection,
pub async fn download_exposure<S: SignedConnectionApi>(
connection: &S,
era: EraIndex,
account_id: &AccountId,
beginning_of_session_block_hash: BlockHash,
Expand Down Expand Up @@ -124,8 +124,8 @@ fn check_rewards(
Ok(())
}

async fn get_node_performance(
connection: &SignedConnection,
async fn get_node_performance<S: SignedConnectionApi>(
connection: &S,
account_id: &AccountId,
before_end_of_session_block_hash: BlockHash,
blocks_to_produce_per_session: u32,
Expand All @@ -152,8 +152,8 @@ async fn get_node_performance(
lenient_performance
}

pub async fn check_points(
connection: &SignedConnection,
pub async fn check_points<S: SignedConnectionApi>(
connection: &S,
session: SessionIndex,
era: EraIndex,
members: impl IntoIterator<Item = AccountId>,
Expand Down
23 changes: 17 additions & 6 deletions e2e-tests/src/test/adder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::str::FromStr;

use aleph_client::{contract::ContractInstance, AccountId, ConnectionApi, SignedConnection};
use aleph_client::{
contract::ContractInstance, AccountId, Connection, ConnectionApi, SignedConnectionApi,
};
use anyhow::{Context, Result};
use assert2::assert;

Expand All @@ -20,15 +22,20 @@ pub async fn adder() -> Result<()> {

let increment = 10;
let before = contract.get(&conn).await?;
contract.add(&account.sign(&conn), increment).await?;
let raw_connection = Connection::new(&config.node).await;
contract
.add(&account.sign(&raw_connection), increment)
.await?;
let after = contract.get(&conn).await?;
assert!(after == before + increment);

let new_name = "test";
contract.set_name(&account.sign(&conn), None).await?;
contract
.set_name(&account.sign(&raw_connection), None)
.await?;
assert!(contract.get_name(&conn).await?.is_none());
contract
.set_name(&account.sign(&conn), Some(new_name))
.set_name(&account.sign(&raw_connection), Some(new_name))
.await?;
assert!(contract.get_name(&conn).await? == Some(new_name.to_string()));

Expand Down Expand Up @@ -69,13 +76,17 @@ impl AdderInstance {
self.contract.contract_read0(conn, "get").await
}

pub async fn add(&self, conn: &SignedConnection, value: u32) -> Result<()> {
pub async fn add<S: SignedConnectionApi>(&self, conn: &S, value: u32) -> Result<()> {
self.contract
.contract_exec(conn, "add", &[value.to_string()])
.await
}

pub async fn set_name(&self, conn: &SignedConnection, name: Option<&str>) -> Result<()> {
pub async fn set_name<S: SignedConnectionApi>(
&self,
conn: &S,
name: Option<&str>,
) -> Result<()> {
let name = name.map_or_else(
|| "None".to_string(),
|name| {
Expand Down
14 changes: 9 additions & 5 deletions e2e-tests/src/test/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ops::Deref;

use aleph_client::{
pallets::balances::BalanceUserApi, AccountId, AsConnection, Connection, KeyPair, Pair,
SignedConnection, TxStatus,
pallets::balances::BalanceUserApi, AccountId, Connection, KeyPair, Pair, SignedConnection,
SignedConnectionApi, TxStatus,
};
use anyhow::Result;
use primitives::Balance;
Expand Down Expand Up @@ -55,7 +55,11 @@ pub fn random_account() -> KeyPairWrapper {
}

/// Transfer `amount` from `from` to `to`
pub async fn transfer(conn: &SignedConnection, to: &KeyPair, amount: Balance) -> Result<()> {
pub async fn transfer<S: SignedConnectionApi>(
conn: &S,
to: &KeyPair,
amount: Balance,
) -> Result<()> {
conn.transfer(to.signer().public().into(), amount, TxStatus::InBlock)
.await
.map(|_| ())
Expand All @@ -69,12 +73,12 @@ pub fn alephs(basic_unit_amount: Balance) -> Balance {
/// Prepares a `(conn, authority, account)` triple with some money in `account` for fees.
pub async fn basic_test_context(
config: &Config,
) -> Result<(Connection, KeyPairWrapper, KeyPairWrapper)> {
) -> Result<(SignedConnection, KeyPairWrapper, KeyPairWrapper)> {
let conn = config.get_first_signed_connection().await;
let authority = KeyPairWrapper(aleph_client::keypair_from_string(&config.sudo_seed));
let account = random_account();

transfer(&conn, &account, alephs(100)).await?;

Ok((conn.as_connection().clone(), authority, account))
Ok((conn.clone(), authority, account))
}
6 changes: 3 additions & 3 deletions e2e-tests/src/test/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use aleph_client::{
primitives::{CommitteeSeats, EraValidators},
utility::SessionEraApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, SignedConnection, TxStatus,
AccountId, SignedConnection, SignedConnectionApi, TxStatus,
};
use log::info;
use primitives::{staking::MIN_VALIDATOR_BOND, EraIndex, SessionIndex};
Expand Down Expand Up @@ -262,8 +262,8 @@ pub async fn change_stake_and_force_new_era() -> anyhow::Result<()> {
Ok(())
}

async fn check_points_after_force_new_era(
connection: &SignedConnection,
async fn check_points_after_force_new_era<S: SignedConnectionApi>(
connection: &S,
start_session: SessionIndex,
start_era: EraIndex,
era_validators: &EraValidators<AccountId>,
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/src/test/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use aleph_client::{
primitives::CommitteeSeats,
sp_core::bounded::bounded_vec::BoundedVec,
waiting::{BlockStatus, WaitingExt},
AccountId, KeyPair, Pair, SignedConnection, TxStatus,
AccountId, KeyPair, Pair, SignedConnection, SignedConnectionApi, TxStatus,
};
use log::info;
use primitives::{
Expand Down Expand Up @@ -240,8 +240,8 @@ pub async fn multi_bond(node: &str, bonders: &[KeyPair], stake: Balance) {
}
}

async fn payout_stakers_and_assert_locked_balance(
stash_connection: &SignedConnection,
async fn payout_stakers_and_assert_locked_balance<S: SignedConnectionApi>(
stash_connection: &S,
accounts_to_check_balance: &[AccountId],
stash_account: &AccountId,
era: BlockNumber,
Expand Down