From 334f5c9118a9e513b26e9466c436f2caad9b21c2 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Thu, 22 Aug 2024 15:19:45 +0200 Subject: [PATCH] feat: bumo foundry to 0.28.0 --- Scarb.lock | 12 ++++++++-- Scarb.toml | 2 +- docs/modules/ROOT/pages/api/testing.adoc | 9 +++++++ packages/presets/src/tests/test_erc1155.cairo | 18 +++++++------- packages/test_common/src/erc1155.cairo | 4 ++-- packages/testing/src/deployment.cairo | 13 ++++++++-- .../src/tests/erc1155/test_erc1155.cairo | 24 +++++++++---------- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/Scarb.lock b/Scarb.lock index 3e044ff3f..487e57136 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -129,7 +129,15 @@ dependencies = [ "snforge_std", ] +[[package]] +name = "snforge_scarb_plugin" +version = "0.1.0" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea" + [[package]] name = "snforge_std" -version = "0.27.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de" +version = "0.28.0" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea" +dependencies = [ + "snforge_scarb_plugin", +] diff --git a/Scarb.toml b/Scarb.toml index 414893774..681fb2f6c 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -39,7 +39,7 @@ keywords = [ [workspace.dependencies] starknet = "2.7.0" -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" } [dependencies] starknet.workspace = true diff --git a/docs/modules/ROOT/pages/api/testing.adoc b/docs/modules/ROOT/pages/api/testing.adoc index c278f12b4..505cce485 100644 --- a/docs/modules/ROOT/pages/api/testing.adoc +++ b/docs/modules/ROOT/pages/api/testing.adoc @@ -120,6 +120,9 @@ A module containing utilities that simplify declaring and deploying contracts us Declares a contract with a `snforge` `declare` call and unwraps the result. +NOTE: If the contract is already declared, this function won't panic but will instead +return the existing class. + [.contract-item] [[testing-deployment-deploy]] ==== `[.contract-item-name]#++deploy++#++(contract_class: ContractClass, calldata: Array) → ContractAddress++` [.item-kind]#function# @@ -157,12 +160,18 @@ deploy_another_at(alice_address, bob_address, array!['BOB_PUBKEY']); Combines the declaration of a class and the deployment of a contract into one function call. +NOTE: If the contract is already declared, this function will skip the declaration step and will +deploy it. + [.contract-item] [[testing-deployment-declare_and_deploy_at]] ==== `[.contract-item-name]#++declare_and_deploy_at++#++(contract_name: ByteArray, target_address: ContractAddress, calldata: Array)++` [.item-kind]#function# Combines the declaration of a class and the deployment of a contract at the given address into one function call. +NOTE: If the contract is already declared, this function will skip the declaration step and will +deploy it. + [.contract] [[testing-events]] === `++events++` diff --git a/packages/presets/src/tests/test_erc1155.cairo b/packages/presets/src/tests/test_erc1155.cairo index c166ca901..7b153f3ff 100644 --- a/packages/presets/src/tests/test_erc1155.cairo +++ b/packages/presets/src/tests/test_erc1155.cairo @@ -4,7 +4,7 @@ use openzeppelin_presets::interfaces::{ }; use openzeppelin_test_common::erc1155::ERC1155SpyHelpers; use openzeppelin_test_common::erc1155::{ - setup_account, setup_receiver, setup_camel_receiver, deploy_another_account_at, setup_src5 + setup_account, setup_receiver, setup_camel_receiver, setup_account_at, setup_src5 }; use openzeppelin_test_common::erc1155::{get_ids_and_values, get_ids_and_split_values}; use openzeppelin_test_common::ownable::OwnableSpyHelpers; @@ -219,7 +219,7 @@ fn test_safe_transfer_from_to_account() { let (mut spy, dispatcher, owner) = setup_dispatcher(); let contract = dispatcher.contract_address; let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID); @@ -235,7 +235,7 @@ fn test_safeTransferFrom_to_account() { let (mut spy, dispatcher, owner) = setup_dispatcher(); let contract = dispatcher.contract_address; let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID); @@ -252,7 +252,7 @@ fn test_safe_transfer_from_approved_operator() { let contract = dispatcher.contract_address; let operator = OPERATOR(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); dispatcher.set_approval_for_all(operator, true); @@ -276,7 +276,7 @@ fn test_safeTransferFrom_approved_operator() { let contract = dispatcher.contract_address; let operator = OPERATOR(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); dispatcher.set_approval_for_all(operator, true); @@ -448,7 +448,7 @@ fn test_safe_batch_transfer_from_to_account() { let contract = dispatcher.contract_address; let (token_ids, values) = get_ids_and_values(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values); @@ -465,7 +465,7 @@ fn test_safeBatchTransferFrom_to_account() { let contract = dispatcher.contract_address; let (token_ids, values) = get_ids_and_values(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values); @@ -484,7 +484,7 @@ fn test_safe_batch_transfer_from_approved_operator() { let (token_ids, values) = get_ids_and_values(); let operator = OPERATOR(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); dispatcher.set_approval_for_all(operator, true); @@ -506,7 +506,7 @@ fn test_safeBatchTransferFrom_approved_operator() { let (token_ids, values) = get_ids_and_values(); let operator = OPERATOR(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); spy.drop_all_events(); dispatcher.set_approval_for_all(operator, true); diff --git a/packages/test_common/src/erc1155.cairo b/packages/test_common/src/erc1155.cairo index 75350ec22..4449be337 100644 --- a/packages/test_common/src/erc1155.cairo +++ b/packages/test_common/src/erc1155.cairo @@ -19,9 +19,9 @@ pub fn setup_account() -> ContractAddress { utils::declare_and_deploy("SnakeAccountMock", calldata) } -pub fn deploy_another_account_at(existing: ContractAddress, target_address: ContractAddress) { +pub fn setup_account_at(target_address: ContractAddress) { let calldata = array![PUBKEY]; - utils::deploy_another_at(existing, target_address, calldata); + utils::declare_and_deploy_at("SnakeAccountMock", target_address, calldata); } pub fn setup_src5() -> ContractAddress { diff --git a/packages/testing/src/deployment.cairo b/packages/testing/src/deployment.cairo index 9ed7b42bc..aaa327b35 100644 --- a/packages/testing/src/deployment.cairo +++ b/packages/testing/src/deployment.cairo @@ -1,11 +1,14 @@ use openzeppelin_testing::panic_data_to_byte_array; -use snforge_std::{ContractClass, ContractClassTrait}; +use snforge_std::{ContractClass, ContractClassTrait, DeclareResultTrait}; use starknet::ContractAddress; /// Declares a contract with a `snforge` `declare` call and unwraps the result. +/// +/// NOTE: If the contract is already declared, this function won't panic but will instead +/// return the existing class. pub fn declare_class(contract_name: ByteArray) -> ContractClass { match snforge_std::declare(contract_name) { - Result::Ok(contract_class) => contract_class, + Result::Ok(declare_result) => *declare_result.contract_class(), Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)) } } @@ -38,6 +41,9 @@ pub fn deploy_another_at( } /// Combines the declaration of a class and the deployment of a contract into one function call. +/// +/// NOTE: If the contract is already declared, this function will skip the declaration step and will +/// deploy it. pub fn declare_and_deploy(contract_name: ByteArray, calldata: Array) -> ContractAddress { let contract_class = declare_class(contract_name); deploy(contract_class, calldata) @@ -45,6 +51,9 @@ pub fn declare_and_deploy(contract_name: ByteArray, calldata: Array) -> /// Combines the declaration of a class and the deployment of a contract at the given address /// into one function call. +/// +/// NOTE: If the contract is already declared, this function will skip the declaration step and will +/// deploy it. pub fn declare_and_deploy_at( contract_name: ByteArray, target_address: ContractAddress, calldata: Array ) { diff --git a/packages/token/src/tests/erc1155/test_erc1155.cairo b/packages/token/src/tests/erc1155/test_erc1155.cairo index 55ae49ddb..1457c770b 100644 --- a/packages/token/src/tests/erc1155/test_erc1155.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155.cairo @@ -4,7 +4,7 @@ use openzeppelin_test_common::erc1155::{ ERC1155SpyHelpers, get_ids_and_values, get_ids_and_split_values }; use openzeppelin_test_common::erc1155::{ - setup_account, deploy_another_account_at, setup_src5, setup_receiver, setup_camel_receiver + setup_account, setup_account_at, setup_src5, setup_receiver, setup_camel_receiver }; use openzeppelin_testing::constants::{ EMPTY_DATA, ZERO, OWNER, RECIPIENT, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, @@ -222,7 +222,7 @@ fn test_safeTransferFrom_owner_to_camel_receiver() { fn test_safe_transfer_from_owner_to_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let mut spy = spy_events(); let contract_address = test_address(); @@ -242,7 +242,7 @@ fn test_safe_transfer_from_owner_to_account() { fn test_safeTransferFrom_owner_to_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let mut spy = spy_events(); let contract_address = test_address(); @@ -262,7 +262,7 @@ fn test_safeTransferFrom_owner_to_account() { fn test_safe_transfer_from_approved_operator() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let operator = OPERATOR(); let mut spy = spy_events(); let contract_address = test_address(); @@ -287,7 +287,7 @@ fn test_safe_transfer_from_approved_operator() { fn test_safeTransferFrom_approved_operator() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let operator = OPERATOR(); let mut spy = spy_events(); let contract_address = test_address(); @@ -490,7 +490,7 @@ fn test_safeBatchTransferFrom_owner_to_camel_receiver() { fn test_safe_batch_transfer_from_owner_to_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events(); let contract_address = test_address(); @@ -511,7 +511,7 @@ fn test_safe_batch_transfer_from_owner_to_account() { fn test_safeBatchTransferFrom_owner_to_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events(); let contract_address = test_address(); @@ -533,7 +533,7 @@ fn test_safeBatchTransferFrom_owner_to_account() { fn test_safe_batch_transfer_from_approved_operator() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let operator = OPERATOR(); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events(); @@ -559,7 +559,7 @@ fn test_safe_batch_transfer_from_approved_operator() { fn test_safeBatchTransferFrom_approved_operator() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let operator = OPERATOR(); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events(); @@ -946,7 +946,7 @@ fn test_update_wac_single_from_non_zero_to_non_zero_camel_receiver() { fn test_update_wac_single_from_non_zero_to_non_zero_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let token_ids = array![TOKEN_ID].span(); let values = array![TOKEN_VALUE].span(); let mut spy = spy_events(); @@ -1009,7 +1009,7 @@ fn test_update_wac_batch_from_non_zero_to_non_zero_camel_receiver() { fn test_update_wac_batch_from_non_zero_to_non_zero_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events(); let contract_address = test_address(); @@ -1088,7 +1088,7 @@ fn test_update_wac_from_zero_to_non_zero_camel_receiver() { fn test_update_wac_from_zero_to_non_zero_account() { let (mut state, owner) = setup(); let recipient = RECIPIENT(); - deploy_another_account_at(owner, recipient); + setup_account_at(recipient); let sender = ZERO(); let (token_ids, values) = get_ids_and_values(); let mut spy = spy_events();