Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Proxy Configuration with Tests for Pure Proxy Creation and Modification #549

Merged
merged 9 commits into from
Apr 9, 2024
98 changes: 97 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,85 @@ 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 = Box::new(RuntimeCall::Proxy(pallet_proxy::Call::add_proxy {
delegate: bob,
proxy_type: ProxyType::Any,
delay,
}));
assert_ok!(pallet_proxy::Pallet::<Runtime>::proxy(
RuntimeOrigin::signed(alice),
pure_proxy,
None,
call
));
assert_eq!(pallet_proxy::Pallet::<Runtime>::proxies(&pure_proxy).0.len(), 2);
});
}
}
Loading