diff --git a/pallets/governance/tests/voting.rs b/pallets/governance/tests/voting.rs index 9bfbd93..211da42 100644 --- a/pallets/governance/tests/voting.rs +++ b/pallets/governance/tests/voting.rs @@ -20,6 +20,7 @@ fn register(account: AccountId, _unused: u16, module: AccountId, stake: u128) { let _ = pallet_governance::whitelist::add_to_whitelist::(module); assert_ok!(pallet_torus0::agent::register::( + module, module, b"agent".to_vec(), b"url".to_vec(), diff --git a/pallets/torus0/src/agent.rs b/pallets/torus0/src/agent.rs index 6120e38..a11f621 100644 --- a/pallets/torus0/src/agent.rs +++ b/pallets/torus0/src/agent.rs @@ -28,6 +28,7 @@ pub struct Agent { } pub fn register( + payer: AccountIdOf, agent_key: AccountIdOf, name: Vec, url: Vec, @@ -46,7 +47,6 @@ pub fn register( crate::Error::::AgentAlreadyRegistered ); - // TODO: Take pruning scores into consideration ensure!( crate::Agents::::iter().count() < crate::MaxAllowedAgents::::get() as usize, crate::Error::::MaxAllowedAgents @@ -93,7 +93,7 @@ pub fn register( let burn = crate::Burn::::get(); let _ = ::Currency::withdraw( - &agent_key, + &payer, burn, WithdrawReasons::except(WithdrawReasons::TIP), ExistenceRequirement::AllowDeath, diff --git a/pallets/torus0/src/lib.rs b/pallets/torus0/src/lib.rs index cf4f3dd..7aa2808 100644 --- a/pallets/torus0/src/lib.rs +++ b/pallets/torus0/src/lib.rs @@ -267,8 +267,8 @@ pub mod pallet { url: Vec, metadata: Vec, ) -> DispatchResult { - ensure_signed(origin)?; - agent::register::(agent_key, name, url, metadata) + let payer = ensure_signed(origin)?; + agent::register::(payer, agent_key, name, url, metadata) } #[pallet::call_index(4)] diff --git a/pallets/torus0/tests/agent.rs b/pallets/torus0/tests/agent.rs index b321254..f009671 100644 --- a/pallets/torus0/tests/agent.rs +++ b/pallets/torus0/tests/agent.rs @@ -15,6 +15,7 @@ fn register_correctly() { )); assert_ok!(pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -39,6 +40,7 @@ fn register_without_being_whitelisted() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -67,6 +69,7 @@ fn register_without_enough_balance() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -92,6 +95,7 @@ fn register_fail_name_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, "".as_bytes().to_vec(), url.clone(), @@ -102,6 +106,7 @@ fn register_fail_name_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, " ".repeat(pallet_torus0::MaxNameLength::::get() as usize + 1) .as_bytes() @@ -114,6 +119,7 @@ fn register_fail_name_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, vec![249u8, 9u8, 42u8], url.clone(), @@ -137,6 +143,7 @@ fn register_fail_url_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), "".as_bytes().to_vec(), @@ -147,6 +154,7 @@ fn register_fail_url_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), " ".repeat(pallet_torus0::MaxNameLength::::get() as usize + 1) @@ -159,6 +167,7 @@ fn register_fail_url_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), vec![249u8, 9u8, 42u8], @@ -182,6 +191,7 @@ fn register_fail_metadata_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -196,6 +206,7 @@ fn register_fail_metadata_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -206,6 +217,7 @@ fn register_fail_metadata_validation() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -232,6 +244,7 @@ fn register_more_than_max_allowed_agents() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -260,6 +273,7 @@ fn register_more_than_allowed_registrations_per_block() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -290,6 +304,7 @@ fn register_more_than_registrations_per_interval() { assert_err!( pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -315,6 +330,7 @@ fn unregister_correctly() { )); assert_ok!(pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -340,6 +356,7 @@ fn unregister_twice() { )); assert_ok!(pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -369,7 +386,7 @@ fn update_correctly() { )); assert_ok!(pallet_torus0::agent::register::( - agent, name, url, metadata, + agent, agent, name, url, metadata, )); let new_name = "new-agent".as_bytes().to_vec(); @@ -412,6 +429,7 @@ fn update_with_zero_staking_fee() { )); assert_ok!(pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), @@ -461,6 +479,7 @@ fn update_with_zero_weight_control_fee() { )); assert_ok!(pallet_torus0::agent::register::( + agent, agent, name.clone(), url.clone(), diff --git a/pallets/torus0/tests/stake.rs b/pallets/torus0/tests/stake.rs index 5201e00..ebfbb9c 100644 --- a/pallets/torus0/tests/stake.rs +++ b/pallets/torus0/tests/stake.rs @@ -14,6 +14,7 @@ fn add_stake_correctly() { assert_ok!(pallet_governance::whitelist::add_to_whitelist::(to)); assert_ok!(pallet_torus0::agent::register::( + to, to, "to".as_bytes().to_vec(), "to://idk".as_bytes().to_vec(), @@ -99,6 +100,7 @@ fn remove_stake_correctly() { assert_ok!(pallet_governance::whitelist::add_to_whitelist::(to)); assert_ok!(pallet_torus0::agent::register::( + to, to, "to".as_bytes().to_vec(), "to://idk".as_bytes().to_vec(), @@ -137,6 +139,7 @@ fn remove_stake_with_less_than_required_amount() { assert_ok!(pallet_governance::whitelist::add_to_whitelist::(to)); assert_ok!(pallet_torus0::agent::register::( + to, to, "to".as_bytes().to_vec(), "to://idk".as_bytes().to_vec(), @@ -180,6 +183,7 @@ fn remove_stake_with_unregistered_agent() { assert_ok!(pallet_governance::whitelist::add_to_whitelist::(to)); assert_ok!(pallet_torus0::agent::register::( + to, to, "to".as_bytes().to_vec(), "to://idk".as_bytes().to_vec(),