@@ -647,255 +647,3 @@ pub fn new_full(config: Configuration, cli: Cli) -> Result<TaskManager, ServiceE
647
647
648
648
Ok ( task_manager)
649
649
}
650
-
651
- #[ cfg( test) ]
652
- mod tests {
653
- use std:: sync:: Arc ;
654
-
655
- use codec:: Encode ;
656
- use kitchensink_runtime:: {
657
- constants:: { currency:: CENTS , time:: SLOT_DURATION } ,
658
- Address , BalancesCall , RuntimeCall , UncheckedExtrinsic ,
659
- } ;
660
- use node_primitives:: { Block , DigestItem , Signature } ;
661
- use sc_client_api:: BlockBackend ;
662
- use sc_consensus:: { BlockImport , BlockImportParams , ForkChoiceStrategy } ;
663
- use sc_consensus_babe:: { BabeIntermediate , CompatibleDigestItem , INTERMEDIATE_KEY } ;
664
- use sc_consensus_epochs:: descendent_query;
665
- use sc_keystore:: LocalKeystore ;
666
- use sc_service_test:: TestNetNode ;
667
- use sc_transaction_pool_api:: { ChainEvent , MaintainedTransactionPool } ;
668
- use sp_consensus:: { BlockOrigin , Environment , Proposer } ;
669
- use sp_core:: crypto:: Pair ;
670
- use sp_inherents:: InherentDataProvider ;
671
- use sp_keyring:: AccountKeyring ;
672
- use sp_keystore:: KeystorePtr ;
673
- use sp_runtime:: {
674
- generic:: { Digest , Era , SignedPayload } ,
675
- key_types:: BABE ,
676
- traits:: { Block as BlockT , Header as HeaderT , IdentifyAccount , Verify } ,
677
- RuntimeAppPublic ,
678
- } ;
679
-
680
- use crate :: service:: { new_full_base, NewFullBase } ;
681
-
682
- type AccountPublic = <Signature as Verify >:: Signer ;
683
-
684
- #[ test]
685
- // It is "ignored", but the node-cli ignored tests are running on the CI.
686
- // This can be run locally with `cargo test --release -p node-cli test_sync -- --ignored`.
687
- #[ ignore]
688
- fn test_sync ( ) {
689
- sp_tracing:: try_init_simple ( ) ;
690
-
691
- let keystore_path = tempfile:: tempdir ( ) . expect ( "Creates keystore path" ) ;
692
- let keystore: KeystorePtr =
693
- LocalKeystore :: open ( keystore_path. path ( ) , None ) . expect ( "Creates keystore" ) . into ( ) ;
694
- let alice: sp_consensus_babe:: AuthorityId = keystore
695
- . sr25519_generate_new ( BABE , Some ( "//Alice" ) )
696
- . expect ( "Creates authority pair" )
697
- . into ( ) ;
698
-
699
- let chain_spec = crate :: chain_spec:: tests:: integration_test_config_with_single_authority ( ) ;
700
-
701
- // For the block factory
702
- let mut slot = 1u64 ;
703
-
704
- // For the extrinsics factory
705
- let bob = Arc :: new ( AccountKeyring :: Bob . pair ( ) ) ;
706
- let charlie = Arc :: new ( AccountKeyring :: Charlie . pair ( ) ) ;
707
- let mut index = 0 ;
708
-
709
- sc_service_test:: sync (
710
- chain_spec,
711
- |config| {
712
- let mut setup_handles = None ;
713
- let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
714
- new_full_base (
715
- config,
716
- false ,
717
- |block_import : & sc_consensus_babe:: BabeBlockImport < Block , _ , _ > ,
718
- babe_link : & sc_consensus_babe:: BabeLink < Block > | {
719
- setup_handles = Some ( ( block_import. clone ( ) , babe_link. clone ( ) ) ) ;
720
- } ,
721
- None ,
722
- ) ?;
723
-
724
- let node = sc_service_test:: TestNetComponents :: new (
725
- task_manager,
726
- client,
727
- network,
728
- sync,
729
- transaction_pool,
730
- ) ;
731
- Ok ( ( node, setup_handles. unwrap ( ) ) )
732
- } ,
733
- |service, & mut ( ref mut block_import, ref babe_link) | {
734
- let parent_hash = service. client ( ) . chain_info ( ) . best_hash ;
735
- let parent_header = service. client ( ) . header ( parent_hash) . unwrap ( ) . unwrap ( ) ;
736
- let parent_number = * parent_header. number ( ) ;
737
-
738
- futures:: executor:: block_on ( service. transaction_pool ( ) . maintain (
739
- ChainEvent :: NewBestBlock { hash : parent_header. hash ( ) , tree_route : None } ,
740
- ) ) ;
741
-
742
- let mut proposer_factory = sc_basic_authorship:: ProposerFactory :: new (
743
- service. spawn_handle ( ) ,
744
- service. client ( ) ,
745
- service. transaction_pool ( ) ,
746
- None ,
747
- None ,
748
- ) ;
749
-
750
- let mut digest = Digest :: default ( ) ;
751
-
752
- // even though there's only one authority some slots might be empty,
753
- // so we must keep trying the next slots until we can claim one.
754
- let ( babe_pre_digest, epoch_descriptor) = loop {
755
- let epoch_descriptor = babe_link
756
- . epoch_changes ( )
757
- . shared_data ( )
758
- . epoch_descriptor_for_child_of (
759
- descendent_query ( & * service. client ( ) ) ,
760
- & parent_hash,
761
- parent_number,
762
- slot. into ( ) ,
763
- )
764
- . unwrap ( )
765
- . unwrap ( ) ;
766
-
767
- let epoch = babe_link
768
- . epoch_changes ( )
769
- . shared_data ( )
770
- . epoch_data ( & epoch_descriptor, |slot| {
771
- sc_consensus_babe:: Epoch :: genesis ( babe_link. config ( ) , slot)
772
- } )
773
- . unwrap ( ) ;
774
-
775
- if let Some ( babe_pre_digest) =
776
- sc_consensus_babe:: authorship:: claim_slot ( slot. into ( ) , & epoch, & keystore)
777
- . map ( |( digest, _) | digest)
778
- {
779
- break ( babe_pre_digest, epoch_descriptor) ;
780
- }
781
-
782
- slot += 1 ;
783
- } ;
784
-
785
- let inherent_data = futures:: executor:: block_on (
786
- (
787
- sp_timestamp:: InherentDataProvider :: new (
788
- std:: time:: Duration :: from_millis ( SLOT_DURATION * slot) . into ( ) ,
789
- ) ,
790
- sp_consensus_babe:: inherents:: InherentDataProvider :: new ( slot. into ( ) ) ,
791
- )
792
- . create_inherent_data ( ) ,
793
- )
794
- . expect ( "Creates inherent data" ) ;
795
-
796
- digest. push ( <DigestItem as CompatibleDigestItem >:: babe_pre_digest ( babe_pre_digest) ) ;
797
-
798
- let new_block = futures:: executor:: block_on ( async move {
799
- let proposer = proposer_factory. init ( & parent_header) . await ;
800
- proposer
801
- . unwrap ( )
802
- . propose ( inherent_data, digest, std:: time:: Duration :: from_secs ( 1 ) , None )
803
- . await
804
- } )
805
- . expect ( "Error making test block" )
806
- . block ;
807
-
808
- let ( new_header, new_body) = new_block. deconstruct ( ) ;
809
- let pre_hash = new_header. hash ( ) ;
810
- // sign the pre-sealed hash of the block and then
811
- // add it to a digest item.
812
- let to_sign = pre_hash. encode ( ) ;
813
- let signature = keystore
814
- . sr25519_sign ( sp_consensus_babe:: AuthorityId :: ID , alice. as_ref ( ) , & to_sign)
815
- . unwrap ( )
816
- . unwrap ( ) ;
817
- let item = <DigestItem as CompatibleDigestItem >:: babe_seal ( signature. into ( ) ) ;
818
- slot += 1 ;
819
-
820
- let mut params = BlockImportParams :: new ( BlockOrigin :: File , new_header) ;
821
- params. post_digests . push ( item) ;
822
- params. body = Some ( new_body) ;
823
- params. insert_intermediate (
824
- INTERMEDIATE_KEY ,
825
- BabeIntermediate :: < Block > { epoch_descriptor } ,
826
- ) ;
827
- params. fork_choice = Some ( ForkChoiceStrategy :: LongestChain ) ;
828
-
829
- futures:: executor:: block_on ( block_import. import_block ( params) )
830
- . expect ( "error importing test block" ) ;
831
- } ,
832
- |service, _| {
833
- let amount = 5 * CENTS ;
834
- let to: Address = AccountPublic :: from ( bob. public ( ) ) . into_account ( ) . into ( ) ;
835
- let from: Address = AccountPublic :: from ( charlie. public ( ) ) . into_account ( ) . into ( ) ;
836
- let genesis_hash = service. client ( ) . block_hash ( 0 ) . unwrap ( ) . unwrap ( ) ;
837
- let best_hash = service. client ( ) . chain_info ( ) . best_hash ;
838
- let ( spec_version, transaction_version) = {
839
- let version = service. client ( ) . runtime_version_at ( best_hash) . unwrap ( ) ;
840
- ( version. spec_version , version. transaction_version )
841
- } ;
842
- let signer = charlie. clone ( ) ;
843
-
844
- let function = RuntimeCall :: Balances ( BalancesCall :: transfer_allow_death {
845
- dest : to,
846
- value : amount,
847
- } ) ;
848
-
849
- let check_non_zero_sender = frame_system:: CheckNonZeroSender :: new ( ) ;
850
- let check_spec_version = frame_system:: CheckSpecVersion :: new ( ) ;
851
- let check_tx_version = frame_system:: CheckTxVersion :: new ( ) ;
852
- let check_genesis = frame_system:: CheckGenesis :: new ( ) ;
853
- let check_era = frame_system:: CheckEra :: from ( Era :: Immortal ) ;
854
- let check_nonce = frame_system:: CheckNonce :: from ( index) ;
855
- let check_weight = frame_system:: CheckWeight :: new ( ) ;
856
- let tx_payment = pallet_asset_tx_payment:: ChargeAssetTxPayment :: from ( 0 , None ) ;
857
- let extra = (
858
- check_non_zero_sender,
859
- check_spec_version,
860
- check_tx_version,
861
- check_genesis,
862
- check_era,
863
- check_nonce,
864
- check_weight,
865
- tx_payment,
866
- ) ;
867
- let raw_payload = SignedPayload :: from_raw (
868
- function,
869
- extra,
870
- ( ( ) , spec_version, transaction_version, genesis_hash, genesis_hash, ( ) , ( ) , ( ) ) ,
871
- ) ;
872
- let signature = raw_payload. using_encoded ( |payload| signer. sign ( payload) ) ;
873
- let ( function, extra, _) = raw_payload. deconstruct ( ) ;
874
- index += 1 ;
875
- UncheckedExtrinsic :: new_signed ( function, from, signature. into ( ) , extra) . into ( )
876
- } ,
877
- ) ;
878
- }
879
-
880
- #[ test]
881
- #[ ignore]
882
- fn test_consensus ( ) {
883
- sp_tracing:: try_init_simple ( ) ;
884
-
885
- sc_service_test:: consensus (
886
- crate :: chain_spec:: tests:: integration_test_config_with_two_authorities ( ) ,
887
- |config| {
888
- let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
889
- new_full_base ( config, false , |_, _| ( ) , None ) ?;
890
- Ok ( sc_service_test:: TestNetComponents :: new (
891
- task_manager,
892
- client,
893
- network,
894
- sync,
895
- transaction_pool,
896
- ) )
897
- } ,
898
- vec ! [ "//Alice" . into( ) , "//Bob" . into( ) ] ,
899
- )
900
- }
901
- }
0 commit comments