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

Remove token dual dispatchers #1174

Prev Previous commit
Next Next commit
feat: remove modules
ericnordelo committed Oct 2, 2024
commit 47428faa422d19d3ee41dfe765b2288e2a261e9d
1 change: 0 additions & 1 deletion packages/presets/src/tests/mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub(crate) mod account_mocks;
pub(crate) mod erc1155_mocks;
pub(crate) mod erc1155_receiver_mocks;
pub(crate) mod erc20_mocks;
pub(crate) mod erc721_mocks;
pub(crate) mod erc721_receiver_mocks;
58 changes: 0 additions & 58 deletions packages/presets/src/tests/mocks/account_mocks.cairo
Original file line number Diff line number Diff line change
@@ -85,61 +85,3 @@ pub(crate) mod SnakeAccountMock {
self.account.initializer(public_key);
}
}

#[starknet::contract(account)]
pub(crate) mod CamelAccountMock {
use openzeppelin_account::AccountComponent;
use openzeppelin_introspection::src5::SRC5Component;
use starknet::account::Call;

component!(path: AccountComponent, storage: account, event: AccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// Account
#[abi(embed_v0)]
impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl<ContractState>;
#[abi(embed_v0)]
impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl<ContractState>;
impl SRC6Impl = AccountComponent::SRC6Impl<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

// SCR5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[storage]
pub struct Storage {
#[substorage(v0)]
pub account: AccountComponent::Storage,
#[substorage(v0)]
pub src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
AccountEvent: AccountComponent::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

#[constructor]
fn constructor(ref self: ContractState, publicKey: felt252) {
self.account.initializer(publicKey);
}

#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn __execute__(self: @ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
self.account.__execute__(calls)
}

#[external(v0)]
fn __validate__(self: @ContractState, mut calls: Array<Call>) -> felt252 {
self.account.__validate__(calls)
}
}
}
51 changes: 0 additions & 51 deletions packages/presets/src/tests/mocks/erc1155_mocks.cairo
Original file line number Diff line number Diff line change
@@ -48,54 +48,3 @@ pub(crate) mod SnakeERC1155Mock {
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span());
}
}

#[starknet::contract]
pub(crate) mod CamelERC1155Mock {
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl};
use starknet::ContractAddress;

component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// ERC1155
#[abi(embed_v0)]
impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155MetadataURIImpl =
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
impl ERC1155InternalImpl = ERC1155Component::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[storage]
pub struct Storage {
#[substorage(v0)]
pub erc1155: ERC1155Component::Storage,
#[substorage(v0)]
pub src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC1155Event: ERC1155Component::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

#[constructor]
fn constructor(
ref self: ContractState,
base_uri: ByteArray,
recipient: ContractAddress,
token_id: u256,
value: u256
) {
self.erc1155.initializer(base_uri);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span());
}
}
42 changes: 0 additions & 42 deletions packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo

This file was deleted.

41 changes: 0 additions & 41 deletions packages/presets/src/tests/mocks/erc20_mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
#[starknet::contract]
pub(crate) mod DualCaseERC20Mock {
use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
#[abi(embed_v0)]
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
pub struct Storage {
#[substorage(v0)]
pub erc20: ERC20Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}

#[constructor]
fn constructor(
ref self: ContractState,
name: ByteArray,
symbol: ByteArray,
initial_supply: u256,
recipient: ContractAddress
) {
self.erc20.initializer(name, symbol);
self.erc20.mint(recipient, initial_supply);
}
}

#[starknet::contract]
pub(crate) mod SnakeERC20Mock {
use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
54 changes: 3 additions & 51 deletions packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const SUCCESS: felt252 = 'SUCCESS';

#[starknet::contract]
pub(crate) mod SnakeERC721ReceiverMock {
pub(crate) mod DualCaseERC721ReceiverMock {
use crate::erc721::ERC721ReceiverComponent;
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_token::erc721::ERC721ReceiverComponent;
use starknet::ContractAddress;

component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent);
@@ -56,51 +56,7 @@ pub(crate) mod SnakeERC721ReceiverMock {
0
}
}
}
}

#[starknet::contract]
pub(crate) mod CamelERC721ReceiverMock {
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_token::erc721::ERC721ReceiverComponent;
use starknet::ContractAddress;

component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// ERC721Receiver
impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl<ContractState>;
impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[storage]
pub struct Storage {
#[substorage(v0)]
pub erc721_receiver: ERC721ReceiverComponent::Storage,
#[substorage(v0)]
pub src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC721ReceiverEvent: ERC721ReceiverComponent::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

#[constructor]
fn constructor(ref self: ContractState) {
self.erc721_receiver.initializer();
}

#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn onERC721Received(
self: @ContractState,
@@ -109,11 +65,7 @@ pub(crate) mod CamelERC721ReceiverMock {
tokenId: u256,
data: Span<felt252>
) -> felt252 {
if *data.at(0) == super::SUCCESS {
self.erc721_receiver.onERC721Received(operator, from, tokenId, data)
} else {
0
}
Self::on_erc721_received(self, operator, from, tokenId, data)
}
}
}
64 changes: 1 addition & 63 deletions packages/presets/src/tests/test_erc1155.cairo
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use core::num::traits::Zero;
use crate::interfaces::{ERC1155UpgradeableABIDispatcher, ERC1155UpgradeableABIDispatcherTrait};
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, deploy_another_account_at, setup_src5
};
use openzeppelin_test_common::erc1155::{get_ids_and_values, get_ids_and_split_values};
use openzeppelin_test_common::ownable::OwnableSpyHelpers;
@@ -168,21 +168,6 @@ fn test_safe_transfer_from_to_receiver() {
assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID);
}

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
fn test_safe_transfer_from_to_camel_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
let contract = dispatcher.contract_address;
let recipient = setup_camel_receiver();

assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID);

dispatcher.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
spy.assert_only_event_transfer_single(contract, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE);

assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID);
}

#[test]
fn test_safeTransferFrom_to_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
@@ -197,21 +182,6 @@ fn test_safeTransferFrom_to_receiver() {
assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID);
}

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
fn test_safeTransferFrom_to_camel_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
let contract = dispatcher.contract_address;
let recipient = setup_camel_receiver();

assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID);

dispatcher.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
spy.assert_only_event_transfer_single(contract, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE);

assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID);
}

#[test]
fn test_safe_transfer_from_to_account() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
@@ -393,22 +363,6 @@ fn test_safe_batch_transfer_from_to_receiver() {
assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values);
}

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
fn test_safe_batch_transfer_from_to_camel_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
let contract = dispatcher.contract_address;
let recipient = setup_camel_receiver();
let (token_ids, values) = get_ids_and_values();

assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values);

dispatcher.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA());
spy.assert_only_event_transfer_batch(contract, owner, owner, recipient, token_ids, values);

assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values);
}

#[test]
fn test_safeBatchTransferFrom_to_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
@@ -424,22 +378,6 @@ fn test_safeBatchTransferFrom_to_receiver() {
assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values);
}

#[test]
#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet.
fn test_safeBatchTransferFrom_to_camel_receiver() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
let contract = dispatcher.contract_address;
let recipient = setup_camel_receiver();
let (token_ids, values) = get_ids_and_values();

assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values);

dispatcher.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA());
spy.assert_only_event_transfer_batch(contract, owner, owner, recipient, token_ids, values);

assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values);
}

#[test]
fn test_safe_batch_transfer_from_to_account() {
let (mut spy, dispatcher, owner) = setup_dispatcher();
Loading