Skip to content

Commit

Permalink
Merge branch 'master' into composability-interact
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca authored May 14, 2024
2 parents 2e62417 + 3ffec5c commit 62365e5
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 160 deletions.
161 changes: 58 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions contracts/feature-tests/scenario-tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ pub trait ScenarioTester {
fn add(&self, value: BigUint) {
self.sum().update(|sum| *sum += value);
}

/// Tests "from" conversion for MultiValueN parameters
#[endpoint]
fn multi_param(&self, _value: MultiValue2<BigUint, BigUint>) {}

/// Tests "from" conversion for MultiValueN return function
#[endpoint]
fn multi_return(&self, value: BigUint) -> MultiValue2<BigUint, BigUint> {
let value_plus_one = &value + 1u32;
(value, value_plus_one).into()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,32 @@ where
.argument(&value)
.original_result()
}

/// Tests "from" conversion for MultiValueN parameters
pub fn multi_param<
Arg0: ProxyArg<MultiValue2<BigUint<Env::Api>, BigUint<Env::Api>>>,
>(
self,
_value: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("multi_param")
.argument(&_value)
.original_result()
}

/// Tests "from" conversion for MultiValueN return function
pub fn multi_return<
Arg0: ProxyArg<BigUint<Env::Api>>,
>(
self,
value: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValue2<BigUint<Env::Api>, BigUint<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("multi_return")
.argument(&value)
.original_result()
}
}
30 changes: 30 additions & 0 deletions contracts/feature-tests/scenario-tester/tests/st_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ fn st_blackbox() {
.add(1u32)
.run();

world
.tx()
.from(OTHER_ADDRESS)
.to(ST_ADDRESS)
.typed(scenario_tester_proxy::ScenarioTesterProxy)
.multi_param(MultiValue2((1u32, 1u16)))
.run();

world
.tx()
.from(OTHER_ADDRESS)
.to(ST_ADDRESS)
.typed(scenario_tester_proxy::ScenarioTesterProxy)
.multi_return(1u32)
.returns(ExpectValue(MultiValue2((1u32, 2u32))))
.run();

let value = world
.tx()
.from(OTHER_ADDRESS)
.to(ST_ADDRESS)
.typed(scenario_tester_proxy::ScenarioTesterProxy)
.multi_return(1u32)
.returns(ReturnsResultUnmanaged)
.run();
assert_eq!(
value,
MultiValue2((RustBigUint::from(1u32), RustBigUint::from(2u32)))
);

world.write_scenario_trace("trace1.scen.json");
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/feature-tests/scenario-tester/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 2
// Endpoints: 4
// Async Callback (empty): 1
// Total number of exported functions: 5
// Total number of exported functions: 7

#![no_std]

Expand All @@ -22,6 +22,8 @@ multiversx_sc_wasm_adapter::endpoints! {
upgrade => upgrade
getSum => sum
add => add
multi_param => multi_param
multi_return => multi_return
)
}

Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use type_description_container::*;

pub type TypeName = alloc::string::String;

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct TypeNames {
pub abi: alloc::string::String,
pub rust: alloc::string::String,
Expand Down
52 changes: 26 additions & 26 deletions framework/base/src/abi/type_abi_impl_codec_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ impl<T: TypeAbi> TypeAbi for OptionalValue<T> {
}

macro_rules! multi_arg_impls {
($(($mval_struct:ident $($n:tt $name:ident)+) )+) => {
($(($mval_struct:ident $($n:tt $t:ident $u:ident)+) )+) => {
$(
impl<$($name),+ > TypeAbiFrom<Self> for crate::codec::multi_types::$mval_struct<$($name,)+>
impl<$($t, $u),+> TypeAbiFrom<crate::codec::multi_types::$mval_struct<$($u,)+>> for crate::codec::multi_types::$mval_struct<$($t,)+>
where
$($name: TypeAbi,)+
$($t: TypeAbiFrom<$u>,)+
{}

impl<$($name),+ > TypeAbi for crate::codec::multi_types::$mval_struct<$($name,)+>
impl<$($t),+> TypeAbi for crate::codec::multi_types::$mval_struct<$($t,)+>
where
$($name: TypeAbi,)+
$($t: TypeAbi,)+
{
type Unmanaged = Self;
type Unmanaged = crate::codec::multi_types::$mval_struct<$($t::Unmanaged,)+>;

fn type_name() -> TypeName {
let mut repr = TypeName::from("multi");
Expand All @@ -95,7 +95,7 @@ macro_rules! multi_arg_impls {
if $n > 0 {
repr.push(',');
}
repr.push_str($name::type_name().as_str());
repr.push_str($t::type_name().as_str());
)+
repr.push('>');
repr
Expand All @@ -108,15 +108,15 @@ macro_rules! multi_arg_impls {
if $n > 0 {
repr.push_str(", ");
}
repr.push_str($name::type_name_rust().as_str());
repr.push_str($t::type_name_rust().as_str());
)+
repr.push('>');
repr
}

fn provide_type_descriptions<TDC: TypeDescriptionContainer>(accumulator: &mut TDC) {
$(
$name::provide_type_descriptions(accumulator);
$t::provide_type_descriptions(accumulator);
)+
}

Expand All @@ -128,10 +128,10 @@ macro_rules! multi_arg_impls {
let mut result = OutputAbis::new();
$(
if output_names.len() > $n {
result.append(&mut $name::output_abis(&[output_names[$n]]));
result.append(&mut $t::output_abis(&[output_names[$n]]));

} else {
result.append(&mut $name::output_abis(&[]));
result.append(&mut $t::output_abis(&[]));
}

)+
Expand All @@ -143,19 +143,19 @@ macro_rules! multi_arg_impls {
}

multi_arg_impls! {
(MultiValue2 0 T0 1 T1)
(MultiValue3 0 T0 1 T1 2 T2)
(MultiValue4 0 T0 1 T1 2 T2 3 T3)
(MultiValue5 0 T0 1 T1 2 T2 3 T3 4 T4)
(MultiValue6 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5)
(MultiValue7 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6)
(MultiValue8 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7)
(MultiValue9 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8)
(MultiValue10 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9)
(MultiValue11 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10)
(MultiValue12 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11)
(MultiValue13 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12)
(MultiValue14 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13)
(MultiValue15 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13 14 T14)
(MultiValue16 0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13 14 T14 15 T15)
(MultiValue2 0 T0 U0 1 T1 U1)
(MultiValue3 0 T0 U0 1 T1 U1 2 T2 U2)
(MultiValue4 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3)
(MultiValue5 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4)
(MultiValue6 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5)
(MultiValue7 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6)
(MultiValue8 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7)
(MultiValue9 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8)
(MultiValue10 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9)
(MultiValue11 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10)
(MultiValue12 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10 11 T11 U11)
(MultiValue13 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10 11 T11 U11 12 T12 U12)
(MultiValue14 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10 11 T11 U11 12 T12 U12 13 T13 U13)
(MultiValue15 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10 11 T11 U11 12 T12 U12 13 T13 U13 14 T14 U14)
(MultiValue16 0 T0 U0 1 T1 U1 2 T2 U2 3 T3 U3 4 T4 U4 5 T5 U5 6 T6 U6 7 T7 U7 8 T8 U8 9 T9 U9 10 T10 U10 11 T11 U11 12 T12 U12 13 T13 U13 14 T14 U14 15 T15 U15)
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ where
let mut opt_new_node_parent = None;
let mut opt_current_node = self.get_root();
while opt_current_node.is_some() {
opt_new_node_parent = opt_current_node.clone();
opt_new_node_parent.clone_from(&opt_current_node);

let current_node = unsafe { opt_current_node.unwrap_unchecked() };
if new_node.data == current_node.data {
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/types/interaction/managed_arg_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,6 @@ where
}

fn type_name_rust() -> TypeName {
"ManagedArgBufer<$API>".into()
"ManagedArgBuffer<$API>".into()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ContractVariantProfile {
result.codegen_units = codegen_units;
}
if let Some(opt_level) = &serde_profile.opt_level {
result.opt_level = opt_level.clone();
result.opt_level.clone_from(opt_level);
}
if let Some(lto) = serde_profile.lto {
result.lto = lto;
Expand All @@ -90,7 +90,7 @@ impl ContractVariantProfile {
result.debug = debug;
}
if let Some(panic) = &serde_profile.panic {
result.panic = panic.clone();
result.panic.clone_from(panic);
}
if let Some(overflow_checks) = serde_profile.overflow_checks {
result.overflow_checks = overflow_checks;
Expand Down
2 changes: 1 addition & 1 deletion framework/scenario/src/api/local_api_vh/print_api_vh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use multiversx_sc::{
use crate::api::{VMHooksApi, VMHooksApiBackend};

thread_local!(
static PRINTED_MESSAGES: RefCell<Vec<String>> = RefCell::new(Vec::new())
static PRINTED_MESSAGES: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) }
);

impl<VHB: VMHooksApiBackend> VMHooksApi<VHB> {
Expand Down
2 changes: 1 addition & 1 deletion framework/scenario/src/facade/expr/bech32_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<'de> Deserialize<'de> for Bech32Address {
// some old interactors have it serialized like this
let mut bech32 = String::deserialize(deserializer)?;
if let Some(stripped) = bech32.strip_prefix("bech32:") {
bech32 = stripped.to_owned();
bech32 = stripped.to_string();
}
Ok(Bech32Address::from_bech32_string(bech32))
}
Expand Down
6 changes: 4 additions & 2 deletions framework/scenario/src/facade/world_tx/scenario_set_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ScenarioWorld {
let accounts = &mut self.get_mut_state().accounts;
for (vm_address_key, account) in accounts.iter_mut() {
if vm_address_key == &address_value.to_vm_address() {
account.egld_balance = balance_value.value.clone();
account.egld_balance.clone_from(&balance_value.value);
}
}
}
Expand Down Expand Up @@ -158,7 +158,9 @@ impl ScenarioWorld {
let accounts = &mut self.get_mut_state().accounts;
for (vm_address, account) in accounts.iter_mut() {
if vm_address == &AddressKey::from(address).to_vm_address() {
account.developer_rewards = BigUintValue::from(developer_rewards).value.clone();
account
.developer_rewards
.clone_from(&BigUintValue::from(developer_rewards).value);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions framework/scenario/src/whitebox_legacy/tx_mandos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ScCallMandos {
}

pub fn add_egld_value(&mut self, egld_value: &num_bigint::BigUint) {
self.egld_value = egld_value.clone();
self.egld_value.clone_from(egld_value);
}

pub fn add_esdt_transfer(
Expand Down Expand Up @@ -101,6 +101,6 @@ impl TxExpectMandos {
}

pub fn set_message(&mut self, msg: &str) {
self.message = msg.to_owned();
self.message = msg.to_string();
}
}
1 change: 1 addition & 0 deletions framework/wasm-adapter/src/wasm_alloc/leaking_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct LeakingAllocator {
unsafe impl Sync for LeakingAllocator {}

impl LeakingAllocator {
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
LeakingAllocator {
used: UnsafeCell::new(0),
Expand Down
1 change: 1 addition & 0 deletions framework/wasm-adapter/src/wasm_alloc/static_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct StaticAllocator<const SIZE: usize> {
}

impl<const SIZE: usize> StaticAllocator<SIZE> {
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
StaticAllocator {
arena: UnsafeCell::new([0; SIZE]),
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# This should actually automatically be shipped with cargo fmt or rustfmt itself!
# ----------------------------------------------------------------------------------

imports_granularity="Crate"
# imports_granularity="Crate"

# Use verbose output.
# Default: false
Expand Down
8 changes: 5 additions & 3 deletions sdk/core/src/crypto/private_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::edwards25519::{sc_mul_add, sc_reduce};
use crate::crypto::edwards25519::extended_group_element::ExtendedGroupElement;
use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -126,9 +128,9 @@ impl PrivateKey {
}
}

impl ToString for PrivateKey {
fn to_string(&self) -> String {
hex::encode(&self.0[..32])
impl Display for PrivateKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
hex::encode(&self.0[..32]).fmt(f)
}
}

Expand Down
8 changes: 5 additions & 3 deletions sdk/core/src/crypto/public_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::private_key::PrivateKey;
use anyhow::Result;
use bech32::{self, ToBase32, Variant};
Expand Down Expand Up @@ -44,9 +46,9 @@ impl<'a> From<&'a PrivateKey> for PublicKey {
}
}

impl ToString for PublicKey {
fn to_string(&self) -> String {
hex::encode(self.0)
impl Display for PublicKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
hex::encode(self.0).fmt(f)
}
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/core/src/data/address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::fmt::{Debug, Display};

use crate::crypto::public_key::PublicKey;
use anyhow::Result;
Expand Down Expand Up @@ -51,9 +51,9 @@ impl<'a> From<&'a PublicKey> for Address {
}
}

impl ToString for Address {
fn to_string(&self) -> String {
self.to_bech32_string().unwrap()
impl Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_bech32_string().unwrap().as_str())
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/scenario-format/src/value_interpreter/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn address_pretty(value: &[u8]) -> String {
format!("address:{}", address_str.trim_end_matches('_').to_owned())
} else {
let mut address_str = String::from_utf8_lossy(&value[..SC_ADDRESS_LENGTH - 1]).to_string();
address_str = address_str.trim_end_matches('_').to_owned();
address_str = address_str.trim_end_matches('_').to_string();
let shard_id = value[SC_ADDRESS_LENGTH - 1];
let address_expr = format!("address:{address_str}#{shard_id:02x}");
if !can_interpret_as_string(&[value[SC_ADDRESS_LENGTH - 1]]) {
Expand Down
Loading

0 comments on commit 62365e5

Please sign in to comment.