mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 01:11:04 +00:00
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:
committed by
Gavin Wood
parent
a1e0076aa8
commit
74d6e660c6
@@ -18,17 +18,27 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use sp_runtime::{testing::Digest, traits::{Header, OnFinalize}};
|
||||
use sp_runtime::{testing::{H256, Digest}, traits::{Header, OnFinalize}};
|
||||
use crate::mock::*;
|
||||
use frame_system::{EventRecord, Phase};
|
||||
use codec::{Decode, Encode};
|
||||
use fg_primitives::ScheduledChange;
|
||||
use super::*;
|
||||
|
||||
fn initialize_block(number: u64, parent_hash: H256) {
|
||||
System::initialize(
|
||||
&number,
|
||||
&parent_hash,
|
||||
&Default::default(),
|
||||
&Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authorities_change_logged() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
Grandpa::schedule_change(to_authorities(vec![(4, 1), (5, 1), (6, 1)]), 0, None).unwrap();
|
||||
|
||||
System::note_finished_extrinsics();
|
||||
@@ -56,7 +66,7 @@ fn authorities_change_logged() {
|
||||
#[test]
|
||||
fn authorities_change_logged_after_delay() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
Grandpa::schedule_change(to_authorities(vec![(4, 1), (5, 1), (6, 1)]), 1, None).unwrap();
|
||||
Grandpa::on_finalize(1);
|
||||
let header = System::finalize();
|
||||
@@ -71,7 +81,7 @@ fn authorities_change_logged_after_delay() {
|
||||
// no change at this height.
|
||||
assert_eq!(System::events(), vec![]);
|
||||
|
||||
System::initialize(&2, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(2, header.hash());
|
||||
System::note_finished_extrinsics();
|
||||
Grandpa::on_finalize(2);
|
||||
|
||||
@@ -89,7 +99,7 @@ fn authorities_change_logged_after_delay() {
|
||||
#[test]
|
||||
fn cannot_schedule_change_when_one_pending() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
Grandpa::schedule_change(to_authorities(vec![(4, 1), (5, 1), (6, 1)]), 1, None).unwrap();
|
||||
assert!(<PendingChange<Test>>::exists());
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_err());
|
||||
@@ -97,14 +107,14 @@ fn cannot_schedule_change_when_one_pending() {
|
||||
Grandpa::on_finalize(1);
|
||||
let header = System::finalize();
|
||||
|
||||
System::initialize(&2, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(2, header.hash());
|
||||
assert!(<PendingChange<Test>>::exists());
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_err());
|
||||
|
||||
Grandpa::on_finalize(2);
|
||||
let header = System::finalize();
|
||||
|
||||
System::initialize(&3, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(3, header.hash());
|
||||
assert!(!<PendingChange<Test>>::exists());
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_ok());
|
||||
|
||||
@@ -132,7 +142,7 @@ fn new_decodes_from_old() {
|
||||
#[test]
|
||||
fn dispatch_forced_change() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
Grandpa::schedule_change(
|
||||
to_authorities(vec![(4, 1), (5, 1), (6, 1)]),
|
||||
5,
|
||||
@@ -146,7 +156,7 @@ fn dispatch_forced_change() {
|
||||
let mut header = System::finalize();
|
||||
|
||||
for i in 2..7 {
|
||||
System::initialize(&i, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(i, header.hash());
|
||||
assert!(<PendingChange<Test>>::get().unwrap().forced.is_some());
|
||||
assert_eq!(Grandpa::next_forced(), Some(11));
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_err());
|
||||
@@ -159,7 +169,7 @@ fn dispatch_forced_change() {
|
||||
// change has been applied at the end of block 6.
|
||||
// add a normal change.
|
||||
{
|
||||
System::initialize(&7, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(7, header.hash());
|
||||
assert!(!<PendingChange<Test>>::exists());
|
||||
assert_eq!(Grandpa::grandpa_authorities(), to_authorities(vec![(4, 1), (5, 1), (6, 1)]));
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_ok());
|
||||
@@ -169,7 +179,7 @@ fn dispatch_forced_change() {
|
||||
|
||||
// run the normal change.
|
||||
{
|
||||
System::initialize(&8, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(8, header.hash());
|
||||
assert!(<PendingChange<Test>>::exists());
|
||||
assert_eq!(Grandpa::grandpa_authorities(), to_authorities(vec![(4, 1), (5, 1), (6, 1)]));
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None).is_err());
|
||||
@@ -180,7 +190,7 @@ fn dispatch_forced_change() {
|
||||
// normal change applied. but we can't apply a new forced change for some
|
||||
// time.
|
||||
for i in 9..11 {
|
||||
System::initialize(&i, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(i, header.hash());
|
||||
assert!(!<PendingChange<Test>>::exists());
|
||||
assert_eq!(Grandpa::grandpa_authorities(), to_authorities(vec![(5, 1)]));
|
||||
assert_eq!(Grandpa::next_forced(), Some(11));
|
||||
@@ -190,7 +200,7 @@ fn dispatch_forced_change() {
|
||||
}
|
||||
|
||||
{
|
||||
System::initialize(&11, &header.hash(), &Default::default(), &Default::default());
|
||||
initialize_block(11, header.hash());
|
||||
assert!(!<PendingChange<Test>>::exists());
|
||||
assert!(Grandpa::schedule_change(to_authorities(vec![(5, 1), (6, 1), (7, 1)]), 5, Some(0)).is_ok());
|
||||
assert_eq!(Grandpa::next_forced(), Some(21));
|
||||
@@ -205,7 +215,7 @@ fn dispatch_forced_change() {
|
||||
fn schedule_pause_only_when_live() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
// we schedule a pause at block 1 with delay of 1
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
Grandpa::schedule_pause(1).unwrap();
|
||||
|
||||
// we've switched to the pending pause state
|
||||
@@ -220,7 +230,7 @@ fn schedule_pause_only_when_live() {
|
||||
Grandpa::on_finalize(1);
|
||||
let _ = System::finalize();
|
||||
|
||||
System::initialize(&2, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(2, Default::default());
|
||||
|
||||
// signaling a pause now should fail
|
||||
assert!(Grandpa::schedule_pause(1).is_err());
|
||||
@@ -239,7 +249,7 @@ fn schedule_pause_only_when_live() {
|
||||
#[test]
|
||||
fn schedule_resume_only_when_paused() {
|
||||
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
|
||||
System::initialize(&1, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(1, Default::default());
|
||||
|
||||
// the set is currently live, resuming it is an error
|
||||
assert!(Grandpa::schedule_resume(1).is_err());
|
||||
@@ -260,16 +270,16 @@ fn schedule_resume_only_when_paused() {
|
||||
);
|
||||
|
||||
// we schedule the set to go back live in 2 blocks
|
||||
System::initialize(&2, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(2, Default::default());
|
||||
Grandpa::schedule_resume(2).unwrap();
|
||||
Grandpa::on_finalize(2);
|
||||
let _ = System::finalize();
|
||||
|
||||
System::initialize(&3, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(3, Default::default());
|
||||
Grandpa::on_finalize(3);
|
||||
let _ = System::finalize();
|
||||
|
||||
System::initialize(&4, &Default::default(), &Default::default(), &Default::default());
|
||||
initialize_block(4, Default::default());
|
||||
Grandpa::on_finalize(4);
|
||||
let _ = System::finalize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user