mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Contracts: seal0::balance should return the free balance (#1254)
This commit is contained in:
@@ -30,7 +30,7 @@ use frame_support::{
|
||||
storage::{with_transaction, TransactionOutcome},
|
||||
traits::{
|
||||
fungible::{Inspect, Mutate},
|
||||
tokens::Preservation,
|
||||
tokens::{Fortitude, Preservation},
|
||||
Contains, OriginTrait, Randomness, Time,
|
||||
},
|
||||
weights::Weight,
|
||||
@@ -1368,7 +1368,11 @@ where
|
||||
}
|
||||
|
||||
fn balance(&self) -> BalanceOf<T> {
|
||||
T::Currency::balance(&self.top_frame().account_id)
|
||||
T::Currency::reducible_balance(
|
||||
&self.top_frame().account_id,
|
||||
Preservation::Preserve,
|
||||
Fortitude::Polite,
|
||||
)
|
||||
}
|
||||
|
||||
fn value_transferred(&self) -> BalanceOf<T> {
|
||||
|
||||
@@ -5891,3 +5891,53 @@ fn root_cannot_instantiate() {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn balance_api_returns_free_balance() {
|
||||
let (wasm, _code_hash) = compile_module::<Test>("balance").unwrap();
|
||||
ExtBuilder::default().existential_deposit(200).build().execute_with(|| {
|
||||
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000);
|
||||
|
||||
// Instantiate the BOB contract without any extra balance.
|
||||
let addr = Contracts::bare_instantiate(
|
||||
ALICE,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
Code::Upload(wasm.to_vec()),
|
||||
vec![],
|
||||
vec![],
|
||||
DebugInfo::Skip,
|
||||
CollectEvents::Skip,
|
||||
)
|
||||
.result
|
||||
.unwrap()
|
||||
.account_id;
|
||||
|
||||
let value = 0;
|
||||
// Call BOB which makes it call the balance runtime API.
|
||||
// The contract code asserts that the returned balance is 0.
|
||||
assert_ok!(Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
value,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![]
|
||||
));
|
||||
|
||||
let value = 1;
|
||||
// Calling with value will trap the contract.
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
value,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
vec![]
|
||||
),
|
||||
<Error<Test>>::ContractTrapped
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user