Truncate new keypair files (#7078)

automerge
This commit is contained in:
Michael Vines 2019-11-21 11:02:04 -07:00 committed by Grimes
parent 15d7568038
commit a2a9f1e331
1 changed files with 19 additions and 0 deletions

View File

@ -168,6 +168,7 @@ pub fn write_keypair_file(
}
}
.write(true)
.truncate(true)
.create(true)
.open(outfile)?;
@ -235,10 +236,28 @@ mod tests {
#[test]
fn test_write_keypair_file_overwrite_ok() {
let outfile = tmp_file_path("test_write_keypair_file_overwrite_ok.json");
write_keypair_file(&Keypair::new(), &outfile).unwrap();
write_keypair_file(&Keypair::new(), &outfile).unwrap();
}
#[test]
fn test_write_keypair_file_truncate() {
let outfile = tmp_file_path("test_write_keypair_file_truncate.json");
write_keypair_file(&Keypair::new(), &outfile).unwrap();
read_keypair_file(&outfile).unwrap();
// Ensure outfile is truncated
{
let mut f = File::create(&outfile).unwrap();
f.write_all(String::from_utf8([b'a'; 2048].to_vec()).unwrap().as_bytes())
.unwrap();
}
write_keypair_file(&Keypair::new(), &outfile).unwrap();
read_keypair_file(&outfile).unwrap();
}
#[test]
fn test_keypair_from_seed() {
let good_seed = vec![0; 32];