Skip to content

Commit

Permalink
contracts Add storage_deposit test (paritytech#14003)
Browse files Browse the repository at this point in the history
* contracts Add storage_deposit test

* fix comments

* PR comments
  • Loading branch information
pgherveou authored and nathanwhit committed Jul 19, 2023
1 parent 4fc7f6e commit de48892
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
39 changes: 39 additions & 0 deletions frame/contracts/fixtures/call.wat
Original file line number Diff line number Diff line change
@@ -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
)
))
)
)
53 changes: 53 additions & 0 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit de48892

Please sign in to comment.