seal: Remove ext_dispatch_call and ext_get_runtime_storage (#6464)

Those are way too hard to audit and make only sense with specific
chains. They shouldn't be in the core API.
This commit is contained in:
Alexander Theißen
2020-06-24 13:53:40 +02:00
committed by GitHub
parent a3a42f599a
commit b14b472edf
11 changed files with 28 additions and 649 deletions
-260
View File
@@ -173,7 +173,6 @@ impl Trait for Test {
type Time = Timestamp;
type Randomness = Randomness;
type Currency = Balances;
type Call = Call;
type DetermineContractAddress = DummyContractAddressFor;
type Event = MetaEvent;
type TrieIdGenerator = DummyTrieIdGenerator;
@@ -446,233 +445,6 @@ fn instantiate_and_call_and_deposit_event() {
});
}
#[test]
fn dispatch_call() {
// This test can fail due to the encoding changes. In case it becomes too annoying
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
let encoded = Encode::encode(&Call::Balances(pallet_balances::Call::transfer(CHARLIE, 50)));
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
let (wasm, code_hash) = compile_module::<Test>("dispatch_call").unwrap();
ExtBuilder::default()
.existential_deposit(50)
.build()
.execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
// Let's keep this assert even though it's redundant. If you ever need to update the
// wasm source this test will fail and will show you the actual hash.
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(1)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(pallet_balances::RawEvent::Endowed(1, 1_000_000)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::CodeStored(code_hash.into())),
topics: vec![],
},
]);
assert_ok!(Contracts::instantiate(
Origin::signed(ALICE),
100,
GAS_LIMIT,
code_hash.into(),
vec![],
));
assert_ok!(Contracts::call(
Origin::signed(ALICE),
BOB, // newly created account
0,
GAS_LIMIT,
vec![],
));
pretty_assertions::assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(1)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(pallet_balances::RawEvent::Endowed(1, 1_000_000)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::CodeStored(code_hash.into())),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(BOB)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Endowed(BOB, 100)
),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Transfer(ALICE, BOB, 100)
),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::Instantiated(ALICE, BOB)),
topics: vec![],
},
// Dispatching the call.
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(CHARLIE)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Endowed(CHARLIE, 50)
),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Transfer(BOB, CHARLIE, 50)
),
topics: vec![],
},
// Event emitted as a result of dispatch.
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::Dispatched(BOB, true)),
topics: vec![],
}
]);
});
}
#[test]
fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
// This test can fail due to the encoding changes. In case it becomes too annoying
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
let encoded = Encode::encode(&Call::Balances(pallet_balances::Call::transfer(CHARLIE, 50)));
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
let (wasm, code_hash) = compile_module::<Test>("dispatch_call_then_trap").unwrap();
ExtBuilder::default()
.existential_deposit(50)
.build()
.execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
// Let's keep this assert even though it's redundant. If you ever need to update the
// wasm source this test will fail and will show you the actual hash.
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(1)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(pallet_balances::RawEvent::Endowed(1, 1_000_000)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::CodeStored(code_hash.into())),
topics: vec![],
},
]);
assert_ok!(Contracts::instantiate(
Origin::signed(ALICE),
100,
GAS_LIMIT,
code_hash.into(),
vec![],
));
// Call the newly instantiated contract. The contract is expected to dispatch a call
// and then trap.
assert_err_ignore_postinfo!(
Contracts::call(
Origin::signed(ALICE),
BOB, // newly created account
0,
GAS_LIMIT,
vec![],
),
"contract trapped during execution"
);
pretty_assertions::assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(1)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(pallet_balances::RawEvent::Endowed(1, 1_000_000)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::CodeStored(code_hash.into())),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(BOB)),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Endowed(BOB, 100)
),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::balances(
pallet_balances::RawEvent::Transfer(ALICE, BOB, 100)
),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::contracts(RawEvent::Instantiated(ALICE, BOB)),
topics: vec![],
},
// ABSENCE of events which would be caused by dispatched Balances::transfer call
]);
});
}
#[test]
fn run_out_of_gas() {
let (wasm, code_hash) = compile_module::<Test>("run_out_of_gas").unwrap();
@@ -1773,38 +1545,6 @@ fn cannot_self_destruct_in_constructor() {
});
}
#[test]
fn get_runtime_storage() {
let (wasm, code_hash) = compile_module::<Test>("get_runtime_storage").unwrap();
ExtBuilder::default()
.existential_deposit(50)
.build()
.execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
frame_support::storage::unhashed::put_raw(
&[1, 2, 3, 4],
0x14144020u32.to_le_bytes().to_vec().as_ref()
);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
assert_ok!(Contracts::instantiate(
Origin::signed(ALICE),
100,
GAS_LIMIT,
code_hash.into(),
vec![],
));
assert_ok!(Contracts::call(
Origin::signed(ALICE),
BOB,
0,
GAS_LIMIT,
vec![],
));
});
}
#[test]
fn crypto_hashes() {
let (wasm, code_hash) = compile_module::<Test>("crypto_hashes").unwrap();