Skip to content

Commit

Permalink
Merge pull request #273 from multiversx/add-integration-test-helper-c…
Browse files Browse the repository at this point in the history
…ontract

Add integration test helper contract
  • Loading branch information
cosmatudor authored Jan 31, 2025
2 parents fde7172 + 2766212 commit 0f77c4a
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ members = [
"bridged-tokens-wrapper/meta",
"test-caller",
"test-caller/meta",
"helper-contract",
"helper-contract/meta",
"common/storage-module",
"common/mock-contracts/mock-price-aggregator/meta",
"common/mock-contracts/mock-multi-transfer-esdt/meta",
Expand Down
6 changes: 6 additions & 0 deletions helper-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target/
*/target/

/output*/

.DS_Store
24 changes: 24 additions & 0 deletions helper-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "helper-contract"
version = "0.0.0"
publish = false
edition = "2021"
authors = ["you"]

[lib]
path = "src/helper_contract.rs"

[dependencies.multiversx-sc]
version = "0.55.0"

[dependencies.transaction]
path = "../common/transaction"

[dependencies.sc-proxies]
path = "../common/sc-proxies"

[dev-dependencies]
num-bigint = "0.4"

[dev-dependencies.multiversx-sc-scenario]
version = "0.55.0"
12 changes: 12 additions & 0 deletions helper-contract/meta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "helper-contract-meta"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies.helper-contract]
path = ".."

[dependencies.multiversx-sc-meta-lib]
version = "0.55.0"
default-features = false
3 changes: 3 additions & 0 deletions helper-contract/meta/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
multiversx_sc_meta_lib::cli_main::<helper_contract::AbiProvider>();
}
3 changes: 3 additions & 0 deletions helper-contract/multiversx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language": "rust"
}
51 changes: 51 additions & 0 deletions helper-contract/src/helper_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![no_std]

#[allow(unused_imports)]
use multiversx_sc::imports::*;

use transaction::{EthTransaction, EthTxAsMultiValue};
use sc_proxies::bridge_proxy_contract_proxy;

#[multiversx_sc::contract]
pub trait HelperContract {
#[init]
fn init(&self) {}

#[upgrade]
fn upgrade(&self) {}

#[endpoint(setBridgeProxyAddress)]
fn set_bridge_proxy_address(&self, address: ManagedAddress) {
self.bridge_proxy_address().set(&address);
}

#[endpoint(callDeposit)]
#[payable("*")]
fn call_deposit(&self, batch_id: u64, eth_tx_multivalue: EthTxAsMultiValue<Self::Api>) {
let callee = self.bridge_proxy_address().get();

let (payment_token, payment_amount) = self.call_value().single_fungible_esdt();

let (from, to, token_id, amount, tx_nonce, call_data) = eth_tx_multivalue.into_tuple();

let eth_tx = EthTransaction {
from,
to,
token_id,
amount,
tx_nonce,
call_data,
};

self.tx()
.to(callee)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(eth_tx, batch_id)
.single_esdt(&payment_token, 0, &payment_amount)
.sync_call();
}

#[view(getBridgeProxyAddress)]
#[storage_mapper("bridgeProxyAddress")]
fn bridge_proxy_address(&self) -> SingleValueMapper<ManagedAddress>;
}
Loading

0 comments on commit 0f77c4a

Please sign in to comment.