Skip to content

Commit

Permalink
A0-3957: Add proxy for foundation nomination program (#1595)
Browse files Browse the repository at this point in the history
Cherry-pick from main (changed aleph-client version to avoid any kind of
conflicts)

Please delete options that are not relevant.

- New feature (non-breaking change which adds functionality)

<!-- delete when not applicable to your PR -->

- I have added tests
- I have bumped aleph-client version if relevant
  • Loading branch information
ggawryal authored Feb 8, 2024
1 parent e086801 commit 1e903b3
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 207 deletions.
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph_client"
version = "3.7.2"
version = "3.7.3"
edition = "2021"
authors = ["Cardinal"]
documentation = "https://docs.rs/aleph_client"
Expand Down
192 changes: 97 additions & 95 deletions aleph-client/src/aleph_zero.rs

Large diffs are not rendered by default.

199 changes: 100 additions & 99 deletions aleph-client/src/aleph_zero_liminal.rs

Large diffs are not rendered by default.

45 changes: 37 additions & 8 deletions bin/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ pub enum ProxyType {
Any = 0,
NonTransfer = 1,
Staking = 2,
Nomination = 3,
}
impl Default for ProxyType {
fn default() -> Self {
Expand Down Expand Up @@ -838,17 +839,30 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
| RuntimeCall::NominationPools(..)
)
}
ProxyType::Nomination => {
matches!(
c,
RuntimeCall::Staking(pallet_staking::Call::nominate { .. })
)
}
}
}
fn is_superset(&self, o: &Self) -> bool {
// ProxyType::Staking ⊆ ProxyType::NonTransfer ⊆ ProxyType::Any
match (self, o) {
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::NonTransfer, ProxyType::Staking) => true,
(ProxyType::Staking, ProxyType::NonTransfer) => false,
(ProxyType::Staking, ProxyType::Staking) => true,
(ProxyType::NonTransfer, ProxyType::NonTransfer) => true,
// ProxyType::Nomination ⊆ ProxyType::Staking ⊆ ProxyType::NonTransfer ⊆ ProxyType::Any
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => match o {
ProxyType::Any => false,
ProxyType::NonTransfer | ProxyType::Staking | ProxyType::Nomination => true,
},
ProxyType::Staking => match o {
ProxyType::Any | ProxyType::NonTransfer => false,
ProxyType::Staking | ProxyType::Nomination => true,
},
ProxyType::Nomination => match o {
ProxyType::Any | ProxyType::NonTransfer | ProxyType::Staking => false,
ProxyType::Nomination => true,
},
}
}
}
Expand Down Expand Up @@ -1287,6 +1301,21 @@ mod tests {

use super::*;

#[test]
fn test_proxy_is_superset() {
let proxies = [
ProxyType::Any,
ProxyType::NonTransfer,
ProxyType::Staking,
ProxyType::Nomination,
];
for (i, proxy) in proxies.iter().enumerate() {
for (j, other) in proxies.iter().enumerate() {
assert_eq!(proxy.is_superset(other), i <= j);
}
}
}

#[test]
// This test is to make sure that we don't break call-runtime.
fn test_staking_pallet_index() {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 56 additions & 2 deletions e2e-tests/src/test/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ use aleph_client::{
keypair_from_string,
pallet_balances::pallet::Call::transfer_allow_death,
pallet_session::pallet::Call::set_keys,
pallet_staking::{pallet::pallet::Call::bond, RewardDestination},
pallet_staking::{
pallet::pallet::Call::{bond, chill, nominate},
RewardDestination,
},
pallet_utility::pallet::Call::batch,
pallets::{balances::BalanceUserApi, proxy::ProxyUserApi},
pallets::{balances::BalanceUserApi, proxy::ProxyUserApi, staking::StakingUserApi},
utility::BlocksApi,
AsConnection, AsSigned, Connection, KeyPair, RootConnection, SignedConnection, TxStatus,
};
use primitives::TOKEN;
use subxt::utils::{MultiAddress, Static};

use crate::{
accounts::{accounts_seeds_to_keys, get_validators_seeds},
config::setup_test,
test::proxy::ProxyCallExpectedStatus::{Failure, Success},
};
Expand Down Expand Up @@ -257,3 +261,53 @@ pub async fn non_transfer_proxy_works() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test]
pub async fn nomination_proxy_works() -> anyhow::Result<()> {
let config = setup_test();
let root_connection = config.create_root_connection().await;
let handle = setup_proxy(root_connection.clone(), ProxyType::Nomination).await;
let test_account_connection = SignedConnection::from_connection(
root_connection.as_connection().clone(),
handle.account.clone(),
);
let validator_0_id = accounts_seeds_to_keys(&get_validators_seeds(config))[0]
.account_id()
.clone();

let calls = vec![
(
RuntimeCall::Staking(bond {
value: 1000,
payee: RewardDestination::Staked,
}),
Failure,
),
(
RuntimeCall::Utility(batch {
calls: vec![RuntimeCall::Staking(bond {
value: 1000,
payee: RewardDestination::Staked,
})],
}),
Failure,
),
];
perform_and_check_calls(root_connection.as_connection().clone(), &handle, calls).await;

test_account_connection
.bond(2500 * TOKEN, TxStatus::Finalized)
.await?;
let calls = vec![
(
RuntimeCall::Staking(nominate {
targets: vec![MultiAddress::Id(Static(validator_0_id.clone()))],
}),
Success,
),
(RuntimeCall::Staking(chill {}), Failure),
];
perform_and_check_calls(root_connection.as_connection().clone(), &handle, calls).await;

Ok(())
}

0 comments on commit 1e903b3

Please sign in to comment.