mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 08:07:58 +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
@@ -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