mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 13:07:56 +00:00
Contracts: seal0::balance should return the free balance (#1254)
This commit is contained in:
@@ -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