Skip to content

Commit

Permalink
fix validation tests
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic authored and appetrosyan committed Dec 20, 2022
1 parent 4b32e1d commit 2901afa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
4 changes: 3 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ impl Iroha {

// Validate every transaction in genesis block
if let Some(ref genesis) = genesis {
let wsv_clone = wsv.clone();

transaction_validator
.validate_every(genesis.iter().cloned(), &wsv)
.validate_every(genesis.iter().cloned(), &wsv_clone)
.wrap_err("Transaction validation failed in genesis block")?;
}

Expand Down
15 changes: 6 additions & 9 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,10 @@ impl ChainedBlock {
) -> ValidBlock {
let mut txs = Vec::new();
let mut rejected = Vec::new();
let wsv_clone = WorldStateView::clone(wsv);
let wsv = if self.header.is_genesis() {
wsv
} else {
&wsv_clone
};

let wsv = wsv.clone();
for tx in self.transactions {
match transaction_validator.validate(tx.into_v1(), self.header.is_genesis(), wsv) {
match transaction_validator.validate(tx.into_v1(), self.header.is_genesis(), &wsv) {
Ok(tx) => txs.push(tx),
Err(tx) => {
iroha_logger::warn!(
Expand Down Expand Up @@ -578,6 +574,7 @@ impl CandidateBlock {
);
}

let wsv = wsv.clone();
let CandidateBlock {
header,
rejected_transactions,
Expand Down Expand Up @@ -617,7 +614,7 @@ impl CandidateBlock {
.map(|accepted_tx| {
accepted_tx.and_then(|tx| {
transaction_validator
.validate(tx, header.is_genesis(), wsv)
.validate(tx, header.is_genesis(), &wsv)
.map_err(|rejected_tx| rejected_tx.into_v1().rejection_reason)
.wrap_err("Failed to validate transaction")
})
Expand All @@ -639,7 +636,7 @@ impl CandidateBlock {
})
.map(|accepted_tx| {
accepted_tx.and_then(|tx| {
match transaction_validator.validate(tx, header.is_genesis(), wsv) {
match transaction_validator.validate(tx, header.is_genesis(), &wsv) {
Err(rejected_transaction) => Ok(rejected_transaction),
Ok(_) => Err(eyre!("Transactions which supposed to be rejected is valid")),
}
Expand Down
15 changes: 2 additions & 13 deletions core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,8 @@ impl TransactionValidator {
}));
}

if is_genesis {
let wsv_cloned = WorldStateView::clone(&wsv);
self.validate_with_builtin_validators(&tx, &wsv_cloned, is_genesis)?;
} else {
self.validate_with_builtin_validators(&tx, &wsv, is_genesis)?;
}

if is_genesis {
let wsv_cloned = WorldStateView::clone(&wsv);
Self::validate_with_runtime_validators(tx, &wsv_cloned)
} else {
Self::validate_with_runtime_validators(tx, &wsv)
}
self.validate_with_builtin_validators(&tx, wsv, is_genesis)?;
Self::validate_with_runtime_validators(tx, wsv)
}

/// Validate signatures for the given transaction
Expand Down

0 comments on commit 2901afa

Please sign in to comment.