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 camel support for ownable #625

Merged
merged 44 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
aeb2632
add camel support
andrew-fleming May 31, 2023
65d6107
add camel tests
andrew-fleming May 31, 2023
e57a6e2
nest ownable into dir
andrew-fleming Jun 17, 2023
28b62e7
move interface
andrew-fleming Jun 17, 2023
e65f141
add dual ownable
andrew-fleming Jun 17, 2023
cdff982
add const selectors
andrew-fleming Jun 17, 2023
96645d8
add try_selector_with_fallback and bool impl
andrew-fleming Jun 17, 2023
6b5bd77
nest access tests in test dirs
andrew-fleming Jun 17, 2023
693be42
move accesscontrol and ownable test mods
andrew-fleming Jun 17, 2023
7c730da
move tests
andrew-fleming Jun 17, 2023
f5036c2
move tests
andrew-fleming Jun 17, 2023
5b4e9c8
add mocks
andrew-fleming Jun 17, 2023
0740651
add dual ownable tests
andrew-fleming Jun 17, 2023
e401048
add panic traits
andrew-fleming Jun 17, 2023
572a36a
tidy up tests
andrew-fleming Jun 18, 2023
67f94c7
fix formatting
andrew-fleming Jun 18, 2023
89b2219
remove comments
andrew-fleming Jun 23, 2023
62aa022
fix hierarchy
andrew-fleming Jun 23, 2023
d3c9cd8
remove import comments
andrew-fleming Jun 23, 2023
ef2bcec
remove comment
andrew-fleming Jun 23, 2023
c852416
Apply suggestions from code review
andrew-fleming Jun 23, 2023
1b072d3
remove unused import
andrew-fleming Jun 23, 2023
27ffce4
fix camel dispatcher
andrew-fleming Jun 23, 2023
1ab8f54
normalize assert error msg
andrew-fleming Jun 23, 2023
c5dd73e
fix formatting
andrew-fleming Jun 23, 2023
9b14aa0
remove redundant assertion
andrew-fleming Jun 23, 2023
560b8fe
change selector casing
andrew-fleming Jun 23, 2023
e34964b
remove unused import
andrew-fleming Jun 25, 2023
cb0f650
fix comments, add ref for ignored tests
andrew-fleming Jun 27, 2023
c8a7fe6
fix comments
andrew-fleming Jun 27, 2023
4d80c68
remove panic trait
andrew-fleming Jun 27, 2023
bf5f66b
bump to cairo v1.1.1
andrew-fleming Jun 28, 2023
02327ad
update Cargo
andrew-fleming Jun 28, 2023
4165163
remove ignore from tests
andrew-fleming Jun 28, 2023
d03269b
Apply suggestions from code review
andrew-fleming Jun 28, 2023
2eef651
remove selectors from constants
andrew-fleming Jun 29, 2023
ae1839b
add selectors to selectors.cairo
andrew-fleming Jun 29, 2023
c38d62f
remove selector bindings
andrew-fleming Jun 30, 2023
07c7bbe
fix comment
andrew-fleming Jun 30, 2023
93f6902
fix conflicts
andrew-fleming Jul 2, 2023
06e4b8c
remove/fix comments
andrew-fleming Jul 2, 2023
967b06b
fix conflicts
andrew-fleming Jul 2, 2023
042311b
Update src/openzeppelin/utils/selectors.cairo
andrew-fleming Jul 3, 2023
c1a39c1
Merge branch 'cairo-1' into camel-ownable
andrew-fleming Jul 3, 2023
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
16 changes: 8 additions & 8 deletions src/openzeppelin/access/ownable/dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait {
}

fn transfer_ownership(self: @DualCaseOwnable, new_owner: ContractAddress) {
let snake_selector = selectors::transfer_ownership;
let camel_selector = selectors::transferOwnership;

let mut args = ArrayTrait::new();
args.append(new_owner.into());

try_selector_with_fallback(
*self.contract_address, snake_selector, camel_selector, args.span()
*self.contract_address,
selectors::transfer_ownership,
selectors::transferOwnership,
args.span()
)
.unwrap_syscall();
}

fn renounce_ownership(self: @DualCaseOwnable) {
let snake_selector = selectors::renounce_ownership;
let camel_selector = selectors::renounceOwnership;

let mut args = ArrayTrait::new();

try_selector_with_fallback(
*self.contract_address, snake_selector, camel_selector, args.span()
*self.contract_address,
selectors::renounce_ownership,
selectors::renounceOwnership,
args.span()
)
.unwrap_syscall();
}
Expand Down
2 changes: 1 addition & 1 deletion src/openzeppelin/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod access;
mod test_reentrancyguard;
mod test_erc165;
mod test_src5;
mod test_account;
mod test_erc20;
mod test_erc721;
Expand Down
2 changes: 2 additions & 0 deletions src/openzeppelin/tests/mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ mod erc721_receiver;
mod erc721_panic_mock;
mod mock_pausable;
mod dual_ownable_mocks;
mod snake721_mock;
mod camel721_mock;
mod non_implementing_mock;
2 changes: 1 addition & 1 deletion src/openzeppelin/tests/mocks/camel721_mock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod CamelERC721Mock {
// View

#[view]
fn supportsInterface(interfaceId: u32) -> bool {
fn supportsInterface(interfaceId: felt252) -> bool {
ERC721::supports_interface(interfaceId)
}

Expand Down
2 changes: 1 addition & 1 deletion src/openzeppelin/tests/mocks/snake721_mock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod SnakeERC721Mock {
// View

#[view]
fn supports_interface(interface_id: u32) -> bool {
fn supports_interface(interface_id: felt252) -> bool {
ERC721::supports_interface(interface_id)
}

Expand Down
2 changes: 2 additions & 0 deletions src/openzeppelin/token/erc721/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const IERC721_METADATA_ID: felt252 =
const IERC721_RECEIVER_ID: felt252 =
0x3a0dff5f70d80458ad14ae37bb182a728e3c8cdda0402a5daa86620bdf910bc;

#[abi]
trait IERC721 {
fn balance_of(account: ContractAddress) -> u256;
fn owner_of(token_id: u256) -> ContractAddress;
Expand All @@ -25,6 +26,7 @@ trait IERC721 {
fn token_uri(token_id: u256) -> felt252;
}

#[abi]
trait IERC721Camel {
fn balanceOf(account: ContractAddress) -> u256;
fn ownerOf(tokenId: u256) -> ContractAddress;
Expand Down
30 changes: 29 additions & 1 deletion src/openzeppelin/utils/selectors.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// List of selectors with their starknet_keccak calculation
// Ownable
//

const owner: felt252 = 0x2016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
Expand All @@ -9,3 +9,31 @@ const transferOwnership: felt252 =
0x14a390f291e2e1f29874769efdef47ddad94d76f77ff516fad206a385e8995f;
const renounce_ownership: felt252 = 0x52580a92c73f4428f1a260c5d768ef462b25955307de00f99957df119865d;
const renounceOwnership: felt252 = 0xd5d33d590e6660853069b37a2aea67c6fdaa0268626bc760350b590490feb5;

//
// ERC721 Selectors
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
//

const name: felt252 = 0x361458367e696363fbcc70777d07ebbd2394e89fd0adcaf147faccd1d294d60;
const symbol: felt252 = 0x216b05c387bab9ac31918a3e61672f4618601f3c598a2f3f2710f37053e1ea4;
const token_uri: felt252 = 0x226ad7e84c1fe08eb4c525ed93cccadf9517670341304571e66f7c4f95cbe54;
const tokenUri: felt252 = 0x362dec5b8b67ab667ad08e83a2c3ba1db7fdb4ab8dc3a33c057c4fddec8d3de;
const balance_of: felt252 = 0x35a73cd311a05d46deda634c5ee045db92f811b4e74bca4437fcb5302b7af33;
const balanceOf: felt252 = 0x2e4263afad30923c891518314c3c95dbe830a16874e8abc5777a9a20b54c76e;
const owner_of: felt252 = 0x3552df12bdc6089cf963c40c4cf56fbfd4bd14680c244d1c5494c2790f1ea5c;
const ownerOf: felt252 = 0x2962ba17806af798afa6eaf4aa8c93a9fb60a3e305045b6eea33435086cae9;
const get_approved: felt252 = 0x309065f1424d76d4a4ace2ff671391d59536e0297409434908d38673290a749;
const getApproved: felt252 = 0xb180e2fe9f14914416216da76338ac0beb980443725c802af615f8431fdb1e;
const is_approved_for_all: felt252 =
0x2aa3ea196f9b8a4f65613b67fcf185e69d8faa9601a3382871d15b3060e30dd;
const isApprovedForAll: felt252 = 0x21cdf9aedfed41bc4485ae779fda471feca12075d9127a0fc70ac6b3b3d9c30;
const approve: felt252 = 0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c;
const set_approval_for_all: felt252 =
0xd86ca3d41635e20c180181046b11abcf19e1bdef3dcaa4c180300ccca1813f;
const setApprovalForAll: felt252 =
0x2d4c8ea4c8fb9f571d1f6f9b7692fff8e5ceaf73b1df98e7da8c1109b39ae9a;
const transfer_from: felt252 = 0x3704ffe8fba161be0e994951751a5033b1462b918ff785c0a636be718dfdb68;
const transferFrom: felt252 = 0x41b033f4a31df8067c24d1e9b550a2ce75fd4a29e1147af9752174f0e6cb20;
const safe_transfer_from: felt252 =
0x16f0218b33b5cf273196787d7cf139a9ad13d58e6674dcdce722b3bf8389863;
const safeTransferFrom: felt252 = 0x19d59d013d4aa1a8b1ce4c8299086f070733b453c02d0dc46e735edc04d6444;