implement contract events (#2161)

* implement contract events

* update runtime

* renaming

* update test code hash

* improve complexity details

* add deposit event base cost

* add test

* Revert "add deposit event base cost"

This reverts commit 58ec010c0f4f4f0e16935ad41da32aedd17a8c57.

* update test

* Revert "update test"

This reverts commit 6fe61a593ccf0d41f09a0b97472b28ed8751a999.

* Revert "Revert "add deposit event base cost""

This reverts commit 145e8a9bac15313a4c380aa66b94fd4d36fa3f6d.

* Fix format a bit
This commit is contained in:
thiolliere
2019-04-03 08:20:01 +02:00
committed by Gav Wood
parent e6cc49cf63
commit c98db99d80
8 changed files with 117 additions and 10 deletions
+15 -4
View File
@@ -291,10 +291,15 @@ fn account_removal_removes_storage() {
const CODE_RETURN_FROM_START_FN: &str = r#"
(module
(import "env" "ext_return" (func $ext_return (param i32 i32)))
(import "env" "ext_deposit_event" (func $ext_deposit_event (param i32 i32)))
(import "env" "memory" (memory 1 1))
(start $start)
(func $start
(call $ext_deposit_event
(i32.const 8)
(i32.const 4)
)
(call $ext_return
(i32.const 8)
(i32.const 4)
@@ -310,10 +315,10 @@ const CODE_RETURN_FROM_START_FN: &str = r#"
(data (i32.const 8) "\01\02\03\04")
)
"#;
const HASH_RETURN_FROM_START_FN: [u8; 32] = hex!("e6411d12daa2a19e4e9c7d8306c31c7d53a352cb8ed84385c8a1d48fc232e708");
const HASH_RETURN_FROM_START_FN: [u8; 32] = hex!("abb4194bdea47b2904fe90b4fd674bd40d96f423956627df8c39d2b1a791ab9d");
#[test]
fn instantiate_and_call() {
fn instantiate_and_call_and_deposit_event() {
let wasm = wabt::wat2wasm(CODE_RETURN_FROM_START_FN).unwrap();
with_externalities(
@@ -327,13 +332,14 @@ fn instantiate_and_call() {
wasm,
));
assert_ok!(Contract::create(
// Check at the end to get hash on error easily
let creation = Contract::create(
Origin::signed(ALICE),
100,
100_000,
HASH_RETURN_FROM_START_FN.into(),
vec![],
));
);
assert_eq!(System::events(), vec![
EventRecord {
@@ -354,12 +360,17 @@ fn instantiate_and_call() {
phase: Phase::ApplyExtrinsic(0),
event: MetaEvent::contract(RawEvent::Transfer(ALICE, BOB, 100))
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: MetaEvent::contract(RawEvent::Contract(BOB, vec![1, 2, 3, 4]))
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: MetaEvent::contract(RawEvent::Instantiated(ALICE, BOB))
}
]);
assert_ok!(creation);
assert!(AccountInfoOf::<Test>::exists(BOB));
},
);