Skip to content

Commit

Permalink
Merge pull request #1685 from multiversx/storage-get-err-msg
Browse files Browse the repository at this point in the history
added storage key to deserialization error message at storage get
  • Loading branch information
mihaicalinluca authored Jul 1, 2024
2 parents 8d3f998 + c49ecaa commit ea7c8e4
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 258 deletions.
726 changes: 488 additions & 238 deletions contracts/core/price-aggregator/scenarios/stress_submit_test.scen.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"expect": {
"out": [],
"status": "4",
"message": "str:storage decode error: input too long",
"message": "str:storage decode error (key: opt_addr): input too long",
"logs": "*",
"gas": "*",
"refund": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"expect": {
"out": [],
"status": "4",
"message": "str:storage decode error: deliberate top decode error"
"message": "str:storage decode error (key: load_with_value_err): deliberate top decode error"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"expect": {
"out": [],
"status": "*",
"message": "str:storage decode error: argument out of range",
"message": "str:storage decode error (key: i64): argument out of range",
"logs": "*",
"gas": "*",
"refund": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"expect": {
"out": [],
"status": "4",
"message": "str:storage decode error: input too long",
"message": "str:storage decode error (key: opt_addr): input too long",
"logs": "*",
"gas": "*",
"refund": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"expect": {
"out": [],
"status": "4",
"message": "str:storage decode error: input too long",
"message": "str:storage decode error (key: u64): input too long",
"logs": "*",
"gas": "*",
"refund": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"expect": {
"out": [],
"status": "4",
"message": "str:storage decode error: input too long",
"message": "str:storage decode error (key: usize): input too long",
"logs": "*",
"gas": "*",
"refund": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"step": "setState",
"accounts": {
"0x00000000000000006c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925": {
"nonce": "0",
"nonce": "1",
"balance": "0",
"esdt": {
"str:COOL-123456": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ fn world() -> ScenarioWorld {
}

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

#[test]
#[ignore]
fn test_esdt_generation_go() {
world().run("scenarios/test_esdt_generation.scen.json");
}

#[test]
#[ignore]
fn test_multiple_sc_go() {
world().run("scenarios/test_multiple_sc.scen.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ fn world() -> ScenarioWorld {
}

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

#[test]
#[ignore]
fn test_esdt_generation_rs() {
world().run("scenarios/test_esdt_generation.scen.json");
}

#[test]
#[ignore]
fn test_multiple_sc_rs() {
world().run("scenarios/test_multiple_sc.scen.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ fn test_esdt_balance() {
})
.assert_ok();

wrapper.add_mandos_set_account(sc_wrapper.address_ref());
wrapper.add_mandos_check_account(sc_wrapper.address_ref());
wrapper.write_mandos_output(TEST_ESDT_OUTPUT_PATH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::marker::PhantomData;

use unwrap_infallible::UnwrapInfallible;

use crate::api::HandleConstraints;
use crate::codec::{TopDecode, TopEncode};

use crate::{
Expand Down Expand Up @@ -65,8 +66,11 @@ where
result_buffer.get_handle(),
);

V::top_decode_or_handle_err(result_buffer, StorageGetErrorHandler::<A>::default())
.unwrap_infallible()
V::top_decode_or_handle_err(
result_buffer,
StorageGetErrorHandler::<A>::new(key.get_handle().get_raw_handle_unchecked()),
)
.unwrap_infallible()
}

/// Write a serializable value to storage under the given key
Expand Down
3 changes: 2 additions & 1 deletion framework/base/src/err_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub const ARG_BAD_LENGTH_32: &str = "argument has wrong length: 32 bytes expecte
pub const ARG_DECODE_ERROR_1: &str = "argument decode error (";
pub const ARG_DECODE_ERROR_2: &str = "): ";
pub const STORAGE_VALUE_OUT_OF_RANGE: &str = "storage value out of range";
pub const STORAGE_DECODE_ERROR: &str = "storage decode error: ";
pub const STORAGE_DECODE_ERROR_1: &str = "storage decode error (key: ";
pub const STORAGE_DECODE_ERROR_2: &str = "): ";
pub const STORAGE_ENCODE_ERROR: &str = "storage encode error: ";
pub const STORAGE_KEY_ENCODE_ERROR: &str = "storage key encode error: ";
pub const STORAGE_VALUE_EXCEEDS_BUFFER: &str = "storage value exceeds buffer";
Expand Down
20 changes: 13 additions & 7 deletions framework/base/src/storage/storage_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use core::{convert::Infallible, marker::PhantomData};

use crate::{
api::{
const_handles, use_raw_handle, ErrorApi, ErrorApiImpl, ManagedBufferApiImpl,
ManagedTypeApi, StaticVarApiImpl, StorageReadApi, StorageReadApiImpl,
const_handles, use_raw_handle, ErrorApi, ErrorApiImpl, HandleConstraints,
ManagedBufferApiImpl, ManagedTypeApi, StaticVarApiImpl, StorageReadApi, StorageReadApiImpl,
},
codec::*,
err_msg,
Expand Down Expand Up @@ -135,9 +135,10 @@ where
T: TopDecode,
A: StorageReadApi + ManagedTypeApi + ErrorApi,
{
let handle = key.get_handle().get_raw_handle_unchecked();
T::top_decode_or_handle_err(
StorageGetInput::new(key),
StorageGetErrorHandler::<A>::default(),
StorageGetErrorHandler::<A>::new(handle),
)
.unwrap_infallible()
}
Expand All @@ -161,17 +162,20 @@ where
M: ManagedTypeApi + ErrorApi,
{
_phantom: PhantomData<M>,
key: i32,
}

impl<M> Copy for StorageGetErrorHandler<M> where M: ManagedTypeApi + ErrorApi {}

impl<M> Default for StorageGetErrorHandler<M>
impl<M> StorageGetErrorHandler<M>
where
M: ManagedTypeApi + ErrorApi,
{
fn default() -> Self {
Self {
#[inline]
pub fn new(key: i32) -> Self {
StorageGetErrorHandler {
_phantom: PhantomData,
key,
}
}
}
Expand All @@ -184,7 +188,9 @@ where

fn handle_error(&self, err: DecodeError) -> Self::HandledErr {
let mut message_buffer =
ManagedBuffer::<M>::new_from_bytes(err_msg::STORAGE_DECODE_ERROR.as_bytes());
ManagedBuffer::<M>::new_from_bytes(err_msg::STORAGE_DECODE_ERROR_1.as_bytes());
M::managed_type_impl().mb_append(message_buffer.get_handle(), self.key.into());
message_buffer.append_bytes(err_msg::STORAGE_DECODE_ERROR_2.as_bytes());
message_buffer.append_bytes(err.message_bytes());
M::error_api_impl().signal_error_from_buffer(message_buffer.get_handle())
}
Expand Down
6 changes: 3 additions & 3 deletions framework/base/src/storage/storage_get_from_address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
api::{
const_handles, use_raw_handle, ErrorApi, ManagedBufferApiImpl, ManagedTypeApi,
StaticVarApiImpl, StorageReadApi, StorageReadApiImpl,
const_handles, use_raw_handle, ErrorApi, HandleConstraints, ManagedBufferApiImpl, ManagedTypeApi, StaticVarApiImpl, StorageReadApi, StorageReadApiImpl
},
codec::*,
types::{
Expand Down Expand Up @@ -148,9 +147,10 @@ where
T: TopDecode,
A: StorageReadApi + ManagedTypeApi + ErrorApi,
{
let handle = key.get_handle().get_raw_handle_unchecked();
T::top_decode_or_handle_err(
StorageGetFromAddressInput::new(addr, key),
StorageGetErrorHandler::<A>::default(),
StorageGetErrorHandler::<A>::new(handle),
)
.unwrap_infallible()
}
Expand Down

0 comments on commit ea7c8e4

Please sign in to comment.