Skip to content

Commit

Permalink
proxy test first new proxy and migration to unified
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Mar 28, 2024
1 parent c4ae976 commit ccaa7ab
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct MessageMeProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for MessageMeProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = MessageMeProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
MessageMeProxyMethods { wrapped_tx: tx }
}
}

pub struct MessageMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> MessageMeProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init<
Arg0: CodecInto<i32>,
>(
self,
init_arg: Arg0,
) -> TxProxyDeploy<Env, From, Gas, i32> {
self.wrapped_tx
.raw_deploy()
.argument(&init_arg)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> MessageMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn upgrade(
self,
) -> TxProxyUpgrade<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_upgrade()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> MessageMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn message_me<
Arg0: CodecInto<i64>,
Arg1: CodecInto<BigUint<Env::Api>>,
Arg2: CodecInto<Vec<u8>>,
Arg3: CodecInto<ManagedAddress<Env::Api>>,
>(
self,
arg1: Arg0,
arg2: Arg1,
arg3: Arg2,
arg4: Arg3,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("messageMe")
.argument(&arg1)
.argument(&arg2)
.argument(&arg3)
.argument(&arg4)
.original_result()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct PayMeProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for PayMeProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = PayMeProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
PayMeProxyMethods { wrapped_tx: tx }
}
}

pub struct PayMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> PayMeProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxProxyDeploy<Env, From, Gas, ()> {
self.wrapped_tx
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> PayMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn upgrade(
self,
) -> TxProxyUpgrade<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_upgrade()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> PayMeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn pay_me<
Arg0: CodecInto<i64>,
>(
self,
arg1: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("payMe")
.argument(&arg1)
.original_result()
}

pub fn pay_me_with_result<
Arg0: CodecInto<i64>,
>(
self,
arg1: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("payMeWithResult")
.argument(&arg1)
.original_result()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,14 @@ multiversx_sc::imports!();

use hex_literal::hex;

pub mod message_me_proxy;
pub mod pay_me_proxy;

static HARDCODED_ADDRESS: [u8; 32] =
hex!("fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe");

mod pay_me_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait PayMe {
#[payable("EGLD")]
#[endpoint(payMe)]
fn pay_me(&self, arg1: i64);

#[payable("EGLD")]
#[endpoint(payMeWithResult)]
fn pay_me_with_result(&self, arg1: i64);
}
}

mod message_me_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait MessageMe {
#[init]
#[payable("EGLD")]
fn init(&self, init_arg: i32) -> i32;

#[endpoint(messageMe)]
fn message_me(&self, arg1: i64, arg2: &BigUint, arg3: Vec<u8>, arg4: &ManagedAddress);
}
}

#[multiversx_sc::contract]
pub trait ProxyTestFirst {
#[proxy]
fn pay_me_proxy(&self) -> pay_me_proxy::Proxy<Self::Api>;

#[proxy]
fn message_me_proxy(&self) -> message_me_proxy::Proxy<Self::Api>;

#[storage_get("other_contract")]
fn get_other_contract(&self) -> ManagedAddress;

Expand All @@ -62,11 +30,26 @@ pub trait ProxyTestFirst {
#[endpoint(deploySecondContract)]
fn deploy_second_contract(&self, code: ManagedBuffer) -> i32 {
let payment = self.call_value().egld_value();
// let (address, init_result) = self
// .tx()
// .egld(payment)
// .raw_deploy()
// .code(code)
// .code_metadata(CodeMetadata::UPGRADEABLE)
// .argument(&123)
// .returns(ReturnsNewAddress)
// .returns(ReturnsResult)
// .sync_call();

let (address, init_result) = self
.message_me_proxy()
.tx()
.typed(message_me_proxy::MessageMeProxy)
.init(123)
.with_egld_transfer(payment.clone_value())
.deploy_contract::<i32>(&code, CodeMetadata::UPGRADEABLE);
.returns(ReturnsNewAddress)
.returns(ReturnsResult)
.egld(payment)
.sync_call();

Check failure on line 51 in contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

the method `sync_call` exists for struct `Tx<TxScEnv<<Self as ContractBase>::Api>, (), (), Egld<ManagedRef<'_, ..., ...>>, ..., ..., ...>`, but its trait bounds were not satisfied

Check failure on line 51 in contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

the method `sync_call` exists for struct `Tx<TxScEnv<<Self as ContractBase>::Api>, (), (), Egld<ManagedRef<'_, ..., ...>>, ..., ..., ...>`, but its trait bounds were not satisfied

Check failure on line 51 in contracts/feature-tests/composability/proxy-test-first/src/proxy-test-first.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

the method `sync_call` exists for struct `Tx<TxScEnv<<Self as ContractBase>::Api>, (), (), Egld<ManagedRef<'_, ..., ...>>, ..., ..., ...>`, but its trait bounds were not satisfied

self.set_other_contract(&address);
init_result + 1
}
Expand All @@ -90,33 +73,36 @@ pub trait ProxyTestFirst {
fn forward_to_other_contract(&self) {
let payment = self.call_value().egld_value();
let other_contract = self.get_other_contract();
self.pay_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(pay_me_proxy::PayMeProxy)
.pay_me(0x56)
.with_egld_transfer(payment.clone_value())
.egld(payment)
.async_call()
.call_and_exit()
.call_and_exit();
}

#[payable("EGLD")]
#[endpoint(forwardToOtherContractWithCallback)]
fn forward_to_other_contract_with_callback(&self) {
let payment = self.call_value().egld_value();
let other_contract = self.get_other_contract();
self.pay_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(pay_me_proxy::PayMeProxy)
.pay_me_with_result(0x56)
.with_egld_transfer(payment.clone_value())
.egld(payment)
.async_call()
.with_callback(self.callbacks().pay_callback())
.call_and_exit()
.call_and_exit();
}

#[endpoint(messageOtherContract)]
fn message_other_contract(&self) {
let other_contract = self.get_other_contract();
self.message_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(message_me_proxy::MessageMeProxy)
.message_me(
0x01,
&BigUint::from(2u32),
Expand All @@ -130,8 +116,9 @@ pub trait ProxyTestFirst {
#[endpoint(messageOtherContractWithCallback)]
fn message_other_contract_with_callback(&self) {
let other_contract = self.get_other_contract();
self.message_me_proxy()
.contract(other_contract)
self.tx()
.to(&other_contract)
.typed(message_me_proxy::MessageMeProxy)
.message_me(
0x01,
&BigUint::from(2u32),
Expand Down

0 comments on commit ccaa7ab

Please sign in to comment.