Skip to content

Commit

Permalink
sdk unit tests: EthSignature -> EthSignatureInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 1, 2020
1 parent 0f19fc2 commit 73f5763
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
16 changes: 8 additions & 8 deletions core/lib/config/src/test_config/unit_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct TxInput {
pub eth_private_key: Vec<u8>,
#[serde(flatten)]
pub tx: Tx,
pub eth_sign_data: EthSignature,
pub eth_sign_data: EthSignatureInputs,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -133,16 +133,16 @@ pub struct ForcedExit {
// Thus, the variants are now sorted starting with the most constrained ones.
// #[serde(tag = "type", content = "ethSignData")]
#[serde(untagged)]
pub enum EthSignature {
Transfer(Box<TransferSignature>),
Withdraw(Box<WithdrawSignature>),
ChangePubKey(Box<ChangePubKeySignature>),
pub enum EthSignatureInputs {
Transfer(Box<TransferSignatureInputs>),
Withdraw(Box<WithdrawSignatureInputs>),
ChangePubKey(Box<ChangePubKeySignatureInputs>),
ForcedExit,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferSignature {
pub struct TransferSignatureInputs {
pub string_amount: String,
pub string_token: String,
pub string_fee: String,
Expand All @@ -153,7 +153,7 @@ pub struct TransferSignature {

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WithdrawSignature {
pub struct WithdrawSignatureInputs {
pub string_amount: String,
pub string_token: String,
pub string_fee: String,
Expand All @@ -164,7 +164,7 @@ pub struct WithdrawSignature {

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChangePubKeySignature {
pub struct ChangePubKeySignatureInputs {
pub pub_key_hash: PubKeyHash,
pub account_id: AccountId,
pub nonce: Nonce,
Expand Down
38 changes: 20 additions & 18 deletions sdk/zksync-rs/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mod utils_with_vectors {
mod signatures_with_vectors {
use super::*;
use zksync::{signer::Signer, WalletCredentials};
use zksync_config::test_config::unit_vectors::{EthSignature, Tx};
use zksync_config::test_config::unit_vectors::{EthSignatureInputs, Tx};
use zksync_eth_signer::PrivateKeySigner;
use zksync_types::{network::Network, AccountId, Address, H256};

Expand All @@ -178,11 +178,12 @@ mod signatures_with_vectors {
let test_vectors = TestVectorsConfig::load();
for TestEntry { inputs, outputs } in test_vectors.transactions.items {
if let Tx::Transfer(transfer_tx) = &inputs.tx {
let sign_data = if let EthSignature::Transfer(sign_data) = inputs.eth_sign_data {
sign_data
} else {
panic!("Signature data does not match transaction type (transfer)")
};
let sign_data =
if let EthSignatureInputs::Transfer(sign_data) = inputs.eth_sign_data {
sign_data
} else {
panic!("Signature data does not match transaction type (transfer)")
};

let signer = get_signer(
&inputs.eth_private_key,
Expand Down Expand Up @@ -233,11 +234,12 @@ mod signatures_with_vectors {
let test_vectors = TestVectorsConfig::load();
for TestEntry { inputs, outputs } in test_vectors.transactions.items {
if let Tx::Withdraw(withdraw_tx) = &inputs.tx {
let sign_data = if let EthSignature::Withdraw(sign_data) = inputs.eth_sign_data {
sign_data
} else {
panic!("Signature data does not match transaction type (withdraw)")
};
let sign_data =
if let EthSignatureInputs::Withdraw(sign_data) = inputs.eth_sign_data {
sign_data
} else {
panic!("Signature data does not match transaction type (withdraw)")
};

let signer = get_signer(
&inputs.eth_private_key,
Expand Down Expand Up @@ -288,12 +290,12 @@ mod signatures_with_vectors {
let test_vectors = TestVectorsConfig::load();
for TestEntry { inputs, outputs } in test_vectors.transactions.items {
if let Tx::ChangePubKey(change_pubkey_tx) = &inputs.tx {
let sign_data = if let EthSignature::ChangePubKey(sign_data) = inputs.eth_sign_data
{
sign_data
} else {
panic!("Signature data does not match transaction type (change pub key)")
};
let sign_data =
if let EthSignatureInputs::ChangePubKey(sign_data) = inputs.eth_sign_data {
sign_data
} else {
panic!("Signature data does not match transaction type (change pub key)")
};

let mut signer = get_signer(
&inputs.eth_private_key,
Expand Down Expand Up @@ -344,7 +346,7 @@ mod signatures_with_vectors {
let test_vectors = TestVectorsConfig::load();
for TestEntry { inputs, outputs } in test_vectors.transactions.items {
if let Tx::ForcedExit(forced_exit) = &inputs.tx {
if let EthSignature::ForcedExit = inputs.eth_sign_data {
if let EthSignatureInputs::ForcedExit = inputs.eth_sign_data {
} else {
panic!("Signature data does not match transaction type (forced exit)")
}
Expand Down

0 comments on commit 73f5763

Please sign in to comment.