Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selector inline macro/fix tokenURI #724

Merged
merged 10 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/access/accesscontrol/dual_accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use array::ArrayTrait;

use openzeppelin::utils::Felt252TryIntoBool;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use starknet::ContractAddress;
Expand All @@ -32,7 +31,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {
args.append_serde(account);

try_selector_with_fallback(
*self.contract_address, selectors::has_role, selectors::hasRole, args.span()
*self.contract_address, selector!("has_role"), selector!("hasRole"), args.span()
)
.unwrap_and_cast()
}
Expand All @@ -42,7 +41,10 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {
args.append_serde(role);

try_selector_with_fallback(
*self.contract_address, selectors::get_role_admin, selectors::getRoleAdmin, args.span()
*self.contract_address,
selector!("get_role_admin"),
selector!("getRoleAdmin"),
args.span()
)
.unwrap_and_cast()
}
Expand All @@ -53,7 +55,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {
args.append_serde(account);

try_selector_with_fallback(
*self.contract_address, selectors::grant_role, selectors::grantRole, args.span()
*self.contract_address, selector!("grant_role"), selector!("grantRole"), args.span()
)
.unwrap_syscall();
}
Expand All @@ -64,7 +66,7 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {
args.append_serde(account);

try_selector_with_fallback(
*self.contract_address, selectors::revoke_role, selectors::revokeRole, args.span()
*self.contract_address, selector!("revoke_role"), selector!("revokeRole"), args.span()
)
.unwrap_syscall();
}
Expand All @@ -75,7 +77,10 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {
args.append_serde(account);

try_selector_with_fallback(
*self.contract_address, selectors::renounce_role, selectors::renounceRole, args.span()
*self.contract_address,
selector!("renounce_role"),
selector!("renounceRole"),
args.span()
)
.unwrap_syscall();
}
Expand All @@ -86,8 +91,8 @@ impl DualCaseAccessControlImpl of DualCaseAccessControlTrait {

try_selector_with_fallback(
*self.contract_address,
selectors::supports_interface,
selectors::supportsInterface,
selector!("supports_interface"),
selector!("supportsInterface"),
args.span()
)
.unwrap_and_cast()
Expand Down
11 changes: 5 additions & 6 deletions src/access/ownable/dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use core::result::ResultTrait;

use openzeppelin::utils::Felt252TryIntoBool;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use option::OptionTrait;
Expand All @@ -32,7 +31,7 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait {
fn owner(self: @DualCaseOwnable) -> ContractAddress {
let args = ArrayTrait::new();

call_contract_syscall(*self.contract_address, selectors::owner, args.span())
call_contract_syscall(*self.contract_address, selector!("owner"), args.span())
.unwrap_and_cast()
}

Expand All @@ -42,8 +41,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait {

try_selector_with_fallback(
*self.contract_address,
selectors::transfer_ownership,
selectors::transferOwnership,
selector!("transfer_ownership"),
selector!("transferOwnership"),
args.span()
)
.unwrap_syscall();
Expand All @@ -54,8 +53,8 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait {

try_selector_with_fallback(
*self.contract_address,
selectors::renounce_ownership,
selectors::renounceOwnership,
selector!("renounce_ownership"),
selector!("renounceOwnership"),
args.span()
)
.unwrap_syscall();
Expand Down
19 changes: 12 additions & 7 deletions src/account/dual_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use array::ArrayTrait;
use array::SpanTrait;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use starknet::ContractAddress;
Expand All @@ -29,7 +28,10 @@ impl DualCaseAccountImpl of DualCaseAccountABI {
let mut args = array![new_public_key];

try_selector_with_fallback(
*self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span()
*self.contract_address,
selector!("set_public_key"),
selector!("setPublicKey"),
args.span()
)
.unwrap_syscall();
}
Expand All @@ -38,7 +40,10 @@ impl DualCaseAccountImpl of DualCaseAccountABI {
let mut args = array![];

try_selector_with_fallback(
*self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span()
*self.contract_address,
selector!("get_public_key"),
selector!("getPublicKey"),
args.span()
)
.unwrap_and_cast()
}
Expand All @@ -51,8 +56,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI {

try_selector_with_fallback(
*self.contract_address,
selectors::is_valid_signature,
selectors::isValidSignature,
selector!("is_valid_signature"),
selector!("isValidSignature"),
args.span()
)
.unwrap_and_cast()
Expand All @@ -63,8 +68,8 @@ impl DualCaseAccountImpl of DualCaseAccountABI {

try_selector_with_fallback(
*self.contract_address,
selectors::supports_interface,
selectors::supportsInterface,
selector!("supports_interface"),
selector!("supportsInterface"),
args.span()
)
.unwrap_and_cast()
Expand Down
5 changes: 2 additions & 3 deletions src/introspection/dual_src5.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use array::ArrayTrait;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::try_selector_with_fallback;
use starknet::ContractAddress;

Expand All @@ -22,8 +21,8 @@ impl DualCaseSRC5Impl of DualCaseSRC5Trait {

try_selector_with_fallback(
*self.contract_address,
selectors::supports_interface,
selectors::supportsInterface,
selector!("supports_interface"),
selector!("supportsInterface"),
args.span()
)
.unwrap_and_cast()
Expand Down
7 changes: 3 additions & 4 deletions src/tests/account/test_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use openzeppelin::tests::utils::constants::ZERO;
use openzeppelin::token::erc20::ERC20;
use openzeppelin::token::erc20::interface::IERC20Dispatcher;
use openzeppelin::token::erc20::interface::IERC20DispatcherTrait;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use option::OptionTrait;
use serde::Serde;
Expand Down Expand Up @@ -300,7 +299,7 @@ fn test_execute_with_version(version: Option<felt252>) {
calldata.append_serde(recipient);
calldata.append_serde(amount);
let call = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata
to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata
};
let mut calls = array![];
calls.append(call);
Expand Down Expand Up @@ -378,7 +377,7 @@ fn test_multicall() {
calldata1.append_serde(recipient1);
calldata1.append_serde(amount1);
let call1 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1
to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1
};

// Craft call2
Expand All @@ -387,7 +386,7 @@ fn test_multicall() {
calldata2.append_serde(recipient2);
calldata2.append_serde(amount2);
let call2 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2
to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2
};

// Bundle calls and exeute
Expand Down
4 changes: 2 additions & 2 deletions src/tests/mocks/camel721_mock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ mod CamelERC721Mock {
}

#[external(v0)]
fn tokenUri(self: @ContractState, tokenId: u256) -> felt252 {
fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 {
let unsafe_state = ERC721::unsafe_new_contract_state();
ERC721::ERC721MetadataCamelOnlyImpl::tokenUri(@unsafe_state, tokenId)
ERC721::ERC721MetadataCamelOnlyImpl::tokenURI(@unsafe_state, tokenId)
}

#[external(v0)]
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mocks/erc721_panic_mock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod CamelERC721PanicMock {
}

#[external(v0)]
fn tokenUri(self: @ContractState, tokenId: u256) -> felt252 {
fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 {
panic_with_felt252('Some error');
3
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/token/test_dual721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,15 @@ fn test_dual_isApprovedForAll_exists_and_panics() {

#[test]
#[available_gas(2000000)]
fn test_dual_tokenUri() {
fn test_dual_tokenURI() {
let (dispatcher, target) = setup_camel();
assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI');
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))]
fn test_dual_tokenUri_exists_and_panics() {
fn test_dual_tokenURI_exists_and_panics() {
let (_, dispatcher) = setup_erc721_panic();
dispatcher.token_uri(TOKEN_ID);
}
Expand Down
22 changes: 12 additions & 10 deletions src/token/erc20/dual20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use array::ArrayTrait;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use starknet::ContractAddress;
Expand Down Expand Up @@ -32,26 +31,26 @@ trait DualERC20Trait {
impl DualERC20Impl of DualERC20Trait {
fn name(self: @DualERC20) -> felt252 {
let args = array![];
call_contract_syscall(*self.contract_address, selectors::name, args.span())
call_contract_syscall(*self.contract_address, selector!("name"), args.span())
.unwrap_and_cast()
}

fn symbol(self: @DualERC20) -> felt252 {
let args = array![];
call_contract_syscall(*self.contract_address, selectors::symbol, args.span())
call_contract_syscall(*self.contract_address, selector!("symbol"), args.span())
.unwrap_and_cast()
}

fn decimals(self: @DualERC20) -> u8 {
let args = array![];
call_contract_syscall(*self.contract_address, selectors::decimals, args.span())
call_contract_syscall(*self.contract_address, selector!("decimals"), args.span())
.unwrap_and_cast()
}

fn total_supply(self: @DualERC20) -> u256 {
let mut args = array![];
try_selector_with_fallback(
*self.contract_address, selectors::total_supply, selectors::totalSupply, args.span()
*self.contract_address, selector!("total_supply"), selector!("totalSupply"), args.span()
)
.unwrap_and_cast()
}
Expand All @@ -61,7 +60,7 @@ impl DualERC20Impl of DualERC20Trait {
args.append_serde(account);

try_selector_with_fallback(
*self.contract_address, selectors::balance_of, selectors::balanceOf, args.span()
*self.contract_address, selector!("balance_of"), selector!("balanceOf"), args.span()
)
.unwrap_and_cast()
}
Expand All @@ -71,7 +70,7 @@ impl DualERC20Impl of DualERC20Trait {
args.append_serde(owner);
args.append_serde(spender);

call_contract_syscall(*self.contract_address, selectors::allowance, args.span())
call_contract_syscall(*self.contract_address, selector!("allowance"), args.span())
.unwrap_and_cast()
}

Expand All @@ -80,7 +79,7 @@ impl DualERC20Impl of DualERC20Trait {
args.append_serde(recipient);
args.append_serde(amount);

call_contract_syscall(*self.contract_address, selectors::transfer, args.span())
call_contract_syscall(*self.contract_address, selector!("transfer"), args.span())
.unwrap_and_cast()
}

Expand All @@ -93,7 +92,10 @@ impl DualERC20Impl of DualERC20Trait {
args.append_serde(amount);

try_selector_with_fallback(
*self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span()
*self.contract_address,
selector!("transfer_from"),
selector!("transferFrom"),
args.span()
)
.unwrap_and_cast()
}
Expand All @@ -103,7 +105,7 @@ impl DualERC20Impl of DualERC20Trait {
args.append_serde(spender);
args.append_serde(amount);

call_contract_syscall(*self.contract_address, selectors::approve, args.span())
call_contract_syscall(*self.contract_address, selector!("approve"), args.span())
.unwrap_and_cast()
}
}
Loading