Skip to content

Commit d34b50b

Browse files
authored
Add tests evm transactions jcli (#3822)
1 parent 17c35db commit d34b50b

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jcli/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ thiserror = "1.0"
3737
bytes = "1.1"
3838
rpassword = "5.0"
3939

40+
[features]
41+
evm = ["jormungandr-lib/evm"]
42+
4043
[dependencies.clap]
4144
version = "2.33"
4245
default-features = false
@@ -50,6 +53,10 @@ features = ["blocking", "rustls-tls", "json"]
5053
[dev-dependencies]
5154
assert_fs = "1.0"
5255
predicates = "2.0"
56+
quickcheck = "0.9"
57+
# FIXME required to work with quickcheck 0.9. Remove after migrating another crate or newer quickcheck
58+
rand07 = { package = "rand", version = "0.7" }
59+
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
5360

5461
[build-dependencies]
5562
versionisator = "1.0.2"

jcli/src/jcli_lib/transaction/add_evm_transaction.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::jcli_lib::transaction::{common, Error};
22
use jormungandr_lib::interfaces::EvmTransaction;
33
use structopt::StructOpt;
44

5-
#[derive(StructOpt)]
5+
#[derive(StructOpt, Debug)]
66
#[structopt(rename_all = "kebab-case")]
77
pub struct AddEvmTransaction {
88
#[structopt(flatten)]
@@ -19,3 +19,41 @@ impl AddEvmTransaction {
1919
self.common.store(&transaction)
2020
}
2121
}
22+
23+
#[cfg(all(test, feature = "evm"))]
24+
mod test {
25+
use super::*;
26+
use chain_impl_mockchain::evm;
27+
use quickcheck::Arbitrary;
28+
29+
impl Arbitrary for AddEvmTransaction {
30+
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
31+
Self {
32+
common: common::CommonTransaction { staging_file: None },
33+
evm_transaction: EvmTransaction(evm::EvmTransaction::arbitrary(g)),
34+
}
35+
}
36+
}
37+
38+
impl Clone for AddEvmTransaction {
39+
fn clone(&self) -> Self {
40+
Self {
41+
common: common::CommonTransaction { staging_file: None },
42+
evm_transaction: self.evm_transaction.clone(),
43+
}
44+
}
45+
}
46+
47+
impl PartialEq for AddEvmTransaction {
48+
fn eq(&self, other: &AddEvmTransaction) -> bool {
49+
self.evm_transaction == other.evm_transaction
50+
}
51+
}
52+
53+
quickcheck! {
54+
fn evm_transaction_encode(add_evm_tx: AddEvmTransaction) -> bool {
55+
let hex_tx = format!("{}", add_evm_tx.evm_transaction);
56+
AddEvmTransaction::from_iter(&["", &hex_tx]) == add_evm_tx
57+
}
58+
}
59+
}

jcli/src/jcli_lib/transaction/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct CommonFees {
3232
pub certificate_vote_cast: Option<u64>,
3333
}
3434

35-
#[derive(StructOpt)]
35+
#[derive(StructOpt, Debug)]
3636
#[structopt(rename_all = "kebab-case")]
3737
pub struct CommonTransaction {
3838
/// place where the transaction is going to be save during its staging phase

jcli/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
#[cfg(all(test, feature = "evm"))]
2+
#[macro_use]
3+
extern crate quickcheck;
4+
15
pub mod jcli_lib;
26
pub use crate::jcli_lib::*;

jormungandr-lib/src/interfaces/evm_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use thiserror::Error;
66
use typed_bytes::ByteBuilder;
77

88
#[derive(Debug, Clone, PartialEq, Eq)]
9-
pub struct EvmTransaction(evm::EvmTransaction);
9+
pub struct EvmTransaction(pub evm::EvmTransaction);
1010

1111
#[derive(Debug, Error)]
1212
pub enum EvmTransactionFromStrError {

0 commit comments

Comments
 (0)