mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 07:01:02 +00:00
Contracts: Translate .wat fixtures to rust (#2654)
- Translate all pallet-contracts fixtures from `wat` to Rust files. - Fix read_sandbox_memory_as to not use MaxEncodedLen as this could break if used with types with a non-fixed encoded len. --------- Co-authored-by: alvicsam <alvicsam@gmail.com> Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -2460,7 +2460,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
result,
|
||||
Err(ExecError {
|
||||
error: Error::<Test>::OutOfBounds.into(),
|
||||
error: Error::<Test>::DecodingFailed.into(),
|
||||
origin: ErrorOrigin::Caller,
|
||||
})
|
||||
);
|
||||
@@ -3428,4 +3428,20 @@ mod tests {
|
||||
assert_eq!(delegate_dependencies.len(), 1);
|
||||
assert_eq!(delegate_dependencies[0].as_bytes(), [1; 32]);
|
||||
}
|
||||
|
||||
// This test checks that [`Runtime::read_sandbox_memory_as`] works, when the decoded type has a
|
||||
// max_len greater than the memory size, but the decoded data fits into the memory.
|
||||
#[test]
|
||||
fn read_sandbox_memory_as_works_with_max_len_out_of_bounds_but_fitting_actual_data() {
|
||||
use frame_support::BoundedVec;
|
||||
use sp_core::ConstU32;
|
||||
|
||||
let mut ext = MockExt::default();
|
||||
let runtime = Runtime::new(&mut ext, vec![]);
|
||||
let data = vec![1u8, 2, 3];
|
||||
let memory = data.encode();
|
||||
let decoded: BoundedVec<u8, ConstU32<128>> =
|
||||
runtime.read_sandbox_memory_as(&memory, 0u32).unwrap();
|
||||
assert_eq!(decoded.into_inner(), data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,9 +583,8 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
|
||||
ptr: u32,
|
||||
) -> Result<D, DispatchError> {
|
||||
let ptr = ptr as usize;
|
||||
let mut bound_checked = memory
|
||||
.get(ptr..ptr + D::max_encoded_len() as usize)
|
||||
.ok_or_else(|| Error::<E::T>::OutOfBounds)?;
|
||||
let mut bound_checked = memory.get(ptr..).ok_or_else(|| Error::<E::T>::OutOfBounds)?;
|
||||
|
||||
let decoded = D::decode_with_depth_limit(MAX_DECODE_NESTING, &mut bound_checked)
|
||||
.map_err(|_| DispatchError::from(Error::<E::T>::DecodingFailed))?;
|
||||
Ok(decoded)
|
||||
|
||||
Reference in New Issue
Block a user