Skip to content

Commit

Permalink
featL apply review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnordelo committed Feb 28, 2024
1 parent 991cc8d commit 71d6235
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 102 deletions.
5 changes: 5 additions & 0 deletions src/account/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const ISRC6_ID: felt252 = 0x2ceccef7f994940b3962a6c67e0ba4fcd37df7d131417c604f91
// Account
//

trait IAccount {
fn is_account();
}


#[starknet::interface]
trait ISRC6<TState> {
fn __execute__(self: @TState, calls: Array<Call>) -> Array<Span<felt252>>;
Expand Down
88 changes: 14 additions & 74 deletions src/tests/mocks/erc1155_receiver_mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ mod DualCaseERC1155ReceiverMock {
);

// ERC1155Receiver
impl ERC1155ReceiverImpl = ERC1155ReceiverComponent::ERC1155ReceiverImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155ReceiverImpl =
ERC1155ReceiverComponent::ERC1155ReceiverImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155ReceiverCamelImpl =
ERC1155ReceiverComponent::ERC1155ReceiverCamelImpl<ContractState>;
impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl<ContractState>;

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

#[storage]
struct Storage {
#[substorage(v0)]
Expand All @@ -36,30 +45,6 @@ mod DualCaseERC1155ReceiverMock {
fn constructor(ref self: ContractState) {
self.erc1155_receiver.initializer();
}

#[external(v0)]
fn on_erc1155_received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.on_erc1155_received(operator, from, token_id, value, data)
}

#[external(v0)]
fn on_erc1155_batch_received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.on_erc1155_batch_received(operator, from, token_ids, values, data)
}
}

#[starknet::contract]
Expand All @@ -74,7 +59,9 @@ mod SnakeERC1155ReceiverMock {
);

// ERC1155Receiver
impl ERC1155ReceiverImpl = ERC1155ReceiverComponent::ERC1155ReceiverImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155ReceiverImpl =
ERC1155ReceiverComponent::ERC1155ReceiverImpl<ContractState>;
impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl<ContractState>;

// SRC5
Expand Down Expand Up @@ -102,30 +89,6 @@ mod SnakeERC1155ReceiverMock {
fn constructor(ref self: ContractState) {
self.erc1155_receiver.initializer();
}

#[external(v0)]
fn on_erc1155_received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.on_erc1155_received(operator, from, token_id, value, data)
}

#[external(v0)]
fn on_erc1155_batch_received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.on_erc1155_batch_received(operator, from, token_ids, values, data)
}
}

#[starknet::contract]
Expand All @@ -140,6 +103,7 @@ mod CamelERC1155ReceiverMock {
);

// ERC1155Receiver
#[abi(embed_v0)]
impl ERC1155ReceiverCamelImpl =
ERC1155ReceiverComponent::ERC1155ReceiverCamelImpl<ContractState>;
impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl<ContractState>;
Expand Down Expand Up @@ -169,30 +133,6 @@ mod CamelERC1155ReceiverMock {
fn constructor(ref self: ContractState) {
self.erc1155_receiver.initializer();
}

#[external(v0)]
fn onERC1155Received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
tokenId: u256,
value: u256,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.onERC1155Received(operator, from, tokenId, value, data)
}

#[external(v0)]
fn onERC1155BatchReceived(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
tokenIds: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252 {
self.erc1155_receiver.onERC1155BatchReceived(operator, from, tokenIds, values, data)
}
}

#[starknet::contract]
Expand Down
3 changes: 1 addition & 2 deletions src/tests/presets/test_erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use openzeppelin::tests::token::test_erc1155::{
};
use openzeppelin::tests::token::test_erc1155::{get_ids_and_values, get_ids_and_split_values};
use openzeppelin::tests::utils::constants::{
EMPTY_DATA, ZERO, OWNER, RECIPIENT, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE,
TOKEN_VALUE_2
EMPTY_DATA, ZERO, OWNER, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2
};
use openzeppelin::tests::utils;
use openzeppelin::token::erc1155::interface::{ERC1155ABIDispatcher, ERC1155ABIDispatcherTrait};
Expand Down
22 changes: 11 additions & 11 deletions src/tests/token/test_dual1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use openzeppelin::tests::mocks::erc1155_mocks::{CamelERC1155PanicMock, SnakeERC1
use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock;
use openzeppelin::tests::token::test_erc1155::{setup_account, setup_receiver};
use openzeppelin::tests::utils::constants::{
DATA, OWNER, RECIPIENT, OPERATOR, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE
EMPTY_DATA, OWNER, RECIPIENT, OPERATOR, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE
};
use openzeppelin::tests::utils;
use openzeppelin::token::erc1155::dual1155::{DualCaseERC1155, DualCaseERC1155Trait};
Expand Down Expand Up @@ -149,22 +149,22 @@ fn test_dual_safe_transfer_from() {
let (dispatcher, target, owner) = setup_snake();
let receiver = setup_receiver();
testing::set_contract_address(owner);
dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
assert_eq!(target.balance_of(receiver, TOKEN_ID), TOKEN_VALUE);
}

#[test]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_safe_transfer_from() {
let dispatcher = setup_non_erc1155();
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
fn test_dual_safe_transfer_from_exists_and_panics() {
let (dispatcher, _) = setup_erc1155_panic();
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
Expand All @@ -175,7 +175,7 @@ fn test_dual_safe_batch_transfer_from() {
let receiver = setup_receiver();
testing::set_contract_address(owner);

dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, DATA(true));
dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, EMPTY_DATA());
assert_eq!(target.balance_of(receiver, TOKEN_ID), TOKEN_VALUE);
assert!(target.balance_of(receiver, TOKEN_ID_2).is_zero());
}
Expand All @@ -186,7 +186,7 @@ fn test_dual_no_safe_batch_transfer_from() {
let dispatcher = setup_non_erc1155();
let token_ids = array![TOKEN_ID, TOKEN_ID_2].span();
let values = array![TOKEN_VALUE, 0].span();
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, DATA(true));
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA());
}

#[test]
Expand All @@ -195,7 +195,7 @@ fn test_dual_safe_batch_transfer_from_exists_and_panics() {
let (dispatcher, _) = setup_erc1155_panic();
let token_ids = array![TOKEN_ID, TOKEN_ID_2].span();
let values = array![TOKEN_VALUE, 0].span();
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, DATA(true));
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA());
}

#[test]
Expand Down Expand Up @@ -308,15 +308,15 @@ fn test_dual_safeTransferFrom() {
let (dispatcher, target, owner) = setup_camel();
let receiver = setup_receiver();
testing::set_contract_address(owner);
dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
assert_eq!(target.balanceOf(receiver, TOKEN_ID), TOKEN_VALUE);
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
fn test_dual_safeTransferFrom_exists_and_panics() {
let (_, dispatcher) = setup_erc1155_panic();
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
Expand All @@ -327,7 +327,7 @@ fn test_dual_safeBatchTransferFrom() {
let receiver = setup_receiver();
testing::set_contract_address(owner);

dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, DATA(true));
dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, EMPTY_DATA());
assert_eq!(target.balanceOf(receiver, TOKEN_ID), TOKEN_VALUE);
assert!(target.balanceOf(receiver, TOKEN_ID_2).is_zero());
}
Expand All @@ -338,7 +338,7 @@ fn test_dual_safeBatchTransferFrom_exists_and_panics() {
let (_, dispatcher) = setup_erc1155_panic();
let token_ids = array![TOKEN_ID, TOKEN_ID_2].span();
let values = array![TOKEN_VALUE, 0].span();
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, DATA(true));
dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA());
}

#[test]
Expand Down
22 changes: 11 additions & 11 deletions src/tests/token/test_dual1155_receiver.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use openzeppelin::tests::mocks::erc1155_receiver_mocks::{
SnakeERC1155ReceiverPanicMock
};
use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock;
use openzeppelin::tests::utils::constants::{DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE};
use openzeppelin::tests::utils::constants::{EMPTY_DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE};
use openzeppelin::tests::utils;
use openzeppelin::token::erc1155::dual1155_receiver::{
DualCaseERC1155Receiver, DualCaseERC1155ReceiverTrait
Expand Down Expand Up @@ -65,22 +65,22 @@ fn setup_erc1155_receiver_panic() -> (DualCaseERC1155Receiver, DualCaseERC1155Re
fn test_dual_on_erc1155_received() {
let (dispatcher, _) = setup_snake();
let result = dispatcher
.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, DATA(true));
.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
assert_eq!(result, IERC1155_RECEIVER_ID,);
}

#[test]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_dual_no_on_erc1155_received() {
let dispatcher = setup_non_erc1155_receiver();
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
fn test_dual_on_erc1155_received_exists_and_panics() {
let (dispatcher, _) = setup_erc1155_receiver_panic();
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
Expand All @@ -89,7 +89,7 @@ fn test_dual_on_erc1155_batch_received() {
let (token_ids, values) = get_ids_and_values();

let result = dispatcher
.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, DATA(true));
.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA());
assert_eq!(result, IERC1155_RECEIVER_ID);
}

Expand All @@ -98,15 +98,15 @@ fn test_dual_on_erc1155_batch_received() {
fn test_dual_no_on_erc1155_batch_received() {
let dispatcher = setup_non_erc1155_receiver();
let (token_ids, values) = get_ids_and_values();
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, DATA(true));
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA());
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
fn test_dual_on_erc1155_batch_received_exists_and_panics() {
let (dispatcher, _) = setup_erc1155_receiver_panic();
let (token_ids, values) = get_ids_and_values();
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, DATA(true));
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA());
}

//
Expand All @@ -117,15 +117,15 @@ fn test_dual_on_erc1155_batch_received_exists_and_panics() {
fn test_dual_onERC1155Received() {
let (dispatcher, _) = setup_camel();
let result = dispatcher
.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, DATA(true));
.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
assert_eq!(result, IERC1155_RECEIVER_ID);
}

#[test]
#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))]
fn test_dual_onERC1155Received_exists_and_panics() {
let (_, dispatcher) = setup_erc1155_receiver_panic();
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, DATA(true));
dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA());
}

#[test]
Expand All @@ -134,7 +134,7 @@ fn test_dual_onERC1155BatchReceived() {
let (token_ids, values) = get_ids_and_values();

let result = dispatcher
.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, DATA(true));
.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA());
assert_eq!(result, IERC1155_RECEIVER_ID);
}

Expand All @@ -143,7 +143,7 @@ fn test_dual_onERC1155BatchReceived() {
fn test_dual_onERC1155BatchReceived_exists_and_panics() {
let (_, dispatcher) = setup_erc1155_receiver_panic();
let (token_ids, values) = get_ids_and_values();
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, DATA(true));
dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA());
}

//
Expand Down
3 changes: 1 addition & 2 deletions src/tests/token/test_erc1155.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use core::starknet::storage::StorageMemberAccessTrait;
use openzeppelin::introspection::src5::SRC5Component::SRC5Impl;
use openzeppelin::introspection::src5;
use openzeppelin::introspection;
use openzeppelin::tests::mocks::account_mocks::{SnakeAccountMock, CamelAccountMock};
use openzeppelin::tests::mocks::account_mocks::SnakeAccountMock;
use openzeppelin::tests::mocks::erc1155_mocks::DualCaseERC1155Mock;
use openzeppelin::tests::mocks::erc1155_receiver_mocks::{
CamelERC1155ReceiverMock, SnakeERC1155ReceiverMock
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn deploy_with_salt(
let (address, _) = starknet::deploy_syscall(
contract_class_hash.try_into().unwrap(), salt, calldata.span(), false
)
.unwrap();
.unwrap_syscall();
address
}

Expand Down
1 change: 0 additions & 1 deletion src/token/erc1155/erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ mod ERC1155Component {
}

mod Errors {
const INVALID_OPERATOR: felt252 = 'ERC1155: invalid operator';
const UNAUTHORIZED: felt252 = 'ERC1155: unauthorized operator';
const SELF_APPROVAL: felt252 = 'ERC1155: self approval';
const INVALID_RECEIVER: felt252 = 'ERC1155: invalid receiver';
Expand Down

0 comments on commit 71d6235

Please sign in to comment.