contract/money/tests/pow_reward: use proper producer tx validation

This commit is contained in:
aggstam
2023-09-15 01:27:37 +03:00
parent 01fac53e39
commit 4d5e779e28
2 changed files with 29 additions and 18 deletions

View File

@@ -25,7 +25,7 @@
//! with detection of erroneous transactions.
use darkfi::Result;
use darkfi_contract_test_harness::{init_logger, Holder, TestHarness, TxAction};
use darkfi_contract_test_harness::{init_logger, Holder, TestHarness};
use darkfi_sdk::{blockchain::expected_reward, crypto::DARK_TOKEN_ID};
use log::info;
@@ -56,14 +56,8 @@ fn pow_reward() -> Result<()> {
info!(target: "money", "[Malicious] =======================================");
info!(target: "money", "[Malicious] Checking PoW reward tx for genesis slot");
info!(target: "money", "[Malicious] =======================================");
th.execute_erroneous_txs(
TxAction::MoneyPoWReward,
&Holder::Alice,
&[pow_reward_tx.clone()],
current_slot,
1,
)
.await?;
th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_slot)
.await?;
current_slot += 1;
th.generate_slot(current_slot).await?;
@@ -78,14 +72,8 @@ fn pow_reward() -> Result<()> {
info!(target: "money", "[Malicious] =======================================");
info!(target: "money", "[Malicious] Checking erroneous amount PoW reward tx");
info!(target: "money", "[Malicious] =======================================");
th.execute_erroneous_txs(
TxAction::MoneyPoWReward,
&Holder::Alice,
&[pow_reward_tx.clone()],
current_slot,
1,
)
.await?;
th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_slot)
.await?;
info!(target: "money", "[Alice] ======================");
info!(target: "money", "[Alice] Building PoW reward tx");

View File

@@ -100,10 +100,33 @@ impl TestHarness {
self.tx_action_benchmarks.get_mut(&TxAction::MoneyPoWReward).unwrap();
let timer = Instant::now();
wallet.validator.read().await.add_transactions(&[tx.clone()], slot, true).await?;
wallet.validator.read().await.add_test_producer_transaction(tx, slot, true).await?;
wallet.money_merkle_tree.append(MerkleNode::from(params.output.coin.inner()));
tx_action_benchmark.verify_times.push(timer.elapsed());
Ok(())
}
pub async fn execute_erroneous_pow_reward_tx(
&mut self,
holder: &Holder,
tx: &Transaction,
slot: u64,
) -> Result<()> {
let wallet = self.holders.get_mut(holder).unwrap();
let tx_action_benchmark =
self.tx_action_benchmarks.get_mut(&TxAction::MoneyPoWReward).unwrap();
let timer = Instant::now();
assert!(wallet
.validator
.read()
.await
.add_test_producer_transaction(tx, slot, true)
.await
.is_err());
tx_action_benchmark.verify_times.push(timer.elapsed());
Ok(())
}
}