Skip to content

Commit

Permalink
Enhance Proxy Configuration with Tests for Pure Proxy Creation and Mo…
Browse files Browse the repository at this point in the history
…dification (#549)

* add test to create proxy

* add proxy to proxied test

* refactoring

* using dispatch

* Fix proxy and test

* Copy polkadot proxy config

* using all calls (#550)

* fix clippy

---------

Co-authored-by: magecnion <magecnion@gmail.com>
  • Loading branch information
asiniscalchi and magecnion authored Apr 9, 2024
1 parent 7ea70ad commit c427544
Showing 1 changed file with 98 additions and 1 deletion.
99 changes: 98 additions & 1 deletion runtime/laos/src/configs/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,27 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, _c: &RuntimeCall) -> bool {
matches!(self, ProxyType::Any)
}

fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::currency::MILLIUNIT;
use crate::{
currency::{MILLIUNIT, UNIT},
tests::{ExtBuilder, ALICE, BOB},
AccountId, RuntimeOrigin,
};
use core::str::FromStr;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use sp_runtime::traits::Dispatchable;

#[test]
fn check_deposits() {
Expand All @@ -100,4 +115,86 @@ mod tests {
560 * MILLIUNIT
);
}

#[test]
fn create_pure_proxy() {
let alice = AccountId::from_str(ALICE).unwrap();

ExtBuilder::default()
.with_balances(vec![(alice, 1000 * UNIT)])
.build()
.execute_with(|| {
let call = RuntimeCall::Proxy(pallet_proxy::Call::create_pure {
proxy_type: ProxyType::Any,
index: 0, // index
delay: 0, // delay
});

assert_ok!(call.dispatch(RuntimeOrigin::signed(alice)));
});
}

#[test]
fn add_proxy_to_pure_proxy_should_succeed() {
let delay = 0;
let index = 0;
let alice = AccountId::from_str(ALICE).unwrap();
let bob = AccountId::from_str(BOB).unwrap();

ExtBuilder::default()
.with_balances(vec![(alice, 1000 * UNIT), (bob, 1000 * UNIT)])
.build()
.execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1);
let call = RuntimeCall::Proxy(pallet_proxy::Call::create_pure {
proxy_type: ProxyType::Any,
index, // index
delay, // delay
});
assert_ok!(call.dispatch(RuntimeOrigin::signed(alice)));

// Get pure proxy address from event
let events = frame_system::Pallet::<Runtime>::events();
let pure_proxy = match events.last().unwrap().event {
RuntimeEvent::Proxy(pallet_proxy::Event::PureCreated { pure, .. }) => pure,
_ => panic!("unexpected event"),
};

assert_eq!(
&pallet_proxy::Pallet::<Runtime>::pure_account(
&alice,
&ProxyType::Any,
index,
None,
),
&pure_proxy
);

// Send some money to pure proxy
let call = RuntimeCall::Balances(pallet_balances::Call::force_transfer {
source: alice,
dest: pure_proxy,
value: 100 * UNIT,
});
assert_ok!(call.dispatch(RawOrigin::Root.into()));

// Initially, there should be 1 proxy after creation
assert_eq!(pallet_proxy::Pallet::<Runtime>::proxies(pure_proxy).0.len(), 1);

// Add a proxy and verify the count increases to 2
let call = RuntimeCall::Proxy(pallet_proxy::Call::add_proxy {
delegate: bob,
proxy_type: ProxyType::Any,
delay,
});

let call = RuntimeCall::Proxy(pallet_proxy::Call::proxy {
real: pure_proxy,
force_proxy_type: None,
call: Box::new(call),
});
assert_ok!(call.dispatch(RuntimeOrigin::signed(alice)));
assert_eq!(pallet_proxy::Pallet::<Runtime>::proxies(pure_proxy).0.len(), 2);
});
}
}

0 comments on commit c427544

Please sign in to comment.