mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Allow to distinguish out of gas from other traps (#4883)
* contracts: Allow to distinguish out of gas from other traps
When a contract encounters a runtime error a wasm trap is
triggered and the execution is halted. Currently, no matter
what was the cause for the trap it is always reported as:
DispatchError::Other("contract trapped during execution").
However, the trap that is triggered if a contract exhausts
its gas budget is particulary interesting. Therefore we add
a seperate error message for this cause:
DispatchError::Other("ran out of gas during contract execution").
A test is added hat executes a contract that never terminates.
Therefore it always exhausts is gas budget.
* fixup! contracts: Allow to distinguish out of gas from other traps
Remove overlong lines.
* fixup! contracts: Allow to distinguish out of gas from other traps
Rename Contract to Contracts
This commit is contained in:
committed by
GitHub
parent
5b7512e2e4
commit
b999911bcf
@@ -722,6 +722,51 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
|
||||
});
|
||||
}
|
||||
|
||||
const CODE_RUN_OUT_OF_GAS: &str = r#"
|
||||
(module
|
||||
(func (export "call")
|
||||
(loop $inf (br $inf)) ;; just run out of gas
|
||||
(unreachable)
|
||||
)
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn run_out_of_gas() {
|
||||
let (wasm, code_hash) = compile_module::<Test>(CODE_RUN_OUT_OF_GAS).unwrap();
|
||||
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(50)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
|
||||
|
||||
assert_ok!(Contracts::instantiate(
|
||||
Origin::signed(ALICE),
|
||||
100,
|
||||
100_000,
|
||||
code_hash.into(),
|
||||
vec![],
|
||||
));
|
||||
|
||||
// Call the contract with a fixed gas limit. It must run out of gas because it just
|
||||
// loops forever.
|
||||
assert_err!(
|
||||
Contracts::call(
|
||||
Origin::signed(ALICE),
|
||||
BOB, // newly created account
|
||||
0,
|
||||
1000,
|
||||
vec![],
|
||||
),
|
||||
"ran out of gas during contract execution"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const CODE_SET_RENT: &str = r#"
|
||||
(module
|
||||
(import "env" "ext_dispatch_call" (func $ext_dispatch_call (param i32 i32)))
|
||||
|
||||
Reference in New Issue
Block a user