mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 22:47:56 +00:00
Remove contracts RPCs (#12358)
* Remove contracts RPCs * Remove serde as RPC serialization is no longer needed * Rename folder to match crate name * Compile fix * Remove Byte wrapper
This commit is contained in:
committed by
GitHub
parent
54713ca17a
commit
bb9d2fa75a
@@ -1384,7 +1384,6 @@ mod tests {
|
||||
use frame_system::{EventRecord, Phase};
|
||||
use pallet_contracts_primitives::ReturnFlags;
|
||||
use pretty_assertions::assert_eq;
|
||||
use sp_core::Bytes;
|
||||
use sp_runtime::{traits::Hash, DispatchError};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
@@ -1517,7 +1516,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn exec_success() -> ExecResult {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() })
|
||||
}
|
||||
|
||||
fn exec_trapped() -> ExecResult {
|
||||
@@ -1586,7 +1585,7 @@ mod tests {
|
||||
|
||||
let success_ch = MockLoader::insert(Call, move |ctx, _| {
|
||||
assert_eq!(ctx.ext.value_transferred(), value);
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() })
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -1621,13 +1620,13 @@ mod tests {
|
||||
|
||||
let success_ch = MockLoader::insert(Call, move |ctx, _| {
|
||||
assert_eq!(ctx.ext.value_transferred(), value);
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() })
|
||||
});
|
||||
|
||||
let delegate_ch = MockLoader::insert(Call, move |ctx, _| {
|
||||
assert_eq!(ctx.ext.value_transferred(), value);
|
||||
let _ = ctx.ext.delegate_call(success_ch, Vec::new())?;
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() })
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -1662,7 +1661,7 @@ mod tests {
|
||||
let dest = BOB;
|
||||
|
||||
let return_ch = MockLoader::insert(Call, |_, _| {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Bytes(Vec::new()) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Vec::new() })
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -1715,7 +1714,7 @@ mod tests {
|
||||
let origin = ALICE;
|
||||
let dest = BOB;
|
||||
let return_ch = MockLoader::insert(Call, |_, _| {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(vec![1, 2, 3, 4]) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![1, 2, 3, 4] })
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -1736,7 +1735,7 @@ mod tests {
|
||||
|
||||
let output = result.unwrap();
|
||||
assert!(!output.did_revert());
|
||||
assert_eq!(output.data, Bytes(vec![1, 2, 3, 4]));
|
||||
assert_eq!(output.data, vec![1, 2, 3, 4]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1747,7 +1746,7 @@ mod tests {
|
||||
let origin = ALICE;
|
||||
let dest = BOB;
|
||||
let return_ch = MockLoader::insert(Call, |_, _| {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Bytes(vec![1, 2, 3, 4]) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![1, 2, 3, 4] })
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -1768,7 +1767,7 @@ mod tests {
|
||||
|
||||
let output = result.unwrap();
|
||||
assert!(output.did_revert());
|
||||
assert_eq!(output.data, Bytes(vec![1, 2, 3, 4]));
|
||||
assert_eq!(output.data, vec![1, 2, 3, 4]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2115,7 +2114,7 @@ mod tests {
|
||||
#[test]
|
||||
fn instantiation_work_with_success_output() {
|
||||
let dummy_ch = MockLoader::insert(Constructor, |_, _| {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(vec![80, 65, 83, 83]) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![80, 65, 83, 83] })
|
||||
});
|
||||
|
||||
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
|
||||
@@ -2140,7 +2139,7 @@ mod tests {
|
||||
&[],
|
||||
None,
|
||||
),
|
||||
Ok((address, ref output)) if output.data == Bytes(vec![80, 65, 83, 83]) => address
|
||||
Ok((address, ref output)) if output.data == vec![80, 65, 83, 83] => address
|
||||
);
|
||||
|
||||
// Check that the newly created account has the expected code hash and
|
||||
@@ -2159,7 +2158,7 @@ mod tests {
|
||||
#[test]
|
||||
fn instantiation_fails_with_failing_output() {
|
||||
let dummy_ch = MockLoader::insert(Constructor, |_, _| {
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Bytes(vec![70, 65, 73, 76]) })
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![70, 65, 73, 76] })
|
||||
});
|
||||
|
||||
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
|
||||
@@ -2184,7 +2183,7 @@ mod tests {
|
||||
&[],
|
||||
None,
|
||||
),
|
||||
Ok((address, ref output)) if output.data == Bytes(vec![70, 65, 73, 76]) => address
|
||||
Ok((address, ref output)) if output.data == vec![70, 65, 73, 76] => address
|
||||
);
|
||||
|
||||
// Check that the account has not been created.
|
||||
|
||||
@@ -123,7 +123,7 @@ use pallet_contracts_primitives::{
|
||||
StorageDeposit,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{crypto::UncheckedFrom, Bytes};
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_runtime::traits::{Convert, Hash, Saturating, StaticLookup};
|
||||
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};
|
||||
|
||||
@@ -512,7 +512,7 @@ pub mod pallet {
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit.map(Into::into),
|
||||
Code::Upload(Bytes(code)),
|
||||
Code::Upload(code),
|
||||
data,
|
||||
salt,
|
||||
None,
|
||||
@@ -743,7 +743,7 @@ pub mod pallet {
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit.map(Into::into),
|
||||
Code::Upload(Bytes(code)),
|
||||
Code::Upload(code),
|
||||
data,
|
||||
salt,
|
||||
None,
|
||||
@@ -1234,7 +1234,7 @@ where
|
||||
let try_exec = || {
|
||||
let schedule = T::Schedule::get();
|
||||
let (extra_deposit, executable) = match code {
|
||||
Code::Upload(Bytes(binary)) => {
|
||||
Code::Upload(binary) => {
|
||||
let executable = PrefabWasmModule::from_code(binary, &schedule, origin.clone())
|
||||
.map_err(|(err, msg)| {
|
||||
debug_message.as_mut().map(|buffer| buffer.extend(msg.as_bytes()));
|
||||
|
||||
@@ -44,7 +44,6 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::{self as system, EventRecord, Phase};
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
use sp_core::Bytes;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_keystore::{testing::KeyStore, KeystoreExt};
|
||||
use sp_runtime::{
|
||||
@@ -1722,7 +1721,7 @@ fn chain_extension_works() {
|
||||
let result =
|
||||
Contracts::bare_call(ALICE, addr.clone(), 0, GAS_LIMIT, None, input.clone(), false);
|
||||
assert_eq!(TestExtension::last_seen_buffer(), input);
|
||||
assert_eq!(result.result.unwrap().data, Bytes(input));
|
||||
assert_eq!(result.result.unwrap().data, input);
|
||||
|
||||
// 1 = treat inputs as integer primitives and store the supplied integers
|
||||
Contracts::bare_call(
|
||||
@@ -1787,7 +1786,7 @@ fn chain_extension_works() {
|
||||
.result
|
||||
.unwrap();
|
||||
assert_eq!(result.flags, ReturnFlags::REVERT);
|
||||
assert_eq!(result.data, Bytes(vec![42, 99]));
|
||||
assert_eq!(result.data, vec![42, 99]);
|
||||
|
||||
// diverging to second chain extension that sets flags to 0x1 and returns a fixed buffer
|
||||
// We set the MSB part to 1 (instead of 0) which routes the request into the second
|
||||
@@ -1804,7 +1803,7 @@ fn chain_extension_works() {
|
||||
.result
|
||||
.unwrap();
|
||||
assert_eq!(result.flags, ReturnFlags::REVERT);
|
||||
assert_eq!(result.data, Bytes(vec![0x4B, 0x1D]));
|
||||
assert_eq!(result.data, vec![0x4B, 0x1D]);
|
||||
|
||||
// Diverging to third chain extension that is disabled
|
||||
// We set the MSB part to 2 (instead of 0) which routes the request into the third extension
|
||||
@@ -2672,7 +2671,7 @@ fn ecdsa_recover() {
|
||||
.result
|
||||
.unwrap();
|
||||
assert!(!result.did_revert());
|
||||
assert_eq!(result.data.as_ref(), &EXPECTED_COMPRESSED_PUBLIC_KEY);
|
||||
assert_eq!(result.data, EXPECTED_COMPRESSED_PUBLIC_KEY);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3503,7 +3502,7 @@ fn contract_reverted() {
|
||||
.result
|
||||
.unwrap();
|
||||
assert_eq!(result.result.flags, flags);
|
||||
assert_eq!(result.result.data.0, buffer);
|
||||
assert_eq!(result.result.data, buffer);
|
||||
assert!(!<ContractInfoOf<Test>>::contains_key(result.account_id));
|
||||
|
||||
// Pass empty flags and therefore successfully instantiate the contract for later use.
|
||||
@@ -3539,7 +3538,7 @@ fn contract_reverted() {
|
||||
.result
|
||||
.unwrap();
|
||||
assert_eq!(result.flags, flags);
|
||||
assert_eq!(result.data.0, buffer);
|
||||
assert_eq!(result.data, buffer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3559,7 +3558,7 @@ fn code_rejected_error_works() {
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
Code::Upload(Bytes(wasm)),
|
||||
Code::Upload(wasm),
|
||||
vec![],
|
||||
vec![],
|
||||
true,
|
||||
|
||||
@@ -281,7 +281,7 @@ mod tests {
|
||||
};
|
||||
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
|
||||
use pretty_assertions::assert_eq;
|
||||
use sp_core::{Bytes, H256};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::DispatchError;
|
||||
use std::{
|
||||
borrow::BorrowMut,
|
||||
@@ -341,8 +341,8 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The call is mocked and just returns this hardcoded value.
|
||||
fn call_return_data() -> Bytes {
|
||||
Bytes(vec![0xDE, 0xAD, 0xBE, 0xEF])
|
||||
fn call_return_data() -> Vec<u8> {
|
||||
vec![0xDE, 0xAD, 0xBE, 0xEF]
|
||||
}
|
||||
|
||||
impl Default for MockExt {
|
||||
@@ -404,7 +404,7 @@ mod tests {
|
||||
});
|
||||
Ok((
|
||||
Contracts::<Test>::contract_address(&ALICE, &code_hash, salt),
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) },
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() },
|
||||
))
|
||||
}
|
||||
fn set_code_hash(&mut self, hash: CodeHash<Self::T>) -> Result<(), DispatchError> {
|
||||
@@ -804,7 +804,7 @@ mod tests {
|
||||
let mut mock_ext = MockExt::default();
|
||||
let input = vec![0xff, 0x2a, 0x99, 0x88];
|
||||
let result = execute(CODE, input.clone(), &mut mock_ext).unwrap();
|
||||
assert_eq!(result.data.0, input);
|
||||
assert_eq!(result.data, input);
|
||||
assert_eq!(
|
||||
&mock_ext.calls,
|
||||
&[CallEntry { to: ALICE, value: 0x2a, data: input, allows_reentry: true }]
|
||||
@@ -907,15 +907,15 @@ mod tests {
|
||||
|
||||
// value does not exist -> sentinel value returned
|
||||
let result = execute(CODE, [3u8; 32].encode(), &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
|
||||
// value did exist -> success
|
||||
let result = execute(CODE, [1u8; 32].encode(), &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 1,);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 1,);
|
||||
|
||||
// value did exist -> success (zero sized type)
|
||||
let result = execute(CODE, [2u8; 32].encode(), &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0,);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0,);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -977,13 +977,13 @@ mod tests {
|
||||
let input = (63, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// sentinel returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
|
||||
// value exists
|
||||
let input = (64, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// true as u32 returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 1);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 1);
|
||||
// getter does not remove the value from storage
|
||||
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()).unwrap(), &[42u8]);
|
||||
|
||||
@@ -991,7 +991,7 @@ mod tests {
|
||||
let input = (19, [2u8; 19]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// true as u32 returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0);
|
||||
// getter does not remove the value from storage
|
||||
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()).unwrap(), &([] as [u8; 0]));
|
||||
}
|
||||
@@ -1234,7 +1234,7 @@ mod tests {
|
||||
let output = execute(CODE_ECDSA_TO_ETH_ADDRESS, vec![], MockExt::default()).unwrap();
|
||||
assert_eq!(
|
||||
output,
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes([0x02; 20].to_vec()) }
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: [0x02; 20].to_vec() }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1311,7 +1311,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
output,
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes([0x22; 32].to_vec()) }
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: [0x22; 32].to_vec() }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1630,10 +1630,7 @@ mod tests {
|
||||
fn return_from_start_fn() {
|
||||
let output = execute(CODE_RETURN_FROM_START_FN, vec![], MockExt::default()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output,
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(vec![1, 2, 3, 4]) }
|
||||
);
|
||||
assert_eq!(output, ExecReturnValue { flags: ReturnFlags::empty(), data: vec![1, 2, 3, 4] });
|
||||
}
|
||||
|
||||
const CODE_TIMESTAMP_NOW: &str = r#"
|
||||
@@ -1902,15 +1899,13 @@ mod tests {
|
||||
output,
|
||||
ExecReturnValue {
|
||||
flags: ReturnFlags::empty(),
|
||||
data: Bytes(
|
||||
(
|
||||
array_bytes::hex2array_unchecked::<32>(
|
||||
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
|
||||
),
|
||||
42u64,
|
||||
)
|
||||
.encode()
|
||||
),
|
||||
data: (
|
||||
array_bytes::hex2array_unchecked::<32>(
|
||||
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
|
||||
),
|
||||
42u64,
|
||||
)
|
||||
.encode()
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -2124,7 +2119,7 @@ mod tests {
|
||||
output,
|
||||
ExecReturnValue {
|
||||
flags: ReturnFlags::empty(),
|
||||
data: Bytes(array_bytes::hex2bytes_unchecked("445566778899")),
|
||||
data: array_bytes::hex2bytes_unchecked("445566778899"),
|
||||
}
|
||||
);
|
||||
assert!(!output.did_revert());
|
||||
@@ -2143,7 +2138,7 @@ mod tests {
|
||||
output,
|
||||
ExecReturnValue {
|
||||
flags: ReturnFlags::REVERT,
|
||||
data: Bytes(array_bytes::hex2bytes_unchecked("5566778899")),
|
||||
data: array_bytes::hex2bytes_unchecked("5566778899"),
|
||||
}
|
||||
);
|
||||
assert!(output.did_revert());
|
||||
@@ -2306,7 +2301,7 @@ mod tests {
|
||||
let result = execute(CODE_CALL_RUNTIME, call.encode(), &mut ext).unwrap();
|
||||
assert_eq!(*ext.runtime_calls.borrow(), vec![call]);
|
||||
// 0 = ReturnCode::Success
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2371,19 +2366,19 @@ mod tests {
|
||||
// value did not exist before -> sentinel returned
|
||||
let input = ([1u8; 32], [42u8, 48]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[42u8, 48]);
|
||||
|
||||
// value do exist -> length of old value returned
|
||||
let input = ([1u8; 32], [0u8; 0]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 2);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 2);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[0u8; 0]);
|
||||
|
||||
// value do exist -> length of old value returned (test for zero sized val)
|
||||
let input = ([1u8; 32], [99u8]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[99u8]);
|
||||
}
|
||||
|
||||
@@ -2442,19 +2437,19 @@ mod tests {
|
||||
// value did not exist before -> sentinel returned
|
||||
let input = (32, [1u8; 32], [42u8, 48]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[42u8, 48]);
|
||||
|
||||
// value do exist -> length of old value returned
|
||||
let input = (32, [1u8; 32], [0u8; 0]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 2);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 2);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[0u8; 0]);
|
||||
|
||||
// value do exist -> length of old value returned (test for zero sized val)
|
||||
let input = (32, [1u8; 32], [99u8]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0);
|
||||
assert_eq!(ext.storage.get(&[1u8; 32].to_vec()).unwrap(), &[99u8]);
|
||||
}
|
||||
|
||||
@@ -2527,7 +2522,7 @@ mod tests {
|
||||
let input = (63, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::KeyNotFound as u32
|
||||
);
|
||||
|
||||
@@ -2535,21 +2530,21 @@ mod tests {
|
||||
let input = (64, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::Success as u32
|
||||
);
|
||||
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()).unwrap(), &[42u8]);
|
||||
assert_eq!(&result.data.0[4..], &[42u8]);
|
||||
assert_eq!(&result.data[4..], &[42u8]);
|
||||
|
||||
// value exists (test for 0 sized)
|
||||
let input = (19, [2u8; 19]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::Success as u32
|
||||
);
|
||||
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()), Some(&vec![]));
|
||||
assert_eq!(&result.data.0[4..], &([] as [u8; 0]));
|
||||
assert_eq!(&result.data[4..], &([] as [u8; 0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2611,14 +2606,14 @@ mod tests {
|
||||
let input = (32, [3u8; 32]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// sentinel returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(ext.storage.get(&[3u8; 32].to_vec()), None);
|
||||
|
||||
// value did exist
|
||||
let input = (64, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// length returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 1);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 1);
|
||||
// value cleared
|
||||
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()), None);
|
||||
|
||||
@@ -2626,14 +2621,14 @@ mod tests {
|
||||
let input = (63, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// sentinel returned
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL);
|
||||
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()), None);
|
||||
|
||||
// value exists
|
||||
let input = (19, [2u8; 19]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
// length returned (test for 0 sized)
|
||||
assert_eq!(u32::from_le_bytes(result.data.0.try_into().unwrap()), 0);
|
||||
assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0);
|
||||
// value cleared
|
||||
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()), None);
|
||||
}
|
||||
@@ -2710,7 +2705,7 @@ mod tests {
|
||||
let input = (63, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::KeyNotFound as u32
|
||||
);
|
||||
|
||||
@@ -2718,21 +2713,21 @@ mod tests {
|
||||
let input = (64, [1u8; 64]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::Success as u32
|
||||
);
|
||||
assert_eq!(ext.storage.get(&[1u8; 64].to_vec()), None);
|
||||
assert_eq!(&result.data.0[4..], &[42u8]);
|
||||
assert_eq!(&result.data[4..], &[42u8]);
|
||||
|
||||
// value did exist -> length returned (test for 0 sized)
|
||||
let input = (19, [2u8; 19]).encode();
|
||||
let result = execute(CODE, input, &mut ext).unwrap();
|
||||
assert_eq!(
|
||||
u32::from_le_bytes(result.data.0[0..4].try_into().unwrap()),
|
||||
u32::from_le_bytes(result.data[0..4].try_into().unwrap()),
|
||||
ReturnCode::Success as u32
|
||||
);
|
||||
assert_eq!(ext.storage.get(&[2u8; 19].to_vec()), None);
|
||||
assert_eq!(&result.data.0[4..], &[0u8; 0]);
|
||||
assert_eq!(&result.data[4..], &[0u8; 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2769,10 +2764,7 @@ mod tests {
|
||||
let output = execute(CODE_IS_CONTRACT, vec![], MockExt::default()).unwrap();
|
||||
|
||||
// The mock ext just always returns 1u32 (`true`).
|
||||
assert_eq!(
|
||||
output,
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(1u32.encode()) },
|
||||
);
|
||||
assert_eq!(output, ExecReturnValue { flags: ReturnFlags::empty(), data: 1u32.encode() },);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2906,10 +2898,7 @@ mod tests {
|
||||
let output = execute(CODE_CALLER_IS_ORIGIN, vec![], MockExt::default()).unwrap();
|
||||
|
||||
// The mock ext just always returns 0u32 (`false`)
|
||||
assert_eq!(
|
||||
output,
|
||||
ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(0u32.encode()) },
|
||||
);
|
||||
assert_eq!(output, ExecReturnValue { flags: ReturnFlags::empty(), data: 0u32.encode() },);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -30,7 +30,7 @@ use codec::{Decode, DecodeLimit, Encode, MaxEncodedLen};
|
||||
use frame_support::{dispatch::DispatchError, ensure, traits::Get, weights::Weight};
|
||||
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
|
||||
use pallet_contracts_proc_macro::define_env;
|
||||
use sp_core::{crypto::UncheckedFrom, Bytes};
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_io::hashing::{blake2_128, blake2_256, keccak_256, sha2_256};
|
||||
use sp_runtime::traits::{Bounded, Zero};
|
||||
use sp_sandbox::SandboxMemory;
|
||||
@@ -483,10 +483,10 @@ where
|
||||
TrapReason::Return(ReturnData { flags, data }) => {
|
||||
let flags =
|
||||
ReturnFlags::from_bits(flags).ok_or(Error::<E::T>::InvalidCallFlags)?;
|
||||
Ok(ExecReturnValue { flags, data: Bytes(data) })
|
||||
Ok(ExecReturnValue { flags, data })
|
||||
},
|
||||
TrapReason::Termination =>
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) }),
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() }),
|
||||
TrapReason::SupervisorError(error) => return Err(error.into()),
|
||||
}
|
||||
}
|
||||
@@ -494,7 +494,7 @@ where
|
||||
// Check the exact type of the error.
|
||||
match sandbox_result {
|
||||
// No traps were generated. Proceed normally.
|
||||
Ok(_) => Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) }),
|
||||
Ok(_) => Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() }),
|
||||
// `Error::Module` is returned only if instantiation or linking failed (i.e.
|
||||
// wasm binary tried to import a function that is not provided by the host).
|
||||
// This shouldn't happen because validation process ought to reject such binaries.
|
||||
@@ -879,7 +879,7 @@ where
|
||||
if let Ok(return_value) = call_outcome {
|
||||
return Err(TrapReason::Return(ReturnData {
|
||||
flags: return_value.flags.bits(),
|
||||
data: return_value.data.0,
|
||||
data: return_value.data,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user