Skip to content

Commit

Permalink
Merge pull request #9 from BeakerTools/release/v0.2.1
Browse files Browse the repository at this point in the history
Release/v0.2.1
  • Loading branch information
arthurvinci committed Jun 7, 2024
2 parents 5704325 + 1aa19fb commit 91413e8
Show file tree
Hide file tree
Showing 34 changed files with 729 additions and 391 deletions.
6 changes: 3 additions & 3 deletions maths/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "decimal-maths"
version = "0.0.1"
version = "0.2.1"
license = "MIT"
edition = "2021"

[dependencies]
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-common = "1.2.0"
radix-common-derive = "1.2.0"

[lib]
5 changes: 3 additions & 2 deletions maths/src/exponential.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use radix_engine::types::{Decimal, I192, I256};
use crate::internal_prelude::*;

pub const SMALLEST_NON_ZERO: Decimal = Decimal(I192::from_digits([
13893700547235832536,
Expand Down Expand Up @@ -41,8 +41,9 @@ impl Exponential for Decimal {
#[cfg(test)]
mod test_exp {
use crate::exponential::{Exponential, SMALLEST_NON_ZERO};
use crate::internal_prelude::*;
use crate::RELATIVE_PRECISION;
use radix_engine::types::{dec, Decimal, I192};
use radix_common_derive::dec;

#[test]
fn test_zero() {
Expand Down
1 change: 1 addition & 0 deletions maths/src/internal_prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use radix_common::prelude::{Decimal, I192, I256, U192};
4 changes: 2 additions & 2 deletions maths/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use radix_engine::types::{Decimal, I192};

use internal_prelude::*;
pub mod exponential;
pub(crate) mod internal_prelude;
pub mod logarithm;
pub mod power;

Expand Down
5 changes: 3 additions & 2 deletions maths/src/logarithm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::exponential::Exponential;
use radix_engine::types::{Decimal, I192, U192};
use crate::internal_prelude::*;

pub const LN_2: Decimal = Decimal(I192::from_digits([693147180559945309, 0, 0]));
pub const LN_10: Decimal = Decimal(I192::from_digits([2302585092994045684, 0, 0]));
Expand Down Expand Up @@ -77,9 +77,10 @@ impl Logarithm for Decimal {
#[cfg(test)]
mod test_ln {
use crate::exponential::Exponential;
use crate::internal_prelude::*;
use crate::logarithm::{Logarithm, LN_2};
use crate::RELATIVE_PRECISION;
use radix_engine::types::{dec, Decimal, I192};
use radix_common_derive::dec;

#[test]
#[should_panic]
Expand Down
2 changes: 1 addition & 1 deletion maths/src/power.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::exponential::Exponential;
use crate::internal_prelude::*;
use crate::logarithm::Logarithm;
use radix_engine::types::Decimal;

pub trait Power {
fn pow(self, exp: Self) -> Self;
Expand Down
15 changes: 8 additions & 7 deletions test-engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[package]
name = "test-engine"
version = "0.2.0"
version = "0.2.1"
license = "MIT"
edition = "2021"

[dependencies]
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.1.1" }
radix-common = "1.2.0"
radix-engine = "1.2.0"
radix-engine-interface = "1.2.0"
radix-transactions = "1.2.0"
scrypto-test = "1.2.0"
radix-substate-store-impls = "1.2.0"
lazy_static = "1.4.0"
indexmap = "2.2.6"

[lib]
2 changes: 1 addition & 1 deletion test-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test-engine = { git = "https://github.com/BeakerTools/scrypto-toolkit", branch =

- [Basics](tutorials/1.Basics.md)
- [Packages and blueprints](tutorials/2.Packages_and_Blueprints.md)
- [Calling methods](tutorials/3.Method_Calls.md)
- [Calling methods](tutorials/3.Methods_Calls)

# Examples

Expand Down
7 changes: 1 addition & 6 deletions test-engine/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use radix_engine::types::Secp256k1PublicKey;
use radix_engine_common::crypto::PublicKey;
use radix_engine_interface::blueprints::resource::FromPublicKey;
use radix_engine_interface::prelude::NonFungibleGlobalId;
use radix_engine_interface::types::ComponentAddress;

use crate::engine_interface::EngineInterface;
use crate::internal_prelude::*;

#[derive(Debug, Clone)]
pub struct Account {
Expand Down
56 changes: 23 additions & 33 deletions test-engine/src/call_builder.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use std::collections::BTreeSet;
use std::vec::Vec;

use radix_engine::transaction::{TransactionReceipt, TransactionResult};
use radix_engine::types::{
manifest_decode, ComponentAddress, Decimal, Encoder, ManifestArgs, ManifestEncoder,
ManifestExpression, ManifestValueKind, NonFungibleLocalId, PackageAddress, ResourceAddress,
FAUCET, MANIFEST_SBOR_V1_MAX_DEPTH, MANIFEST_SBOR_V1_PAYLOAD_PREFIX,
};

use transaction::builder::{ManifestBuilder, ResolvableGlobalAddress};
use transaction::manifest::decompiler::ManifestObjectNames;
use transaction::manifest::dumper::dump_manifest_to_file_system;
use transaction::prelude::{dec, DynamicGlobalAddress, ResolvableArguments, TransactionManifestV1};

use crate::account::Account;
use crate::environment::{Environment, EnvironmentEncode};
use crate::manifest_args;
use crate::environment::{EnvironmentEncode, Fungible, NonFungible};
use crate::internal_prelude::*;
use crate::method_call::SimpleMethodCaller;
use crate::references::{ComponentReference, GlobalReference, ReferenceName, ResourceReference};
use crate::test_engine::TestEngine;
use crate::to_id::ToId;

struct TransactionManifestData {
transaction_manifest: TransactionManifestV1,
Expand Down Expand Up @@ -150,7 +139,11 @@ impl<'a> CallBuilder<'a> {
/// * `recipient`: resources to transfer to.
/// * `resource`: reference name of the resource to transfer.
/// * `amount`: amount to transfer.
pub fn transfer<E: ReferenceName, R: ReferenceName + Clone + 'static, D: TryInto<Decimal>>(
pub fn transfer<
E: ReferenceName,
R: ReferenceName + Clone + 'static,
D: TryInto<Decimal> + Clone + 'static,
>(
self,
recipient: E,
resource: R,
Expand All @@ -163,10 +156,7 @@ impl<'a> CallBuilder<'a> {
recipient,
"try_deposit_or_abort",
vec![
Box::new(Environment::FungibleBucket(
resource.clone(),
amount.try_into().unwrap(),
)),
Box::new(Fungible::Bucket(resource.clone(), amount)),
Box::new(None::<u64>),
],
)
Expand All @@ -178,17 +168,20 @@ impl<'a> CallBuilder<'a> {
/// * `recipient`: resources to transfer to.
/// * `resource`: reference name of the resource to transfer.
/// * `ids`: ids to transfer.
pub fn transfer_non_fungibles<E: ReferenceName, R: ReferenceName + Clone + 'static>(
pub fn transfer_non_fungibles<E: ReferenceName, R: ReferenceName + Clone + 'static, T: ToId>(
self,
recipient: E,
resource: R,
ids: Vec<NonFungibleLocalId>,
ids: Vec<T>,
) -> Self {
self.call_from_component(
recipient,
"try_deposit_or_abort",
vec![
Box::new(Environment::NonFungibleBucket(resource, ids)),
Box::new(NonFungible::Bucket(
resource,
ids.into_iter().map(|id| id.to_id()).collect(),
)),
Box::new(None::<u64>),
],
)
Expand Down Expand Up @@ -351,7 +344,7 @@ impl<'a> CallBuilder<'a> {

manifest.instructions.insert(
0,
transaction::model::InstructionV1::CallMethod {
InstructionV1::CallMethod {
address: DynamicGlobalAddress::from(self.fee_payer),
method_name: "lock_fee".to_string(),
args: manifest_args!(self.fee_locked).resolve(),
Expand All @@ -362,22 +355,19 @@ impl<'a> CallBuilder<'a> {
fn write_deposit(&mut self) {
let manifest = &mut self.manifest_data.as_mut().unwrap().transaction_manifest;

manifest
.instructions
.push(transaction::model::InstructionV1::CallMethod {
address: DynamicGlobalAddress::from(*self.caller.address()),
method_name: "deposit_batch".to_string(),
args: manifest_args!(ManifestExpression::EntireWorktop).resolve(),
});
manifest.instructions.push(InstructionV1::CallMethod {
address: DynamicGlobalAddress::from(*self.caller.address()),
method_name: "deposit_batch".to_string(),
args: manifest_args!(ManifestExpression::EntireWorktop).resolve(),
});
}
fn write_badge(&mut self) {
let manifest = &mut self.manifest_data.as_mut().unwrap().transaction_manifest;

for (badge, opt_ids) in &self.admin_badge {
if badge.is_fungible() {
manifest.instructions.insert(
1,
transaction::model::InstructionV1::CallMethod {
InstructionV1::CallMethod {
address: DynamicGlobalAddress::from(*self.caller.address()),
method_name: "create_proof_of_amount".to_string(),
args: manifest_args!(badge, Decimal::one()).resolve(),
Expand All @@ -386,7 +376,7 @@ impl<'a> CallBuilder<'a> {
} else {
manifest.instructions.insert(
1,
transaction::model::InstructionV1::CallMethod {
InstructionV1::CallMethod {
address: DynamicGlobalAddress::from(*self.caller.address()),
method_name: "create_proof_of_non_fungibles".to_string(),
args: manifest_args!(badge, opt_ids.clone().unwrap()).resolve(),
Expand Down
Loading

0 comments on commit 91413e8

Please sign in to comment.