-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Contracts: runtime_call and storage_deposit #13990
Conversation
62fc1e3
to
909cbae
Compare
frame/contracts/src/tests.rs
Outdated
data.encode(), | ||
); | ||
|
||
assert_err_ignore_postinfo!(result, TokenError::FundsUnavailable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to test that the transaction gas were actually charge to the user, but I am not too sure how this can be done within our test framework
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just check that Alice's balance became lower than it was before the tx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the test, so we can validate that the fees are the same whether the transaction fails (because the payment failed) or not.
I don't think we can test Alice's balance because as far as I know, this would be done in the pre/post hook of the transaction_payment pallet that does not exist in the Test config
for reference
substrate/frame/transaction-payment/src/lib.rs
Lines 816 to 842 in ec43399
fn pre_dispatch( | |
self, | |
who: &Self::AccountId, | |
call: &Self::Call, | |
info: &DispatchInfoOf<Self::Call>, | |
len: usize, | |
) -> Result<Self::Pre, TransactionValidityError> { | |
let (_fee, imbalance) = self.withdraw_fee(who, call, info, len)?; | |
Ok((self.0, who.clone(), imbalance)) | |
} | |
fn post_dispatch( | |
maybe_pre: Option<Self::Pre>, | |
info: &DispatchInfoOf<Self::Call>, | |
post_info: &PostDispatchInfoOf<Self::Call>, | |
len: usize, | |
_result: &DispatchResult, | |
) -> Result<(), TransactionValidityError> { | |
if let Some((tip, who, imbalance)) = maybe_pre { | |
let actual_fee = Pallet::<T>::compute_actual_fee(len as u32, info, post_info, tip); | |
T::OnChargeTransaction::correct_and_deposit_fee( | |
&who, info, post_info, actual_fee, tip, imbalance, | |
)?; | |
Pallet::<T>::deposit_event(Event::<T>::TransactionFeePaid { who, actual_fee, tip }); | |
} | |
Ok(()) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the events emitted during execution. We do that in other tests. There is a event for transaction fee payment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would need the transaction_payment pallet for this in test, I don't think we have it 🤔 might have overlooked, will check again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah. You are right. We didn't set this up in tests. It is fine. We don't really need to test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nitpicks
frame/contracts/src/tests.rs
Outdated
data.encode(), | ||
); | ||
|
||
assert_err_ignore_postinfo!(result, TokenError::FundsUnavailable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just check that Alice's balance became lower than it was before the tx?
also some PR description would be great to have |
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
bot help |
Here's a link to docs |
bot rebase |
Rebased |
@@ -366,14 +366,14 @@ where | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs above this line could be improved a bit to reflect the fact this is now a fallible fn
bot merge |
* wip * add comments * fix comment * comments * comments * PR comment * field orders * Update frame/contracts/src/tests.rs * Update frame/contracts/fixtures/call_runtime_and_call.wat Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/tests.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Validate fees of failed call * Update frame/contracts/src/tests.rs * Update frame/contracts/src/tests.rs * Update frame/contracts/src/tests.rs * bubble up refund error * rename fixture file --------- Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: parity-processbot <>
* wip * add comments * fix comment * comments * comments * PR comment * field orders * Update frame/contracts/src/tests.rs * Update frame/contracts/fixtures/call_runtime_and_call.wat Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/tests.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Validate fees of failed call * Update frame/contracts/src/tests.rs * Update frame/contracts/src/tests.rs * Update frame/contracts/src/tests.rs * bubble up refund error * rename fixture file --------- Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: parity-processbot <>
This PR makes the
charge
function fallible, so that when the the caller is unable to pay for the storage deposit we rollback the whole transaction.