Skip to content

Commit

Permalink
shrink scope of this PR to bandaid
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-solana committed Jan 15, 2020
1 parent ad7d9c9 commit f4b4842
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 54 deletions.
52 changes: 0 additions & 52 deletions runtime/src/system_instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ fn assign_account_to_program(
keyed_account: &mut KeyedAccount,
program_id: &Pubkey,
) -> Result<(), InstructionError> {
// no work to do, just return
if keyed_account.account.owner == *program_id {
return Ok(());
}

if keyed_account.signer_key().is_none() {
debug!("Assign: account must sign");
return Err(InstructionError::MissingRequiredSignature);
Expand Down Expand Up @@ -718,14 +713,6 @@ mod tests {
),
Err(InstructionError::MissingRequiredSignature)
);
// no change, no signature needed
assert_eq!(
assign_account_to_program(
&mut KeyedAccount::new(&from, false, &mut from_account),
&system_program::id(),
),
Ok(())
);

assert_eq!(
process_instruction(
Expand Down Expand Up @@ -842,45 +829,6 @@ mod tests {
)
}

#[test]
fn test_create_account_no_transfer() {
solana_logger::setup();
let (genesis_config, alice_keypair) = create_genesis_config(100);
let alice_pubkey = alice_keypair.pubkey();
let bob_keypair = Keypair::new();
let bob_pubkey = bob_keypair.pubkey();

// Fund to account to bypass AccountNotFound error
let bank = Bank::new(&genesis_config);
let bank_client = BankClient::new(bank);
bank_client
.transfer(50, &alice_keypair, &bob_pubkey)
.unwrap();
let program_id = Pubkey::new_rand();

// test system_instruction: that alice's signature is not asked for
let instruction =
system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, 1, &program_id);

assert!(!instruction.accounts[0].is_signer);

// test system_instruction_processor: that alice's signature is needed
assert!(bank_client
.send_instruction(&bob_keypair, instruction)
.is_ok());

assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 50);
assert_eq!(
bank_client.get_account(&bob_pubkey).unwrap().unwrap(),
Account {
data: vec![0; 1],
owner: program_id,
lamports: 50,
..Account::default()
}
);
}

#[test]
fn test_system_unsigned_transaction() {
let (genesis_config, alice_keypair) = create_genesis_config(100);
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/system_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn create_account(
program_id: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_pubkey, lamports != 0), // no signature required if no transfer
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, true),
];
Instruction::new(
Expand All @@ -173,7 +173,7 @@ pub fn create_account_with_seed(
program_id: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_pubkey, lamports != 0),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, false),
]
.with_signer(base);
Expand Down

0 comments on commit f4b4842

Please sign in to comment.