diff --git a/vdr/Cargo.lock b/vdr/Cargo.lock
index 825467bf..de53b143 100644
--- a/vdr/Cargo.lock
+++ b/vdr/Cargo.lock
@@ -1047,6 +1047,12 @@ dependencies = [
"rand_core",
]
+[[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
[[package]]
name = "gloo-timers"
version = "0.2.6"
@@ -1357,6 +1363,7 @@ dependencies = [
"mockall",
"once_cell",
"rand",
+ "rstest",
"secp256k1 0.28.0",
"serde",
"serde_derive",
@@ -2133,6 +2140,12 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
+[[package]]
+name = "relative-path"
+version = "1.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e898588f33fdd5b9420719948f9f2a32c922a246964576f71ba7f24f80610fbc"
+
[[package]]
name = "reqwest"
version = "0.11.23"
@@ -2203,6 +2216,35 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "rstest"
+version = "0.18.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "97eeab2f3c0a199bc4be135c36c924b6590b88c377d416494288c14f2db30199"
+dependencies = [
+ "futures",
+ "futures-timer",
+ "rstest_macros",
+ "rustc_version",
+]
+
+[[package]]
+name = "rstest_macros"
+version = "0.18.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d428f8247852f894ee1be110b375111b586d4fa431f6c46e64ba5a0dcccbe605"
+dependencies = [
+ "cfg-if",
+ "glob",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "relative-path",
+ "rustc_version",
+ "syn 2.0.37",
+ "unicode-ident",
+]
+
[[package]]
name = "rustc-demangle"
version = "0.1.23"
diff --git a/vdr/Cargo.toml b/vdr/Cargo.toml
index edadacd1..d239ddf9 100644
--- a/vdr/Cargo.toml
+++ b/vdr/Cargo.toml
@@ -47,6 +47,7 @@ web-sys = { version = "0.3.64", optional = true, features = ["Window"] }
web3-wasm = { package = "web3", version = "0.19.0", default-features = false, features = ["wasm", "http", "http-tls"], optional = true }
[dev-dependencies]
+rstest = "0.18.2"
mockall = "0.12.0"
env_logger = "0.10.0"
rand = "0.8.5"
\ No newline at end of file
diff --git a/vdr/src/client/client.rs b/vdr/src/client/client.rs
index 091ed6b7..8fc12850 100644
--- a/vdr/src/client/client.rs
+++ b/vdr/src/client/client.rs
@@ -213,10 +213,9 @@ impl Debug for LedgerClient {
#[cfg(test)]
pub mod test {
use super::*;
- use crate::types::EventLog;
- use async_trait::async_trait;
+ use crate::{client::MockClient, signer::basic_signer::test::basic_signer};
use once_cell::sync::Lazy;
- use std::{env, fs};
+ use std::{env, fs, sync::RwLock};
pub const CHAIN_ID: u64 = 1337;
pub const CONTRACTS_SPEC_BASE_PATH: &str = "../smart_contracts/artifacts/contracts/";
@@ -235,6 +234,7 @@ pub mod test {
"http://127.0.0.1:21004",
];
pub const DEFAULT_NONCE: u64 = 0;
+ pub const INVALID_ADDRESS: &str = "123";
pub static SCHEMA_REGISTRY_ADDRESS: Lazy
=
Lazy::new(|| Address::from("0x0000000000000000000000000000000000005555"));
@@ -302,64 +302,219 @@ pub mod test {
LedgerClient::new(CHAIN_ID, RPC_NODE_ADDRESS, &contracts(), None).unwrap()
}
- pub struct MockClient {}
-
- impl Debug for MockClient {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- write!(f, r#"MockClient {{ }}"#)
- }
- }
-
- #[async_trait]
- impl Client for MockClient {
- async fn get_transaction_count(&self, _address: &Address) -> VdrResult {
- Ok(0)
- }
-
- async fn submit_transaction(&self, _transaction: &[u8]) -> VdrResult> {
- todo!()
- }
+ pub fn mock_client() -> LedgerClient {
+ let mut ledger_client = LedgerClient::new(
+ CHAIN_ID,
+ RPC_NODE_ADDRESS,
+ &contracts(),
+ Some(&QuorumConfig::default()),
+ )
+ .unwrap();
- async fn call_transaction(&self, _to: &str, _transaction: &[u8]) -> VdrResult> {
- todo!()
- }
+ let mut client = MockClient::new();
+ client.expect_get_transaction_count().returning(|_| Ok(0));
- async fn query_events(&self, _query: &EventQuery) -> VdrResult> {
- todo!()
- }
+ ledger_client.client = Box::new(client);
+ ledger_client
+ }
- async fn get_receipt(&self, _hash: &[u8]) -> VdrResult {
- todo!()
- }
+ pub fn write_transaction() -> Transaction {
+ let transaction = Transaction {
+ type_: TransactionType::Write,
+ from: Some(TRUSTEE_ACC.clone()),
+ to: VALIDATOR_CONTROL_ADDRESS.clone(),
+ nonce: Some(DEFAULT_NONCE.clone()),
+ chain_id: CHAIN_ID,
+ data: vec![],
+ signature: RwLock::new(None),
+ hash: None,
+ };
+ let signer = basic_signer();
+ let sign_bytes = transaction.get_signing_bytes().unwrap();
+ let signature = signer.sign(&sign_bytes, TRUSTEE_ACC.as_ref()).unwrap();
+ transaction.set_signature(signature);
- async fn get_block(&self, _block: Option) -> VdrResult {
- todo!()
- }
+ transaction
+ }
- async fn get_transaction(&self, _hash: &[u8]) -> VdrResult