Skip to content

Commit c7b90ff

Browse files
committed
chore(permission0): allow 0 weight recipients
1 parent b768d21 commit c7b90ff

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pallets/permission0/src/ext/stream_impl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,10 @@ fn validate_stream_permission_recipients<T: Config>(
451451

452452
for (recipient, weight) in recipients {
453453
ensure!(delegator != recipient, Error::<T>::InvalidRecipientWeight);
454-
ensure!(*weight > 0, Error::<T>::InvalidRecipientWeight);
454+
ensure!(
455+
revocation.is_revokable() || *weight > 0,
456+
Error::<T>::InvalidRecipientWeight
457+
);
455458
ensure!(
456459
T::Torus::is_agent_registered(recipient),
457460
Error::<T>::NotRegisteredAgent

pallets/permission0/tests/lifetime.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ fn irrevocable() {
3939
let agent_1 = bob();
4040
let agent_2 = charlie();
4141

42+
assert_err!(
43+
delegate_stream_permission(
44+
agent_0,
45+
vec![(agent_1, 0), (agent_2, u16::MAX / 2)],
46+
pallet_permission0_api::StreamAllocation::FixedAmount(as_tors(10)),
47+
pallet_permission0_api::DistributionControl::Manual,
48+
pallet_permission0_api::PermissionDuration::Indefinite,
49+
pallet_permission0_api::RevocationTerms::Irrevocable,
50+
pallet_permission0_api::EnforcementAuthority::None,
51+
),
52+
Error::<Test>::InvalidRecipientWeight
53+
);
54+
4255
let permission_id = assert_ok!(delegate_stream_permission(
4356
agent_0,
4457
vec![(agent_1, u16::MAX / 2), (agent_2, u16::MAX / 2)],
@@ -81,7 +94,7 @@ fn revocable_by_delegator() {
8194

8295
let permission_id = assert_ok!(delegate_stream_permission(
8396
agent_0,
84-
vec![(agent_1, u16::MAX / 2), (agent_2, u16::MAX / 2)],
97+
vec![(agent_1, 0), (agent_2, u16::MAX / 2)],
8598
pallet_permission0_api::StreamAllocation::FixedAmount(as_tors(10)),
8699
pallet_permission0_api::DistributionControl::Manual,
87100
pallet_permission0_api::PermissionDuration::Indefinite,
@@ -128,6 +141,19 @@ fn revocable_after_block() {
128141
let agent_1 = bob();
129142
let agent_2 = charlie();
130143

144+
assert_err!(
145+
delegate_stream_permission(
146+
agent_0,
147+
vec![(agent_1, 0), (agent_2, u16::MAX / 2)],
148+
pallet_permission0_api::StreamAllocation::FixedAmount(as_tors(10)),
149+
pallet_permission0_api::DistributionControl::Manual,
150+
pallet_permission0_api::PermissionDuration::Indefinite,
151+
pallet_permission0_api::RevocationTerms::RevocableAfter(2),
152+
pallet_permission0_api::EnforcementAuthority::None,
153+
),
154+
Error::<Test>::InvalidRecipientWeight
155+
);
156+
131157
let permission_id = assert_ok!(delegate_stream_permission(
132158
agent_0,
133159
vec![(agent_1, u16::MAX / 2), (agent_2, u16::MAX / 2)],

0 commit comments

Comments
 (0)