|
|
@@ -43,7 +43,6 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
|
|
|
|
|
|
// Slot to verify against
|
|
|
let mut current_slot = 1;
|
|
|
- let mut current_epoch = 1;
|
|
|
|
|
|
// Initialize harness
|
|
|
let mut th = ConsensusTestHarness::new().await?;
|
|
|
@@ -73,18 +72,17 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
|
|
|
info!(target: "consensus", "[Alice] Building stake tx");
|
|
|
info!(target: "consensus", "[Alice] =================");
|
|
|
let (stake_tx, stake_params, stake_secret_key) =
|
|
|
- th.stake_native(Holder::Alice, current_epoch, alice_oc.clone())?;
|
|
|
+ th.stake(Holder::Alice, current_slot, alice_oc.clone()).await?;
|
|
|
|
|
|
info!(target: "consensus", "[Faucet] ========================");
|
|
|
info!(target: "consensus", "[Faucet] Executing Alice stake tx");
|
|
|
info!(target: "consensus", "[Faucet] ========================");
|
|
|
- th.execute_stake_native_tx(Holder::Faucet, stake_tx.clone(), &stake_params, current_slot)
|
|
|
- .await?;
|
|
|
+ th.execute_stake_tx(Holder::Faucet, stake_tx.clone(), &stake_params, current_slot).await?;
|
|
|
|
|
|
info!(target: "consensus", "[Alice] ========================");
|
|
|
info!(target: "consensus", "[Alice] Executing Alice stake tx");
|
|
|
info!(target: "consensus", "[Alice] ========================");
|
|
|
- th.execute_stake_native_tx(Holder::Alice, stake_tx, &stake_params, current_slot).await?;
|
|
|
+ th.execute_stake_tx(Holder::Alice, stake_tx, &stake_params, current_slot).await?;
|
|
|
|
|
|
th.assert_trees();
|
|
|
|
|
|
@@ -97,27 +95,18 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
|
|
|
|
|
|
// We progress one slot
|
|
|
current_slot += 1;
|
|
|
-
|
|
|
- // We generate current slot checkpoint to simulate its proposal
|
|
|
let slot_checkpoint = th.generate_slot_checkpoint(current_slot).await?;
|
|
|
|
|
|
// Since alice didn't wait for the grace period to pass, her proposal should fail
|
|
|
- info!(target: "consensus", "[Alice] ====================");
|
|
|
- info!(target: "consensus", "[Alice] Building proposal tx");
|
|
|
- info!(target: "consensus", "[Alice] ====================");
|
|
|
- let (proposal_tx, _, _) =
|
|
|
- th.proposal(Holder::Alice, slot_checkpoint, alice_staked_oc.clone())?;
|
|
|
-
|
|
|
info!(target: "consensus", "[Malicious] =====================================");
|
|
|
info!(target: "consensus", "[Malicious] Checking proposal before grace period");
|
|
|
info!(target: "consensus", "[Malicious] =====================================");
|
|
|
+ let (proposal_tx, _, _) =
|
|
|
+ th.proposal(Holder::Alice, slot_checkpoint, alice_staked_oc.clone())?;
|
|
|
th.execute_erroneous_proposal_txs(Holder::Alice, vec![proposal_tx], current_slot, 1).await?;
|
|
|
|
|
|
// We progress after grace period
|
|
|
- current_epoch += calculate_grace_period();
|
|
|
- current_slot += current_epoch * EPOCH_LENGTH;
|
|
|
-
|
|
|
- // We generate current slot checkpoint to simulate its proposal
|
|
|
+ current_slot += (calculate_grace_period() * EPOCH_LENGTH) + EPOCH_LENGTH;
|
|
|
let slot_checkpoint = th.generate_slot_checkpoint(current_slot).await?;
|
|
|
|
|
|
// With alice's current coin value she can become the slot proposer,
|
|
|
@@ -152,23 +141,95 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
|
|
|
// Verify values match
|
|
|
assert!((alice_staked_oc.note.value + REWARD) == alice_rewarded_staked_oc.note.value);
|
|
|
|
|
|
+ // We progress one slot
|
|
|
+ current_slot += 1;
|
|
|
+ th.generate_slot_checkpoint(current_slot).await?;
|
|
|
+
|
|
|
+ // Alice can request for her owncoin to get unstaked
|
|
|
+ info!(target: "consensus", "[Alice] ===========================");
|
|
|
+ info!(target: "consensus", "[Alice] Building unstake request tx");
|
|
|
+ info!(target: "consensus", "[Alice] ===========================");
|
|
|
+ let (unstake_request_tx, unstake_request_params, unstake_request_secret_key) =
|
|
|
+ th.unstake_request(Holder::Alice, current_slot, alice_rewarded_staked_oc.clone()).await?;
|
|
|
+
|
|
|
+ info!(target: "consensus", "[Faucet] ==================================");
|
|
|
+ info!(target: "consensus", "[Faucet] Executing Alice unstake request tx");
|
|
|
+ info!(target: "consensus", "[Faucet] ==================================");
|
|
|
+ th.execute_unstake_request_tx(
|
|
|
+ Holder::Faucet,
|
|
|
+ unstake_request_tx.clone(),
|
|
|
+ &unstake_request_params,
|
|
|
+ current_slot,
|
|
|
+ )
|
|
|
+ .await?;
|
|
|
+
|
|
|
+ info!(target: "consensus", "[Alice] ==================================");
|
|
|
+ info!(target: "consensus", "[Alice] Executing Alice unstake request tx");
|
|
|
+ info!(target: "consensus", "[Alice] ==================================");
|
|
|
+ th.execute_unstake_request_tx(
|
|
|
+ Holder::Alice,
|
|
|
+ unstake_request_tx,
|
|
|
+ &unstake_request_params,
|
|
|
+ current_slot,
|
|
|
+ )
|
|
|
+ .await?;
|
|
|
+
|
|
|
+ th.assert_trees();
|
|
|
+
|
|
|
+ // Gather new unstake request owncoin
|
|
|
+ let alice_unstake_request_oc = th.gather_consensus_owncoin(
|
|
|
+ Holder::Alice,
|
|
|
+ unstake_request_params.output,
|
|
|
+ Some(unstake_request_secret_key),
|
|
|
+ )?;
|
|
|
+
|
|
|
+ // Verify values match
|
|
|
+ assert!(alice_rewarded_staked_oc.note.value == alice_unstake_request_oc.note.value);
|
|
|
+
|
|
|
+ // Now we will test if we can reuse token in proposal or unstake it again
|
|
|
+ current_slot += 1;
|
|
|
+ let slot_checkpoint = th.generate_slot_checkpoint(current_slot).await?;
|
|
|
+
|
|
|
+ info!(target: "consensus", "[Malicious] ========================================");
|
|
|
+ info!(target: "consensus", "[Malicious] Checking using unstaked coin in proposal");
|
|
|
+ info!(target: "consensus", "[Malicious] ========================================");
|
|
|
+ let (proposal_tx, _, _) =
|
|
|
+ th.proposal(Holder::Alice, slot_checkpoint, alice_unstake_request_oc.clone())?;
|
|
|
+ th.execute_erroneous_proposal_txs(Holder::Alice, vec![proposal_tx], current_slot, 1).await?;
|
|
|
+
|
|
|
+ info!(target: "consensus", "[Malicious] =============================");
|
|
|
+ info!(target: "consensus", "[Malicious] Checking unstaking coin again");
|
|
|
+ info!(target: "consensus", "[Malicious] =============================");
|
|
|
+ let (unstake_request_tx, _, _) =
|
|
|
+ th.unstake_request(Holder::Alice, current_slot, alice_unstake_request_oc.clone()).await?;
|
|
|
+ th.execute_erroneous_unstake_request_txs(
|
|
|
+ Holder::Alice,
|
|
|
+ vec![unstake_request_tx],
|
|
|
+ current_slot,
|
|
|
+ 1,
|
|
|
+ )
|
|
|
+ .await?;
|
|
|
+
|
|
|
+ // We progress after grace period
|
|
|
+ current_slot += (calculate_grace_period() * EPOCH_LENGTH) + EPOCH_LENGTH;
|
|
|
+
|
|
|
// Now Alice can unstake her owncoin
|
|
|
info!(target: "consensus", "[Alice] ===================");
|
|
|
info!(target: "consensus", "[Alice] Building unstake tx");
|
|
|
info!(target: "consensus", "[Alice] ===================");
|
|
|
let (unstake_tx, unstake_params, unstake_secret_key) =
|
|
|
- th.unstake_native(Holder::Alice, alice_rewarded_staked_oc.clone())?;
|
|
|
+ th.unstake(Holder::Alice, alice_unstake_request_oc.clone())?;
|
|
|
|
|
|
info!(target: "consensus", "[Faucet] ==========================");
|
|
|
info!(target: "consensus", "[Faucet] Executing Alice unstake tx");
|
|
|
info!(target: "consensus", "[Faucet] ==========================");
|
|
|
- th.execute_unstake_native_tx(Holder::Faucet, unstake_tx.clone(), &unstake_params, current_slot)
|
|
|
+ th.execute_unstake_tx(Holder::Faucet, unstake_tx.clone(), &unstake_params, current_slot)
|
|
|
.await?;
|
|
|
|
|
|
info!(target: "consensus", "[Alice] ==========================");
|
|
|
info!(target: "consensus", "[Alice] Executing Alice unstake tx");
|
|
|
info!(target: "consensus", "[Alice] ==========================");
|
|
|
- th.execute_unstake_native_tx(Holder::Alice, unstake_tx, &unstake_params, current_slot).await?;
|
|
|
+ th.execute_unstake_tx(Holder::Alice, unstake_tx, &unstake_params, current_slot).await?;
|
|
|
|
|
|
th.assert_trees();
|
|
|
|
|
|
@@ -177,7 +238,7 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
|
|
|
th.gather_owncoin(Holder::Alice, unstake_params.output, Some(unstake_secret_key))?;
|
|
|
|
|
|
// Verify values match
|
|
|
- assert!(alice_rewarded_staked_oc.note.value == alice_unstaked_oc.note.value);
|
|
|
+ assert!(alice_unstake_request_oc.note.value == alice_unstaked_oc.note.value);
|
|
|
|
|
|
// Statistics
|
|
|
th.statistics();
|