Skip to content

Commit

Permalink
remove test-only bool arg from calculate_fee (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored Oct 25, 2024
1 parent df5b94e commit aad0381
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 264 deletions.
14 changes: 10 additions & 4 deletions cli/tests/address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);

let mut config = CliConfig::recent_for_tests();
let keypair = Keypair::new();
Expand Down Expand Up @@ -138,8 +141,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);

let mut config = CliConfig::recent_for_tests();
let keypair = Keypair::new();
Expand Down
49 changes: 40 additions & 9 deletions cli/tests/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_fees(
mint_pubkey,
Some(faucet_addr),
SocketAddrSpace::Unspecified,
);

let rpc_client =
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
Expand All @@ -43,15 +46,16 @@ 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(),
sol_to_lamports(2000.0),
airdrop_amount,
)
.unwrap();
check_balance!(
sol_to_lamports(2000.0),
airdrop_amount,
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand Down Expand Up @@ -80,23 +84,26 @@ 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(sol_to_lamports(1000.0)),
amount: SpendAmount::Some(spend_amount),
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!(
sol_to_lamports(1000.0),
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);
check_balance!(sol_to_lamports(1000.0), &rpc_client, &nonce_account);
check_balance!(spend_amount, &rpc_client, &nonce_account);

// Get nonce
config_payer.signers.pop();
Expand Down Expand Up @@ -129,6 +136,14 @@ 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 @@ -149,8 +164,9 @@ 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!(
sol_to_lamports(1000.0),
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand All @@ -175,6 +191,13 @@ 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 @@ -194,6 +217,13 @@ 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 @@ -204,8 +234,9 @@ 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!(
sol_to_lamports(1000.0),
expected_payer_balance,
&rpc_client,
&config_payer.signers[0].pubkey(),
);
Expand Down
84 changes: 60 additions & 24 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -286,8 +289,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -678,8 +684,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -1079,8 +1088,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -1232,8 +1244,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -1351,8 +1366,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -1521,8 +1539,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -2008,8 +2029,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -2180,8 +2204,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -2306,8 +2333,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -2499,8 +2529,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 @@ -2696,8 +2729,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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: 5 additions & 2 deletions cli/tests/request_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ 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_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
let test_validator = TestValidator::with_no_base_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 aad0381

Please sign in to comment.