diff --git a/common/src/block.rs b/common/src/block.rs index 24da8c7..5e256d8 100644 --- a/common/src/block.rs +++ b/common/src/block.rs @@ -1,7 +1,7 @@ use rs_merkle::Hasher; use std::io::{Cursor, Read}; -use crate::{transaction::TransactionBody, OwnHasher}; +use crate::{OwnHasher, transaction::TransactionBody}; pub type BlockHash = [u8; 32]; pub type BlockId = u64; diff --git a/common/src/lib.rs b/common/src/lib.rs index a0e6df8..67d628d 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,6 @@ use rs_merkle::Hasher; use serde::Deserialize; -use sha2::{digest::FixedOutput, Digest, Sha256}; +use sha2::{Digest, Sha256, digest::FixedOutput}; pub mod block; pub mod commitment; diff --git a/common/src/transaction.rs b/common/src/transaction.rs index 336635d..956853f 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -1,7 +1,4 @@ -use k256::ecdsa::{ - Signature, SigningKey, VerifyingKey, - signature::{Signer, Verifier}, -}; +use k256::ecdsa::{Signature, SigningKey, VerifyingKey}; use log::info; use serde::{Deserialize, Serialize}; @@ -188,14 +185,11 @@ pub type SignaturePrivateKey = SigningKey; #[cfg(test)] mod tests { - use super::*; - use k256::{FieldBytes, ecdsa::signature::Signer}; - use secp256k1_zkp::{Tweak, constants::SECRET_KEY_SIZE}; use sha2::{Digest, digest::FixedOutput}; use crate::{ - transaction::{TransactionBody, TxKind}, TreeHashType, + transaction::{TransactionBody, TxKind}, }; fn test_transaction_body() -> TransactionBody { @@ -228,62 +222,5 @@ mod tests { let body_new = TransactionBody::from_bytes(body_bytes); assert_eq!(body, body_new); - #[test] - fn test_into_authenticated_succeeds_for_valid_signature() { - let transaction = test_transaction(); - let authenticated_tx = transaction.clone().into_authenticated().unwrap(); - - let signature = authenticated_tx.transaction().signature; - let hash = authenticated_tx.hash(); - - assert_eq!(authenticated_tx.transaction(), &transaction); - assert_eq!(hash, &transaction.body.hash()); - assert!( - authenticated_tx - .transaction() - .public_key - .verify(&transaction.body.to_bytes(), &signature) - .is_ok() - ); - } - - #[test] - fn test_into_authenticated_fails_for_invalid_signature() { - let body = test_transaction_body(); - let key_bytes = FieldBytes::from_slice(&[37; 32]); - let private_key: SigningKey = SigningKey::from_bytes(key_bytes).unwrap(); - let transaction = { - let mut this = Transaction::new(body, private_key.clone()); - // Modify the signature to make it invalid - // We do this by changing it to the signature of something else - this.signature = private_key.sign(b"deadbeef"); - this - }; - - matches!( - transaction.into_authenticated(), - Err(TransactionSignatureError::InvalidSignature) - ); - } - - #[test] - fn test_authenticated_transaction_getter() { - let transaction = test_transaction(); - let authenticated_tx = transaction.clone().into_authenticated().unwrap(); - assert_eq!(authenticated_tx.transaction(), &transaction); - } - - #[test] - fn test_authenticated_transaction_hash_getter() { - let transaction = test_transaction(); - let authenticated_tx = transaction.clone().into_authenticated().unwrap(); - assert_eq!(authenticated_tx.hash(), &transaction.body.hash()); - } - - #[test] - fn test_authenticated_transaction_into_transaction() { - let transaction = test_transaction(); - let authenticated_tx = transaction.clone().into_authenticated().unwrap(); - assert_eq!(authenticated_tx.into_transaction(), transaction); } } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 0ce778a..8571d36 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use anyhow::Result; -use common::{block::HashableBlockData, transaction::TransactionBody, TreeHashType}; +use common::{TreeHashType, block::HashableBlockData, transaction::TransactionBody}; use config::SequencerConfig; use log::{info, warn}; use mempool::MemPool; diff --git a/sequencer_core/src/sequencer_store/block_store.rs b/sequencer_core/src/sequencer_store/block_store.rs index b3b74ee..4c8f25e 100644 --- a/sequencer_core/src/sequencer_store/block_store.rs +++ b/sequencer_core/src/sequencer_store/block_store.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, path::Path}; use anyhow::Result; -use common::{block::Block, transaction::TransactionBody, TreeHashType}; +use common::{TreeHashType, block::Block, transaction::TransactionBody}; use storage::RocksDBIO; pub struct SequecerBlockStore { diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index fb06727..a9f828e 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -5,6 +5,7 @@ use sequencer_core::config::AccountInitialData; use serde_json::Value; use common::{ + TreeHashType, block::HashableBlockData, rpc_primitives::{ errors::RpcError, @@ -18,7 +19,6 @@ use common::{ }, }, transaction::TransactionBody, - TreeHashType, }; use common::rpc_primitives::requests::{ @@ -276,8 +276,8 @@ impl JsonHandler { mod tests { use std::sync::Arc; - use crate::{rpc_handler, JsonHandler}; - use base64::{engine::general_purpose, Engine}; + use crate::{JsonHandler, rpc_handler}; + use base64::{Engine, engine::general_purpose}; use common::{ rpc_primitives::RpcPollingConfig, test_utils::sequencer_sign_key_for_testing, transaction::TransactionBody, diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 6aa9522..ae564d3 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -2,10 +2,9 @@ use std::{fs::File, io::Write, path::PathBuf, str::FromStr, sync::Arc}; use base64::Engine; use common::{ - sequencer_client::{json::SendTxResponse, SequencerClient}, - transaction::TransactionBody, ExecutionFailureKind, sequencer_client::{SequencerClient, json::SendTxResponse}, + transaction::TransactionBody, }; use anyhow::Result; @@ -122,7 +121,7 @@ impl WalletCore { let tx = nssa::PublicTransaction::new(message, witness_set); - Ok(self.sequencer_client.send_tx(tx).await?) + Ok(self.sequencer_client.send_tx_public(tx).await?) } else { Err(ExecutionFailureKind::InsufficientFundsError) }