Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Feb 19, 2024
1 parent fbb7f06 commit f7c69ed
Showing 1 changed file with 65 additions and 26 deletions.
91 changes: 65 additions & 26 deletions substrate/frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub trait Ext: sealing::Sealed {
fn call(
&mut self,
gas_limit: Weight,
deposit_limit: Option<BalanceOf<Self::T>>,
deposit_limit: BalanceOf<Self::T>,
to: AccountIdOf<Self::T>,
value: BalanceOf<Self::T>,
input_data: Vec<u8>,
Expand All @@ -168,7 +168,7 @@ pub trait Ext: sealing::Sealed {
fn instantiate(
&mut self,
gas_limit: Weight,
deposit_limit: Option<BalanceOf<Self::T>>,
deposit_limit: BalanceOf<Self::T>,
code: CodeHash<Self::T>,
value: BalanceOf<Self::T>,
input_data: Vec<u8>,
Expand Down Expand Up @@ -750,7 +750,7 @@ where
gas_meter,
Weight::zero(),
storage_meter,
None,
BalanceOf::<T>::zero(),
determinism,
)?;

Expand Down Expand Up @@ -782,7 +782,7 @@ where
gas_meter: &mut GasMeter<T>,
gas_limit: Weight,
storage_meter: &mut storage::meter::GenericMeter<T, S>,
deposit_limit: Option<BalanceOf<T>>,
deposit_limit: BalanceOf<T>,
determinism: Determinism,
) -> Result<(Frame<T>, E, Option<u64>), ExecError> {
let (account_id, contract_info, executable, delegate_caller, entry_point, nonce) =
Expand Down Expand Up @@ -851,7 +851,7 @@ where
frame_args: FrameArgs<T, E>,
value_transferred: BalanceOf<T>,
gas_limit: Weight,
deposit_limit: Option<BalanceOf<T>>,
deposit_limit: BalanceOf<T>,
) -> Result<E, ExecError> {
if self.frames.len() == T::CallStack::size() {
return Err(Error::<T>::MaxCallDepthReached.into())
Expand Down Expand Up @@ -1188,7 +1188,7 @@ where
fn call(
&mut self,
gas_limit: Weight,
deposit_limit: Option<BalanceOf<T>>,
deposit_limit: BalanceOf<T>,
to: T::AccountId,
value: BalanceOf<T>,
input_data: Vec<u8>,
Expand Down Expand Up @@ -1249,15 +1249,15 @@ where
},
value,
Weight::zero(),
None,
BalanceOf::<T>::zero(),
)?;
self.run(executable, input_data)
}

fn instantiate(
&mut self,
gas_limit: Weight,
deposit_limit: Option<BalanceOf<Self::T>>,
deposit_limit: BalanceOf<Self::T>,
code_hash: CodeHash<T>,
value: BalanceOf<T>,
input_data: Vec<u8>,
Expand Down Expand Up @@ -2098,7 +2098,7 @@ mod tests {
let value = Default::default();
let recurse_ch = MockLoader::insert(Call, |ctx, _| {
// Try to call into yourself.
let r = ctx.ext.call(Weight::zero(), None, BOB, 0, vec![], true);
let r = ctx.ext.call(Weight::zero(), BalanceOf::<Test>::zero(), BOB, 0, vec![], true);

ReachedBottom::mutate(|reached_bottom| {
if !*reached_bottom {
Expand Down Expand Up @@ -2156,7 +2156,11 @@ mod tests {
});

// Call into CHARLIE contract.
assert_matches!(ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], true), Ok(_));
assert_matches!(
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), CHARLIE, 0, vec![], true),
Ok(_)
);
exec_success()
});
let charlie_ch = MockLoader::insert(Call, |ctx, _| {
Expand Down Expand Up @@ -2300,7 +2304,8 @@ mod tests {
// ALICE is the origin of the call stack
assert!(ctx.ext.caller_is_origin());
// BOB calls CHARLIE
ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], true)
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), CHARLIE, 0, vec![], true)
});

ExtBuilder::default().build().execute_with(|| {
Expand Down Expand Up @@ -2398,7 +2403,8 @@ mod tests {
// root is the origin of the call stack.
assert!(ctx.ext.caller_is_root());
// BOB calls CHARLIE.
ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], true)
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), CHARLIE, 0, vec![], true)
});

ExtBuilder::default().build().execute_with(|| {
Expand Down Expand Up @@ -2431,7 +2437,11 @@ mod tests {
assert_eq!(*ctx.ext.address(), BOB);

// Call into charlie contract.
assert_matches!(ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], true), Ok(_));
assert_matches!(
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), CHARLIE, 0, vec![], true),
Ok(_)
);
exec_success()
});
let charlie_ch = MockLoader::insert(Call, |ctx, _| {
Expand Down Expand Up @@ -2606,7 +2616,7 @@ mod tests {
.ext
.instantiate(
Weight::zero(),
None,
BalanceOf::<Test>::zero(),
dummy_ch,
<Test as Config>::Currency::minimum_balance(),
vec![],
Expand Down Expand Up @@ -2682,7 +2692,7 @@ mod tests {
assert_matches!(
ctx.ext.instantiate(
Weight::zero(),
None,
BalanceOf::<Test>::zero(),
dummy_ch,
<Test as Config>::Currency::minimum_balance(),
vec![],
Expand Down Expand Up @@ -2791,15 +2801,25 @@ mod tests {
assert_eq!(info.storage_byte_deposit, 0);
info.storage_byte_deposit = 42;
assert_eq!(
ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], true),
ctx.ext.call(
Weight::zero(),
BalanceOf::<Test>::zero(),
CHARLIE,
0,
vec![],
true
),
exec_trapped()
);
assert_eq!(ctx.ext.contract_info().storage_byte_deposit, 42);
}
exec_success()
});
let code_charlie = MockLoader::insert(Call, |ctx, _| {
assert!(ctx.ext.call(Weight::zero(), None, BOB, 0, vec![99], true).is_ok());
assert!(ctx
.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), BOB, 0, vec![99], true)
.is_ok());
exec_trapped()
});

Expand Down Expand Up @@ -2831,7 +2851,7 @@ mod tests {
fn recursive_call_during_constructor_fails() {
let code = MockLoader::insert(Constructor, |ctx, _| {
assert_matches!(
ctx.ext.call(Weight::zero(), None, ctx.ext.address().clone(), 0, vec![], true),
ctx.ext.call(Weight::zero(), BalanceOf::<Test>::zero(), ctx.ext.address().clone(), 0, vec![], true),
Err(ExecError{error, ..}) if error == <Error<Test>>::ContractNotFound.into()
);
exec_success()
Expand Down Expand Up @@ -2981,7 +3001,7 @@ mod tests {
// call the contract passed as input with disabled reentry
let code_bob = MockLoader::insert(Call, |ctx, _| {
let dest = Decode::decode(&mut ctx.input_data.as_ref()).unwrap();
ctx.ext.call(Weight::zero(), None, dest, 0, vec![], false)
ctx.ext.call(Weight::zero(), BalanceOf::<Test>::zero(), dest, 0, vec![], false)
});

let code_charlie = MockLoader::insert(Call, |_, _| exec_success());
Expand Down Expand Up @@ -3030,15 +3050,16 @@ mod tests {
fn call_deny_reentry() {
let code_bob = MockLoader::insert(Call, |ctx, _| {
if ctx.input_data[0] == 0 {
ctx.ext.call(Weight::zero(), None, CHARLIE, 0, vec![], false)
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), CHARLIE, 0, vec![], false)
} else {
exec_success()
}
});

// call BOB with input set to '1'
let code_charlie = MockLoader::insert(Call, |ctx, _| {
ctx.ext.call(Weight::zero(), None, BOB, 0, vec![1], true)
ctx.ext.call(Weight::zero(), BalanceOf::<Test>::zero(), BOB, 0, vec![1], true)
});

ExtBuilder::default().build().execute_with(|| {
Expand Down Expand Up @@ -3234,7 +3255,7 @@ mod tests {
ctx.ext
.instantiate(
Weight::zero(),
None,
BalanceOf::<Test>::zero(),
fail_code,
ctx.ext.minimum_balance() * 100,
vec![],
Expand All @@ -3248,7 +3269,7 @@ mod tests {
.ext
.instantiate(
Weight::zero(),
None,
BalanceOf::<Test>::zero(),
success_code,
ctx.ext.minimum_balance() * 100,
vec![],
Expand All @@ -3257,7 +3278,9 @@ mod tests {
.unwrap();

// a plain call should not influence the account counter
ctx.ext.call(Weight::zero(), None, account_id, 0, vec![], false).unwrap();
ctx.ext
.call(Weight::zero(), BalanceOf::<Test>::zero(), account_id, 0, vec![], false)
.unwrap();

exec_success()
});
Expand Down Expand Up @@ -3775,15 +3798,31 @@ mod tests {
assert_eq!(ctx.ext.nonce(), 1);
// Should not change with a failed instantiation
assert_err!(
ctx.ext.instantiate(Weight::zero(), None, fail_code, 0, vec![], &[],),
ctx.ext.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
fail_code,
0,
vec![],
&[],
),
ExecError {
error: <Error<Test>>::ContractTrapped.into(),
origin: ErrorOrigin::Callee
}
);
assert_eq!(ctx.ext.nonce(), 1);
// Successful instantiation increments
ctx.ext.instantiate(Weight::zero(), None, success_code, 0, vec![], &[]).unwrap();
ctx.ext
.instantiate(
Weight::zero(),
BalanceOf::<Test>::zero(),
success_code,
0,
vec![],
&[],
)
.unwrap();
assert_eq!(ctx.ext.nonce(), 2);
exec_success()
});
Expand Down

0 comments on commit f7c69ed

Please # to comment.