seal_delegate_call api function (support for library contracts) (#10617)

* seal_call_code implementation

- tests
- benchmark

* Addressing @xgreenx's comments

* Fix test-linux-stable-int

* Rename seal_call_code to seal_delegate_call

* Pass value unchanged into lib contract

* Address @athei's comments

- whitespace .wat issues
- wrong/missing .wat comments
- redundant .wat calls/declarations

- change order of functions (seal_delegate_call right after seal_call)
  in decls, tests, benchmark
- fix comments, move doc comments to enum variants
- remove unnecessary empty lines

- rename runtime cost DelegateCall to DelegateCallBase
- do not set CallFlags::ALLOW_REENTRY for delegate_call

* Do not pass CallFlags::ALLOWS_REENTRY for delegate_call

* Update comment for seal_delegate_call and CallFlags

* Addressing @athei's comments (minor)

* Allow reentry for a new frame after delegate_call (revert)

* Same seal_caller and seal_value_transferred for lib contract

- test
- refactor frame args due to review
- logic for seal_caller (please review)

* Put caller on frame for delegate_call, minor fixes

* Update comment for delegate_call

* Addressing @athei's comments

* Update weights generated by benchmark

* Improve comments

* Address @HCastano's comments

* Update weights, thanks @joao-paulo-parity

* Improve InvalidCallFlags error comment
This commit is contained in:
Yarik Bratashchuk
2022-02-08 13:43:32 +02:00
committed by GitHub
parent 1d62516fad
commit d14e1c641e
10 changed files with 574 additions and 49 deletions
+38
View File
@@ -692,6 +692,44 @@ fn deploy_and_call_other_contract() {
});
}
#[test]
#[cfg(feature = "unstable-interface")]
fn delegate_call() {
let (caller_wasm, caller_code_hash) = compile_module::<Test>("delegate_call").unwrap();
let (callee_wasm, callee_code_hash) = compile_module::<Test>("delegate_call_lib").unwrap();
let caller_addr = Contracts::contract_address(&ALICE, &caller_code_hash, &[]);
ExtBuilder::default().existential_deposit(500).build().execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
// Instantiate the 'caller'
assert_ok!(Contracts::instantiate_with_code(
Origin::signed(ALICE),
300_000,
GAS_LIMIT,
None,
caller_wasm,
vec![],
vec![],
));
// Only upload 'callee' code
assert_ok!(Contracts::upload_code(
Origin::signed(ALICE),
callee_wasm,
Some(codec::Compact(100_000)),
));
assert_ok!(Contracts::call(
Origin::signed(ALICE),
caller_addr.clone(),
1337,
GAS_LIMIT,
None,
callee_code_hash.as_ref().to_vec(),
));
});
}
#[test]
fn cannot_self_destruct_through_draning() {
let (wasm, code_hash) = compile_module::<Test>("drain").unwrap();