diff --git a/pallet/src/balance.rs b/pallet/src/balance.rs index 5d33114..e5c3e38 100644 --- a/pallet/src/balance.rs +++ b/pallet/src/balance.rs @@ -69,6 +69,21 @@ impl BalanceAdapter { } } + /// Creates a new [`BalanceAdapter`] with unlimited cheque-limits for every signer for the + /// usage within a dry-run. Therefor, the extracted arguments and the signer count of a given + /// script transaction has to be provided. + pub fn for_dry_run(args: &[&[u8]], signer_count: usize) -> Result, Error> { + let mut handler = BalanceAdapter::new(); + + let accounts = Pallet::::extract_account_ids_from_args(args, signer_count)?; + + for acc in &accounts { + handler.write_cheque_internal(acc, &BalanceOf::::from(u128::MAX)); + } + + Ok(handler) + } + /// Writes a cheque for the account. pub fn write_cheque( &mut self, @@ -76,7 +91,12 @@ impl BalanceAdapter { balance: &BalanceOf, ) -> DispatchResult { self.ensure_can_withdraw(account, balance)?; + self.write_cheque_internal(account, balance); + Ok(()) + } + // Internal method for writing the cheque. + fn write_cheque_internal(&mut self, account: &AccountIdOf, balance: &BalanceOf) { let account: EncodedAccount = account.encode(); let mut cheques = self.cheques.borrow_mut(); @@ -91,8 +111,6 @@ impl BalanceAdapter { } else { self.initial_state.insert(account.clone(), *balance); } - - Ok(()) } /// Executes the true transactions on the blockchain/substrate side after execution of diff --git a/pallet/src/lib.rs b/pallet/src/lib.rs index 0caaa9f..1bcb051 100644 --- a/pallet/src/lib.rs +++ b/pallet/src/lib.rs @@ -515,7 +515,7 @@ pub mod pallet { .map_err(|e| format!("error in get_resource: {e:?}").into()) } - fn extract_account_ids_from_args( + pub(crate) fn extract_account_ids_from_args( script_args: &[&[u8]], signer_count: usize, ) -> Result, Error> {