Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysidorov committed Mar 30, 2017
1 parent 6577778 commit 249e2ce
Show file tree
Hide file tree
Showing 22 changed files with 347 additions and 228 deletions.
16 changes: 12 additions & 4 deletions examples/anchoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ fn main() {
let dir = GenerateCommand::output_dir(matches);
let start_port = GenerateCommand::start_port(matches).unwrap_or(2000);

let host = matches.value_of("ANCHORING_RPC_HOST").unwrap().to_string();
let user = matches.value_of("ANCHORING_RPC_USER").map(|x| x.to_string());
let passwd = matches.value_of("ANCHORING_RPC_PASSWD").map(|x| x.to_string());
let total_funds: u64 = matches.value_of("ANCHORING_FUNDS")
let host = matches
.value_of("ANCHORING_RPC_HOST")
.unwrap()
.to_string();
let user = matches
.value_of("ANCHORING_RPC_USER")
.map(|x| x.to_string());
let passwd = matches
.value_of("ANCHORING_RPC_PASSWD")
.map(|x| x.to_string());
let total_funds: u64 = matches
.value_of("ANCHORING_FUNDS")
.unwrap()
.parse()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ fn main() {
for node_thread in node_threads {
node_thread.join().unwrap();
}
}
}
37 changes: 22 additions & 15 deletions sandbox_tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub fn gen_update_config_tx(sandbox: &Sandbox,
-> RawTransaction {
let mut cfg = sandbox.cfg();
cfg.actual_from = actual_from;
*cfg.services.get_mut(&ANCHORING_SERVICE.to_string()).unwrap() = service_cfg.to_json();
*cfg.services
.get_mut(&ANCHORING_SERVICE.to_string())
.unwrap() = service_cfg.to_json();
let tx = TxConfig::new(&sandbox.p(0), &cfg.serialize(), actual_from, sandbox.s(0));
tx.raw().clone()
}
Expand All @@ -78,10 +80,7 @@ pub fn block_hash_on_height(sandbox: &Sandbox, height: u64) -> Hash {
let blockchain = sandbox.blockchain_ref();
let view = blockchain.view();
let schema = Schema::new(&view);
schema.heights()
.get(height)
.unwrap()
.unwrap()
schema.heights().get(height).unwrap().unwrap()
}

/// Anchor genesis block using funding tx
Expand Down Expand Up @@ -130,11 +129,15 @@ pub fn anchor_first_block(sandbox: &Sandbox,
params: [anchored_tx.to_hex()]
}]);

let signatures = signatures.into_iter().map(|tx| tx.raw().clone()).collect::<Vec<_>>();
let signatures = signatures
.into_iter()
.map(|tx| tx.raw().clone())
.collect::<Vec<_>>();
add_one_height_with_transactions(&sandbox, &sandbox_state, &signatures);

let txs =
(0..4).map(|idx| gen_service_tx_lect(sandbox, idx, &anchored_tx, 1)).collect::<Vec<_>>();
let txs = (0..4)
.map(|idx| gen_service_tx_lect(sandbox, idx, &anchored_tx, 1))
.collect::<Vec<_>>();
sandbox.broadcast(txs[0].clone());
add_one_height_with_transactions(sandbox, sandbox_state, &txs);
}
Expand Down Expand Up @@ -211,8 +214,9 @@ pub fn anchor_first_block_lect_lost(sandbox: &Sandbox,
}]);
add_one_height_with_transactions(sandbox, sandbox_state, &[]);

let txs =
(0..4).map(|idx| gen_service_tx_lect(sandbox, idx, &other_lect, 2)).collect::<Vec<_>>();
let txs = (0..4)
.map(|idx| gen_service_tx_lect(sandbox, idx, &other_lect, 2))
.collect::<Vec<_>>();
sandbox.broadcast(txs[0].clone());

client.expect(vec![request! {
Expand Down Expand Up @@ -263,7 +267,8 @@ pub fn anchor_first_block_lect_different(sandbox: &Sandbox,

let (other_lect, other_signatures) = {
let anchored_tx = anchoring_state.latest_anchored_tx();
let other_signatures = anchoring_state.latest_anchored_tx_signatures()
let other_signatures = anchoring_state
.latest_anchored_tx_signatures()
.iter()
.filter(|tx| tx.validator() != 0)
.cloned()
Expand Down Expand Up @@ -298,8 +303,9 @@ pub fn anchor_first_block_lect_different(sandbox: &Sandbox,
}]);
add_one_height_with_transactions(sandbox, sandbox_state, &[]);

let txs =
(0..4).map(|idx| gen_service_tx_lect(sandbox, idx, &other_lect, 2)).collect::<Vec<_>>();
let txs = (0..4)
.map(|idx| gen_service_tx_lect(sandbox, idx, &other_lect, 2))
.collect::<Vec<_>>();
sandbox.broadcast(txs[0].clone());

add_one_height_with_transactions(sandbox, sandbox_state, &txs);
Expand Down Expand Up @@ -356,8 +362,9 @@ pub fn anchor_second_block_normal(sandbox: &Sandbox,
]);
add_one_height_with_transactions(sandbox, sandbox_state, &signatures);

let txs =
(0..4).map(|idx| gen_service_tx_lect(sandbox, idx, &anchored_tx, 2)).collect::<Vec<_>>();
let txs = (0..4)
.map(|idx| gen_service_tx_lect(sandbox, idx, &anchored_tx, 2))
.collect::<Vec<_>>();
sandbox.broadcast(txs[0].clone());
client.expect(vec![request! {
method: "listunspent",
Expand Down
30 changes: 14 additions & 16 deletions sandbox_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,11 @@ impl AnchoringSandboxState {
}

pub fn latest_anchored_tx(&self) -> &AnchoringTx {
&self.latest_anchored_tx
.as_ref()
.unwrap()
.0
&self.latest_anchored_tx.as_ref().unwrap().0
}

pub fn latest_anchored_tx_signatures(&self) -> &[MsgAnchoringSignature] {
self.latest_anchored_tx
.as_ref()
.unwrap()
.1
.as_ref()
self.latest_anchored_tx.as_ref().unwrap().1.as_ref()
}

pub fn gen_anchoring_tx_with_signatures(&mut self,
Expand Down Expand Up @@ -107,7 +100,10 @@ impl AnchoringSandboxState {
};
self.latest_anchored_tx = Some((signed_tx, signs.clone()));

let signs = signs.into_iter().map(|tx| tx.raw().clone()).collect::<Vec<_>>();
let signs = signs
.into_iter()
.map(|tx| tx.raw().clone())
.collect::<Vec<_>>();
(propose_tx, signs)
}

Expand Down Expand Up @@ -177,10 +173,10 @@ pub fn gen_sandbox_anchoring_config(client: &mut AnchoringRpc)
client.expect(requests);
let mut rng: StdRng = SeedableRng::from_seed([1, 2, 3, 4].as_ref());
gen_anchoring_testnet_config_with_rng(client,
btc::Network::Testnet,
4,
ANCHORING_FUNDS,
&mut rng)
btc::Network::Testnet,
4,
ANCHORING_FUNDS,
&mut rng)
}

pub fn anchoring_sandbox<'a, I>(priv_keys: I) -> (Sandbox, AnchoringRpc, AnchoringSandboxState)
Expand All @@ -194,8 +190,10 @@ pub fn anchoring_sandbox<'a, I>(priv_keys: I) -> (Sandbox, AnchoringRpc, Anchori
genesis.frequency = ANCHORING_FREQUENCY;
for &&(ref addr, ref keys) in &priv_keys {
for (id, key) in keys.iter().enumerate() {
nodes[id].private_keys.insert(addr.to_string(),
btc::PrivateKey::from_base58check(key).unwrap());
nodes[id]
.private_keys
.insert(addr.to_string(),
btc::PrivateKey::from_base58check(key).unwrap());
}
}

Expand Down
4 changes: 3 additions & 1 deletion sandbox_tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ fn test_rpc_validateaddress() {
"account":"node_0","address":"n2cCRtaXxRAbmWYhH9sZUBBwqZc8mMV8tb","hdkeypath":"m/0'/0'/1023'","hdmasterkeyid":"e2aabb596d105e11c1838c0b6bede91e1f2a95ee","iscompressed":true,"ismine":true,"isscript":false,"isvalid":true,"iswatchonly":false,"pubkey":"0394a06ac465776c110cb43d530663d7e7df5684013075988917f02ff007edd364","scriptPubKey":"76a914e7588549f0c4149e7949cd7ea933cfcdde45f8c888ac"
}
}]);
client.validateaddress("n2cCRtaXxRAbmWYhH9sZUBBwqZc8mMV8tb").unwrap();
client
.validateaddress("n2cCRtaXxRAbmWYhH9sZUBBwqZc8mMV8tb")
.unwrap();
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions sandbox_tests/tests/anchoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ fn test_anchoring_second_block_additional_funds() {
}]);
add_one_height_with_transactions(&sandbox, &sandbox_state, &[]);

let (_, signatures) =
anchoring_state.gen_anchoring_tx_with_signatures(&sandbox,
10,
block_hash_on_height(&sandbox, 10),
&[funds],
None,
&anchoring_addr);
let (_, signatures) = anchoring_state
.gen_anchoring_tx_with_signatures(&sandbox,
10,
block_hash_on_height(&sandbox, 10),
&[funds],
None,
&anchoring_addr);

sandbox.broadcast(signatures[0].clone());
sandbox.broadcast(signatures[1].clone());
Expand Down
Loading

0 comments on commit 249e2ce

Please sign in to comment.