From 7fe11303c408caa78b17dd08c79d07e313d361ef Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 2 Jul 2024 01:39:26 -0500 Subject: [PATCH 1/3] clean up code --- docs/modules/ROOT/pages/udc.adoc | 2 +- src/access/ownable/dual_ownable.cairo | 2 +- src/presets/universal_deployer.cairo | 3 +-- src/tests/token/erc1155/common.cairo | 4 ++-- src/tests/token/erc1155/test_dual1155_receiver.cairo | 4 ++-- src/token/erc20/dual20.cairo | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/modules/ROOT/pages/udc.adoc b/docs/modules/ROOT/pages/udc.adoc index d0af0dd0c..fd30ce729 100644 --- a/docs/modules/ROOT/pages/udc.adoc +++ b/docs/modules/ROOT/pages/udc.adoc @@ -56,7 +56,7 @@ fn deploy() -> ContractAddress { >(); let salt = 1234567879; let from_zero = false; - let mut calldata = array![]; + let calldata = array![]; // The UDC returns the deployed contract address dispatcher.deploy_contract(class_hash, salt, from_zero, calldata.span()) diff --git a/src/access/ownable/dual_ownable.cairo b/src/access/ownable/dual_ownable.cairo index d4ae86aa2..7c3052c81 100644 --- a/src/access/ownable/dual_ownable.cairo +++ b/src/access/ownable/dual_ownable.cairo @@ -42,7 +42,7 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait { } fn renounce_ownership(self: @DualCaseOwnable) { - let mut args = array![]; + let args = array![]; try_selector_with_fallback( *self.contract_address, diff --git a/src/presets/universal_deployer.cairo b/src/presets/universal_deployer.cairo index 2d4f84070..d4a928ca9 100644 --- a/src/presets/universal_deployer.cairo +++ b/src/presets/universal_deployer.cairo @@ -45,8 +45,7 @@ pub(crate) mod UniversalDeployer { let deployer: ContractAddress = get_caller_address(); let mut _salt: felt252 = salt; if !from_zero { - let mut hash_state = PoseidonTrait::new(); - _salt = hash_state.update_with(deployer).update_with(salt).finalize(); + _salt = PoseidonTrait::new().update_with(deployer).update_with(salt).finalize() } let (address, _) = starknet::syscalls::deploy_syscall( diff --git a/src/tests/token/erc1155/common.cairo b/src/tests/token/erc1155/common.cairo index 3230c45b0..ba7ca499a 100644 --- a/src/tests/token/erc1155/common.cairo +++ b/src/tests/token/erc1155/common.cairo @@ -22,12 +22,12 @@ pub(crate) fn setup_camel_receiver() -> ContractAddress { } pub(crate) fn setup_account() -> ContractAddress { - let mut calldata = array![PUBKEY]; + let calldata = array![PUBKEY]; utils::deploy(SnakeAccountMock::TEST_CLASS_HASH, calldata) } pub(crate) fn setup_account_with_salt(salt: felt252) -> ContractAddress { - let mut calldata = array![PUBKEY]; + let calldata = array![PUBKEY]; utils::deploy_with_salt(SnakeAccountMock::TEST_CLASS_HASH, calldata, salt) } diff --git a/src/tests/token/erc1155/test_dual1155_receiver.cairo b/src/tests/token/erc1155/test_dual1155_receiver.cairo index da0b87bba..d8ba26e9b 100644 --- a/src/tests/token/erc1155/test_dual1155_receiver.cairo +++ b/src/tests/token/erc1155/test_dual1155_receiver.cairo @@ -21,7 +21,7 @@ use openzeppelin::token::erc1155::interface::{ // fn setup_snake() -> (DualCaseERC1155Receiver, IERC1155ReceiverDispatcher) { - let mut calldata = ArrayTrait::new(); + let calldata = ArrayTrait::new(); let target = utils::deploy(SnakeERC1155ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC1155Receiver { contract_address: target }, @@ -30,7 +30,7 @@ fn setup_snake() -> (DualCaseERC1155Receiver, IERC1155ReceiverDispatcher) { } fn setup_camel() -> (DualCaseERC1155Receiver, IERC1155ReceiverCamelDispatcher) { - let mut calldata = ArrayTrait::new(); + let calldata = ArrayTrait::new(); let target = utils::deploy(CamelERC1155ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC1155Receiver { contract_address: target }, diff --git a/src/token/erc20/dual20.cairo b/src/token/erc20/dual20.cairo index 54b42697e..6c0f50628 100644 --- a/src/token/erc20/dual20.cairo +++ b/src/token/erc20/dual20.cairo @@ -48,7 +48,7 @@ impl DualCaseERC20Impl of DualCaseERC20Trait { } fn total_supply(self: @DualCaseERC20) -> u256 { - let mut args = array![]; + let args = array![]; try_selector_with_fallback( *self.contract_address, selectors::total_supply, selectors::totalSupply, args.span() ) From e41f6cda16795ee83a748c7877f0cd07014fbf46 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 2 Jul 2024 01:49:04 -0500 Subject: [PATCH 2/3] change array syntax --- src/account/utils.cairo | 2 +- src/tests/security/test_reentrancyguard.cairo | 2 +- src/tests/token/erc1155/test_dual1155_receiver.cairo | 10 +++++----- src/tests/token/erc721/test_dual721_receiver.cairo | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/account/utils.cairo b/src/account/utils.cairo index 8dfe7b49d..a1209c732 100644 --- a/src/account/utils.cairo +++ b/src/account/utils.cairo @@ -15,7 +15,7 @@ pub const QUERY_OFFSET: u256 = 0x100000000000000000000000000000000; pub const QUERY_VERSION: u256 = 0x100000000000000000000000000000001; pub fn execute_calls(mut calls: Array) -> Array> { - let mut res = ArrayTrait::new(); + let mut res = array![]; loop { match calls.pop_front() { Option::Some(call) => { diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index 327f72fa4..b243b4aa4 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -76,7 +76,7 @@ fn test_remote_callback() { let contract = deploy_mock(); // Deploy attacker - let calldata = ArrayTrait::new(); + let calldata = array![]; let attacker_addr = utils::deploy(Attacker::TEST_CLASS_HASH, calldata); contract.count_and_call(attacker_addr); diff --git a/src/tests/token/erc1155/test_dual1155_receiver.cairo b/src/tests/token/erc1155/test_dual1155_receiver.cairo index d8ba26e9b..d5d22c27e 100644 --- a/src/tests/token/erc1155/test_dual1155_receiver.cairo +++ b/src/tests/token/erc1155/test_dual1155_receiver.cairo @@ -21,7 +21,7 @@ use openzeppelin::token::erc1155::interface::{ // fn setup_snake() -> (DualCaseERC1155Receiver, IERC1155ReceiverDispatcher) { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(SnakeERC1155ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC1155Receiver { contract_address: target }, @@ -30,7 +30,7 @@ fn setup_snake() -> (DualCaseERC1155Receiver, IERC1155ReceiverDispatcher) { } fn setup_camel() -> (DualCaseERC1155Receiver, IERC1155ReceiverCamelDispatcher) { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(CamelERC1155ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC1155Receiver { contract_address: target }, @@ -39,17 +39,17 @@ fn setup_camel() -> (DualCaseERC1155Receiver, IERC1155ReceiverCamelDispatcher) { } fn setup_non_erc1155_receiver() -> DualCaseERC1155Receiver { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata); DualCaseERC1155Receiver { contract_address: target } } fn setup_erc1155_receiver_panic() -> (DualCaseERC1155Receiver, DualCaseERC1155Receiver) { let snake_target = utils::deploy( - SnakeERC1155ReceiverPanicMock::TEST_CLASS_HASH, ArrayTrait::new() + SnakeERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![] ); let camel_target = utils::deploy( - CamelERC1155ReceiverPanicMock::TEST_CLASS_HASH, ArrayTrait::new() + CamelERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![] ); ( DualCaseERC1155Receiver { contract_address: snake_target }, diff --git a/src/tests/token/erc721/test_dual721_receiver.cairo b/src/tests/token/erc721/test_dual721_receiver.cairo index b201b14d3..770b9cc60 100644 --- a/src/tests/token/erc721/test_dual721_receiver.cairo +++ b/src/tests/token/erc721/test_dual721_receiver.cairo @@ -23,7 +23,7 @@ use openzeppelin::token::erc721::interface::{ // fn setup_snake() -> (DualCaseERC721Receiver, IERC721ReceiverDispatcher) { - let mut calldata = ArrayTrait::new(); + let mut calldata = array![]; let target = utils::deploy(SnakeERC721ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC721Receiver { contract_address: target }, @@ -32,7 +32,7 @@ fn setup_snake() -> (DualCaseERC721Receiver, IERC721ReceiverDispatcher) { } fn setup_camel() -> (DualCaseERC721Receiver, IERC721ReceiverCamelDispatcher) { - let mut calldata = ArrayTrait::new(); + let mut calldata = array![]; let target = utils::deploy(CamelERC721ReceiverMock::TEST_CLASS_HASH, calldata); ( DualCaseERC721Receiver { contract_address: target }, @@ -41,17 +41,17 @@ fn setup_camel() -> (DualCaseERC721Receiver, IERC721ReceiverCamelDispatcher) { } fn setup_non_erc721_receiver() -> DualCaseERC721Receiver { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata); DualCaseERC721Receiver { contract_address: target } } fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Receiver) { let snake_target = utils::deploy( - SnakeERC721ReceiverPanicMock::TEST_CLASS_HASH, ArrayTrait::new() + SnakeERC721ReceiverPanicMock::TEST_CLASS_HASH, array![] ); let camel_target = utils::deploy( - CamelERC721ReceiverPanicMock::TEST_CLASS_HASH, ArrayTrait::new() + CamelERC721ReceiverPanicMock::TEST_CLASS_HASH, array![] ); ( DualCaseERC721Receiver { contract_address: snake_target }, From 12a04ba078b7d5d74a957fa1a9957f71f2b8ac6b Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 2 Jul 2024 01:49:20 -0500 Subject: [PATCH 3/3] fix fmt --- src/tests/token/erc1155/test_dual1155_receiver.cairo | 8 ++------ src/tests/token/erc721/test_dual721_receiver.cairo | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/tests/token/erc1155/test_dual1155_receiver.cairo b/src/tests/token/erc1155/test_dual1155_receiver.cairo index d5d22c27e..d62ab277b 100644 --- a/src/tests/token/erc1155/test_dual1155_receiver.cairo +++ b/src/tests/token/erc1155/test_dual1155_receiver.cairo @@ -45,12 +45,8 @@ fn setup_non_erc1155_receiver() -> DualCaseERC1155Receiver { } fn setup_erc1155_receiver_panic() -> (DualCaseERC1155Receiver, DualCaseERC1155Receiver) { - let snake_target = utils::deploy( - SnakeERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![] - ); - let camel_target = utils::deploy( - CamelERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![] - ); + let snake_target = utils::deploy(SnakeERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![]); + let camel_target = utils::deploy(CamelERC1155ReceiverPanicMock::TEST_CLASS_HASH, array![]); ( DualCaseERC1155Receiver { contract_address: snake_target }, DualCaseERC1155Receiver { contract_address: camel_target } diff --git a/src/tests/token/erc721/test_dual721_receiver.cairo b/src/tests/token/erc721/test_dual721_receiver.cairo index 770b9cc60..d6073197d 100644 --- a/src/tests/token/erc721/test_dual721_receiver.cairo +++ b/src/tests/token/erc721/test_dual721_receiver.cairo @@ -47,12 +47,8 @@ fn setup_non_erc721_receiver() -> DualCaseERC721Receiver { } fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Receiver) { - let snake_target = utils::deploy( - SnakeERC721ReceiverPanicMock::TEST_CLASS_HASH, array![] - ); - let camel_target = utils::deploy( - CamelERC721ReceiverPanicMock::TEST_CLASS_HASH, array![] - ); + let snake_target = utils::deploy(SnakeERC721ReceiverPanicMock::TEST_CLASS_HASH, array![]); + let camel_target = utils::deploy(CamelERC721ReceiverPanicMock::TEST_CLASS_HASH, array![]); ( DualCaseERC721Receiver { contract_address: snake_target }, DualCaseERC721Receiver { contract_address: camel_target }