require `to` account signature (#6658)
* require to signature * fixing invocation to create_account * fix create_account references * address review comment * whacking bugs in tests * fixing stake program tests
This commit is contained in:
parent
f7b6e777bf
commit
5bd05fba09
|
@ -178,19 +178,28 @@ where
|
||||||
|
|
||||||
info!("Generating {:?} account keys", total_keys);
|
info!("Generating {:?} account keys", total_keys);
|
||||||
let mut account_keypairs = generate_keypairs(total_keys);
|
let mut account_keypairs = generate_keypairs(total_keys);
|
||||||
let src_pubkeys: Vec<_> = account_keypairs
|
let src_keypairs: Vec<_> = account_keypairs
|
||||||
.drain(0..accounts_in_groups)
|
.drain(0..accounts_in_groups)
|
||||||
|
.map(|keypair| keypair)
|
||||||
|
.collect();
|
||||||
|
let src_pubkeys: Vec<Pubkey> = src_keypairs
|
||||||
|
.iter()
|
||||||
.map(|keypair| keypair.pubkey())
|
.map(|keypair| keypair.pubkey())
|
||||||
.collect();
|
.collect();
|
||||||
let profit_pubkeys: Vec<_> = account_keypairs
|
|
||||||
|
let profit_keypairs: Vec<_> = account_keypairs
|
||||||
.drain(0..accounts_in_groups)
|
.drain(0..accounts_in_groups)
|
||||||
|
.map(|keypair| keypair)
|
||||||
|
.collect();
|
||||||
|
let profit_pubkeys: Vec<Pubkey> = profit_keypairs
|
||||||
|
.iter()
|
||||||
.map(|keypair| keypair.pubkey())
|
.map(|keypair| keypair.pubkey())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
info!("Create {:?} source token accounts", src_pubkeys.len());
|
info!("Create {:?} source token accounts", src_pubkeys.len());
|
||||||
create_token_accounts(client, &trader_signers, &src_pubkeys);
|
create_token_accounts(client, &trader_signers, &src_keypairs);
|
||||||
info!("Create {:?} profit token accounts", profit_pubkeys.len());
|
info!("Create {:?} profit token accounts", profit_pubkeys.len());
|
||||||
create_token_accounts(client, &swapper_signers, &profit_pubkeys);
|
create_token_accounts(client, &swapper_signers, &profit_keypairs);
|
||||||
|
|
||||||
// Collect the max transaction rate and total tx count seen (single node only)
|
// Collect the max transaction rate and total tx count seen (single node only)
|
||||||
let sample_stats = Arc::new(RwLock::new(Vec::new()));
|
let sample_stats = Arc::new(RwLock::new(Vec::new()));
|
||||||
|
@ -564,7 +573,7 @@ fn trader<T>(
|
||||||
trade_account: trade.pubkey(),
|
trade_account: trade.pubkey(),
|
||||||
order_info,
|
order_info,
|
||||||
});
|
});
|
||||||
trades.push((signer, trade.pubkey(), side, src));
|
trades.push((signer, trade, side, src));
|
||||||
}
|
}
|
||||||
account_group = (account_group + 1) % account_groups as usize;
|
account_group = (account_group + 1) % account_groups as usize;
|
||||||
|
|
||||||
|
@ -575,16 +584,28 @@ fn trader<T>(
|
||||||
trades.chunks(chunk_size).for_each(|chunk| {
|
trades.chunks(chunk_size).for_each(|chunk| {
|
||||||
let trades_txs: Vec<_> = chunk
|
let trades_txs: Vec<_> = chunk
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(signer, trade, side, src)| {
|
.map(|(owner, trade, side, src)| {
|
||||||
let s: &Keypair = &signer;
|
let owner_pubkey = &owner.pubkey();
|
||||||
let owner = &signer.pubkey();
|
let trade_pubkey = &trade.pubkey();
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
Transaction::new_signed_instructions(
|
Transaction::new_signed_instructions(
|
||||||
&[s],
|
&[owner.as_ref(), trade],
|
||||||
vec![
|
vec![
|
||||||
system_instruction::create_account(owner, trade, 1, space, &id()),
|
system_instruction::create_account(
|
||||||
|
owner_pubkey,
|
||||||
|
trade_pubkey,
|
||||||
|
1,
|
||||||
|
space,
|
||||||
|
&id(),
|
||||||
|
),
|
||||||
exchange_instruction::trade_request(
|
exchange_instruction::trade_request(
|
||||||
owner, trade, *side, pair, tokens, price, src,
|
owner_pubkey,
|
||||||
|
trade_pubkey,
|
||||||
|
*side,
|
||||||
|
pair,
|
||||||
|
tokens,
|
||||||
|
price,
|
||||||
|
src,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -803,21 +824,27 @@ pub fn fund_keys(client: &dyn Client, source: &Keypair, dests: &[Arc<Keypair>],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], accounts: &[Pubkey]) {
|
pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], accounts: &[Keypair]) {
|
||||||
let mut notfunded: Vec<(&Arc<Keypair>, &Pubkey)> = signers.iter().zip(accounts).collect();
|
let mut notfunded: Vec<(&Arc<Keypair>, &Keypair)> = signers.iter().zip(accounts).collect();
|
||||||
|
|
||||||
while !notfunded.is_empty() {
|
while !notfunded.is_empty() {
|
||||||
notfunded.chunks(FUND_CHUNK_LEN).for_each(|chunk| {
|
notfunded.chunks(FUND_CHUNK_LEN).for_each(|chunk| {
|
||||||
let mut to_create_txs: Vec<_> = chunk
|
let mut to_create_txs: Vec<_> = chunk
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(signer, new)| {
|
.map(|(from_keypair, new_keypair)| {
|
||||||
let owner_pubkey = &signer.pubkey();
|
let owner_pubkey = &from_keypair.pubkey();
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
let create_ix =
|
let create_ix = system_instruction::create_account(
|
||||||
system_instruction::create_account(owner_pubkey, new, 1, space, &id());
|
owner_pubkey,
|
||||||
let request_ix = exchange_instruction::account_request(owner_pubkey, new);
|
&new_keypair.pubkey(),
|
||||||
|
1,
|
||||||
|
space,
|
||||||
|
&id(),
|
||||||
|
);
|
||||||
|
let request_ix =
|
||||||
|
exchange_instruction::account_request(owner_pubkey, &new_keypair.pubkey());
|
||||||
(
|
(
|
||||||
signer,
|
(from_keypair, new_keypair),
|
||||||
Transaction::new_unsigned_instructions(vec![create_ix, request_ix]),
|
Transaction::new_unsigned_instructions(vec![create_ix, request_ix]),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -838,9 +865,10 @@ pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], acco
|
||||||
let (blockhash, _fee_calculator) = client
|
let (blockhash, _fee_calculator) = client
|
||||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
.expect("Failed to get blockhash");
|
.expect("Failed to get blockhash");
|
||||||
to_create_txs.par_iter_mut().for_each(|(k, tx)| {
|
to_create_txs
|
||||||
let kp: &Keypair = k;
|
.par_iter_mut()
|
||||||
tx.sign(&[kp], blockhash);
|
.for_each(|((from_keypair, to_keypair), tx)| {
|
||||||
|
tx.sign(&[from_keypair.as_ref(), to_keypair], blockhash);
|
||||||
});
|
});
|
||||||
to_create_txs.iter().for_each(|(_, tx)| {
|
to_create_txs.iter().for_each(|(_, tx)| {
|
||||||
client.async_send_transaction(tx.clone()).expect("transfer");
|
client.async_send_transaction(tx.clone()).expect("transfer");
|
||||||
|
@ -878,10 +906,10 @@ pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], acco
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut new_notfunded: Vec<(&Arc<Keypair>, &Pubkey)> = vec![];
|
let mut new_notfunded: Vec<(&Arc<Keypair>, &Keypair)> = vec![];
|
||||||
for f in ¬funded {
|
for f in ¬funded {
|
||||||
if client
|
if client
|
||||||
.get_balance_with_commitment(&f.1, CommitmentConfig::recent())
|
.get_balance_with_commitment(&f.1.pubkey(), CommitmentConfig::recent())
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
== 0
|
== 0
|
||||||
{
|
{
|
||||||
|
|
|
@ -795,13 +795,10 @@ fn fund_move_keys<T: Client>(
|
||||||
|
|
||||||
info!("creating the libra funding account..");
|
info!("creating the libra funding account..");
|
||||||
let libra_funding_key = Keypair::new();
|
let libra_funding_key = Keypair::new();
|
||||||
let tx = librapay_transaction::create_account(
|
let tx = librapay_transaction::create_account(funding_key, &libra_funding_key, 1, blockhash);
|
||||||
funding_key,
|
client
|
||||||
&libra_funding_key.pubkey(),
|
.send_message(&[funding_key, &libra_funding_key], tx.message)
|
||||||
1,
|
.unwrap();
|
||||||
blockhash,
|
|
||||||
);
|
|
||||||
client.send_message(&[funding_key], tx.message).unwrap();
|
|
||||||
|
|
||||||
info!("minting to funding keypair");
|
info!("minting to funding keypair");
|
||||||
let tx = librapay_transaction::mint_tokens(
|
let tx = librapay_transaction::mint_tokens(
|
||||||
|
@ -829,8 +826,8 @@ fn fund_move_keys<T: Client>(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pubkeys: Vec<_> = keys.iter().map(|k| k.pubkey()).collect();
|
let keypairs: Vec<_> = keys.iter().map(|k| k).collect();
|
||||||
let tx = librapay_transaction::create_accounts(funding_key, &pubkeys, 1, blockhash);
|
let tx = librapay_transaction::create_accounts(funding_key, &keypairs, 1, blockhash);
|
||||||
|
|
||||||
let ser_size = bincode::serialized_size(&tx).unwrap();
|
let ser_size = bincode::serialized_size(&tx).unwrap();
|
||||||
|
|
||||||
|
@ -877,10 +874,9 @@ fn fund_move_keys<T: Client>(
|
||||||
|
|
||||||
let libra_funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
|
let libra_funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
|
||||||
for (i, key) in libra_funding_keys.iter().enumerate() {
|
for (i, key) in libra_funding_keys.iter().enumerate() {
|
||||||
let tx =
|
let tx = librapay_transaction::create_account(&funding_keys[i], &key, 1, blockhash);
|
||||||
librapay_transaction::create_account(&funding_keys[i], &key.pubkey(), 1, blockhash);
|
|
||||||
client
|
client
|
||||||
.send_message(&[&funding_keys[i]], tx.message)
|
.send_message(&[&funding_keys[i], &key], tx.message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let tx = librapay_transaction::transfer(
|
let tx = librapay_transaction::transfer(
|
||||||
|
|
|
@ -622,7 +622,7 @@ fn process_deploy(
|
||||||
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(program_data.len())?;
|
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(program_data.len())?;
|
||||||
let mut create_account_tx = system_transaction::create_account(
|
let mut create_account_tx = system_transaction::create_account(
|
||||||
&config.keypair,
|
&config.keypair,
|
||||||
&program_id.pubkey(),
|
&program_id,
|
||||||
blockhash,
|
blockhash,
|
||||||
minimum_balance,
|
minimum_balance,
|
||||||
program_data.len() as u64,
|
program_data.len() as u64,
|
||||||
|
@ -656,8 +656,7 @@ fn process_deploy(
|
||||||
check_account_for_multiple_fees(rpc_client, config, &fee_calculator, &messages)?;
|
check_account_for_multiple_fees(rpc_client, config, &fee_calculator, &messages)?;
|
||||||
|
|
||||||
trace!("Creating program account");
|
trace!("Creating program account");
|
||||||
let result =
|
let result = rpc_client.send_and_confirm_transaction(&mut create_account_tx, &signers);
|
||||||
rpc_client.send_and_confirm_transaction(&mut create_account_tx, &[&config.keypair]);
|
|
||||||
log_instruction_custom_error::<SystemError>(result)
|
log_instruction_custom_error::<SystemError>(result)
|
||||||
.map_err(|_| CliError::DynamicProgramError("Program allocate space failed".to_string()))?;
|
.map_err(|_| CliError::DynamicProgramError("Program allocate space failed".to_string()))?;
|
||||||
|
|
||||||
|
@ -723,9 +722,14 @@ fn process_pay(
|
||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, blockhash);
|
let mut tx = Transaction::new_signed_instructions(
|
||||||
|
&[&config.keypair, &contract_state],
|
||||||
|
ixs,
|
||||||
|
blockhash,
|
||||||
|
);
|
||||||
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
|
let result =
|
||||||
|
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
|
||||||
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
|
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
|
||||||
|
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
|
@ -756,8 +760,13 @@ fn process_pay(
|
||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, blockhash);
|
let mut tx = Transaction::new_signed_instructions(
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
|
&[&config.keypair, &contract_state],
|
||||||
|
ixs,
|
||||||
|
blockhash,
|
||||||
|
);
|
||||||
|
let result =
|
||||||
|
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
|
||||||
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
||||||
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
|
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;
|
||||||
|
|
||||||
|
|
|
@ -424,11 +424,12 @@ pub fn process_create_stake_account(
|
||||||
let mut tx = Transaction::new_signed_with_payer(
|
let mut tx = Transaction::new_signed_with_payer(
|
||||||
ixs,
|
ixs,
|
||||||
Some(&config.keypair.pubkey()),
|
Some(&config.keypair.pubkey()),
|
||||||
&[&config.keypair],
|
&[&config.keypair, stake_account],
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
);
|
);
|
||||||
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
|
let result =
|
||||||
|
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, stake_account]);
|
||||||
log_instruction_custom_error::<SystemError>(result)
|
log_instruction_custom_error::<SystemError>(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,9 +174,14 @@ pub fn process_create_storage_account(
|
||||||
1,
|
1,
|
||||||
account_type,
|
account_type,
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
let mut tx = Transaction::new_signed_instructions(
|
||||||
|
&[&config.keypair, &storage_account],
|
||||||
|
ixs,
|
||||||
|
recent_blockhash,
|
||||||
|
);
|
||||||
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
|
let result =
|
||||||
|
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &storage_account]);
|
||||||
log_instruction_custom_error::<SystemError>(result)
|
log_instruction_custom_error::<SystemError>(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,9 +267,13 @@ pub fn process_create_vote_account(
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
let mut tx = Transaction::new_signed_instructions(
|
||||||
|
&[&config.keypair, vote_account],
|
||||||
|
ixs,
|
||||||
|
recent_blockhash,
|
||||||
|
);
|
||||||
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
|
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, vote_account]);
|
||||||
log_instruction_custom_error::<SystemError>(result)
|
log_instruction_custom_error::<SystemError>(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -402,7 +402,11 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
51,
|
51,
|
||||||
);
|
);
|
||||||
let tx = Transaction::new_signed_instructions(&[&contract_funds], ixs, blockhash);
|
let tx = Transaction::new_signed_instructions(
|
||||||
|
&[&contract_funds, &contract_state],
|
||||||
|
ixs,
|
||||||
|
blockhash,
|
||||||
|
);
|
||||||
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
|
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
|
|
||||||
|
|
|
@ -316,7 +316,7 @@ mod tests {
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let tx = system_transaction::create_account(
|
let tx = system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice,
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
|
@ -371,7 +371,7 @@ mod tests {
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let tx = system_transaction::create_account(
|
let tx = system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice,
|
||||||
blockhash,
|
blockhash,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
|
|
|
@ -86,7 +86,7 @@ mod tests {
|
||||||
StorageAccountType::Archiver,
|
StorageAccountType::Archiver,
|
||||||
);
|
);
|
||||||
let account_tx = Transaction::new_signed_instructions(
|
let account_tx = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair, &archiver_keypair],
|
||||||
account_ix,
|
account_ix,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -534,6 +534,7 @@ pub mod tests {
|
||||||
};
|
};
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
@ -1576,6 +1577,10 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
let mut hash = bank.last_blockhash();
|
let mut hash = bank.last_blockhash();
|
||||||
|
|
||||||
|
let present_account_key = Keypair::new();
|
||||||
|
let present_account = Account::new(1, 10, &Pubkey::default());
|
||||||
|
bank.store_account(&present_account_key.pubkey(), &present_account);
|
||||||
|
|
||||||
let entries: Vec<_> = (0..NUM_TRANSFERS)
|
let entries: Vec<_> = (0..NUM_TRANSFERS)
|
||||||
.step_by(NUM_TRANSFERS_PER_ENTRY)
|
.step_by(NUM_TRANSFERS_PER_ENTRY)
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
|
@ -1592,7 +1597,7 @@ pub mod tests {
|
||||||
|
|
||||||
transactions.push(system_transaction::create_account(
|
transactions.push(system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&solana_sdk::sysvar::clock::id(), // puts a TX error in results
|
&present_account_key, // puts a TX error in results
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
|
@ -1926,6 +1931,10 @@ pub mod tests {
|
||||||
.expect("funding failed");
|
.expect("funding failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let present_account_key = Keypair::new();
|
||||||
|
let present_account = Account::new(1, 10, &Pubkey::default());
|
||||||
|
bank.store_account(&present_account_key.pubkey(), &present_account);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut hash = bank.last_blockhash();
|
let mut hash = bank.last_blockhash();
|
||||||
let mut root: Option<Arc<Bank>> = None;
|
let mut root: Option<Arc<Bank>> = None;
|
||||||
|
@ -1947,7 +1956,7 @@ pub mod tests {
|
||||||
|
|
||||||
transactions.push(system_transaction::create_account(
|
transactions.push(system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&solana_sdk::sysvar::clock::id(), // puts a TX error in results
|
&present_account_key, // puts a TX error in results
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
100,
|
100,
|
||||||
100,
|
100,
|
||||||
|
|
|
@ -402,8 +402,10 @@ mod tests {
|
||||||
|
|
||||||
fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ixs = budget_instruction::payment(&pubkey, &pubkey, 1);
|
let budget_contract = Keypair::new();
|
||||||
Transaction::new_signed_instructions(&[keypair], ixs, hash)
|
let budget_pubkey = budget_contract.pubkey();
|
||||||
|
let ixs = budget_instruction::payment(&pubkey, &pubkey, &budget_pubkey, 1);
|
||||||
|
Transaction::new_signed_instructions(&[keypair, &budget_contract], ixs, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
|
|
|
@ -247,6 +247,7 @@ mod tests {
|
||||||
EpochSchedule, DEFAULT_LEADER_SCHEDULE_SLOT_OFFSET, DEFAULT_SLOTS_PER_EPOCH,
|
EpochSchedule, DEFAULT_LEADER_SCHEDULE_SLOT_OFFSET, DEFAULT_SLOTS_PER_EPOCH,
|
||||||
MINIMUM_SLOTS_PER_EPOCH,
|
MINIMUM_SLOTS_PER_EPOCH,
|
||||||
};
|
};
|
||||||
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use std::{sync::mpsc::channel, sync::Arc, thread::Builder};
|
use std::{sync::mpsc::channel, sync::Arc, thread::Builder};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -496,11 +497,11 @@ mod tests {
|
||||||
|
|
||||||
// Create new vote account
|
// Create new vote account
|
||||||
let node_pubkey = Pubkey::new_rand();
|
let node_pubkey = Pubkey::new_rand();
|
||||||
let vote_pubkey = Pubkey::new_rand();
|
let vote_account = Keypair::new();
|
||||||
setup_vote_and_stake_accounts(
|
setup_vote_and_stake_accounts(
|
||||||
&bank,
|
&bank,
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&vote_pubkey,
|
&vote_account,
|
||||||
&node_pubkey,
|
&node_pubkey,
|
||||||
BOOTSTRAP_LEADER_LAMPORTS,
|
BOOTSTRAP_LEADER_LAMPORTS,
|
||||||
);
|
);
|
||||||
|
|
|
@ -88,7 +88,7 @@ where
|
||||||
// Find if any slot has achieved sufficient votes for supermajority lockout
|
// Find if any slot has achieved sufficient votes for supermajority lockout
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
for (stake, slot) in stakes_and_lockouts {
|
for (stake, slot) in stakes_and_lockouts {
|
||||||
total += stake;
|
total += *stake;
|
||||||
if total > supermajority_stake {
|
if total > supermajority_stake {
|
||||||
return Some(slot);
|
return Some(slot);
|
||||||
}
|
}
|
||||||
|
@ -125,10 +125,11 @@ pub(crate) mod tests {
|
||||||
pub(crate) fn setup_vote_and_stake_accounts(
|
pub(crate) fn setup_vote_and_stake_accounts(
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
from_account: &Keypair,
|
from_account: &Keypair,
|
||||||
vote_pubkey: &Pubkey,
|
vote_account: &Keypair,
|
||||||
node_pubkey: &Pubkey,
|
node_pubkey: &Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
) {
|
) {
|
||||||
|
let vote_pubkey = vote_account.pubkey();
|
||||||
fn process_instructions<T: KeypairUtil>(
|
fn process_instructions<T: KeypairUtil>(
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
keypairs: &[&T],
|
keypairs: &[&T],
|
||||||
|
@ -145,14 +146,14 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
process_instructions(
|
process_instructions(
|
||||||
bank,
|
bank,
|
||||||
&[from_account],
|
&[from_account, vote_account],
|
||||||
vote_instruction::create_account(
|
vote_instruction::create_account(
|
||||||
&from_account.pubkey(),
|
&from_account.pubkey(),
|
||||||
vote_pubkey,
|
&vote_pubkey,
|
||||||
&VoteInit {
|
&VoteInit {
|
||||||
node_pubkey: *node_pubkey,
|
node_pubkey: *node_pubkey,
|
||||||
authorized_voter: *vote_pubkey,
|
authorized_voter: vote_pubkey,
|
||||||
authorized_withdrawer: *vote_pubkey,
|
authorized_withdrawer: vote_pubkey,
|
||||||
commission: 0,
|
commission: 0,
|
||||||
},
|
},
|
||||||
amount,
|
amount,
|
||||||
|
@ -168,7 +169,7 @@ pub(crate) mod tests {
|
||||||
stake_instruction::create_stake_account_and_delegate_stake(
|
stake_instruction::create_stake_account_and_delegate_stake(
|
||||||
&from_account.pubkey(),
|
&from_account.pubkey(),
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
vote_pubkey,
|
&vote_pubkey,
|
||||||
&Authorized::auto(&stake_account_pubkey),
|
&Authorized::auto(&stake_account_pubkey),
|
||||||
amount,
|
amount,
|
||||||
),
|
),
|
||||||
|
@ -193,7 +194,7 @@ pub(crate) mod tests {
|
||||||
} = create_genesis_block(10_000);
|
} = create_genesis_block(10_000);
|
||||||
|
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let vote_pubkey = Pubkey::new_rand();
|
let vote_account = Keypair::new();
|
||||||
|
|
||||||
// Give the validator some stake but don't setup a staking account
|
// Give the validator some stake but don't setup a staking account
|
||||||
// Validator has no lamports staked, so they get filtered out. Only the bootstrap leader
|
// Validator has no lamports staked, so they get filtered out. Only the bootstrap leader
|
||||||
|
@ -206,7 +207,7 @@ pub(crate) mod tests {
|
||||||
setup_vote_and_stake_accounts(
|
setup_vote_and_stake_accounts(
|
||||||
&bank,
|
&bank,
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&vote_pubkey,
|
&vote_account,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
stake,
|
stake,
|
||||||
);
|
);
|
||||||
|
|
|
@ -472,7 +472,7 @@ impl LocalCluster {
|
||||||
// 1) Create vote account
|
// 1) Create vote account
|
||||||
|
|
||||||
let mut transaction = Transaction::new_signed_instructions(
|
let mut transaction = Transaction::new_signed_instructions(
|
||||||
&[from_account.as_ref()],
|
&[from_account.as_ref(), vote_account],
|
||||||
vote_instruction::create_account(
|
vote_instruction::create_account(
|
||||||
&from_account.pubkey(),
|
&from_account.pubkey(),
|
||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
|
@ -596,7 +596,8 @@ impl LocalCluster {
|
||||||
),
|
),
|
||||||
Some(&from_keypair.pubkey()),
|
Some(&from_keypair.pubkey()),
|
||||||
);
|
);
|
||||||
let signer_keys = vec![from_keypair.as_ref()];
|
|
||||||
|
let signer_keys = vec![from_keypair.as_ref(), &storage_keypair];
|
||||||
let blockhash = client
|
let blockhash = client
|
||||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -82,8 +82,7 @@ pub fn create_account(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new payment script.
|
/// Create a new payment script.
|
||||||
pub fn payment(from: &Pubkey, to: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
pub fn payment(from: &Pubkey, to: &Pubkey, contract: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
||||||
let contract = Pubkey::new_rand();
|
|
||||||
let expr = BudgetExpr::new_payment(lamports, to);
|
let expr = BudgetExpr::new_payment(lamports, to);
|
||||||
create_account(from, &contract, lamports, expr)
|
create_account(from, &contract, lamports, expr)
|
||||||
}
|
}
|
||||||
|
@ -181,7 +180,8 @@ mod tests {
|
||||||
fn test_budget_instruction_verify() {
|
fn test_budget_instruction_verify() {
|
||||||
let alice_pubkey = Pubkey::new_rand();
|
let alice_pubkey = Pubkey::new_rand();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
payment(&alice_pubkey, &bob_pubkey, 1); // No panic! indicates success.
|
let budget_pubkey = Pubkey::new_rand();
|
||||||
|
payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 1); // No panic! indicates success.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -210,10 +210,13 @@ mod tests {
|
||||||
let bank_client = BankClient::new(bank);
|
let bank_client = BankClient::new(bank);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let instructions = budget_instruction::payment(&alice_pubkey, &bob_pubkey, 100);
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
|
let instructions =
|
||||||
|
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 100);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 100);
|
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 100);
|
||||||
}
|
}
|
||||||
|
@ -225,7 +228,8 @@ mod tests {
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let witness = Pubkey::new_rand();
|
let witness = Pubkey::new_rand();
|
||||||
let instructions = budget_instruction::when_signed(
|
let instructions = budget_instruction::when_signed(
|
||||||
|
@ -238,7 +242,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Attack! Part 1: Sign a witness transaction with a random key.
|
// Attack! Part 1: Sign a witness transaction with a random key.
|
||||||
|
@ -273,7 +277,8 @@ mod tests {
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let instructions = budget_instruction::on_date(
|
let instructions = budget_instruction::on_date(
|
||||||
|
@ -287,7 +292,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
||||||
|
@ -320,10 +325,12 @@ mod tests {
|
||||||
let (bank, alice_keypair) = create_bank(2);
|
let (bank, alice_keypair) = create_bank(2);
|
||||||
let bank_client = BankClient::new(bank);
|
let bank_client = BankClient::new(bank);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let mallory_pubkey = Pubkey::new_rand();
|
let mallory_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
|
|
||||||
let instructions = budget_instruction::on_date(
|
let instructions = budget_instruction::on_date(
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
@ -335,7 +342,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 1);
|
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 1);
|
||||||
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 1);
|
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 1);
|
||||||
|
@ -389,7 +396,8 @@ mod tests {
|
||||||
let (bank, alice_keypair) = create_bank(3);
|
let (bank, alice_keypair) = create_bank(3);
|
||||||
let bank_client = BankClient::new(bank);
|
let bank_client = BankClient::new(bank);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
|
|
||||||
|
@ -404,7 +412,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 2);
|
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 2);
|
||||||
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 1);
|
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 1);
|
||||||
|
@ -461,7 +469,8 @@ mod tests {
|
||||||
|
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let game_hash = hash(&[1, 2, 3]);
|
let game_hash = hash(&[1, 2, 3]);
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_keypair = Keypair::new();
|
||||||
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let bob_pubkey = bob_keypair.pubkey();
|
let bob_pubkey = bob_keypair.pubkey();
|
||||||
|
|
||||||
|
@ -481,7 +490,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
||||||
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 41);
|
assert_eq!(bank_client.get_balance(&budget_pubkey).unwrap(), 41);
|
||||||
|
|
|
@ -371,10 +371,11 @@ fn test_config_updates_requiring_config() {
|
||||||
fn test_config_initialize_no_panic() {
|
fn test_config_initialize_no_panic() {
|
||||||
let (bank, alice_keypair) = create_bank(3);
|
let (bank, alice_keypair) = create_bank(3);
|
||||||
let bank_client = BankClient::new(bank);
|
let bank_client = BankClient::new(bank);
|
||||||
|
let config_account = Keypair::new();
|
||||||
|
|
||||||
let mut instructions = config_instruction::create_account::<MyConfig>(
|
let mut instructions = config_instruction::create_account::<MyConfig>(
|
||||||
&alice_keypair.pubkey(),
|
&alice_keypair.pubkey(),
|
||||||
&Pubkey::new_rand(),
|
&config_account.pubkey(),
|
||||||
1,
|
1,
|
||||||
vec![],
|
vec![],
|
||||||
);
|
);
|
||||||
|
@ -383,7 +384,7 @@ fn test_config_initialize_no_panic() {
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &config_account], message)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
TransactionError::InstructionError(1, InstructionError::NotEnoughAccountKeys)
|
TransactionError::InstructionError(1, InstructionError::NotEnoughAccountKeys)
|
||||||
|
|
|
@ -458,6 +458,7 @@ mod test {
|
||||||
use solana_runtime::bank_client::BankClient;
|
use solana_runtime::bank_client::BankClient;
|
||||||
use solana_sdk::client::SyncClient;
|
use solana_sdk::client::SyncClient;
|
||||||
use solana_sdk::genesis_block::create_genesis_block;
|
use solana_sdk::genesis_block::create_genesis_block;
|
||||||
|
use solana_sdk::message::Message;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -557,18 +558,20 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
fn create_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
||||||
let new = Pubkey::new_rand();
|
let new = Keypair::new();
|
||||||
|
|
||||||
let instruction = system_instruction::create_account(
|
let instruction = system_instruction::create_account(
|
||||||
&owner.pubkey(),
|
&owner.pubkey(),
|
||||||
&new,
|
&new.pubkey(),
|
||||||
1,
|
1,
|
||||||
mem::size_of::<ExchangeState>() as u64,
|
mem::size_of::<ExchangeState>() as u64,
|
||||||
&id(),
|
&id(),
|
||||||
);
|
);
|
||||||
|
|
||||||
client
|
client
|
||||||
.send_instruction(&owner, instruction)
|
.send_message(&[owner, &new], Message::new(vec![instruction]))
|
||||||
.expect(&format!("{}:{}", line!(), file!()));
|
.expect(&format!("{}:{}", line!(), file!()));
|
||||||
new
|
new.pubkey()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
||||||
|
|
|
@ -36,7 +36,13 @@ pub fn create_genesis<T: Client>(from_key: &Keypair, client: &T, amount: u64) ->
|
||||||
as u64,
|
as u64,
|
||||||
&solana_sdk::move_loader::id(),
|
&solana_sdk::move_loader::id(),
|
||||||
);
|
);
|
||||||
client.send_instruction(&from_key, instruction).unwrap();
|
|
||||||
|
client
|
||||||
|
.send_message(
|
||||||
|
&[&from_key, &libra_genesis_key],
|
||||||
|
Message::new(vec![instruction]),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let instruction = librapay_instruction::genesis(&libra_genesis_key.pubkey(), amount);
|
let instruction = librapay_instruction::genesis(&libra_genesis_key.pubkey(), amount);
|
||||||
let message = Message::new_with_payer(vec![instruction], Some(&from_key.pubkey()));
|
let message = Message::new_with_payer(vec![instruction], Some(&from_key.pubkey()));
|
||||||
|
|
|
@ -63,32 +63,35 @@ pub fn transfer(
|
||||||
|
|
||||||
pub fn create_accounts(
|
pub fn create_accounts(
|
||||||
from: &Keypair,
|
from: &Keypair,
|
||||||
tos: &[Pubkey],
|
to: &[&Keypair],
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let instructions = tos
|
let instructions = to
|
||||||
.iter()
|
.iter()
|
||||||
.map(|to| {
|
.map(|to| {
|
||||||
system_instruction::create_account(
|
system_instruction::create_account(
|
||||||
&from.pubkey(),
|
&from.pubkey(),
|
||||||
to,
|
&to.pubkey(),
|
||||||
lamports,
|
lamports,
|
||||||
400,
|
400,
|
||||||
&solana_sdk::move_loader::id(),
|
&solana_sdk::move_loader::id(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Transaction::new_signed_instructions(&[from], instructions, recent_blockhash)
|
|
||||||
|
let mut from_signers = vec![from];
|
||||||
|
from_signers.extend_from_slice(to);
|
||||||
|
Transaction::new_signed_instructions(&from_signers, instructions, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(
|
pub fn create_account(
|
||||||
from: &Keypair,
|
from: &Keypair,
|
||||||
to: &Pubkey,
|
to: &Keypair,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
create_accounts(from, &[*to], lamports, recent_blockhash)
|
create_accounts(from, &[to], lamports, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -172,12 +175,7 @@ mod tests {
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
|
|
||||||
let tx = create_accounts(
|
let tx = create_accounts(&mint_keypair, &[&from, &to], 1, bank.last_blockhash());
|
||||||
&mint_keypair,
|
|
||||||
&[from.pubkey(), to.pubkey()],
|
|
||||||
1,
|
|
||||||
bank.last_blockhash(),
|
|
||||||
);
|
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn test_stake_account_delegate() {
|
||||||
10,
|
10,
|
||||||
));
|
));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair], message)
|
.send_message(&[&mint_keypair, &vote_keypair], message)
|
||||||
.expect("failed to create vote account");
|
.expect("failed to create vote account");
|
||||||
|
|
||||||
let authorized = stake_state::Authorized::auto(&staker_pubkey);
|
let authorized = stake_state::Authorized::auto(&staker_pubkey);
|
||||||
|
|
|
@ -56,8 +56,10 @@ fn test_instruction(
|
||||||
#[test]
|
#[test]
|
||||||
fn test_account_owner() {
|
fn test_account_owner() {
|
||||||
let account_owner = Pubkey::new_rand();
|
let account_owner = Pubkey::new_rand();
|
||||||
let validator_storage_pubkey = Pubkey::new_rand();
|
let validator_storage_keypair = Keypair::new();
|
||||||
let archiver_storage_pubkey = Pubkey::new_rand();
|
let validator_storage_pubkey = validator_storage_keypair.pubkey();
|
||||||
|
let archiver_storage_keypair = Keypair::new();
|
||||||
|
let archiver_storage_pubkey = archiver_storage_keypair.pubkey();
|
||||||
|
|
||||||
let GenesisBlockInfo {
|
let GenesisBlockInfo {
|
||||||
genesis_block,
|
genesis_block,
|
||||||
|
@ -78,7 +80,7 @@ fn test_account_owner() {
|
||||||
StorageAccountType::Validator,
|
StorageAccountType::Validator,
|
||||||
));
|
));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair], message)
|
.send_message(&[&mint_keypair, &validator_storage_keypair], message)
|
||||||
.expect("failed to create account");
|
.expect("failed to create account");
|
||||||
let account = bank
|
let account = bank
|
||||||
.get_account(&validator_storage_pubkey)
|
.get_account(&validator_storage_pubkey)
|
||||||
|
@ -98,7 +100,7 @@ fn test_account_owner() {
|
||||||
StorageAccountType::Archiver,
|
StorageAccountType::Archiver,
|
||||||
));
|
));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair], message)
|
.send_message(&[&mint_keypair, &archiver_storage_keypair], message)
|
||||||
.expect("failed to create account");
|
.expect("failed to create account");
|
||||||
let account = bank
|
let account = bank
|
||||||
.get_account(&archiver_storage_pubkey)
|
.get_account(&archiver_storage_pubkey)
|
||||||
|
@ -290,8 +292,8 @@ fn test_validate_mining() {
|
||||||
&owner_pubkey,
|
&owner_pubkey,
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[&validator_storage_id],
|
&[&validator_storage_keypair],
|
||||||
&[&archiver_1_storage_id, &archiver_2_storage_id],
|
&[&archiver_1_storage_keypair, &archiver_2_storage_keypair],
|
||||||
10,
|
10,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -465,19 +467,21 @@ fn init_storage_accounts(
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
client: &BankClient,
|
client: &BankClient,
|
||||||
mint: &Keypair,
|
mint: &Keypair,
|
||||||
validator_accounts_to_create: &[&Pubkey],
|
validator_accounts_to_create: &[&Keypair],
|
||||||
archiver_accounts_to_create: &[&Pubkey],
|
archiver_accounts_to_create: &[&Keypair],
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) {
|
) {
|
||||||
|
let mut signers = vec![mint];
|
||||||
let mut ixs: Vec<_> = vec![system_instruction::transfer(&mint.pubkey(), owner, 1)];
|
let mut ixs: Vec<_> = vec![system_instruction::transfer(&mint.pubkey(), owner, 1)];
|
||||||
ixs.append(
|
ixs.append(
|
||||||
&mut validator_accounts_to_create
|
&mut validator_accounts_to_create
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|account| {
|
.flat_map(|account| {
|
||||||
|
signers.push(&account);
|
||||||
storage_instruction::create_storage_account(
|
storage_instruction::create_storage_account(
|
||||||
&mint.pubkey(),
|
&mint.pubkey(),
|
||||||
owner,
|
owner,
|
||||||
account,
|
&account.pubkey(),
|
||||||
lamports,
|
lamports,
|
||||||
StorageAccountType::Validator,
|
StorageAccountType::Validator,
|
||||||
)
|
)
|
||||||
|
@ -485,16 +489,17 @@ fn init_storage_accounts(
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
archiver_accounts_to_create.into_iter().for_each(|account| {
|
archiver_accounts_to_create.into_iter().for_each(|account| {
|
||||||
|
signers.push(&account);
|
||||||
ixs.append(&mut storage_instruction::create_storage_account(
|
ixs.append(&mut storage_instruction::create_storage_account(
|
||||||
&mint.pubkey(),
|
&mint.pubkey(),
|
||||||
owner,
|
owner,
|
||||||
account,
|
&account.pubkey(),
|
||||||
lamports,
|
lamports,
|
||||||
StorageAccountType::Archiver,
|
StorageAccountType::Archiver,
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
let message = Message::new(ixs);
|
let message = Message::new(ixs);
|
||||||
client.send_message(&[mint], message).unwrap();
|
client.send_message(&signers, message).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_storage_segment<C: SyncClient>(client: &C, account: &Pubkey) -> u64 {
|
fn get_storage_segment<C: SyncClient>(client: &C, account: &Pubkey) -> u64 {
|
||||||
|
@ -594,7 +599,9 @@ fn test_bank_storage() {
|
||||||
11,
|
11,
|
||||||
StorageAccountType::Archiver,
|
StorageAccountType::Archiver,
|
||||||
));
|
));
|
||||||
bank_client.send_message(&[&mint_keypair], message).unwrap();
|
bank_client
|
||||||
|
.send_message(&[&mint_keypair, &archiver_keypair], message)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let message = Message::new(storage_instruction::create_storage_account(
|
let message = Message::new(storage_instruction::create_storage_account(
|
||||||
&mint_pubkey,
|
&mint_pubkey,
|
||||||
|
@ -603,7 +610,9 @@ fn test_bank_storage() {
|
||||||
1,
|
1,
|
||||||
StorageAccountType::Validator,
|
StorageAccountType::Validator,
|
||||||
));
|
));
|
||||||
bank_client.send_message(&[&mint_keypair], message).unwrap();
|
bank_client
|
||||||
|
.send_message(&[&mint_keypair, &validator_keypair], message)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new_with_payer(
|
||||||
vec![storage_instruction::advertise_recent_blockhash(
|
vec![storage_instruction::advertise_recent_blockhash(
|
||||||
|
|
|
@ -192,7 +192,7 @@ mod tests {
|
||||||
|
|
||||||
fn create_vest_account(
|
fn create_vest_account(
|
||||||
bank_client: &BankClient,
|
bank_client: &BankClient,
|
||||||
contract_pubkey: &Pubkey,
|
contract_keypair: &Keypair,
|
||||||
payer_keypair: &Keypair,
|
payer_keypair: &Keypair,
|
||||||
terminator_pubkey: &Pubkey,
|
terminator_pubkey: &Pubkey,
|
||||||
payee_pubkey: &Pubkey,
|
payee_pubkey: &Pubkey,
|
||||||
|
@ -203,14 +203,14 @@ mod tests {
|
||||||
let instructions = vest_instruction::create_account(
|
let instructions = vest_instruction::create_account(
|
||||||
&payer_keypair.pubkey(),
|
&payer_keypair.pubkey(),
|
||||||
&terminator_pubkey,
|
&terminator_pubkey,
|
||||||
&contract_pubkey,
|
&contract_keypair.pubkey(),
|
||||||
&payee_pubkey,
|
&payee_pubkey,
|
||||||
start_date,
|
start_date,
|
||||||
&date_pubkey,
|
&date_pubkey,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client.send_message(&[&payer_keypair], message)
|
bank_client.send_message(&[&payer_keypair, &contract_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_set_terminator(
|
fn send_set_terminator(
|
||||||
|
@ -327,10 +327,12 @@ mod tests {
|
||||||
fn test_initialize_no_panic() {
|
fn test_initialize_no_panic() {
|
||||||
let (bank_client, alice_keypair) = create_bank_client(3);
|
let (bank_client, alice_keypair) = create_bank_client(3);
|
||||||
|
|
||||||
|
let contract_keypair = Keypair::new();
|
||||||
|
|
||||||
let mut instructions = vest_instruction::create_account(
|
let mut instructions = vest_instruction::create_account(
|
||||||
&alice_keypair.pubkey(),
|
&alice_keypair.pubkey(),
|
||||||
&Pubkey::new_rand(),
|
&Pubkey::new_rand(),
|
||||||
&Pubkey::new_rand(),
|
&contract_keypair.pubkey(),
|
||||||
&Pubkey::new_rand(),
|
&Pubkey::new_rand(),
|
||||||
Utc::now().date(),
|
Utc::now().date(),
|
||||||
&Pubkey::new_rand(),
|
&Pubkey::new_rand(),
|
||||||
|
@ -341,7 +343,7 @@ mod tests {
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair], message)
|
.send_message(&[&alice_keypair, &contract_keypair], message)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
TransactionError::InstructionError(1, InstructionError::NotEnoughAccountKeys)
|
TransactionError::InstructionError(1, InstructionError::NotEnoughAccountKeys)
|
||||||
|
@ -352,14 +354,15 @@ mod tests {
|
||||||
let (bank_client, alice_keypair) = create_bank_client(39);
|
let (bank_client, alice_keypair) = create_bank_client(39);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let date_pubkey = Pubkey::new_rand();
|
let date_pubkey = Pubkey::new_rand();
|
||||||
let contract_pubkey = Pubkey::new_rand();
|
let contract_keypair = Keypair::new();
|
||||||
|
let contract_pubkey = contract_keypair.pubkey();
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let bob_pubkey = bob_keypair.pubkey();
|
let bob_pubkey = bob_keypair.pubkey();
|
||||||
let start_date = Utc.ymd(2018, 1, 1);
|
let start_date = Utc.ymd(2018, 1, 1);
|
||||||
|
|
||||||
create_vest_account(
|
create_vest_account(
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&contract_pubkey,
|
&contract_keypair,
|
||||||
&alice_keypair,
|
&alice_keypair,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
@ -422,14 +425,15 @@ mod tests {
|
||||||
let (bank_client, alice_keypair) = create_bank_client(38);
|
let (bank_client, alice_keypair) = create_bank_client(38);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let date_pubkey = Pubkey::new_rand();
|
let date_pubkey = Pubkey::new_rand();
|
||||||
let contract_pubkey = Pubkey::new_rand();
|
let contract_keypair = Keypair::new();
|
||||||
|
let contract_pubkey = contract_keypair.pubkey();
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let bob_pubkey = bob_keypair.pubkey();
|
let bob_pubkey = bob_keypair.pubkey();
|
||||||
let start_date = Utc.ymd(2018, 1, 1);
|
let start_date = Utc.ymd(2018, 1, 1);
|
||||||
|
|
||||||
create_vest_account(
|
create_vest_account(
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&contract_pubkey,
|
&contract_keypair,
|
||||||
&alice_keypair,
|
&alice_keypair,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
@ -481,13 +485,14 @@ mod tests {
|
||||||
let current_date = Utc.ymd(2019, 1, 1);
|
let current_date = Utc.ymd(2019, 1, 1);
|
||||||
create_date_account(&bank_client, &date_keypair, &alice_keypair, current_date).unwrap();
|
create_date_account(&bank_client, &date_keypair, &alice_keypair, current_date).unwrap();
|
||||||
|
|
||||||
let contract_pubkey = Pubkey::new_rand();
|
let contract_keypair = Keypair::new();
|
||||||
|
let contract_pubkey = contract_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let start_date = Utc.ymd(2018, 1, 1);
|
let start_date = Utc.ymd(2018, 1, 1);
|
||||||
|
|
||||||
create_vest_account(
|
create_vest_account(
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&contract_pubkey,
|
&contract_keypair,
|
||||||
&alice_keypair,
|
&alice_keypair,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
@ -542,7 +547,8 @@ mod tests {
|
||||||
fn test_terminate_and_refund() {
|
fn test_terminate_and_refund() {
|
||||||
let (bank_client, alice_keypair) = create_bank_client(3);
|
let (bank_client, alice_keypair) = create_bank_client(3);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let contract_pubkey = Pubkey::new_rand();
|
let contract_keypair = Keypair::new();
|
||||||
|
let contract_pubkey = contract_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let start_date = Utc::now().date();
|
let start_date = Utc::now().date();
|
||||||
|
|
||||||
|
@ -554,7 +560,7 @@ mod tests {
|
||||||
|
|
||||||
create_vest_account(
|
create_vest_account(
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&contract_pubkey,
|
&contract_keypair,
|
||||||
&alice_keypair,
|
&alice_keypair,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
@ -585,7 +591,8 @@ mod tests {
|
||||||
fn test_terminate_and_send_funds() {
|
fn test_terminate_and_send_funds() {
|
||||||
let (bank_client, alice_keypair) = create_bank_client(3);
|
let (bank_client, alice_keypair) = create_bank_client(3);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let contract_pubkey = Pubkey::new_rand();
|
let contract_keypair = Keypair::new();
|
||||||
|
let contract_pubkey = contract_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let start_date = Utc::now().date();
|
let start_date = Utc::now().date();
|
||||||
|
|
||||||
|
@ -597,7 +604,7 @@ mod tests {
|
||||||
|
|
||||||
create_vest_account(
|
create_vest_account(
|
||||||
&bank_client,
|
&bank_client,
|
||||||
&contract_pubkey,
|
&contract_keypair,
|
||||||
&alice_keypair,
|
&alice_keypair,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
|
|
@ -3066,7 +3066,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let transaction = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair, &vote_keypair],
|
||||||
instructions,
|
instructions,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
@ -3287,7 +3287,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let transaction = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair, &mock_account],
|
||||||
instructions,
|
instructions,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
@ -3328,7 +3328,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let transaction = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair, &mock_account],
|
||||||
instructions,
|
instructions,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,7 +24,10 @@ pub fn load_program<T: Client>(
|
||||||
loader_pubkey,
|
loader_pubkey,
|
||||||
);
|
);
|
||||||
bank_client
|
bank_client
|
||||||
.send_instruction(&from_keypair, instruction)
|
.send_message(
|
||||||
|
&[from_keypair, &program_keypair],
|
||||||
|
Message::new(vec![instruction]),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let chunk_size = 256; // Size of chunk just needs to fit into tx
|
let chunk_size = 256; // Size of chunk just needs to fit into tx
|
||||||
|
|
|
@ -117,7 +117,9 @@ pub(crate) mod tests {
|
||||||
11,
|
11,
|
||||||
StorageAccountType::Archiver,
|
StorageAccountType::Archiver,
|
||||||
));
|
));
|
||||||
bank_client.send_message(&[&mint_keypair], message).unwrap();
|
bank_client
|
||||||
|
.send_message(&[&mint_keypair, &archiver_keypair], message)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let message = Message::new(storage_instruction::create_storage_account(
|
let message = Message::new(storage_instruction::create_storage_account(
|
||||||
&mint_pubkey,
|
&mint_pubkey,
|
||||||
|
@ -126,7 +128,9 @@ pub(crate) mod tests {
|
||||||
11,
|
11,
|
||||||
StorageAccountType::Validator,
|
StorageAccountType::Validator,
|
||||||
));
|
));
|
||||||
bank_client.send_message(&[&mint_keypair], message).unwrap();
|
bank_client
|
||||||
|
.send_message(&[&mint_keypair, &validator_keypair], message)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(validator_accounts(bank.as_ref()).len(), 1);
|
assert_eq!(validator_accounts(bank.as_ref()).len(), 1);
|
||||||
assert_eq!(archiver_accounts(bank.as_ref()).len(), 1);
|
assert_eq!(archiver_accounts(bank.as_ref()).len(), 1);
|
||||||
|
|
|
@ -20,6 +20,11 @@ fn create_system_account(
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if to.signer_key().is_none() {
|
||||||
|
debug!("CreateAccount: to must sign");
|
||||||
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
|
}
|
||||||
|
|
||||||
// if it looks like the to account is already in use, bail
|
// if it looks like the to account is already in use, bail
|
||||||
if to.account.lamports != 0
|
if to.account.lamports != 0
|
||||||
|| !to.account.data.is_empty()
|
|| !to.account.data.is_empty()
|
||||||
|
@ -157,7 +162,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
create_system_account(
|
create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&to, false, &mut to_account),
|
&mut KeyedAccount::new(&to, true, &mut to_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -188,7 +193,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
create_system_account(
|
create_system_account(
|
||||||
&mut KeyedAccount::new(&from, false, &mut from_account), // no signer
|
&mut KeyedAccount::new(&from, false, &mut from_account), // no signer
|
||||||
&mut KeyedAccount::new(&to, false, &mut to_account),
|
&mut KeyedAccount::new(&to, true, &mut to_account),
|
||||||
0,
|
0,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -219,7 +224,7 @@ mod tests {
|
||||||
|
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&to, false, &mut to_account),
|
&mut KeyedAccount::new(&to, true, &mut to_account),
|
||||||
150,
|
150,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -244,7 +249,7 @@ mod tests {
|
||||||
|
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&owned_key, false, &mut owned_account),
|
&mut KeyedAccount::new(&owned_key, true, &mut owned_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -259,7 +264,7 @@ mod tests {
|
||||||
let unchanged_account = owned_account.clone();
|
let unchanged_account = owned_account.clone();
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&owned_key, false, &mut owned_account),
|
&mut KeyedAccount::new(&owned_key, true, &mut owned_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -281,8 +286,21 @@ mod tests {
|
||||||
let mut owned_account = Account::new(0, 0, &Pubkey::default());
|
let mut owned_account = Account::new(0, 0, &Pubkey::default());
|
||||||
let unchanged_account = owned_account.clone();
|
let unchanged_account = owned_account.clone();
|
||||||
|
|
||||||
|
// Haven't signed from account
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, false, &mut from_account),
|
&mut KeyedAccount::new(&from, false, &mut from_account),
|
||||||
|
&mut KeyedAccount::new(&owned_key, true, &mut owned_account),
|
||||||
|
50,
|
||||||
|
2,
|
||||||
|
&new_program_owner,
|
||||||
|
);
|
||||||
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
assert_eq!(from_account.lamports, 100);
|
||||||
|
assert_eq!(owned_account, unchanged_account);
|
||||||
|
|
||||||
|
// Haven't signed to account
|
||||||
|
let result = create_system_account(
|
||||||
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&owned_key, false, &mut owned_account),
|
&mut KeyedAccount::new(&owned_key, false, &mut owned_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
|
@ -295,7 +313,7 @@ mod tests {
|
||||||
// support creation/assignment with zero lamports (ephemeral account)
|
// support creation/assignment with zero lamports (ephemeral account)
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, false, &mut from_account),
|
&mut KeyedAccount::new(&from, false, &mut from_account),
|
||||||
&mut KeyedAccount::new(&owned_key, false, &mut owned_account),
|
&mut KeyedAccount::new(&owned_key, true, &mut owned_account),
|
||||||
0,
|
0,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
@ -317,7 +335,7 @@ mod tests {
|
||||||
// fail to create a sysvar::id() owned account
|
// fail to create a sysvar::id() owned account
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&to, false, &mut to_account),
|
&mut KeyedAccount::new(&to, true, &mut to_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&sysvar::id(),
|
&sysvar::id(),
|
||||||
|
@ -330,7 +348,7 @@ mod tests {
|
||||||
// fail to create an account with a sysvar id
|
// fail to create an account with a sysvar id
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&to, false, &mut to_account),
|
&mut KeyedAccount::new(&to, true, &mut to_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&system_program::id(),
|
&system_program::id(),
|
||||||
|
@ -357,7 +375,7 @@ mod tests {
|
||||||
|
|
||||||
let result = create_system_account(
|
let result = create_system_account(
|
||||||
&mut KeyedAccount::new(&from, true, &mut from_account),
|
&mut KeyedAccount::new(&from, true, &mut from_account),
|
||||||
&mut KeyedAccount::new(&populated_key, false, &mut populated_account),
|
&mut KeyedAccount::new(&populated_key, true, &mut populated_account),
|
||||||
50,
|
50,
|
||||||
2,
|
2,
|
||||||
&new_program_owner,
|
&new_program_owner,
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub fn create_account(
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*from_pubkey, true),
|
AccountMeta::new(*from_pubkey, true),
|
||||||
AccountMeta::new(*to_pubkey, false),
|
AccountMeta::new(*to_pubkey, true),
|
||||||
];
|
];
|
||||||
Instruction::new(
|
Instruction::new(
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
|
|
|
@ -11,17 +11,22 @@ use crate::{
|
||||||
/// Create and sign new SystemInstruction::CreateAccount transaction
|
/// Create and sign new SystemInstruction::CreateAccount transaction
|
||||||
pub fn create_account(
|
pub fn create_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: &Pubkey,
|
to_keypair: &Keypair,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
space: u64,
|
space: u64,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
|
let to_pubkey = to_keypair.pubkey();
|
||||||
let create_instruction =
|
let create_instruction =
|
||||||
system_instruction::create_account(&from_pubkey, to, lamports, space, program_id);
|
system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
|
||||||
let instructions = vec![create_instruction];
|
let instructions = vec![create_instruction];
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
Transaction::new_signed_instructions(
|
||||||
|
&[from_keypair, to_keypair],
|
||||||
|
instructions,
|
||||||
|
recent_blockhash,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign new system_instruction::Assign transaction
|
/// Create and sign new system_instruction::Assign transaction
|
||||||
|
|
Loading…
Reference in New Issue