Skip to content

Commit

Permalink
Permit paying oneself (#10337)
Browse files Browse the repository at this point in the history
* Allow paying to oneself

* cargo fmt

* Permit pay-to-self in CLI

No test here because we're just removing an [untested] special case.

Fixes #10339

(cherry picked from commit 5d248fe)

# Conflicts:
#	runtime/src/system_instruction_processor.rs
  • Loading branch information
garious authored and mergify-bot committed May 31, 2020
1 parent c344a87 commit 8ac23ac
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 88 deletions.
5 changes: 0 additions & 5 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,11 +1584,6 @@ fn process_transfer(
) -> ProcessResult {
let from = config.signers[from];

check_unique_pubkeys(
(&from.pubkey(), "cli keypair".to_string()),
(to, "to".to_string()),
)?;

let (recent_blockhash, fee_calculator) =
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
let ixs = vec![system_instruction::transfer(&from.pubkey(), to, lamports)];
Expand Down
32 changes: 0 additions & 32 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,38 +1393,6 @@ mod tests {
}
}

#[test]
fn test_load_account_pay_to_self() {
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
let mut error_counters = ErrorCounters::default();

let keypair = Keypair::new();
let pubkey = keypair.pubkey();

let account = Account::new(10, 1, &Pubkey::default());
accounts.push((pubkey, account));

let instructions = vec![CompiledInstruction::new(0, &(), vec![0, 1])];
// Simulate pay-to-self transaction, which loads the same account twice
let tx = Transaction::new_with_compiled_instructions(
&[&keypair],
&[pubkey],
Hash::default(),
vec![native_loader::id()],
instructions,
);
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);

assert_eq!(loaded_accounts.len(), 1);
assert_eq!(
loaded_accounts[0],
(
Err(TransactionError::InvalidAccountForFee),
Some(HashAgeKind::Extant)
)
);
}

#[test]
fn test_load_by_program_slot() {
let accounts = Accounts::new(Vec::new());
Expand Down
6 changes: 1 addition & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4973,13 +4973,9 @@ mod tests {
let _res = bank.process_transaction(&tx);

assert_eq!(bank.get_balance(&key1.pubkey()), 1);

// TODO: Why do we convert errors to Oks?
//res[0].clone().unwrap_err();

bank.get_signature_status(&tx.signatures[0])
.unwrap()
.unwrap_err();
.unwrap();
}

fn new_from_parent(parent: &Arc<Bank>) -> Bank {
Expand Down
Loading

0 comments on commit 8ac23ac

Please sign in to comment.