Skip to content

Commit

Permalink
Merge pull request #2062 from radixdlt/misc/typed-invocation-tests
Browse files Browse the repository at this point in the history
Adding typed invocation tests to cuttlefish
  • Loading branch information
0xOmarA authored Jan 21, 2025
2 parents cec1378 + 693364a commit 8e15032
Show file tree
Hide file tree
Showing 23 changed files with 646 additions and 167 deletions.
38 changes: 38 additions & 0 deletions radix-common/src/data/manifest/model/manifest_address_kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ macro_rules! labelled_resolvable_address {
};
}

pub trait IntoManifestAddress {
type ManifestAddress;

fn into_manifest_address(self) -> Self::ManifestAddress;
}

// Alias for backwards-compatibility
pub type DynamicGlobalAddress = ManifestGlobalAddress;

Expand All @@ -73,6 +79,14 @@ pub enum ManifestGlobalAddress {
Named(ManifestNamedAddress),
}

impl IntoManifestAddress for GlobalAddress {
type ManifestAddress = ManifestGlobalAddress;

fn into_manifest_address(self) -> Self::ManifestAddress {
Self::ManifestAddress::Static(self)
}
}

scrypto_describe_for_manifest_type!(
ManifestGlobalAddress,
GLOBAL_ADDRESS_TYPE,
Expand Down Expand Up @@ -253,6 +267,14 @@ pub enum ManifestPackageAddress {
Named(ManifestNamedAddress),
}

impl IntoManifestAddress for PackageAddress {
type ManifestAddress = ManifestPackageAddress;

fn into_manifest_address(self) -> Self::ManifestAddress {
Self::ManifestAddress::Static(self)
}
}

scrypto_describe_for_manifest_type!(
ManifestPackageAddress,
PACKAGE_ADDRESS_TYPE,
Expand Down Expand Up @@ -410,6 +432,14 @@ pub enum ManifestComponentAddress {
Named(ManifestNamedAddress),
}

impl IntoManifestAddress for ComponentAddress {
type ManifestAddress = ManifestComponentAddress;

fn into_manifest_address(self) -> Self::ManifestAddress {
Self::ManifestAddress::Static(self)
}
}

scrypto_describe_for_manifest_type!(
ManifestComponentAddress,
COMPONENT_ADDRESS_TYPE,
Expand Down Expand Up @@ -517,6 +547,14 @@ pub enum ManifestResourceAddress {
Named(ManifestNamedAddress),
}

impl IntoManifestAddress for ResourceAddress {
type ManifestAddress = ManifestResourceAddress;

fn into_manifest_address(self) -> Self::ManifestAddress {
Self::ManifestAddress::Static(self)
}
}

scrypto_describe_for_manifest_type!(
ManifestResourceAddress,
RESOURCE_ADDRESS_TYPE,
Expand Down
18 changes: 9 additions & 9 deletions radix-common/src/data/manifest/model/manifest_blob.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#[cfg(feature = "fuzzing")]
use arbitrary::Arbitrary;
use radix_rust::copy_u8_array;
use sbor::rust::convert::TryFrom;
#[cfg(not(feature = "alloc"))]
use sbor::rust::fmt;
use sbor::rust::vec::Vec;
use sbor::*;

use crate::data::manifest::*;
use crate::*;
use crate::internal_prelude::*;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -57,10 +50,17 @@ impl ManifestBlobRef {

manifest_type!(ManifestBlobRef, ManifestCustomValueKind::Blob, 32);

impl sbor::Describe<ScryptoCustomTypeKind> for ManifestBlobRef {
const TYPE_ID: sbor::RustTypeId = <Vec<u8> as Describe<ScryptoCustomTypeKind>>::TYPE_ID;

fn type_data() -> sbor::TypeData<ScryptoCustomTypeKind, sbor::RustTypeId> {
Vec::<u8>::type_data()
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::internal_prelude::*;

#[test]
fn manifest_blob_parse_fail() {
Expand Down
1 change: 1 addition & 0 deletions radix-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub mod prelude {

pub(crate) mod internal_prelude {
pub use super::prelude::*;
pub use crate::manifest_type;
pub use sbor::representations::*;
pub use sbor::traversal::*;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct AccessControllerCreateInput {
pub address_reservation: Option<GlobalAddressReservation>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccessControllerCreateManifestInput {
pub controlled_asset: ManifestBucket,
pub rule_set: RuleSet,
Expand Down Expand Up @@ -358,7 +358,7 @@ pub struct AccessControllerContributeRecoveryFeeInput {
pub bucket: Bucket,
}

#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccessControllerContributeRecoveryFeeManifestInput {
pub bucket: ManifestBucket,
}
Expand Down
54 changes: 31 additions & 23 deletions radix-engine-interface/src/blueprints/account/invocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct AccountCreateAdvancedInput {
}

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountCreateAdvancedManifestInput {
pub owner_role: OwnerRole,
pub address_reservation: Option<ManifestAddressReservation>,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct AccountDepositInput {
pub bucket: Bucket,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountDepositManifestInput {
pub bucket: ManifestBucket,
}
Expand All @@ -141,7 +141,7 @@ pub struct AccountDepositBatchInput {
pub buckets: Vec<Bucket>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountDepositBatchManifestInput {
pub buckets: ManifestBucketBatch,
}
Expand All @@ -160,7 +160,7 @@ pub struct AccountWithdrawInput {
pub amount: Decimal,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountWithdrawManifestInput {
pub resource_address: ManifestResourceAddress,
pub amount: Decimal,
Expand All @@ -180,7 +180,7 @@ pub struct AccountWithdrawNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountWithdrawNonFungiblesManifestInput {
pub resource_address: ManifestResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
Expand All @@ -201,7 +201,7 @@ pub struct AccountLockFeeAndWithdrawInput {
pub amount: Decimal,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountLockFeeAndWithdrawManifestInput {
pub amount_to_lock: Decimal,
pub resource_address: ManifestResourceAddress,
Expand All @@ -224,7 +224,7 @@ pub struct AccountLockFeeAndWithdrawNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountLockFeeAndWithdrawNonFungiblesManifestInput {
pub amount_to_lock: Decimal,
pub resource_address: ManifestResourceAddress,
Expand All @@ -245,7 +245,7 @@ pub struct AccountCreateProofOfAmountInput {
pub amount: Decimal,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountCreateProofOfAmountManifestInput {
pub resource_address: ManifestResourceAddress,
pub amount: Decimal,
Expand All @@ -265,7 +265,7 @@ pub struct AccountCreateProofOfNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountCreateProofOfNonFungiblesManifestInput {
pub resource_address: ManifestResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
Expand Down Expand Up @@ -300,7 +300,7 @@ pub struct AccountSetResourcePreferenceInput {
pub resource_preference: ResourcePreference,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountSetResourcePreferenceManifestInput {
pub resource_address: ManifestResourceAddress,
pub resource_preference: ResourcePreference,
Expand All @@ -319,7 +319,7 @@ pub struct AccountRemoveResourcePreferenceInput {
pub resource_address: ResourceAddress,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountRemoveResourcePreferenceManifestInput {
pub resource_address: ManifestResourceAddress,
}
Expand All @@ -338,7 +338,7 @@ pub struct AccountTryDepositOrRefundInput {
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountTryDepositOrRefundManifestInput {
pub bucket: ManifestBucket,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
Expand All @@ -358,7 +358,7 @@ pub struct AccountTryDepositBatchOrRefundInput {
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountTryDepositBatchOrRefundManifestInput {
pub buckets: ManifestBucketBatch,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
Expand All @@ -378,7 +378,7 @@ pub struct AccountTryDepositOrAbortInput {
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountTryDepositOrAbortManifestInput {
pub bucket: ManifestBucket,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
Expand All @@ -398,7 +398,7 @@ pub struct AccountTryDepositBatchOrAbortInput {
pub authorized_depositor_badge: Option<ResourceOrNonFungible>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountTryDepositBatchOrAbortManifestInput {
pub buckets: ManifestBucketBatch,
pub authorized_depositor_badge: Option<ManifestResourceOrNonFungible>,
Expand All @@ -418,7 +418,7 @@ pub struct AccountBurnInput {
pub amount: Decimal,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountBurnManifestInput {
pub resource_address: ManifestResourceAddress,
pub amount: Decimal,
Expand All @@ -438,7 +438,7 @@ pub struct AccountBurnNonFungiblesInput {
pub ids: IndexSet<NonFungibleLocalId>,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountBurnNonFungiblesManifestInput {
pub resource_address: ManifestResourceAddress,
pub ids: IndexSet<NonFungibleLocalId>,
Expand All @@ -457,7 +457,7 @@ pub struct AccountAddAuthorizedDepositorInput {
pub badge: ResourceOrNonFungible,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountAddAuthorizedDepositorManifestInput {
pub badge: ManifestResourceOrNonFungible,
}
Expand All @@ -475,7 +475,7 @@ pub struct AccountRemoveAuthorizedDepositorInput {
pub badge: ResourceOrNonFungible,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountRemoveAuthorizedDepositorManifestInput {
pub badge: ManifestResourceOrNonFungible,
}
Expand All @@ -493,8 +493,8 @@ pub struct AccountBalanceInput {
pub resource_address: ResourceAddress,
}

#[derive(Debug, Eq, PartialEq, ManifestSbor)]
pub struct AccountBalanceDynamicInput {
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountBalanceManifestInput {
pub resource_address: ManifestResourceAddress,
}

Expand All @@ -512,7 +512,11 @@ pub struct AccountNonFungibleLocalIdsInput {
pub limit: u32,
}

pub type AccountNonFungibleLocalIdsManifestInput = AccountNonFungibleLocalIdsInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountNonFungibleLocalIdsManifestInput {
pub resource_address: ManifestResourceAddress,
pub limit: u32,
}

pub type AccountNonFungibleLocalIdsOutput = IndexSet<NonFungibleLocalId>;

Expand All @@ -528,6 +532,10 @@ pub struct AccountHasNonFungibleInput {
pub local_id: NonFungibleLocalId,
}

pub type AccountHasNonFungibleManifestInput = AccountHasNonFungibleInput;
#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
pub struct AccountHasNonFungibleManifestInput {
pub resource_address: ManifestResourceAddress,
pub local_id: NonFungibleLocalId,
}

pub type AccountHasNonFungibleOutput = bool;
Loading

0 comments on commit 8e15032

Please sign in to comment.