Skip to content

Commit

Permalink
Revert "remove test-only bool arg from calculate_fee (#3211)" (#3367)
Browse files Browse the repository at this point in the history
This reverts commit aad0381.
  • Loading branch information
apfitzge authored Oct 29, 2024
1 parent e9616d0 commit cec2324
Show file tree
Hide file tree
Showing 21 changed files with 264 additions and 267 deletions.
14 changes: 4 additions & 10 deletions cli/tests/address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ fn test_cli_create_extend_and_freeze_address_lookup_table() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let mut config = CliConfig::recent_for_tests();
let keypair = Keypair::new();
Expand Down Expand Up @@ -141,11 +138,8 @@ fn test_cli_create_and_deactivate_address_lookup_table() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let mut config = CliConfig::recent_for_tests();
let keypair = Keypair::new();
Expand Down
49 changes: 9 additions & 40 deletions cli/tests/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand All @@ -46,16 +43,15 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
let payer = Keypair::new();
config_payer.signers = vec![&payer];

let airdrop_amount = sol_to_lamports(2000.0);
request_and_confirm_airdrop(
&rpc_client,
&config_payer,
&config_payer.signers[0].pubkey(),
airdrop_amount,
sol_to_lamports(2000.0),
)
.unwrap();
check_balance!(
airdrop_amount,
sol_to_lamports(2000.0),
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand Down Expand Up @@ -84,26 +80,23 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
};

// Create nonce account
let spend_amount = sol_to_lamports(1000.0);
config_payer.signers.push(&nonce_keypair);
config_payer.command = CliCommand::CreateNonceAccount {
nonce_account: 1,
seed,
nonce_authority: optional_authority,
memo: None,
amount: SpendAmount::Some(spend_amount),
amount: SpendAmount::Some(sol_to_lamports(1000.0)),
compute_unit_price,
};

process_command(&config_payer).unwrap();
let priority_fee = compute_unit_price.map(|_| 600).unwrap_or(0);
let expected_payer_balance = airdrop_amount - spend_amount - priority_fee;
check_balance!(
expected_payer_balance,
sol_to_lamports(1000.0),
&rpc_client,
&config_payer.signers[0].pubkey(),
);
check_balance!(spend_amount, &rpc_client, &nonce_account);
check_balance!(sol_to_lamports(1000.0), &rpc_client, &nonce_account);

// Get nonce
config_payer.signers.pop();
Expand Down Expand Up @@ -136,14 +129,6 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
};
process_command(&config_payer).unwrap();

let priority_fee = compute_unit_price.map(|_| 450).unwrap_or(0);
let expected_payer_balance = expected_payer_balance - priority_fee;
check_balance!(
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);

// Get nonce
config_payer.signers = vec![&payer];
config_payer.command = CliCommand::GetNonce(nonce_account);
Expand All @@ -164,9 +149,8 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
compute_unit_price,
};
process_command(&config_payer).unwrap();
let expected_payer_balance = expected_payer_balance - priority_fee;
check_balance!(
expected_payer_balance,
sol_to_lamports(1000.0),
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand All @@ -191,13 +175,6 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
};
process_command(&config_payer).unwrap();

let expected_payer_balance = expected_payer_balance - priority_fee;
check_balance!(
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);

// Old authority fails now
config_payer.command = CliCommand::NewNonce {
nonce_account,
Expand All @@ -217,13 +194,6 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
};
process_command(&config_payer).unwrap();

let expected_payer_balance = expected_payer_balance - priority_fee;
check_balance!(
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);

// New authority can withdraw from nonce account
config_payer.command = CliCommand::WithdrawFromNonceAccount {
nonce_account,
Expand All @@ -234,9 +204,8 @@ fn test_nonce(seed: Option<String>, use_nonce_authority: bool, compute_unit_pric
compute_unit_price,
};
process_command(&config_payer).unwrap();
let expected_payer_balance = expected_payer_balance - priority_fee;
check_balance!(
expected_payer_balance,
sol_to_lamports(1000.0),
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand Down
84 changes: 24 additions & 60 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ fn test_cli_program_deploy_non_upgradeable() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -289,11 +286,8 @@ fn test_cli_program_deploy_no_authority() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -684,11 +678,8 @@ fn test_cli_program_deploy_with_authority() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -1088,11 +1079,8 @@ fn test_cli_program_upgrade_auto_extend() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -1244,11 +1232,8 @@ fn test_cli_program_close_program() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -1366,11 +1351,8 @@ fn test_cli_program_extend_program() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -1539,11 +1521,8 @@ fn test_cli_program_write_buffer() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -2029,11 +2008,8 @@ fn test_cli_program_set_buffer_authority() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -2204,11 +2180,8 @@ fn test_cli_program_mismatch_buffer_authority() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -2333,11 +2306,8 @@ fn test_cli_program_deploy_with_offline_signing(use_offline_signer_as_fee_payer:
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -2529,11 +2499,8 @@ fn test_cli_program_show() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down Expand Up @@ -2729,11 +2696,8 @@ fn test_cli_program_dump() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand Down
7 changes: 2 additions & 5 deletions cli/tests/request_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ fn test_cli_request_airdrop() {
let mint_keypair = Keypair::new();
let mint_pubkey = mint_keypair.pubkey();
let faucet_addr = run_local_faucet(mint_keypair, None);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);
let test_validator =
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);

let mut bob_config = CliConfig::recent_for_tests();
bob_config.json_rpc_url = test_validator.rpc_url();
Expand Down
Loading

0 comments on commit cec2324

Please sign in to comment.