mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 14:48:01 +00:00
contracts Add storage_deposit test (#14003)
* contracts Add storage_deposit test * fix comments * PR comments
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
;; This calls another contract as passed as its account id.
|
||||
(module
|
||||
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
|
||||
(import "seal1" "seal_call" (func $seal_call (param i32 i32 i64 i32 i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(func $assert (param i32)
|
||||
(block $ok
|
||||
(br_if $ok
|
||||
(get_local 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "deploy"))
|
||||
|
||||
(func (export "call")
|
||||
;; Store length of input buffer.
|
||||
(i32.store (i32.const 0) (i32.const 512))
|
||||
|
||||
;; Copy input at address 4.
|
||||
(call $seal_input (i32.const 4) (i32.const 0))
|
||||
|
||||
;; Call passed contract.
|
||||
(call $assert (i32.eqz
|
||||
(call $seal_call
|
||||
(i32.const 0) ;; No flags
|
||||
(i32.const 8) ;; Pointer to "callee" address.
|
||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||
(i32.const 512) ;; Pointer to the buffer with value to transfer
|
||||
(i32.const 4) ;; Pointer to input data buffer address
|
||||
(i32.const 4) ;; Length of input data buffer
|
||||
(i32.const 4294967295) ;; u32 max value is the sentinel value: do not copy output
|
||||
(i32.const 0) ;; Length is ignored in this case
|
||||
)
|
||||
))
|
||||
)
|
||||
)
|
||||
@@ -3582,6 +3582,59 @@ fn storage_deposit_works() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_deposit_callee_works() {
|
||||
let (wasm_caller, _code_hash_caller) = compile_module::<Test>("call").unwrap();
|
||||
let (wasm_callee, _code_hash_callee) = compile_module::<Test>("store").unwrap();
|
||||
const ED: u64 = 200;
|
||||
ExtBuilder::default().existential_deposit(ED).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
// Create both contracts: Constructors do nothing.
|
||||
let addr_caller = Contracts::bare_instantiate(
|
||||
ALICE,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
Code::Upload(wasm_caller),
|
||||
vec![],
|
||||
vec![],
|
||||
false,
|
||||
)
|
||||
.result
|
||||
.unwrap()
|
||||
.account_id;
|
||||
let addr_callee = Contracts::bare_instantiate(
|
||||
ALICE,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
Code::Upload(wasm_callee),
|
||||
vec![],
|
||||
vec![],
|
||||
false,
|
||||
)
|
||||
.result
|
||||
.unwrap()
|
||||
.account_id;
|
||||
|
||||
assert_ok!(Contracts::call(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr_caller,
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
(100u32, &addr_callee).encode()
|
||||
));
|
||||
|
||||
let callee = get_contract(&addr_callee);
|
||||
let deposit = ED + DepositPerByte::get() * 100 + DepositPerItem::get() * 1;
|
||||
|
||||
assert_eq!(test_utils::get_balance(callee.deposit_account()), deposit);
|
||||
assert_eq!(callee.total_deposit(), deposit);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_code_extrinsic() {
|
||||
let (wasm, code_hash) = compile_module::<Test>("dummy").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user