Update dependencies of pallet_contracts (#8637)

* Update parity-wasm

* Cleanup Cargo.toml files

- Sort dependencies
- Remove minor and fix version where they are not necessary

* Update pretty_assertions

* Update rand
This commit is contained in:
Alexander Theißen
2021-04-19 12:47:46 +02:00
committed by GitHub
parent ea10494ca9
commit 18000a9ae8
9 changed files with 126 additions and 77 deletions
@@ -128,14 +128,14 @@ where
let mut contract = parity_wasm::builder::module()
// deploy function (first internal function)
.function()
.signature().with_return_type(None).build()
.signature().build()
.with_body(def.deploy_body.unwrap_or_else(||
FuncBody::new(Vec::new(), Instructions::empty())
))
.build()
// call function (second internal function)
.function()
.signature().with_return_type(None).build()
.signature().build()
.with_body(def.call_body.unwrap_or_else(||
FuncBody::new(Vec::new(), Instructions::empty())
))
@@ -147,7 +147,7 @@ where
if let Some(body) = def.aux_body {
let mut signature = contract
.function()
.signature().with_return_type(None);
.signature();
for _ in 0 .. def.aux_arg_num {
signature = signature.with_param(ValueType::I64);
}
@@ -166,7 +166,7 @@ where
for func in def.imported_functions {
let sig = parity_wasm::builder::signature()
.with_params(func.params)
.with_return_type(func.return_type)
.with_results(func.return_type.into_iter().collect())
.build_sig();
let sig = contract.push_signature(sig);
contract = contract.import()
@@ -450,11 +450,11 @@ pub mod body {
vec![Instruction::I32Const(current as i32)]
},
DynInstr::RandomUnaligned(low, high) => {
let unaligned = rng.gen_range(*low, *high) | 1;
let unaligned = rng.gen_range(*low..*high) | 1;
vec![Instruction::I32Const(unaligned as i32)]
},
DynInstr::RandomI32(low, high) => {
vec![Instruction::I32Const(rng.gen_range(*low, *high))]
vec![Instruction::I32Const(rng.gen_range(*low..*high))]
},
DynInstr::RandomI32Repeated(num) => {
(&mut rng).sample_iter(Standard).take(*num).map(|val|
@@ -469,19 +469,19 @@ pub mod body {
.collect()
},
DynInstr::RandomGetLocal(low, high) => {
vec![Instruction::GetLocal(rng.gen_range(*low, *high))]
vec![Instruction::GetLocal(rng.gen_range(*low..*high))]
},
DynInstr::RandomSetLocal(low, high) => {
vec![Instruction::SetLocal(rng.gen_range(*low, *high))]
vec![Instruction::SetLocal(rng.gen_range(*low..*high))]
},
DynInstr::RandomTeeLocal(low, high) => {
vec![Instruction::TeeLocal(rng.gen_range(*low, *high))]
vec![Instruction::TeeLocal(rng.gen_range(*low..*high))]
},
DynInstr::RandomGetGlobal(low, high) => {
vec![Instruction::GetGlobal(rng.gen_range(*low, *high))]
vec![Instruction::GetGlobal(rng.gen_range(*low..*high))]
},
DynInstr::RandomSetGlobal(low, high) => {
vec![Instruction::SetGlobal(rng.gen_range(*low, *high))]
vec![Instruction::SetGlobal(rng.gen_range(*low..*high))]
},
}
)
+6 -6
View File
@@ -836,16 +836,16 @@ fn signed_claim_surcharge_contract_removals() {
#[test]
fn claim_surcharge_malus() {
// Test surcharge malus for inherent
claim_surcharge(9, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), true);
claim_surcharge(8, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), true);
claim_surcharge(7, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), true);
claim_surcharge(6, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), false);
claim_surcharge(6, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), true);
claim_surcharge(5, |addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok(), false);
// Test surcharge malus for signed
claim_surcharge(9, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), true);
claim_surcharge(8, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), false);
claim_surcharge(8, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), true);
claim_surcharge(7, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), false);
claim_surcharge(6, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), false);
claim_surcharge(5, |addr| Contracts::claim_surcharge(Origin::signed(ALICE), addr, None).is_ok(), false);
}
/// Claim surcharge with the given trigger_call at the given blocks.
@@ -1732,7 +1732,7 @@ fn self_destruct_works() {
EventRecord {
phase: Phase::Initialization,
event: Event::pallet_balances(
pallet_balances::Event::Transfer(addr.clone(), DJANGO, 93_654)
pallet_balances::Event::Transfer(addr.clone(), DJANGO, 93_086)
),
topics: vec![],
},
@@ -1755,7 +1755,7 @@ fn self_destruct_works() {
// check that the beneficiary (django) got remaining balance
// some rent was deducted before termination
assert_eq!(Balances::free_balance(DJANGO), 1_093_654);
assert_eq!(Balances::free_balance(DJANGO), 1_093_086);
});
}
@@ -28,15 +28,15 @@ macro_rules! convert_args {
macro_rules! gen_signature {
( ( $( $params: ty ),* ) ) => (
{
parity_wasm::elements::FunctionType::new(convert_args!($($params),*), None)
parity_wasm::elements::FunctionType::new(convert_args!($($params),*), vec![])
}
);
( ( $( $params: ty ),* ) -> $returns: ty ) => (
{
parity_wasm::elements::FunctionType::new(convert_args!($($params),*), Some({
parity_wasm::elements::FunctionType::new(convert_args!($($params),*), vec![{
use $crate::wasm::env_def::ConvertibleToWasm; <$returns>::VALUE_TYPE
}))
}])
}
);
}
@@ -301,12 +301,12 @@ mod tests {
fn macro_gen_signature() {
assert_eq!(
gen_signature!((i32)),
FunctionType::new(vec![ValueType::I32], None),
FunctionType::new(vec![ValueType::I32], vec![]),
);
assert_eq!(
gen_signature!( (i32, u32) -> u32 ),
FunctionType::new(vec![ValueType::I32, ValueType::I32], Some(ValueType::I32)),
FunctionType::new(vec![ValueType::I32, ValueType::I32], vec![ValueType::I32]),
);
}
@@ -348,10 +348,10 @@ mod tests {
);
assert!(
Env::can_satisfy(b"seal0", b"seal_gas",&FunctionType::new(vec![ValueType::I32], None))
Env::can_satisfy(b"seal0", b"seal_gas",&FunctionType::new(vec![ValueType::I32], vec![]))
);
assert!(
!Env::can_satisfy(b"seal0", b"not_exists", &FunctionType::new(vec![], None))
!Env::can_satisfy(b"seal0", b"not_exists", &FunctionType::new(vec![], vec![]))
);
}
}
@@ -152,8 +152,8 @@ impl<'a, T: Config> ContractModule<'a, T> {
for wasm_type in type_section.types() {
match wasm_type {
Type::Function(func_type) => {
let return_type = func_type.return_type();
for value_type in func_type.params().iter().chain(return_type.iter()) {
let return_type = func_type.results().get(0);
for value_type in func_type.params().iter().chain(return_type) {
match value_type {
ValueType::F32 | ValueType::F64 =>
return Err("use of floating point type in function types is forbidden"),
@@ -279,9 +279,7 @@ impl<'a, T: Config> ContractModule<'a, T> {
let Type::Function(ref func_ty) = types
.get(func_ty_idx as usize)
.ok_or_else(|| "function has a non-existent type")?;
if !func_ty.params().is_empty() ||
!(func_ty.return_type().is_none() ||
func_ty.return_type() == Some(ValueType::I32)) {
if !(func_ty.params().is_empty() && func_ty.results().is_empty()) {
return Err("entry point has wrong signature");
}
}