Skip to content

Commit

Permalink
Merge 5839d46 into d826c39
Browse files Browse the repository at this point in the history
  • Loading branch information
talekhinezh committed Sep 15, 2024
2 parents d826c39 + 5839d46 commit 7660dd4
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 27 deletions.
8 changes: 8 additions & 0 deletions radix-engine-tests/tests/kernel/panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ impl<M: SystemCallbackObject> KernelStackApi for MockKernel<M> {
panic1!()
}

fn kernel_send_to_stack(
&mut self,
_id: usize,
_value: IndexedScryptoValue,
) -> Result<(), RuntimeError> {
panic1!()
}

fn kernel_set_call_frame_data(&mut self, _data: Actor) -> Result<(), RuntimeError> {
panic1!()
}
Expand Down
1 change: 1 addition & 0 deletions radix-engine-tests/tests/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod subintent_auth;
mod subintent_leaks;
mod subintent_lock_fee;
mod subintent_txn_shape;
mod subintent_yield;
mod system;
mod system_access_rule;
mod system_actor_collection;
Expand Down
315 changes: 315 additions & 0 deletions radix-engine-tests/tests/system/subintent_yield.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
use radix_common::prelude::ManifestArgs;
use radix_common::prelude::{FromPublicKey, NonFungibleGlobalId, XRD};
use radix_common::{manifest_args, to_manifest_value_and_unwrap};
use radix_engine::errors::{RuntimeError, SystemError, YieldError};
use radix_engine::transaction::ExecutionConfig;
use radix_engine_interface::macros::dec;
use radix_rust::btreeset;
use radix_transactions::builder::{ManifestBuilder, ResolvableArguments};
use radix_transactions::manifest::YieldToChild;
use radix_transactions::model::{ManifestNamedIntentIndex, TestTransaction};
use scrypto_test::ledger_simulator::LedgerSimulatorBuilder;

#[test]
fn can_send_resources_to_child_subintent() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let (public_key, _, account) = ledger.new_allocated_account();

// Act
let intents = vec![
{
let manifest = ManifestBuilder::new_v2()
.lock_standard_test_fee(account)
.withdraw_from_account(account, XRD, dec!(10))
.take_all_from_worktop(XRD, "xrd")
.with_name_lookup(|builder, lookup| {
builder
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: to_manifest_value_and_unwrap!(&lookup.bucket("xrd")),
})
.0
})
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![1],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
{
let manifest = ManifestBuilder::new_v2()
.assert_worktop_contains(XRD, dec!(10))
.deposit_entire_worktop(account)
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
];

let receipt = ledger.execute_transaction(
TestTransaction::new_v2_from_nonce(intents)
.prepare()
.expect("expected transaction to be preparable")
.get_executable(),
ExecutionConfig::for_test_transaction(),
);

// Assert
receipt.expect_commit_success();
}

#[test]
fn can_send_resources_to_parent_subintent() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let (public_key, _, account) = ledger.new_allocated_account();

// Act
let intents = vec![
{
let manifest = ManifestBuilder::new_v2()
.lock_standard_test_fee(account)
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: ().resolve(),
})
.0
.assert_worktop_contains(XRD, dec!(10))
.deposit_entire_worktop(account)
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: ().resolve(),
})
.0
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![1],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
{
let manifest = ManifestBuilder::new_v2()
.withdraw_from_account(account, XRD, dec!(10))
.take_all_from_worktop(XRD, "xrd")
.with_name_lookup(|builder, lookup| {
builder.yield_to_parent(manifest_args!(lookup.bucket("xrd")))
})
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
];

let receipt = ledger.execute_transaction(
TestTransaction::new_v2_from_nonce(intents)
.prepare()
.expect("expected transaction to be preparable")
.get_executable(),
ExecutionConfig::for_test_transaction(),
);

// Assert
receipt.expect_commit_success();
}

#[test]
fn can_send_and_receive_resources_as_subintent() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let (public_key, _, account) = ledger.new_allocated_account();

// Act
let intents = vec![
{
let manifest = ManifestBuilder::new_v2()
.lock_standard_test_fee(account)
.withdraw_from_account(account, XRD, dec!(10))
.take_all_from_worktop(XRD, "xrd")
.with_name_lookup(|builder, lookup| {
builder
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: to_manifest_value_and_unwrap!(&lookup.bucket("xrd")),
})
.0
})
.assert_worktop_contains(XRD, dec!(10))
.deposit_entire_worktop(account)
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: to_manifest_value_and_unwrap!(&()),
})
.0
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![1],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
{
let manifest = ManifestBuilder::new_v2()
.take_all_from_worktop(XRD, "xrd")
.with_name_lookup(|builder, lookup| {
builder.yield_to_parent(manifest_args!(lookup.bucket("xrd")))
})
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
];

let receipt = ledger.execute_transaction(
TestTransaction::new_v2_from_nonce(intents)
.prepare()
.expect("expected transaction to be preparable")
.get_executable(),
ExecutionConfig::for_test_transaction(),
);

// Assert
receipt.expect_commit_success();
}

#[test]
fn cannot_send_proof_to_child_subintent() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let (public_key, _, account) = ledger.new_allocated_account();

// Act
let intents = vec![
{
let manifest = ManifestBuilder::new_v2()
.lock_standard_test_fee(account)
.create_proof_from_account_of_amount(account, XRD, dec!(10))
.create_proof_from_auth_zone_of_amount(XRD, dec!(10), "proof")
.with_name_lookup(|builder, lookup| {
builder
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: to_manifest_value_and_unwrap!(&lookup.proof("proof")),
})
.0
})
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![1],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
{
let manifest = ManifestBuilder::new_v2().build();

(
manifest,
ledger.next_transaction_nonce(),
vec![],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
];

let receipt = ledger.execute_transaction(
TestTransaction::new_v2_from_nonce(intents)
.prepare()
.expect("expected transaction to be preparable")
.get_executable(),
ExecutionConfig::for_test_transaction(),
);

// Assert
receipt.expect_specific_failure(|e| {
matches!(
e,
RuntimeError::SystemError(SystemError::YieldError(YieldError::CannotYieldProof))
)
});
}

#[test]
fn cannot_send_proof_to_parent_subintent() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let (public_key, _, account) = ledger.new_allocated_account();

// Act
let intents = vec![
{
let manifest = ManifestBuilder::new_v2()
.lock_standard_test_fee(account)
.add_instruction_advanced(YieldToChild {
child_index: ManifestNamedIntentIndex(0),
args: ().resolve(),
})
.0
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![1],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
{
let manifest = ManifestBuilder::new_v2()
.create_proof_from_account_of_amount(account, XRD, dec!(10))
.create_proof_from_auth_zone_of_amount(XRD, dec!(10), "proof")
.with_name_lookup(|builder, lookup| {
builder.yield_to_parent(manifest_args!(lookup.proof("proof")))
})
.build();

(
manifest,
ledger.next_transaction_nonce(),
vec![],
btreeset![NonFungibleGlobalId::from_public_key(&public_key)],
)
},
];

let receipt = ledger.execute_transaction(
TestTransaction::new_v2_from_nonce(intents)
.prepare()
.expect("expected transaction to be preparable")
.get_executable(),
ExecutionConfig::for_test_transaction(),
);

// Assert
receipt.expect_specific_failure(|e| {
matches!(
e,
RuntimeError::SystemError(SystemError::YieldError(YieldError::CannotYieldProof))
)
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl TransactionProcessorBlueprint {
max_total_size_of_blobs,
api,
)?;
let resume_result = txn_processor_single_thread.resume(api)?;
let resume_result = txn_processor_single_thread.resume(None, api)?;
if !matches!(resume_result, ResumeResult::Done) {
panic!("Unexpected yield occurred in v1 transaction processing");
}
Expand Down
3 changes: 1 addition & 2 deletions radix-engine/src/blueprints/transaction_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mod blueprint;
mod instructions;
mod package;

pub use crate::system::transaction::instructions::*;
pub use crate::system::transaction::txn_processor::*;
pub use blueprint::*;
pub use instructions::*;
pub use package::*;
6 changes: 6 additions & 0 deletions radix-engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ pub enum SystemError {
SystemPanic(String),

CannotLockFeeInChildSubintent(usize),
YieldError(YieldError),
}

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
pub enum YieldError {
CannotYieldProof,
}

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
Expand Down
4 changes: 0 additions & 4 deletions radix-engine/src/kernel/call_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,6 @@ impl<C, L: Clone> CallFrame<C, L> {
}

for node_id in message.copy_stable_transient_references {
if from.depth >= to.depth {
panic!("Transient references only supported for downstream calls.");
}

if let Some(ref_origin) = from.get_node_visibility(&node_id).reference_origin(node_id) {
to.transient_references
.entry(node_id.clone())
Expand Down
Loading

0 comments on commit 7660dd4

Please sign in to comment.