Skip to content

Commit

Permalink
Merge pull request #68 from radixdlt/update-to-scrypto-1.3.0
Browse files Browse the repository at this point in the history
Update to scrypto 1.3.0
  • Loading branch information
azizi-a authored Dec 13, 2024
2 parents a09e4ac + c7c79bb commit da6af20
Show file tree
Hide file tree
Showing 100 changed files with 5,045 additions and 4,200 deletions.
411 changes: 239 additions & 172 deletions getting-started/hello-token/Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions getting-started/hello-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ edition = "2021"
resolver = "2"

[dependencies]
scrypto = { version = "1.2.0" }
scrypto = { version = "1.3.0" }

[dev-dependencies]
scrypto-test = { version = "1.2.0" }
scrypto-test = { version = "1.3.0" }

[profile.release]
opt-level = 'z' # Optimize for size.
Expand Down
2 changes: 1 addition & 1 deletion getting-started/hello-token/manifests/free_token_resim.rtm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CALL_METHOD
Address("component_sim1cptxxxxxxxxxfaucetxxxxxxxxx000527798379xxxxxxxxxhkrefh")
"lock_fee"
Decimal("5000")
Decimal("5")
;
CALL_METHOD
Address("_hello_token_component_address_")
Expand Down
4 changes: 3 additions & 1 deletion getting-started/hello-token/manifests/instantiate_resim.rtm
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
CALL_METHOD
Address("component_sim1cptxxxxxxxxxfaucetxxxxxxxxx000527798379xxxxxxxxxhkrefh")
"lock_fee"
Decimal("5000")
Decimal("50")
;
CALL_FUNCTION
Address("_resim_package_address_")
"HelloToken"
"instantiate_hello_token"
# Dapp definition address is not used in resim so we can use any address
Address("component_sim1cptxxxxxxxxxfaucetxxxxxxxxx000527798379xxxxxxxxxhkrefh")
;
CALL_METHOD
Address("_resim_account_address_")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CALL_FUNCTION
Address("_stokenet_package_address_")
"HelloToken"
"instantiate_hello_token"
Address("account_tdx_2_12y7ue9sslrkpywpgqyu3nj8cut0uu5arpr7qyalz7y9j7j5q4ayhv6")
;
CALL_METHOD
Address("_your_account_address_")
Expand Down
19 changes: 7 additions & 12 deletions getting-started/hello-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ use scrypto::prelude::*;
mod hello_token {
struct HelloToken {
// Define what resources and data will be managed by Hello components
hello_token_resource_manager: ResourceManager,
hello_token_resource_manager: FungibleResourceManager,
}

impl HelloToken {
// Implement the functions and methods which will manage those resources and data
// This is a function, and can be called directly on the blueprint once deployed
pub fn instantiate_hello_token() -> (Global<HelloToken>, FungibleBucket) {
// Get the address of the dapp definition as an Address type
let dapp_def_address = global_component!(
Account,
"account_tdx_2_12y7ue9sslrkpywpgqyu3nj8cut0uu5arpr7qyalz7y9j7j5q4ayhv6"
)
.address();

pub fn instantiate_hello_token(
dapp_definition: ComponentAddress,
) -> (Global<HelloToken>, FungibleBucket) {
// Create owner badge
let owner_badge = ResourceBuilder::new_fungible(OwnerRole::None)
.metadata(metadata!(init{"name"=>"Hello Token owner badge", locked;}))
Expand All @@ -33,7 +28,7 @@ mod hello_token {
"symbol" => "HT", locked;
"description" => "A simple token welcoming you to the Radix DLT network.", locked;
"icon_url" => Url::of("https://assets.radixdlt.com/icons/hello-token-164.png"), locked;
"dapp_definitions" => [dapp_def_address], locked;
"dapp_definitions" => [dapp_definition], locked;
}
})
.mint_roles(mint_roles! {
Expand All @@ -59,15 +54,15 @@ mod hello_token {
},
init {
"Name" => "HelloToken Component", locked;
"dapp_definition" => dapp_def_address, locked;
"dapp_definition" => dapp_definition, locked;
}
})
.globalize();
return (component, owner_badge);
}

// This is a method, because it needs a reference to self. Methods can only be called on components
pub fn free_token(&mut self) -> Bucket {
pub fn free_token(&mut self) -> FungibleBucket {
// Mint a hello token and return it to the caller
self.hello_token_resource_manager.mint(1)
}
Expand Down
27 changes: 16 additions & 11 deletions getting-started/hello-token/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use scrypto_test::prelude::*;
use hello_token::hello_token_test::*;

#[test]
fn test_hello_token() {
fn test_hello_token_with_ledger_simulator() {
// Setup the environment
let mut ledger = LedgerSimulatorBuilder::new().build();

Expand All @@ -15,12 +15,16 @@ fn test_hello_token() {

// Test the `instantiate_hello` function.
let manifest = ManifestBuilder::new()
.lock_fee_from_faucet()
.call_function(
package_address,
"HelloToken",
"instantiate_hello_token",
manifest_args!(),
manifest_args!(
account, // account used as dapp_definition in the test
),
)
.deposit_entire_worktop(account)
.build();
let receipt = ledger.execute_manifest(
manifest,
Expand All @@ -31,12 +35,9 @@ fn test_hello_token() {

// Test the `free_token` method.
let manifest = ManifestBuilder::new()
.lock_fee_from_faucet()
.call_method(component, "free_token", manifest_args!())
.call_method(
account,
"deposit_batch",
manifest_args!(ManifestExpression::EntireWorktop),
)
.deposit_entire_worktop(account)
.build();
let receipt = ledger.execute_manifest(
manifest,
Expand All @@ -47,16 +48,20 @@ fn test_hello_token() {
}

#[test]
fn test_hello_with_test_environment() -> Result<(), RuntimeError> {
fn test_hello_token_with_test_environment() -> Result<(), RuntimeError> {
// Arrange
let mut env = TestEnvironment::new();
let package_address =
PackageFactory::compile_and_publish(this_package!(), &mut env, CompileProfile::Fast)?;

let instantiate_hello_token = HelloToken::instantiate_hello_token(package_address, &mut env)?;
let mut component = instantiate_hello_token.0;
// faucet address used as account address for testing
let account_address = FAUCET;

let (mut hello_token, _) =
HelloToken::instantiate_hello_token(account_address, package_address, &mut env)?;

// Act
let bucket = component.free_token(&mut env)?;
let bucket = hello_token.free_token(&mut env)?;

// Assert
let amount = bucket.amount(&mut env)?;
Expand Down
Loading

0 comments on commit da6af20

Please sign in to comment.