Răsfoiți Sursa

src/contract/money: add check for already initialized logger and commented wip test, repo fmt

aggstam 3 ani în urmă
părinte
comite
7c6cfd638c

+ 7 - 19
src/consensus/leadcoin.rs

@@ -177,12 +177,7 @@ impl LeadCoin {
     }
 
     pub fn sn(&self) -> pallas::Base {
-        let sn_msg = [
-            pallas::Base::from(PREFIX_SN),
-            self.coin1_sk_root.inner(),
-            self.nonce,
-            ZERO,
-        ];
+        let sn_msg = [pallas::Base::from(PREFIX_SN), self.coin1_sk_root.inner(), self.nonce, ZERO];
         poseidon_hash(sn_msg)
     }
 
@@ -216,12 +211,8 @@ impl LeadCoin {
         let c1_cm = self.coin1_commitment.to_affine().coordinates().unwrap();
         let c2_cm = self.coin2_commitment.to_affine().coordinates().unwrap();
         // lottery seed
-        let seed_msg = [
-            pallas::Base::from(PREFIX_SEED),
-            self.coin1_sk_root.inner(),
-            self.nonce,
-            ZERO,
-        ];
+        let seed_msg =
+            [pallas::Base::from(PREFIX_SEED), self.coin1_sk_root.inner(), self.nonce, ZERO];
         let seed = poseidon_hash(seed_msg);
         // y
         let y_msg = [seed, self.y_mu];
@@ -249,9 +240,8 @@ impl LeadCoin {
     }
 
     fn util_pk(sk_root: MerkleNode, tau: pallas::Base) -> pallas::Base {
-        let pk_msg =
-            [pallas::Base::from(PREFIX_PK), sk_root.inner(), tau, ZERO];
-        
+        let pk_msg = [pallas::Base::from(PREFIX_PK), sk_root.inner(), tau, ZERO];
+
         poseidon_hash(pk_msg)
     }
     /// calculate coin public key: hash of root coin secret key
@@ -261,9 +251,8 @@ impl LeadCoin {
     }
 
     fn util_derived_rho(sk_root: MerkleNode, nonce: pallas::Base) -> pallas::Base {
-        let rho_msg =
-            [pallas::Base::from(PREFIX_EVL), sk_root.inner(), nonce, ZERO];
-        
+        let rho_msg = [pallas::Base::from(PREFIX_EVL), sk_root.inner(), nonce, ZERO];
+
         poseidon_hash(rho_msg)
     }
     /// calculate derived coin nonce: hash of root coin secret key
@@ -289,7 +278,6 @@ impl LeadCoin {
         info!("is_leader(): y = {:?}", y);
         info!("is_leader(): T = {:?}", target);
 
-        
         y < target
     }
 

+ 1 - 1
src/contract/money/Makefile

@@ -20,7 +20,7 @@ ZKAS_BIN = $(ZKAS_SRC:=.bin)
 WASM_BIN = money_contract.wasm
 
 # Filter test to run
-FILTER = 'tx_faucet_verification'
+FILTER = ''
 
 all: $(ZKAS_BIN) $(WASM_BIN)
 

+ 17 - 17
src/contract/money/tests/tx_verification.rs

@@ -45,7 +45,7 @@ use darkfi_sdk::{
     tx::ContractCall,
 };
 use darkfi_serial::{deserialize, serialize, Encodable};
-use log::info;
+use log::{info, warn};
 use rand::rngs::OsRng;
 
 use darkfi_money_contract::{
@@ -58,12 +58,14 @@ use darkfi_money_contract::{
 fn init_logger() -> Result<()> {
     let mut cfg = simplelog::ConfigBuilder::new();
     cfg.add_filter_ignore("sled".to_string());
-    simplelog::TermLogger::init(
+    if let Err(_) = simplelog::TermLogger::init(
         simplelog::LevelFilter::Info,
         cfg.build(),
         simplelog::TerminalMode::Mixed,
         simplelog::ColorChoice::Auto,
-    )?;
+    ) {
+        warn!("Logger already initialized");
+    }
 
     Ok(())
 }
@@ -391,7 +393,7 @@ async fn tx_alice_to_alice_verification() -> Result<()> {
 }
 
 /// Check Alice to Bob N transactions with random amounts verification performance
-#[async_std::test]
+//#[async_std::test]
 async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
     init_logger()?;
 
@@ -426,10 +428,10 @@ async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
         false,
     )
     .await?;
-    
+
     // Generate Bob keys
     let bob_kp = Keypair::random(&mut OsRng);
-    
+
     // TODO: Generate more tokens to play with
     // Generating airdrop transaction
     info!("Generating faucet airdrop transaction");
@@ -457,15 +459,13 @@ async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
     // Executing airdrop transaction on Alice's blockchain db
     alice_state.read().await.verify_transactions(&[tx.clone()], true).await?;
     alice_merkle_tree.append(&MerkleNode::from(params.outputs[0].coin));
-    
+
     // Extracting aidrop owncoin
     let leaf_position = alice_merkle_tree.witness().unwrap();
     let params: MoneyTransferParams = deserialize(&tx.calls[0].data[1..])?;
     let output = &params.outputs[0];
-    let encrypted_note = EncryptedNote {
-        ciphertext: output.ciphertext.clone(),
-        ephem_public: output.ephem_public,
-    };
+    let encrypted_note =
+        EncryptedNote { ciphertext: output.ciphertext.clone(), ephem_public: output.ephem_public };
     let note = encrypted_note.decrypt(&alice_kp.secret)?;
     let owncoin = OwnCoin {
         coin: Coin::from(output.coin),
@@ -485,12 +485,12 @@ async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
         //let index = rand::thread_rng().gen_range(0..owncoins.len());
         let index = 0;
         let owncoin = owncoins[index].clone();
-        
+
         // Pick random amount
         // 1000000 = 0.1
         //let amount = rand::thread_rng().gen_range(1000000..owncoin.note.value);
         let amount = decode_base10("1", 8, true)?;
-        
+
         info!("Selected coin balance: {}", owncoin.note.value);
         info!("Transfering amount: {}", amount);
         let (params, proofs, secret_keys, _spent_coins) = build_transfer_tx(
@@ -519,7 +519,7 @@ async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
         alice_merkle_tree.append(&MerkleNode::from(params.outputs[0].coin));
 
         txs.push(tx.clone());
-        
+
         // Replace spent owncoin
         let leaf_position = alice_merkle_tree.witness().unwrap();
         let params: MoneyTransferParams = deserialize(&tx.calls[0].data[1..])?;
@@ -535,17 +535,17 @@ async fn chaotic_tx_alice_to_bob_verification() -> Result<()> {
             secret: alice_kp.secret,
             nullifier: Nullifier::from(poseidon_hash([alice_kp.secret.inner(), note.serial])),
             leaf_position,
-        };        
+        };
         owncoins[index] = owncoin;
     }
     let generation_elapsed_time = init.elapsed();
     assert_eq!(txs.len(), n as usize);
-    
+
     // Sanity check
     info!("Verifying Alice to Bob transactions in Alice state");
     alice_state.read().await.verify_transactions(&txs, true).await?;
 
-    // Verifying transaction    
+    // Verifying transaction
     info!("Verifying Alice to Bob transactions...");
     let init = Timestamp::current_time();
     faucet_state.read().await.verify_transactions(&txs, true).await?;

+ 2 - 3
src/net/protocol/protocol_version.rs

@@ -158,9 +158,8 @@ impl ProtocolVersion {
         self.channel.set_remote_node_id(version.node_id.clone()).await;
 
         // Send version acknowledgement
-        let verack = message::VerackMessage {
-            app: self.settings.app_version.clone().unwrap_or_default(),
-        };
+        let verack =
+            message::VerackMessage { app: self.settings.app_version.clone().unwrap_or_default() };
         self.channel.clone().send(verack).await?;
 
         debug!(target: "net", "ProtocolVersion::recv_version() [END]");