Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnaveira committed Jun 16, 2024
1 parent 353674a commit 6fbedc2
Showing 1 changed file with 77 additions and 43 deletions.
120 changes: 77 additions & 43 deletions dan_layer/engine/tests/account_nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ fn basic_nft_mint() {
let account_nft_template = account_nft_template_test.get_template_address("AccountNonFungible");

// create the AccountNft component associated with the user account
let result = create_nft_component(&mut account_nft_template_test, account_nft_template, owner_token.clone());
let result = create_nft_component(
&mut account_nft_template_test,
account_nft_template,
owner_token.clone(),
);
assert!(result.finalize.result.is_accept());
let nft_component_address: ComponentAddress = result.finalize.execution_results[0].decode().unwrap();

Expand All @@ -45,7 +49,13 @@ fn basic_nft_mint() {
metadata.insert("name".to_string(), "my_custom_nft".to_string());
metadata.insert("brightness".to_string(), "100".to_string());

let result = mint_account_nft(&mut account_nft_template_test, nft_component_address, owner_component_address, owner_token.clone(), metadata);
let result = mint_account_nft(
&mut account_nft_template_test,
nft_component_address,
owner_component_address,
owner_token.clone(),
metadata,
);
assert!(result.finalize.result.is_accept());

let bucket_nfts = result.finalize.execution_results[2]
Expand All @@ -66,56 +76,80 @@ fn mint_multiple_times() {
let account_nft_template = account_nft_template_test.get_template_address("AccountNonFungible");

// create the account nft component
let result = create_nft_component(&mut account_nft_template_test, account_nft_template, owner_token.clone());
let result = create_nft_component(
&mut account_nft_template_test,
account_nft_template,
owner_token.clone(),
);
assert!(result.finalize.result.is_accept());
let nft_component_address: ComponentAddress = result.finalize.execution_results[0].decode().unwrap();

// mint one nft
let result = mint_account_nft(&mut account_nft_template_test, nft_component_address, owner_component_address, owner_token.clone(), Metadata::new());
let result = mint_account_nft(
&mut account_nft_template_test,
nft_component_address,
owner_component_address,
owner_token.clone(),
Metadata::new(),
);
assert!(result.finalize.result.is_accept());

// mint a second nft
let result = mint_account_nft(&mut account_nft_template_test, nft_component_address, owner_component_address, owner_token.clone(), Metadata::new());
let result = mint_account_nft(
&mut account_nft_template_test,
nft_component_address,
owner_component_address,
owner_token.clone(),
Metadata::new(),
);
assert!(result.finalize.result.is_accept());
}

fn create_nft_component(test: &mut TemplateTest, nft_template: TemplateAddress, owner_token: NonFungibleAddress) -> ExecuteResult {
test
.execute_and_commit(
vec![Instruction::CallFunction {
template_address: nft_template,
function: "create".to_string(),
args: args![owner_token],
}],
vec![],
)
.unwrap()
fn create_nft_component(
test: &mut TemplateTest,
nft_template: TemplateAddress,
owner_token: NonFungibleAddress,
) -> ExecuteResult {
test.execute_and_commit(
vec![Instruction::CallFunction {
template_address: nft_template,
function: "create".to_string(),
args: args![owner_token],
}],
vec![],
)
.unwrap()
}

fn mint_account_nft(test: &mut TemplateTest, nft_component: ComponentAddress, account: ComponentAddress, owner_token: NonFungibleAddress, metadata: Metadata) -> ExecuteResult {
test
.execute_and_commit(
vec![
Instruction::CallMethod {
component_address: nft_component,
method: "mint".to_string(),
args: args![metadata],
},
Instruction::PutLastInstructionOutputOnWorkspace {
key: b"my_nft".to_vec(),
},
Instruction::CallFunction {
template_address: test.get_template_address("Account"),
function: "get_non_fungible_ids_for_bucket".to_string(),
args: args![Variable("my_nft")],
},
Instruction::CallMethod {
component_address: account,
method: "deposit".to_string(),
args: args![Variable("my_nft")],
},
],
vec![owner_token],
)
.unwrap()
}
fn mint_account_nft(
test: &mut TemplateTest,
nft_component: ComponentAddress,
account: ComponentAddress,
owner_token: NonFungibleAddress,
metadata: Metadata,
) -> ExecuteResult {
test.execute_and_commit(
vec![
Instruction::CallMethod {
component_address: nft_component,
method: "mint".to_string(),
args: args![metadata],
},
Instruction::PutLastInstructionOutputOnWorkspace {
key: b"my_nft".to_vec(),
},
Instruction::CallFunction {
template_address: test.get_template_address("Account"),
function: "get_non_fungible_ids_for_bucket".to_string(),
args: args![Variable("my_nft")],
},
Instruction::CallMethod {
component_address: account,
method: "deposit".to_string(),
args: args![Variable("my_nft")],
},
],
vec![owner_token],
)
.unwrap()
}

0 comments on commit 6fbedc2

Please sign in to comment.