@@ -298,125 +298,125 @@ where
298298
299299#[ cfg( test) ]
300300mod tests {
301- use super :: * ;
302-
303- use futures:: executor:: block_on;
304- use sc_transaction_pool:: BasicPool ;
305- use sp_runtime:: {
306- transaction_validity:: { InvalidTransaction , TransactionValidityError } ,
307- ApplyExtrinsicResult ,
308- } ;
309- use substrate_test_runtime_client:: { runtime:: Transfer , AccountKeyring } ;
310-
311- #[ test]
312- fn should_return_next_nonce_for_some_account ( ) {
313- sp_tracing:: try_init_simple ( ) ;
314-
315- // given
316- let client = Arc :: new ( substrate_test_runtime_client:: new ( ) ) ;
317- let spawner = sp_core:: testing:: TaskExecutor :: new ( ) ;
318- let pool =
319- BasicPool :: new_full ( Default :: default ( ) , true . into ( ) , None , spawner, client. clone ( ) ) ;
320-
321- let source = sp_runtime:: transaction_validity:: TransactionSource :: External ;
322- let new_transaction = |nonce : u64 | {
323- let t = Transfer {
324- from : AccountKeyring :: Alice . into ( ) ,
325- to : AccountKeyring :: Bob . into ( ) ,
326- amount : 5 ,
327- nonce,
328- } ;
329- t. into_signed_tx ( )
330- } ;
331- // Populate the pool
332- let ext0 = new_transaction ( 0 ) ;
333- block_on ( pool. submit_one ( & BlockId :: number ( 0 ) , source, ext0) ) . unwrap ( ) ;
334- let ext1 = new_transaction ( 1 ) ;
335- block_on ( pool. submit_one ( & BlockId :: number ( 0 ) , source, ext1) ) . unwrap ( ) ;
336-
337- let accounts = SystemRpcBackendFull :: new ( client, pool, DenyUnsafe :: Yes ) ;
338-
339- // when
340- let nonce = accounts. nonce ( AccountKeyring :: Alice . into ( ) ) ;
341-
342- // then
343- assert_eq ! ( block_on( nonce) . unwrap( ) , 2 ) ;
344- }
345-
346- #[ test]
347- fn dry_run_should_deny_unsafe ( ) {
348- sp_tracing:: try_init_simple ( ) ;
349-
350- // given
351- let client = Arc :: new ( substrate_test_runtime_client:: new ( ) ) ;
352- let spawner = sp_core:: testing:: TaskExecutor :: new ( ) ;
353- let pool =
354- BasicPool :: new_full ( Default :: default ( ) , true . into ( ) , None , spawner, client. clone ( ) ) ;
355-
356- let accounts = SystemRpcBackendFull :: new ( client, pool, DenyUnsafe :: Yes ) ;
357-
358- // when
359- let res = accounts. dry_run ( vec ! [ ] . into ( ) , None ) ;
360-
361- // then
362- assert_eq ! ( block_on( res) , Err ( RpcError :: method_not_found( ) ) ) ;
363- }
364-
365- #[ test]
366- fn dry_run_should_work ( ) {
367- sp_tracing:: try_init_simple ( ) ;
368-
369- // given
370- let client = Arc :: new ( substrate_test_runtime_client:: new ( ) ) ;
371- let spawner = sp_core:: testing:: TaskExecutor :: new ( ) ;
372- let pool =
373- BasicPool :: new_full ( Default :: default ( ) , true . into ( ) , None , spawner, client. clone ( ) ) ;
374-
375- let accounts = SystemRpcBackendFull :: new ( client, pool, DenyUnsafe :: No ) ;
376-
377- let tx = Transfer {
378- from : AccountKeyring :: Alice . into ( ) ,
379- to : AccountKeyring :: Bob . into ( ) ,
380- amount : 5 ,
381- nonce : 0 ,
382- }
383- . into_signed_tx ( ) ;
384-
385- // when
386- let res = accounts. dry_run ( tx. encode ( ) . into ( ) , None ) ;
387-
388- // then
389- let bytes = block_on ( res) . unwrap ( ) . 0 ;
390- let apply_res: ApplyExtrinsicResult = Decode :: decode ( & mut bytes. as_slice ( ) ) . unwrap ( ) ;
391- assert_eq ! ( apply_res, Ok ( Ok ( ( ) ) ) ) ;
392- }
393-
394- #[ test]
395- fn dry_run_should_indicate_error ( ) {
396- sp_tracing:: try_init_simple ( ) ;
397-
398- // given
399- let client = Arc :: new ( substrate_test_runtime_client:: new ( ) ) ;
400- let spawner = sp_core:: testing:: TaskExecutor :: new ( ) ;
401- let pool =
402- BasicPool :: new_full ( Default :: default ( ) , true . into ( ) , None , spawner, client. clone ( ) ) ;
403-
404- let accounts = SystemRpcBackendFull :: new ( client, pool, DenyUnsafe :: No ) ;
405-
406- let tx = Transfer {
407- from : AccountKeyring :: Alice . into ( ) ,
408- to : AccountKeyring :: Bob . into ( ) ,
409- amount : 5 ,
410- nonce : 100 ,
411- }
412- . into_signed_tx ( ) ;
413-
414- // when
415- let res = accounts. dry_run ( tx. encode ( ) . into ( ) , None ) ;
416-
417- // then
418- let bytes = block_on ( res) . unwrap ( ) . 0 ;
419- let apply_res: ApplyExtrinsicResult = Decode :: decode ( & mut bytes. as_slice ( ) ) . unwrap ( ) ;
420- assert_eq ! ( apply_res, Err ( TransactionValidityError :: Invalid ( InvalidTransaction :: Stale ) ) ) ;
421- }
301+ // use super::*;
302+
303+ // use futures::executor::block_on;
304+ // use sc_transaction_pool::BasicPool;
305+ // use sp_runtime::{
306+ // transaction_validity::{InvalidTransaction, TransactionValidityError},
307+ // ApplyExtrinsicResult,
308+ // };
309+ // use substrate_test_runtime_client::{runtime::Transfer, AccountKeyring};
310+
311+ // #[test]
312+ // fn should_return_next_nonce_for_some_account() {
313+ // sp_tracing::try_init_simple();
314+
315+ // // given
316+ // let client = Arc::new(substrate_test_runtime_client::new());
317+ // let spawner = sp_core::testing::TaskExecutor::new();
318+ // let pool =
319+ // BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone());
320+
321+ // let source = sp_runtime::transaction_validity::TransactionSource::External;
322+ // let new_transaction = |nonce: u64| {
323+ // let t = Transfer {
324+ // from: AccountKeyring::Alice.into(),
325+ // to: AccountKeyring::Bob.into(),
326+ // amount: 5,
327+ // nonce,
328+ // };
329+ // t.into_signed_tx()
330+ // };
331+ // // Populate the pool
332+ // let ext0 = new_transaction(0);
333+ // block_on(pool.submit_one(&BlockId::number(0), source, ext0)).unwrap();
334+ // let ext1 = new_transaction(1);
335+ // block_on(pool.submit_one(&BlockId::number(0), source, ext1)).unwrap();
336+
337+ // let accounts = SystemRpcBackendFull::new(client, pool, DenyUnsafe::Yes);
338+
339+ // // when
340+ // let nonce = accounts.nonce(AccountKeyring::Alice.into());
341+
342+ // // then
343+ // assert_eq!(block_on(nonce).unwrap(), 2);
344+ // }
345+
346+ // #[test]
347+ // fn dry_run_should_deny_unsafe() {
348+ // sp_tracing::try_init_simple();
349+
350+ // // given
351+ // let client = Arc::new(substrate_test_runtime_client::new());
352+ // let spawner = sp_core::testing::TaskExecutor::new();
353+ // let pool =
354+ // BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone());
355+
356+ // let accounts = SystemRpcBackendFull::new(client, pool, DenyUnsafe::Yes);
357+
358+ // // when
359+ // let res = accounts.dry_run(vec![].into(), None);
360+
361+ // // then
362+ // assert_eq!(block_on(res), Err(RpcError::method_not_found()));
363+ // }
364+
365+ // #[test]
366+ // fn dry_run_should_work() {
367+ // sp_tracing::try_init_simple();
368+
369+ // // given
370+ // let client = Arc::new(substrate_test_runtime_client::new());
371+ // let spawner = sp_core::testing::TaskExecutor::new();
372+ // let pool =
373+ // BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone());
374+
375+ // let accounts = SystemRpcBackendFull::new(client, pool, DenyUnsafe::No);
376+
377+ // let tx = Transfer {
378+ // from: AccountKeyring::Alice.into(),
379+ // to: AccountKeyring::Bob.into(),
380+ // amount: 5,
381+ // nonce: 0,
382+ // }
383+ // .into_signed_tx();
384+
385+ // // when
386+ // let res = accounts.dry_run(tx.encode().into(), None);
387+
388+ // // then
389+ // let bytes = block_on(res).unwrap().0;
390+ // let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
391+ // assert_eq!(apply_res, Ok(Ok(())));
392+ // }
393+
394+ // #[test]
395+ // fn dry_run_should_indicate_error() {
396+ // sp_tracing::try_init_simple();
397+
398+ // // given
399+ // let client = Arc::new(substrate_test_runtime_client::new());
400+ // let spawner = sp_core::testing::TaskExecutor::new();
401+ // let pool =
402+ // BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone());
403+
404+ // let accounts = SystemRpcBackendFull::new(client, pool, DenyUnsafe::No);
405+
406+ // let tx = Transfer {
407+ // from: AccountKeyring::Alice.into(),
408+ // to: AccountKeyring::Bob.into(),
409+ // amount: 5,
410+ // nonce: 100,
411+ // }
412+ // .into_signed_tx();
413+
414+ // // when
415+ // let res = accounts.dry_run(tx.encode().into(), None);
416+
417+ // // then
418+ // let bytes = block_on(res).unwrap().0;
419+ // let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
420+ // assert_eq!(apply_res, Err(TransactionValidityError::Invalid(InvalidTransaction::Stale)));
421+ // }
422422}
0 commit comments