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

feat(sponsorship): add more details to sponsorship events #798

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 56 additions & 13 deletions pallets/sponsorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,42 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event emitted when a new pot is created.
PotCreated { pot: T::PotId },
PotCreated {
pot: T::PotId,
sponsor: T::AccountId,
sponsorship_type: T::SponsorshipType,
fee_quota: BalanceOf<T>,
reserve_quota: BalanceOf<T>,
},
/// Event emitted when a pot is removed.
PotRemoved { pot: T::PotId },
/// Event emitted when a pot is updated.
PotUpdated { pot: T::PotId },
PotUpdated {
pot: T::PotId,
fee_quota: BalanceOf<T>,
reserve_quota: BalanceOf<T>,
},
/// Event emitted when a pot is updated.
PotSponsorshipTypeUpdated { pot: T::PotId },
PotSponsorshipTypeUpdated {
pot: T::PotId,
sponsorship_type: T::SponsorshipType,
},
/// Event emitted when user/users are registered indicating the list of them
UsersRegistered { pot: T::PotId, users: Vec<T::AccountId> },
UsersRegistered {
pot: T::PotId,
users: Vec<T::AccountId>,
fee_quota: BalanceOf<T>,
reserve_quota: BalanceOf<T>,
},
/// Event emitted when user/users are removed indicating the list of them
UsersRemoved { pot: T::PotId, users: Vec<T::AccountId> },
/// Event emitted when fee_quota or reserve_quota or both are updated for the given list
UsersLimitsUpdated { pot: T::PotId, users: Vec<T::AccountId> },
UsersLimitsUpdated {
pot: T::PotId,
users: Vec<T::AccountId>,
fee_quota: BalanceOf<T>,
reserve_quota: BalanceOf<T>,
},
/// Event emitted when a sponsor_me call has been successful indicating the reserved amount
Sponsored { paid: BalanceOf<T>, repaid: BalanceOf<T> },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What repaid means?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Douglasacost paid is how much was borrowed from the sponsor at the beginning of this call and repaid means how much debt was payed off from the user's account at the end of this call.

/// Event emitted when the transaction fee is paid showing the payer and the amount
Expand Down Expand Up @@ -222,14 +245,20 @@ pub mod pallet {
<Pot<T>>::insert(
pot,
PotDetailsOf::<T> {
sponsor: who,
sponsorship_type,
sponsor: who.clone(),
sponsorship_type: sponsorship_type.clone(),
fee_quota: LimitedBalance::with_limit(fee_quota),
reserve_quota: LimitedBalance::with_limit(reserve_quota),
},
);

Self::deposit_event(Event::PotCreated { pot });
Self::deposit_event(Event::PotCreated {
pot,
sponsor: who,
sponsorship_type,
fee_quota,
reserve_quota,
});
Ok(())
}

Expand Down Expand Up @@ -287,7 +316,12 @@ pub mod pallet {
},
);
}
Self::deposit_event(Event::UsersRegistered { pot, users });
Self::deposit_event(Event::UsersRegistered {
pot,
users,
fee_quota: common_fee_quota,
reserve_quota: common_reserve_quota,
});
Ok(())
}

Expand Down Expand Up @@ -403,7 +437,11 @@ pub mod pallet {
.map_err(|_| Error::<T>::CannotUpdateReserveLimit)?;

<Pot<T>>::insert(pot, pot_details);
Self::deposit_event(Event::PotUpdated { pot });
Self::deposit_event(Event::PotUpdated {
pot,
fee_quota: new_fee_quota,
reserve_quota: new_reserve_quota,
});
Ok(())
}

Expand Down Expand Up @@ -437,7 +475,12 @@ pub mod pallet {
}

<Pot<T>>::insert(pot, pot_details);
Self::deposit_event(Event::UsersLimitsUpdated { pot, users });
Self::deposit_event(Event::UsersLimitsUpdated {
pot,
users,
fee_quota: new_fee_quota,
reserve_quota: new_reserve_quota,
});
Ok(())
}

Expand All @@ -455,11 +498,11 @@ pub mod pallet {
Pot::<T>::try_mutate(pot, |maybe_pot_details| -> DispatchResult {
let pot_details = maybe_pot_details.as_mut().ok_or(Error::<T>::PotNotExist)?;
ensure!(pot_details.sponsor == who, Error::<T>::NoPermission);
pot_details.sponsorship_type = sponsorship_type;
pot_details.sponsorship_type = sponsorship_type.clone();
Ok(())
})?;

Self::deposit_event(Event::PotSponsorshipTypeUpdated { pot });
Self::deposit_event(Event::PotSponsorshipTypeUpdated { pot, sponsorship_type });
Ok(())
}
}
Expand Down
43 changes: 40 additions & 3 deletions pallets/sponsorship/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ fn creator_of_pot_becomes_sponsor() {
pot_details.reserve_quota.limit()
));
assert_eq!(Pot::<Test>::get(pot), Some(pot_details));
System::assert_last_event(Event::PotCreated { pot }.into());
System::assert_last_event(
Event::PotCreated {
pot,
sponsor: 1,
sponsorship_type: SponsorshipType::Uniques,
fee_quota: 5,
reserve_quota: 7,
}
.into(),
);
});
}

Expand Down Expand Up @@ -239,7 +248,14 @@ fn sponsors_can_always_increase_pot_limits() {
unused_pot_details.fee_quota.limit() + 1,
unused_pot_details.reserve_quota.limit() + 1
));
System::assert_last_event(Event::PotUpdated { pot: unused_pot }.into());
System::assert_last_event(
Event::PotUpdated {
pot: unused_pot,
fee_quota: 6,
reserve_quota: 8,
}
.into(),
);
let updated_pot = Pot::<Test>::get(unused_pot).unwrap();
assert_eq!(updated_pot.fee_quota.limit(), unused_pot_details.fee_quota.limit() + 1);
assert_eq!(
Expand All @@ -264,7 +280,14 @@ fn sponsors_can_always_increase_pot_limits() {
fully_used_pot_details.fee_quota.limit() + 1,
fully_used_pot_details.reserve_quota.limit() + 1
));
System::assert_last_event(Event::PotUpdated { pot: fully_used_pot }.into());
System::assert_last_event(
Event::PotUpdated {
pot: fully_used_pot,
fee_quota: 6,
reserve_quota: 8,
}
.into(),
);
let updated_pot = Pot::<Test>::get(fully_used_pot).unwrap();
assert_eq!(
updated_pot.fee_quota.limit(),
Expand Down Expand Up @@ -353,6 +376,8 @@ fn sponsors_can_decrease_pot_limits_only_when_available_margin_allows() {
System::assert_last_event(
Event::PotUpdated {
pot: partially_used_pot,
fee_quota: 4,
reserve_quota: 3,
}
.into(),
);
Expand Down Expand Up @@ -446,6 +471,8 @@ fn sponsors_can_register_new_users() {
Event::UsersRegistered {
pot,
users: vec![user_1, user_2],
fee_quota: common_fee_quota,
reserve_quota: common_reserve_quota,
}
.into(),
);
Expand Down Expand Up @@ -474,6 +501,8 @@ fn sponsors_can_register_new_users() {
Event::UsersRegistered {
pot,
users: vec![user_3],
fee_quota: user_3_fee_quota,
reserve_quota: user_3_reserve_quota,
}
.into(),
);
Expand Down Expand Up @@ -684,6 +713,8 @@ fn only_sponsors_have_permission_to_update_users_limits() {
Event::UsersLimitsUpdated {
pot,
users: vec![user_1, user_2],
fee_quota: common_fee_quota + 1,
reserve_quota: common_reserve_quota + 1,
}
.into(),
);
Expand Down Expand Up @@ -836,6 +867,8 @@ fn sponsors_can_always_set_user_limits_to_an_amount_equal_or_greater_than_before
Event::UsersLimitsUpdated {
pot,
users: vec![user_1, user_2],
fee_quota: common_fee_quota + 1,
reserve_quota: common_reserve_quota + 1,
}
.into(),
);
Expand Down Expand Up @@ -933,6 +966,8 @@ fn sponsors_can_reduce_user_limits_when_available_margin_allows() {
Event::UsersLimitsUpdated {
pot,
users: vec![user_1],
fee_quota: lowest_fee_limit,
reserve_quota: lowest_reserve_limit,
}
.into(),
);
Expand All @@ -949,6 +984,8 @@ fn sponsors_can_reduce_user_limits_when_available_margin_allows() {
Event::UsersLimitsUpdated {
pot,
users: vec![user_2],
fee_quota: lowest_fee_limit - 1,
reserve_quota: lowest_reserve_limit - 1,
}
.into(),
);
Expand Down
Loading
Loading