Skip to content

Commit

Permalink
feat: bumo foundry to 0.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnordelo committed Aug 22, 2024
1 parent 42ec58a commit 334f5c9
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 28 deletions.
12 changes: 10 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/modules/ROOT/pages/api/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252>) → ContractAddress++` [.item-kind]#function#
Expand Down Expand Up @@ -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<felt252>)++` [.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++`
Expand Down
18 changes: 9 additions & 9 deletions packages/presets/src/tests/test_erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/test_common/src/erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions packages/testing/src/deployment.cairo
Original file line number Diff line number Diff line change
@@ -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))
}
}
Expand Down Expand Up @@ -38,13 +41,19 @@ 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<felt252>) -> ContractAddress {
let contract_class = declare_class(contract_name);
deploy(contract_class, calldata)
}

/// 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<felt252>
) {
Expand Down
24 changes: 12 additions & 12 deletions packages/token/src/tests/erc1155/test_erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 334f5c9

Please sign in to comment.