Skip to content

Commit

Permalink
Eth-connector silo balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Aug 24, 2023
1 parent a4438b9 commit 9fe8578
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
3 changes: 0 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,8 @@ category = "Test"
command = "${CARGO}"
args = [
"test",
"test_silo_connector",
"--features",
"${CARGO_FEATURES_TEST}",
"--",
"--nocapture"
]

[tasks.bench-modexp-test]
Expand Down
15 changes: 11 additions & 4 deletions engine-tests-connector/src/silo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::eth::{create_eth_acc, set_submit_tx, submit_transaction};
use crate::utils::eth::{create_eth_acc, prepare_submit_transaction, set_submit_tx};
use crate::utils::{mock_proof, TestContract};

const ETH: u128 = 10u128.pow(18);
Expand All @@ -7,7 +7,7 @@ const ETH: u128 = 10u128.pow(18);
async fn test_silo_connector() {
let (addr, sk) = create_eth_acc();
let contract = TestContract::new_silo_contract().await.unwrap();
let res = contract.add_addr_to_white_list(addr.clone()).await.unwrap();
let res = contract.add_addr_to_white_list(addr).await.unwrap();
assert!(res.is_success());

let amount = 5 * ETH;
Expand All @@ -19,6 +19,13 @@ async fn test_silo_connector() {
assert_eq!(res, 5 * ETH);

let (recv, _) = create_eth_acc();
let tx = set_submit_tx(0, recv, 30);
submit_transaction(contract, &sk, tx).await;
let tx_args = set_submit_tx(0, recv, ETH);
let tx = prepare_submit_transaction(&sk, tx_args).await;
let res = contract.submit(tx).await.unwrap();
assert!(res.is_success());

let res = contract.get_eth_balance(&addr).await.unwrap();
assert_eq!(res, 3 * ETH);
let res = contract.get_eth_balance(&recv).await.unwrap();
assert_eq!(res, ETH);
}
34 changes: 15 additions & 19 deletions engine-tests-connector/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ impl TestContract {
.await?)
}

pub async fn submit(&self, tx: Vec<u8>) -> anyhow::Result<ExecutionFinalResult> {
Ok(self
.engine_contract
.call("submit")
.args(tx)
.gas(DEFAULT_GAS)
.transact()
.await?)
}

pub async fn add_addr_to_white_list(
&self,
address: Address,
Expand Down Expand Up @@ -554,7 +564,7 @@ pub fn mock_proof(
sender: Address::new(H160([0u8; 20])),
token_message_data,
amount: NEP141Wei::new(deposit_amount),
fee: fee.clone(),
fee,
};

let event_schema = ethabi::Event {
Expand Down Expand Up @@ -585,7 +595,7 @@ pub fn mock_proof(
}

pub mod eth {
use crate::utils::{Address, TestContract, Wei, DEFAULT_GAS};
use crate::utils::{Address, Wei};
use aurora_engine_transactions::legacy::{LegacyEthSignedTransaction, TransactionLegacy};
use aurora_engine_types::U256;
use libsecp256k1::{Message, PublicKey, SecretKey};
Expand Down Expand Up @@ -650,23 +660,9 @@ pub mod eth {
}
}

pub async fn submit_transaction(
contract: TestContract,
sk: &SecretKey,
transaction: TransactionLegacy,
) {
pub async fn prepare_submit_transaction(sk: &SecretKey, tx_args: TransactionLegacy) -> Vec<u8> {
let chain_id = 0;
let signed_tx = sign_transaction(transaction, sk, Some(chain_id));
let tx = rlp::encode(&signed_tx).to_vec();

let res = contract
.engine_contract
.call("submit")
.args(tx)
.gas(DEFAULT_GAS)
.transact()
.await
.unwrap();
println!("{res:#?}");
let signed_tx = sign_transaction(tx_args, sk, Some(chain_id));
rlp::encode(&signed_tx).to_vec()
}
}

0 comments on commit 9fe8578

Please sign in to comment.