Create aligned number of keypairs so they all get funded (#4685)

This commit is contained in:
sakridge 2019-06-14 11:11:52 -07:00 committed by GitHub
parent bd884a56bf
commit 589a9d3a72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

@ -587,12 +587,9 @@ pub fn generate_keypairs(seed_keypair: &Keypair, count: u64) -> Vec<Keypair> {
seed.copy_from_slice(&seed_keypair.to_bytes()[..32]); seed.copy_from_slice(&seed_keypair.to_bytes()[..32]);
let mut rnd = GenKeys::new(seed); let mut rnd = GenKeys::new(seed);
let mut total_keys = 0; let mut total_keys = 1;
let mut target = count; while total_keys < count {
while target > 1 { total_keys *= MAX_SPENDS_PER_TX;
total_keys += target;
// Use the upper bound for this division otherwise it may not generate enough keys
target = (target + MAX_SPENDS_PER_TX - 1) / MAX_SPENDS_PER_TX;
} }
rnd.gen_n_keypairs(total_keys) rnd.gen_n_keypairs(total_keys)
} }
@ -739,8 +736,7 @@ mod tests {
generate_and_fund_keypairs(&client, None, &id, tx_count, lamports).unwrap(); generate_and_fund_keypairs(&client, None, &id, tx_count, lamports).unwrap();
for kp in &keypairs { for kp in &keypairs {
// TODO: This should be >= lamports, but fails at the moment assert!(client.get_balance(&kp.pubkey()).unwrap() >= lamports);
assert_ne!(client.get_balance(&kp.pubkey()).unwrap(), 0);
} }
} }
} }