From 98ac8fa05247c47a3c9fc59b79c783ed9729e57f Mon Sep 17 00:00:00 2001 From: Evgeny Ukhanov Date: Tue, 28 Feb 2023 00:41:35 +0100 Subject: [PATCH] Fix test --- Makefile.toml | 1 - eth-connector-tests/src/connector.rs | 31 ++++++++++------------------ eth-connector-tests/src/utils.rs | 17 ++++++++------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 215a8d6..f56c884 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -174,7 +174,6 @@ category = "Test" command = "${CARGO}" args = [ "test", - "test_deposit_pausability", "--features", "${CARGO_FEATURES_TEST}", "--", diff --git a/eth-connector-tests/src/connector.rs b/eth-connector-tests/src/connector.rs index 6a7e4b7..58dab3c 100644 --- a/eth-connector-tests/src/connector.rs +++ b/eth-connector-tests/src/connector.rs @@ -733,17 +733,15 @@ async fn test_deposit_pausability() -> anyhow::Result<()> { let contract = TestContract::new_with_custodian_and_owner(CUSTODIAN_ADDRESS, "owner.root").await?; - contract.call_deposit_eth_to_near().await?; + let owner_acc = contract.create_sub_account("owner").await?; let user_acc = contract.create_sub_account("eth_recipient").await?; contract.set_and_check_access_right(user_acc.id()).await?; // 1st deposit call - should succeed - let res = contract - .user_deposit_with_proof(&user_acc, &contract.get_proof(PROOF_DATA_NEAR)) - .await?; - println!("{:#?}", res); + let proof1 = contract.mock_proof(user_acc.id(), 10, 1); + let res = contract.user_deposit_with_proof(&user_acc, &proof1).await?; assert!(res.is_success()); // Pause deposit @@ -756,18 +754,15 @@ async fn test_deposit_pausability() -> anyhow::Result<()> { .await?; assert!(res.is_success()); - // 2nd deposit call - should fail - // NB: We can use `PROOF_DATA_ETH` this will be just a different proof but the same deposit - // method which should be paused - let res = contract - .user_deposit_with_proof(&user_acc, &contract.get_proof(PROOF_DATA_ETH)) - .await?; + // 2nd deposit call - should fail for `user_acc` + let proof2 = contract.mock_proof(user_acc.id(), 20, 2); + let res = contract.user_deposit_with_proof(&user_acc, &proof2).await?; assert!(res.is_failure()); assert!(contract.check_error_message(res, "ERR_PAUSED")); - let proof_data = TestContract::mock_proof(owner_acc.id(), 10); + let proof3 = contract.mock_proof(user_acc.id(), 30, 3); let res = contract - .user_deposit_with_proof(&owner_acc, &contract.get_proof(&proof_data)) + .user_deposit_with_proof(&owner_acc, &proof3) .await?; assert!(res.is_success()); @@ -782,14 +777,10 @@ async fn test_deposit_pausability() -> anyhow::Result<()> { assert!(res.is_success()); // 3rd deposit call - should succeed - let res = contract - .user_deposit_with_proof(&user_acc, &contract.get_proof(PROOF_DATA_ETH)) - .await?; + let proof4 = contract.mock_proof(user_acc.id(), 40, 4); + let res = contract.user_deposit_with_proof(&user_acc, &proof4).await?; assert!(res.is_success()); - assert_eq!( - contract.total_supply().await?.0, - DEPOSITED_AMOUNT + DEPOSITED_EVM_AMOUNT - ); + assert_eq!(contract.total_supply().await?.0, 80); Ok(()) } diff --git a/eth-connector-tests/src/utils.rs b/eth-connector-tests/src/utils.rs index c00eb6c..b645a1a 100644 --- a/eth-connector-tests/src/utils.rs +++ b/eth-connector-tests/src/utils.rs @@ -300,7 +300,12 @@ impl TestContract { Ok(()) } - pub fn mock_proof(recipient_id: &AccountId, deposit_amount: u128) -> String { + pub fn mock_proof( + &self, + recipient_id: &AccountId, + deposit_amount: u128, + proof_index: u64, + ) -> Proof { use aurora_engine_types::{ types::{Fee, NEP141Wei}, H160, H256, U256, @@ -344,21 +349,19 @@ impl TestContract { ethabi::Token::Uint(U256::from(deposit_event.fee.as_u128())), ]), }; - let data = Proof { - log_index: 1, + Proof { + log_index: proof_index, // Only this field matters for the purpose of this test log_entry_data: rlp::encode(&log_entry).to_vec(), receipt_index: 1, receipt_data: Vec::new(), header_data: Vec::new(), proof: Vec::new(), - }; - serde_json::to_string(&data).expect("failed serialize proof") + } } pub async fn call_deposit_contract(&self) -> anyhow::Result<()> { - let proof: Proof = - self.get_proof(&Self::mock_proof(self.contract.id(), DEPOSITED_CONTRACT)); + let proof: Proof = self.mock_proof(self.contract.id(), DEPOSITED_CONTRACT, 1); let res = self.deposit_with_proof(&proof).await?; assert!(res.is_success(), "call_deposit_contract: {:#?}", res); Ok(())