Skip to content

Commit

Permalink
Merge pull request #1858 from multiversx/multi-value-encoded-counted
Browse files Browse the repository at this point in the history
MultiValueEncodedCounted
  • Loading branch information
andrei-marinica authored Nov 13, 2024
2 parents 7894acc + a48e24a commit a73cf9e
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"sc:basic-features": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../output/basic-features.mxsc.json"
},
"address:an_account": {
"nonce": "0",
"balance": "0"
}
}
},
{
"step": "scCall",
"id": "1",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "echo_varags_vec_with_counted",
"arguments": [
"str:alice",
"2",
"101",
"102",
"str:bob",
"0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [
"str:alice",
"2",
"101",
"102",
"str:bob",
"0"
],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"sc:basic-features": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../output/basic-features.mxsc.json"
},
"address:an_account": {
"nonce": "0",
"balance": "0"
}
}
},
{
"step": "scCall",
"id": "1",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "echo_varags_vec_with_counted_pairs",
"arguments": [
"str:alice",
"1",
"100",
"address:a100",
"str:bob",
"0",
"str:charlie",
"3",
"300",
"address:a300",
"301",
"address:a301",
"302",
"address:a302"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [
"str:alice",
"1",
"100",
"address:a100",
"str:bob",
"0",
"str:charlie",
"3",
"300",
"address:a300",
"301",
"address:a301",
"302",
"address:a302"
],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
23 changes: 23 additions & 0 deletions contracts/feature-tests/basic-features/src/echo_managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,27 @@ pub trait EchoManagedTypes {
}
result
}

#[endpoint]
fn echo_varags_vec_with_counted(
&self,
m: MultiValueEncoded<MultiValue2<ManagedBuffer, MultiValueManagedVecCounted<usize>>>,
) -> MultiValueEncoded<MultiValue2<ManagedBuffer, MultiValueManagedVecCounted<usize>>> {
m
}

#[endpoint]
fn echo_varags_vec_with_counted_pairs(
&self,
m: MultiValueEncoded<
MultiValue2<
ManagedBuffer,
MultiValueEncodedCounted<MultiValue2<usize, ManagedAddress>>,
>,
>,
) -> MultiValueEncoded<
MultiValue2<ManagedBuffer, MultiValueEncodedCounted<MultiValue2<usize, ManagedAddress>>>,
> {
m
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ fn crypto_verify_bls_go() {

#[test]
#[ignore = "requires EI 1.4 in mx-scenario-go"]
fn crypto_verify_bls_share_go() {
world().run("scenarios/crypto_verify_bls_share.scen.json");
fn crypto_verify_bls_aggregated_signature_go() {
world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json");
}

#[test]
#[ignore = "requires EI 1.4 in mx-scenario-go"]
fn crypto_verify_bls_aggregated_go() {
world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json");
fn crypto_verify_bls_share_go() {
world().run("scenarios/crypto_verify_bls_share.scen.json");
}

#[test]
Expand Down Expand Up @@ -192,6 +192,16 @@ fn echo_usize_go() {
world().run("scenarios/echo_usize.scen.json");
}

#[test]
fn echo_varags_vec_with_counted_go() {
world().run("scenarios/echo_varags_vec_with_counted.scen.json");
}

#[test]
fn echo_varags_vec_with_counted_pairs_go() {
world().run("scenarios/echo_varags_vec_with_counted_pairs.scen.json");
}

#[test]
fn echo_varargs_managed_eager_go() {
world().run("scenarios/echo_varargs_managed_eager.scen.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ fn crypto_verify_bls_rs() {

#[test]
#[ignore]
fn crypto_verify_bls_share_rs() {
world().run("scenarios/crypto_verify_bls_share.scen.json");
fn crypto_verify_bls_aggregated_signature_rs() {
world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json");
}

#[test]
#[ignore]
fn crypto_verify_bls_aggregated_rs() {
world().run("scenarios/crypto_verify_bls_aggregated_signature.scen.json");
fn crypto_verify_bls_share_rs() {
world().run("scenarios/crypto_verify_bls_share.scen.json");
}

#[test]
Expand Down Expand Up @@ -212,6 +212,16 @@ fn echo_usize_rs() {
world().run("scenarios/echo_usize.scen.json");
}

#[test]
fn echo_varags_vec_with_counted_rs() {
world().run("scenarios/echo_varags_vec_with_counted.scen.json");
}

#[test]
fn echo_varags_vec_with_counted_pairs_rs() {
world().run("scenarios/echo_varags_vec_with_counted_pairs.scen.json");
}

#[test]
fn echo_varargs_managed_eager_rs() {
world().run("scenarios/echo_varargs_managed_eager.scen.json");
Expand Down
2 changes: 2 additions & 0 deletions framework/base/src/types/managed/multi_value/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
mod async_call_result_managed;
mod esdt_token_payment_multi_value;
mod multi_value_encoded;
mod multi_value_encoded_counted;
mod multi_value_encoded_iter;
mod multi_value_managed_vec;
mod multi_value_managed_vec_counted;

pub use async_call_result_managed::{ManagedAsyncCallError, ManagedAsyncCallResult};
pub use esdt_token_payment_multi_value::{EsdtTokenPaymentMultiArg, EsdtTokenPaymentMultiValue};
pub use multi_value_encoded::{ManagedMultiResultVec, ManagedVarArgs, MultiValueEncoded};
pub use multi_value_encoded_counted::MultiValueEncodedCounted;
pub use multi_value_encoded_iter::MultiValueEncodedIterator;
pub use multi_value_managed_vec::{
ManagedMultiResultVecEager, ManagedVarArgsEager, MultiValueManagedVec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::{
};
use core::{iter::FromIterator, marker::PhantomData};

use super::MultiValueEncodedIterator;

/// A multi-value container, that keeps raw values as ManagedBuffer
/// It allows encoding and decoding of multi-values.
///
Expand Down Expand Up @@ -147,6 +149,18 @@ where
}
}

impl<M, T> IntoIterator for MultiValueEncoded<M, T>
where
M: ManagedTypeApi + ErrorApi,
T: TopDecodeMulti,
{
type Item = T;
type IntoIter = MultiValueEncodedIterator<M, T>;
fn into_iter(self) -> Self::IntoIter {
MultiValueEncodedIterator::new(self.raw_buffers)
}
}

impl<M, T> MultiValueEncoded<M, T>
where
M: ManagedTypeApi + ErrorApi,
Expand Down
Loading

0 comments on commit a73cf9e

Please sign in to comment.