Cleanup transaction with offset (#1514)
* cleanup build::transaction_with_offset * rustfmt
This commit is contained in:
@@ -16,12 +16,12 @@ extern crate grin_chain as chain;
|
||||
extern crate grin_core as core;
|
||||
extern crate grin_keychain as keychain;
|
||||
extern crate grin_store as store;
|
||||
extern crate grin_wallet as wallet;
|
||||
extern crate grin_util as util;
|
||||
extern crate grin_wallet as wallet;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::iter::FromIterator;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -81,12 +81,9 @@ fn test_some_raw_txs() {
|
||||
let coinbase_reward = 60_000_000_000;
|
||||
|
||||
// tx1 spends the original coinbase output from the block
|
||||
let tx1 = build::transaction_with_offset(
|
||||
let tx1 = build::transaction(
|
||||
vec![
|
||||
build::coinbase_input(
|
||||
coinbase_reward,
|
||||
key_id1.clone(),
|
||||
),
|
||||
build::coinbase_input(coinbase_reward, key_id1.clone()),
|
||||
build::output(100, key_id2.clone()),
|
||||
build::output(150, key_id3.clone()),
|
||||
],
|
||||
@@ -95,19 +92,16 @@ fn test_some_raw_txs() {
|
||||
|
||||
// tx2 attempts to "double spend" the coinbase output from the block (conflicts
|
||||
// with tx1)
|
||||
let tx2 = build::transaction_with_offset(
|
||||
let tx2 = build::transaction(
|
||||
vec![
|
||||
build::coinbase_input(
|
||||
coinbase_reward,
|
||||
key_id1.clone(),
|
||||
),
|
||||
build::coinbase_input(coinbase_reward, key_id1.clone()),
|
||||
build::output(100, key_id4.clone()),
|
||||
],
|
||||
&keychain,
|
||||
).unwrap();
|
||||
|
||||
// tx3 spends one output from tx1
|
||||
let tx3 = build::transaction_with_offset(
|
||||
let tx3 = build::transaction(
|
||||
vec![
|
||||
build::input(100, key_id2.clone()),
|
||||
build::output(90, key_id5.clone()),
|
||||
@@ -116,7 +110,7 @@ fn test_some_raw_txs() {
|
||||
).unwrap();
|
||||
|
||||
// tx4 spends the other output from tx1 and the output from tx3
|
||||
let tx4 = build::transaction_with_offset(
|
||||
let tx4 = build::transaction(
|
||||
vec![
|
||||
build::input(150, key_id3.clone()),
|
||||
build::input(90, key_id5.clone()),
|
||||
@@ -160,47 +154,87 @@ fn test_unexpected_zip() {
|
||||
assert!(txhashset::zip_read(db_root.clone(), &BlockHeader::default()).is_ok());
|
||||
// Check that the temp dir dos not contains the strange files
|
||||
let txhashset_zip_path = Path::new(&db_root).join("txhashset_zip");
|
||||
assert!(txhashset_contains_expected_files("txhashset_zip".to_string(), txhashset_zip_path.clone()));
|
||||
assert!(txhashset_contains_expected_files(
|
||||
"txhashset_zip".to_string(),
|
||||
txhashset_zip_path.clone()
|
||||
));
|
||||
fs::remove_dir_all(Path::new(&db_root).join("txhashset_zip")).unwrap();
|
||||
|
||||
let zip_file = File::open(zip_path).unwrap();
|
||||
assert!(txhashset::zip_write(db_root.clone(), zip_file, &BlockHeader::default()).is_ok());
|
||||
// Check that the txhashset dir dos not contains the strange files
|
||||
let txhashset_path = Path::new(&db_root).join("txhashset");
|
||||
assert!(txhashset_contains_expected_files("txhashset".to_string(), txhashset_path.clone()));
|
||||
assert!(txhashset_contains_expected_files(
|
||||
"txhashset".to_string(),
|
||||
txhashset_path.clone()
|
||||
));
|
||||
fs::remove_dir_all(Path::new(&db_root).join("txhashset")).unwrap();
|
||||
}
|
||||
|
||||
fn write_file (db_root: String) {
|
||||
fn write_file(db_root: String) {
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&db_root).join("txhashset").join("kernel").join("strange0")).unwrap();
|
||||
.open(
|
||||
Path::new(&db_root)
|
||||
.join("txhashset")
|
||||
.join("kernel")
|
||||
.join("strange0"),
|
||||
)
|
||||
.unwrap();
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&db_root).join("txhashset").join("strange1")).unwrap();
|
||||
.open(Path::new(&db_root).join("txhashset").join("strange1"))
|
||||
.unwrap();
|
||||
fs::create_dir(Path::new(&db_root).join("txhashset").join("strange_dir")).unwrap();
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&db_root).join("txhashset").join("strange_dir").join("strange2")).unwrap();
|
||||
fs::create_dir(Path::new(&db_root).join("txhashset").join("strange_dir").join("strange_subdir")).unwrap();
|
||||
.open(
|
||||
Path::new(&db_root)
|
||||
.join("txhashset")
|
||||
.join("strange_dir")
|
||||
.join("strange2"),
|
||||
)
|
||||
.unwrap();
|
||||
fs::create_dir(
|
||||
Path::new(&db_root)
|
||||
.join("txhashset")
|
||||
.join("strange_dir")
|
||||
.join("strange_subdir"),
|
||||
).unwrap();
|
||||
OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(Path::new(&db_root).join("txhashset").join("strange_dir").join("strange_subdir").join("strange3")).unwrap();
|
||||
.open(
|
||||
Path::new(&db_root)
|
||||
.join("txhashset")
|
||||
.join("strange_dir")
|
||||
.join("strange_subdir")
|
||||
.join("strange3"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn txhashset_contains_expected_files(dirname: String, path_buf: PathBuf) -> bool {
|
||||
let list_zip_files = file::list_files(path_buf.into_os_string().into_string().unwrap());
|
||||
let zip_files_hashset: HashSet<_> = HashSet::from_iter(list_zip_files.iter().cloned());
|
||||
let expected_files = vec![dirname, "output".to_string(), "rangeproof".to_string(), "kernel".to_string(), "pmmr_hash.bin".to_string(), "pmmr_data.bin".to_string()];
|
||||
let expected_files = vec![
|
||||
dirname,
|
||||
"output".to_string(),
|
||||
"rangeproof".to_string(),
|
||||
"kernel".to_string(),
|
||||
"pmmr_hash.bin".to_string(),
|
||||
"pmmr_data.bin".to_string(),
|
||||
];
|
||||
let expected_files_hashset = HashSet::from_iter(expected_files.iter().cloned());
|
||||
let intersection: HashSet<_> = zip_files_hashset.difference(&expected_files_hashset).collect();
|
||||
let intersection: HashSet<_> = zip_files_hashset
|
||||
.difference(&expected_files_hashset)
|
||||
.collect();
|
||||
if intersection.is_empty() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user