Add documentation to SubmitSignedTransaction and actually make it work (#4200)

* Add documentation to signed transactions and actually make them work.

* Fix naming and bounds.

* Forgotten import.

* Remove warning.

* Make accounts optional, fix logic.

* Split the method to avoid confusing type error message.

* Move executor tests to integration.

* Add submit transactions tests.

* Make `submit_transaction` tests compile

* Remove a file that was accidently committed

* Add can_sign helper function.

* Fix compilation.

* Add a key to keystore.

* Fix the tests.

* Remove env_logger.

* Fix sending multiple transactions.

* Remove commented code.

* Bring back criterion.

* Remove stray debug log.

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Make sure to initialize block correctly.

* Initialize block for offchain workers.

* Add test for transaction validity.

* Fix tests.

* Review suggestions.

* Remove redundant comment.

* Make sure to use correct block number of authoring.

* Change the runtime API.

* Support both versions.

* Bump spec version, fix RPC test.

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Gavin Wood <github@gavwood.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Tomasz Drwięga
2020-01-10 01:46:55 +01:00
committed by Gavin Wood
parent a1e0076aa8
commit 74d6e660c6
29 changed files with 2096 additions and 1413 deletions
+44 -5
View File
@@ -531,6 +531,27 @@ pub fn ensure_none<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), BadOrig
}
}
/// A type of block initialization to perform.
pub enum InitKind {
/// Leave inspectable storage entries in state.
///
/// i.e. `Events` are not being reset.
/// Should only be used for off-chain calls,
/// regular block execution should clear those.
Inspection,
/// Reset also inspectable storage entries.
///
/// This should be used for regular block execution.
Full,
}
impl Default for InitKind {
fn default() -> Self {
InitKind::Full
}
}
impl<T: Trait> Module<T> {
/// Deposits an event into this block's event record.
pub fn deposit_event(event: impl Into<T::Event>) {
@@ -633,6 +654,7 @@ impl<T: Trait> Module<T> {
parent_hash: &T::Hash,
txs_root: &T::Hash,
digest: &DigestOf<T>,
kind: InitKind,
) {
// populate environment
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32);
@@ -641,9 +663,12 @@ impl<T: Trait> Module<T> {
<ParentHash<T>>::put(parent_hash);
<BlockHash<T>>::insert(*number - One::one(), parent_hash);
<ExtrinsicsRoot<T>>::put(txs_root);
<Events<T>>::kill();
EventCount::kill();
<EventTopics<T>>::remove_all();
if let InitKind::Full = kind {
<Events<T>>::kill();
EventCount::kill();
<EventTopics<T>>::remove_all();
}
}
/// Remove temporary "environment" entries in storage.
@@ -1220,7 +1245,13 @@ mod tests {
#[test]
fn deposit_event_should_work() {
new_test_ext().execute_with(|| {
System::initialize(&1, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
System::initialize(
&1,
&[0u8; 32].into(),
&[0u8; 32].into(),
&Default::default(),
InitKind::Full,
);
System::note_finished_extrinsics();
System::deposit_event(1u16);
System::finalize();
@@ -1235,7 +1266,13 @@ mod tests {
]
);
System::initialize(&2, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
System::initialize(
&2,
&[0u8; 32].into(),
&[0u8; 32].into(),
&Default::default(),
InitKind::Full,
);
System::deposit_event(42u16);
System::note_applied_extrinsic(&Ok(()), 0, Default::default());
System::note_applied_extrinsic(&Err(DispatchError::BadOrigin), 0, Default::default());
@@ -1264,6 +1301,7 @@ mod tests {
&[0u8; 32].into(),
&[0u8; 32].into(),
&Default::default(),
InitKind::Full,
);
System::note_finished_extrinsics();
@@ -1329,6 +1367,7 @@ mod tests {
&[n as u8 - 1; 32].into(),
&[0u8; 32].into(),
&Default::default(),
InitKind::Full,
);
System::finalize();