Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Feb 27, 2023
1 parent a2cf73c commit 98ac8fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
1 change: 0 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ category = "Test"
command = "${CARGO}"
args = [
"test",
"test_deposit_pausability",
"--features",
"${CARGO_FEATURES_TEST}",
"--",
Expand Down
31 changes: 11 additions & 20 deletions eth-connector-tests/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());

Expand All @@ -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(())
}

Expand Down
17 changes: 10 additions & 7 deletions eth-connector-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 98ac8fa

Please sign in to comment.