mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
Rename more things related to contract instantiation (#3664)
* Rename more things related to contract instantiation * rename `creator_ch` * Fix node runtime * fix contracts tests * Little fix
This commit is contained in:
@@ -421,7 +421,7 @@ where
|
||||
) -> Result<(T::AccountId, ExecReturnValue), ExecError> {
|
||||
if self.depth == self.config.max_depth as usize {
|
||||
return Err(ExecError {
|
||||
reason: "reached maximum depth, cannot create",
|
||||
reason: "reached maximum depth, cannot instantiate",
|
||||
buffer: input_data,
|
||||
});
|
||||
}
|
||||
@@ -448,7 +448,7 @@ where
|
||||
|
||||
let output = self.with_nested_context(dest.clone(), dest_trie_id, |nested| {
|
||||
try_or_exec_error!(
|
||||
nested.overlay.create_contract(&dest, code_hash.clone()),
|
||||
nested.overlay.instantiate_contract(&dest, code_hash.clone()),
|
||||
input_data
|
||||
);
|
||||
|
||||
@@ -941,7 +941,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, exec_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, exec_ch).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ctx.call(BOB, value, &mut gas_meter, data),
|
||||
@@ -1041,7 +1041,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, return_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, return_ch).unwrap();
|
||||
ctx.overlay.set_balance(&origin, 100);
|
||||
ctx.overlay.set_balance(&dest, 0);
|
||||
|
||||
@@ -1064,7 +1064,7 @@ mod tests {
|
||||
let dest = BOB;
|
||||
|
||||
// This test sends 50 units of currency to a non-existent account.
|
||||
// This should create lead to creation of a new account thus
|
||||
// This should lead to creation of a new account thus
|
||||
// a fee should be charged.
|
||||
with_externalities(
|
||||
&mut ExtBuilder::default().existential_deposit(15).build(),
|
||||
@@ -1123,7 +1123,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// This test sends 50 units of currency as an endownment to a newly
|
||||
// created contract.
|
||||
// instantiated contract.
|
||||
with_externalities(
|
||||
&mut ExtBuilder::default().existential_deposit(15).build(),
|
||||
|| {
|
||||
@@ -1202,7 +1202,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, return_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, return_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
dest,
|
||||
@@ -1233,7 +1233,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, return_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, return_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
dest,
|
||||
@@ -1261,7 +1261,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, input_data_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, input_data_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
BOB,
|
||||
@@ -1330,7 +1330,7 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, recurse_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, recurse_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
BOB,
|
||||
@@ -1375,8 +1375,8 @@ mod tests {
|
||||
let cfg = Config::preload();
|
||||
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&dest, bob_ch).unwrap();
|
||||
ctx.overlay.create_contract(&CHARLIE, charlie_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&dest, bob_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&CHARLIE, charlie_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
dest,
|
||||
@@ -1416,8 +1416,8 @@ mod tests {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.create_contract(&BOB, bob_ch).unwrap();
|
||||
ctx.overlay.create_contract(&CHARLIE, charlie_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, bob_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&CHARLIE, charlie_ch).unwrap();
|
||||
|
||||
let result = ctx.call(
|
||||
BOB,
|
||||
@@ -1472,7 +1472,7 @@ mod tests {
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.set_balance(&ALICE, 1000);
|
||||
|
||||
let created_contract_address = assert_matches!(
|
||||
let instantiated_contract_address = assert_matches!(
|
||||
ctx.instantiate(
|
||||
100,
|
||||
&mut GasMeter::<Test>::with_limit(10000, 1),
|
||||
@@ -1484,14 +1484,14 @@ mod tests {
|
||||
|
||||
// Check that the newly created account has the expected code hash and
|
||||
// there are instantiation event.
|
||||
assert_eq!(ctx.overlay.get_code_hash(&created_contract_address).unwrap(), dummy_ch);
|
||||
assert_eq!(ctx.overlay.get_code_hash(&instantiated_contract_address).unwrap(), dummy_ch);
|
||||
assert_eq!(&ctx.events(), &[
|
||||
DeferredAction::DepositEvent {
|
||||
event: RawEvent::Transfer(ALICE, created_contract_address, 100),
|
||||
event: RawEvent::Transfer(ALICE, instantiated_contract_address, 100),
|
||||
topics: Vec::new(),
|
||||
},
|
||||
DeferredAction::DepositEvent {
|
||||
event: RawEvent::Instantiated(ALICE, created_contract_address),
|
||||
event: RawEvent::Instantiated(ALICE, instantiated_contract_address),
|
||||
topics: Vec::new(),
|
||||
}
|
||||
]);
|
||||
@@ -1515,7 +1515,7 @@ mod tests {
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.set_balance(&ALICE, 1000);
|
||||
|
||||
let created_contract_address = assert_matches!(
|
||||
let instantiated_contract_address = assert_matches!(
|
||||
ctx.instantiate(
|
||||
100,
|
||||
&mut GasMeter::<Test>::with_limit(10000, 1),
|
||||
@@ -1526,7 +1526,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// Check that the account has not been created.
|
||||
assert!(ctx.overlay.get_code_hash(&created_contract_address).is_none());
|
||||
assert!(ctx.overlay.get_code_hash(&instantiated_contract_address).is_none());
|
||||
assert!(ctx.events().is_empty());
|
||||
}
|
||||
);
|
||||
@@ -1538,12 +1538,12 @@ mod tests {
|
||||
|
||||
let mut loader = MockLoader::empty();
|
||||
let dummy_ch = loader.insert(|_| exec_success());
|
||||
let created_contract_address = Rc::new(RefCell::new(None::<u64>));
|
||||
let creator_ch = loader.insert({
|
||||
let instantiated_contract_address = Rc::new(RefCell::new(None::<u64>));
|
||||
let instantiator_ch = loader.insert({
|
||||
let dummy_ch = dummy_ch.clone();
|
||||
let created_contract_address = Rc::clone(&created_contract_address);
|
||||
let instantiated_contract_address = Rc::clone(&instantiated_contract_address);
|
||||
move |ctx| {
|
||||
// Instantiate a contract and save it's address in `created_contract_address`.
|
||||
// Instantiate a contract and save it's address in `instantiated_contract_address`.
|
||||
let (address, output) = ctx.ext.instantiate(
|
||||
&dummy_ch,
|
||||
15u64,
|
||||
@@ -1551,7 +1551,7 @@ mod tests {
|
||||
vec![]
|
||||
).unwrap();
|
||||
|
||||
*created_contract_address.borrow_mut() = address.into();
|
||||
*instantiated_contract_address.borrow_mut() = address.into();
|
||||
Ok(output)
|
||||
}
|
||||
});
|
||||
@@ -1562,29 +1562,29 @@ mod tests {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.set_balance(&ALICE, 1000);
|
||||
ctx.overlay.create_contract(&BOB, creator_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, instantiator_ch).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ctx.call(BOB, 20, &mut GasMeter::<Test>::with_limit(1000, 1), vec![]),
|
||||
Ok(_)
|
||||
);
|
||||
|
||||
let created_contract_address = created_contract_address.borrow().as_ref().unwrap().clone();
|
||||
let instantiated_contract_address = instantiated_contract_address.borrow().as_ref().unwrap().clone();
|
||||
|
||||
// Check that the newly created account has the expected code hash and
|
||||
// there are instantiation event.
|
||||
assert_eq!(ctx.overlay.get_code_hash(&created_contract_address).unwrap(), dummy_ch);
|
||||
assert_eq!(ctx.overlay.get_code_hash(&instantiated_contract_address).unwrap(), dummy_ch);
|
||||
assert_eq!(&ctx.events(), &[
|
||||
DeferredAction::DepositEvent {
|
||||
event: RawEvent::Transfer(ALICE, BOB, 20),
|
||||
topics: Vec::new(),
|
||||
},
|
||||
DeferredAction::DepositEvent {
|
||||
event: RawEvent::Transfer(BOB, created_contract_address, 15),
|
||||
event: RawEvent::Transfer(BOB, instantiated_contract_address, 15),
|
||||
topics: Vec::new(),
|
||||
},
|
||||
DeferredAction::DepositEvent {
|
||||
event: RawEvent::Instantiated(BOB, created_contract_address),
|
||||
event: RawEvent::Instantiated(BOB, instantiated_contract_address),
|
||||
topics: Vec::new(),
|
||||
},
|
||||
]);
|
||||
@@ -1600,10 +1600,10 @@ mod tests {
|
||||
let dummy_ch = loader.insert(
|
||||
|_| Err(ExecError { reason: "It's a trap!", buffer: Vec::new() })
|
||||
);
|
||||
let creator_ch = loader.insert({
|
||||
let instantiator_ch = loader.insert({
|
||||
let dummy_ch = dummy_ch.clone();
|
||||
move |ctx| {
|
||||
// Instantiate a contract and save it's address in `created_contract_address`.
|
||||
// Instantiate a contract and save it's address in `instantiated_contract_address`.
|
||||
assert_matches!(
|
||||
ctx.ext.instantiate(
|
||||
&dummy_ch,
|
||||
@@ -1624,14 +1624,14 @@ mod tests {
|
||||
let cfg = Config::preload();
|
||||
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
|
||||
ctx.overlay.set_balance(&ALICE, 1000);
|
||||
ctx.overlay.create_contract(&BOB, creator_ch).unwrap();
|
||||
ctx.overlay.instantiate_contract(&BOB, instantiator_ch).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ctx.call(BOB, 20, &mut GasMeter::<Test>::with_limit(1000, 1), vec![]),
|
||||
Ok(_)
|
||||
);
|
||||
|
||||
// The contract wasn't created so we don't expect to see an instantiation
|
||||
// The contract wasn't instantiated so we don't expect to see an instantiation
|
||||
// event here.
|
||||
assert_eq!(&ctx.events(), &[
|
||||
DeferredAction::DepositEvent {
|
||||
|
||||
Reference in New Issue
Block a user