mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 11:57:56 +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:
@@ -178,7 +178,7 @@ parameter_types! {
|
||||
pub struct TestExtension {
|
||||
enabled: bool,
|
||||
last_seen_buffer: Vec<u8>,
|
||||
last_seen_inputs: (u32, u32, u32, u32),
|
||||
last_seen_input_len: u32,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -201,14 +201,14 @@ impl TestExtension {
|
||||
TestExtensionTestValue::get().last_seen_buffer.clone()
|
||||
}
|
||||
|
||||
fn last_seen_inputs() -> (u32, u32, u32, u32) {
|
||||
TestExtensionTestValue::get().last_seen_inputs
|
||||
fn last_seen_input_len() -> u32 {
|
||||
TestExtensionTestValue::get().last_seen_input_len
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TestExtension {
|
||||
fn default() -> Self {
|
||||
Self { enabled: true, last_seen_buffer: vec![], last_seen_inputs: (0, 0, 0, 0) }
|
||||
Self { enabled: true, last_seen_buffer: vec![], last_seen_input_len: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,9 +231,7 @@ impl ChainExtension<Test> for TestExtension {
|
||||
},
|
||||
1 => {
|
||||
let env = env.only_in();
|
||||
TestExtensionTestValue::mutate(|e| {
|
||||
e.last_seen_inputs = (env.val0(), env.val1(), env.val2(), env.val3())
|
||||
});
|
||||
TestExtensionTestValue::mutate(|e| e.last_seen_input_len = env.val1());
|
||||
Ok(RetVal::Converging(id))
|
||||
},
|
||||
2 => {
|
||||
@@ -2154,8 +2152,7 @@ fn chain_extension_works() {
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
// those values passed in the fixture
|
||||
assert_eq!(TestExtension::last_seen_inputs(), (4, 4, 16, 12));
|
||||
assert_eq!(TestExtension::last_seen_input_len(), 4);
|
||||
|
||||
// 2 = charge some extra weight (amount supplied in the fifth byte)
|
||||
let result = Contracts::bare_call(
|
||||
@@ -3511,7 +3508,7 @@ fn failed_deposit_charge_should_roll_back_call() {
|
||||
let result = execute().unwrap();
|
||||
|
||||
// Bump the deposit per byte to a high value to trigger a FundsUnavailable error.
|
||||
DEPOSIT_PER_BYTE.with(|c| *c.borrow_mut() = ED);
|
||||
DEPOSIT_PER_BYTE.with(|c| *c.borrow_mut() = 20);
|
||||
assert_err_with_weight!(execute(), TokenError::FundsUnavailable, result.actual_weight);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user