Browse Source

contract/consensus: tests fixed

aggstam 3 years ago
parent
commit
ee54c27b67

+ 1 - 2
src/contract/consensus/src/client/proposal_v1_2.rs

@@ -259,8 +259,7 @@ pub fn create_proposal_proof(
     };
     };
 
 
     // New coin
     // New coin
-    let new_serial =
-        poseidon_hash([SERIAL_PREFIX, input.secret.inner(), input.note.serial]);
+    let new_serial = poseidon_hash([SERIAL_PREFIX, input.secret.inner(), input.note.serial]);
     let new_serial_blind = pallas::Scalar::random(&mut OsRng);
     let new_serial_blind = pallas::Scalar::random(&mut OsRng);
     let new_serial_commit = pedersen_commitment_base(new_serial, new_serial_blind);
     let new_serial_commit = pedersen_commitment_base(new_serial, new_serial_blind);
     let new_value_commit = pedersen_commitment_u64(output.value, output.value_blind);
     let new_value_commit = pedersen_commitment_u64(output.value, output.value_blind);

+ 35 - 34
src/contract/consensus/tests/stake_unstake.rs

@@ -94,40 +94,41 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
 
 
     // Verify values match
     // Verify values match
     assert!(alice_oc.note.value == alice_staked_oc.note.value);
     assert!(alice_oc.note.value == alice_staked_oc.note.value);
-    /*
-        // We simulate the proposal of genesis slot
-        let slot_checkpoint = th.get_slot_checkpoints_by_slot(current_slot).await?;
-
-        // With alice's current coin value she can become the slot proposer,
-        // so she creates a proposal transaction to burn her staked coin,
-        // reward herself and mint the new coin.
-        info!(target: "consensus", "[Alice] ====================");
-        info!(target: "consensus", "[Alice] Building proposal tx");
-        info!(target: "consensus", "[Alice] ====================");
-        let (proposal_tx, proposal_params) =
-            th.proposal(Holder::Alice, slot_checkpoint, alice_staked_oc.clone())?;
-
-        info!(target: "consensus", "[Faucet] ===========================");
-        info!(target: "consensus", "[Faucet] Executing Alice proposal tx");
-        info!(target: "consensus", "[Faucet] ===========================");
-        th.execute_proposal_tx(Holder::Faucet, proposal_tx.clone(), &proposal_params, current_slot)
-            .await?;
-
-        info!(target: "consensus", "[Alice] ===========================");
-        info!(target: "consensus", "[Alice] Executing Alice proposal tx");
-        info!(target: "consensus", "[Alice] ===========================");
-        th.execute_proposal_tx(Holder::Alice, proposal_tx, &proposal_params, current_slot).await?;
-
-        th.assert_trees();
-
-        // Gather new staked owncoin which includes the reward
-        let alice_rewarded_staked_oc =
-            th.gather_owncoin(Holder::Alice, proposal_params.output, true)?;
-
-        // Verify values match
-        assert!((alice_staked_oc.note.value + REWARD) == alice_rewarded_staked_oc.note.value);
-    */
-    let alice_rewarded_staked_oc = alice_staked_oc;
+
+    // We simulate the proposal of genesis slot
+    let slot_checkpoint = th.get_slot_checkpoints_by_slot(current_slot).await?;
+
+    // With alice's current coin value she can become the slot proposer,
+    // so she creates a proposal transaction to burn her staked coin,
+    // reward herself and mint the new coin.
+    info!(target: "consensus", "[Alice] ====================");
+    info!(target: "consensus", "[Alice] Building proposal tx");
+    info!(target: "consensus", "[Alice] ====================");
+    let (proposal_tx, proposal_params, proposal_secret_key) =
+        th.proposal(Holder::Alice, slot_checkpoint, alice_staked_oc.clone())?;
+
+    info!(target: "consensus", "[Faucet] ===========================");
+    info!(target: "consensus", "[Faucet] Executing Alice proposal tx");
+    info!(target: "consensus", "[Faucet] ===========================");
+    th.execute_proposal_tx(Holder::Faucet, proposal_tx.clone(), &proposal_params, current_slot)
+        .await?;
+
+    info!(target: "consensus", "[Alice] ===========================");
+    info!(target: "consensus", "[Alice] Executing Alice proposal tx");
+    info!(target: "consensus", "[Alice] ===========================");
+    th.execute_proposal_tx(Holder::Alice, proposal_tx, &proposal_params, current_slot).await?;
+
+    th.assert_trees();
+
+    // Gather new staked owncoin which includes the reward
+    let alice_rewarded_staked_oc = th.gather_consensus_owncoin(
+        Holder::Alice,
+        proposal_params.output,
+        Some(proposal_secret_key),
+    )?;
+
+    // Verify values match
+    assert!((alice_staked_oc.note.value + REWARD) == alice_rewarded_staked_oc.note.value);
 
 
     // Now Alice can unstake her owncoin
     // Now Alice can unstake her owncoin
     info!(target: "consensus", "[Alice] ===================");
     info!(target: "consensus", "[Alice] ===================");