CLI: Disallow blockhash/fee-calc lookups when offline (#7981)

* CLI: Add BlockhashSpec to tighten control over --blockhash

* Use BlockhashSpec

* Add a matches-free constructor

* More descriptive naming
This commit is contained in:
Trent Nelson
2020-01-30 09:21:32 -07:00
committed by GitHub
parent 400412d76c
commit 966d077431
5 changed files with 284 additions and 87 deletions

View File

@@ -1,9 +1,13 @@
use serde_json::Value;
use solana_cli::cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig};
use solana_cli::{
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
offline::BlockhashQuery,
};
use solana_client::rpc_client::RpcClient;
use solana_faucet::faucet::run_local_faucet;
use solana_sdk::{
account_utils::StateMut,
fee_calculator::FeeCalculator,
hash::Hash,
nonce_state::NonceState,
pubkey::Pubkey,
@@ -132,7 +136,7 @@ fn test_seed_stake_delegation_and_deactivation() {
force: true,
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -144,7 +148,7 @@ fn test_seed_stake_delegation_and_deactivation() {
stake_authority: None,
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -220,7 +224,7 @@ fn test_stake_delegation_and_deactivation() {
force: true,
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -232,7 +236,7 @@ fn test_stake_delegation_and_deactivation() {
stake_authority: None,
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -313,7 +317,7 @@ fn test_offline_stake_delegation_and_deactivation() {
force: true,
sign_only: true,
signers: None,
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
nonce_account: None,
nonce_authority: None,
};
@@ -328,7 +332,7 @@ fn test_offline_stake_delegation_and_deactivation() {
force: true,
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
nonce_account: None,
nonce_authority: None,
};
@@ -341,7 +345,7 @@ fn test_offline_stake_delegation_and_deactivation() {
stake_authority: None,
sign_only: true,
signers: None,
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
nonce_account: None,
nonce_authority: None,
};
@@ -354,7 +358,7 @@ fn test_offline_stake_delegation_and_deactivation() {
stake_authority: None,
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
nonce_account: None,
nonce_authority: None,
};
@@ -441,7 +445,7 @@ fn test_nonced_stake_delegation_and_deactivation() {
force: true,
sign_only: false,
signers: None,
blockhash: Some(nonce_hash),
blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()),
nonce_account: Some(nonce_account.pubkey()),
nonce_authority: None,
};
@@ -462,7 +466,7 @@ fn test_nonced_stake_delegation_and_deactivation() {
stake_authority: None,
sign_only: false,
signers: None,
blockhash: Some(nonce_hash),
blockhash_query: BlockhashQuery::FeeCalculator(nonce_hash),
nonce_account: Some(nonce_account.pubkey()),
nonce_authority: Some(config_keypair.into()),
};
@@ -516,7 +520,7 @@ fn test_stake_authorize() {
authority: None,
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -541,7 +545,7 @@ fn test_stake_authorize() {
authority: Some(read_keypair_file(&online_authority_file).unwrap().into()),
sign_only: false,
signers: None,
blockhash: None,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: None,
};
@@ -567,7 +571,7 @@ fn test_stake_authorize() {
authority: Some(read_keypair_file(&offline_authority_file).unwrap().into()),
sign_only: true,
signers: None,
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
nonce_account: None,
nonce_authority: None,
};
@@ -580,7 +584,7 @@ fn test_stake_authorize() {
authority: Some(offline_authority_pubkey.into()),
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
nonce_account: None,
nonce_authority: None,
};
@@ -628,7 +632,7 @@ fn test_stake_authorize() {
authority: Some(read_keypair_file(&nonced_authority_file).unwrap().into()),
sign_only: true,
signers: None,
blockhash: Some(nonce_hash),
blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()),
nonce_account: Some(nonce_account.pubkey()),
nonce_authority: None,
};
@@ -642,7 +646,7 @@ fn test_stake_authorize() {
authority: Some(nonced_authority_pubkey.into()),
sign_only: false,
signers: Some(signers),
blockhash: Some(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
nonce_account: Some(nonce_account.pubkey()),
nonce_authority: None,
};