Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test helper contract #273

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file added helper-contract/.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be committed.

Binary file not shown.
4 changes: 4 additions & 0 deletions helper-contract/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add .DS_Store to .gitignore

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
*/target/

/output*/
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) {}

#[view(getCalleeAddress)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storage mapper usually go last.
Start with init, upgrade, endpoints and end with storages.

#[storage_mapper("callee_address")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of storage mappers should be camelCase. In this case calleeAddress

fn callee_address(&self) -> SingleValueMapper<ManagedAddress>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should actually be bridge proxy contract. Rename it accordingly


#[endpoint(setCallee)]
fn set_callee(&self, address: ManagedAddress) {
self.callee_address().set(&address);
}

#[endpoint(callDeposit)]
#[payable("*")]
fn call_deposit(&self, batch_id: u64, eth_tx_multivalue: EthTxAsMultiValue<Self::Api>) {
let callee = self.callee_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();
}
}
225 changes: 225 additions & 0 deletions helper-contract/wasm/Cargo.lock

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

Loading
Loading