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]);
let mut rnd = GenKeys::new(seed);
let mut total_keys = 0;
let mut target = count;
while target > 1 {
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;
let mut total_keys = 1;
while total_keys < count {
total_keys *= MAX_SPENDS_PER_TX;
}
rnd.gen_n_keypairs(total_keys)
}
@ -739,8 +736,7 @@ mod tests {
generate_and_fund_keypairs(&client, None, &id, tx_count, lamports).unwrap();
for kp in &keypairs {
// TODO: This should be >= lamports, but fails at the moment
assert_ne!(client.get_balance(&kp.pubkey()).unwrap(), 0);
assert!(client.get_balance(&kp.pubkey()).unwrap() >= lamports);
}
}
}