Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jun 13, 2020
1 parent 374376b commit 39bc8ef
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions utils/frame/rpc/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ mod tests {
use futures::executor::block_on;
use substrate_test_runtime_client::{runtime::Transfer, AccountKeyring};
use sc_transaction_pool::{BasicPool, FullChainApi};
use sp_runtime::{ApplyExtrinsicResult, transaction_validity::{TransactionValidityError, InvalidTransaction}};

#[test]
fn should_return_next_nonce_for_some_account() {
Expand Down Expand Up @@ -352,4 +353,68 @@ mod tests {
// then
assert_eq!(res.wait(), Err(RpcError::method_not_found()));
}

#[test]
fn dry_run_should_work() {
let _ = env_logger::try_init();

// given
let client = Arc::new(substrate_test_runtime_client::new());
let pool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone())),
None,
).0
);

let accounts = FullSystem::new(client, pool, DenyUnsafe::No);

let tx = Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
amount: 5,
nonce: 0,
}.into_signed_tx();

// when
let res = accounts.dry_run(tx.encode().into(), None);

// then
let bytes = res.wait().unwrap().0;
let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
assert_eq!(apply_res, Ok(Ok(())));
}

#[test]
fn dry_run_should_indicate_error() {
let _ = env_logger::try_init();

// given
let client = Arc::new(substrate_test_runtime_client::new());
let pool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone())),
None,
).0
);

let accounts = FullSystem::new(client, pool, DenyUnsafe::No);

let tx = Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
amount: 5,
nonce: 100,
}.into_signed_tx();

// when
let res = accounts.dry_run(tx.encode().into(), None);

// then
let bytes = res.wait().unwrap().0;
let apply_res: ApplyExtrinsicResult = Decode::decode(&mut bytes.as_slice()).unwrap();
assert_eq!(apply_res, Err(TransactionValidityError::Invalid(InvalidTransaction::Stale)));
}
}

0 comments on commit 39bc8ef

Please sign in to comment.