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 ERC1155 #896

Merged
merged 33 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e1ffb47
Add ERC1155 module, dual and interface
Dec 11, 2023
1378e54
Implement ERC1155 and update token_id variable names
Dec 12, 2023
5e27ef8
Add ERC1155 receiver mocks and test dual1155 receiver
Dec 12, 2023
8ec925e
apply linter
Dec 12, 2023
1e815d4
Update token_uri variable and remove IERC1155MetadataCamelOnly support
Dec 12, 2023
3fcd640
Add ERC1155 mocks and tests and add ERC1155 preset
Dec 15, 2023
5bf2d86
update CHANGELOG
Dec 15, 2023
7862594
adding PR number (#852)
Dec 15, 2023
1be1f2c
reset changlog
Dec 15, 2023
8836cdd
Merge branch 'main' into migrate-erc1155-contracts
Jan 17, 2024
24d695f
Update ERC1155Component Event and add batch_burn
Jan 18, 2024
fd41fdb
Add batch minting functions for ERC1155 tokens
Jan 18, 2024
5514177
Refactor code for better readability
Jan 24, 2024
a8e27e0
Merge branch 'migrate-erc1155-contracts' of github.com:cloudvenger/ca…
ericnordelo Feb 5, 2024
6ff198e
feat: finish first version with 2.5.3
ericnordelo Feb 5, 2024
d321db6
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 12, 2024
6172605
feat: apply review updates
ericnordelo Feb 12, 2024
c729003
feat: add tests
ericnordelo Feb 13, 2024
3b69f0e
feat: bump version and add entry to CHANGELOG
ericnordelo Feb 13, 2024
7877a83
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 13, 2024
57e3474
feat: add more tests
ericnordelo Feb 15, 2024
c4dc742
fix: remove print
ericnordelo Feb 15, 2024
76922ef
feat: add preset tests
ericnordelo Feb 16, 2024
6da745a
fix: format
ericnordelo Feb 16, 2024
027851a
feat: uncomment test
ericnordelo Feb 16, 2024
00a37e6
refactor: shortening test names
ericnordelo Feb 16, 2024
98dc3aa
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 20, 2024
814ccab
feat: move assertion
ericnordelo Feb 21, 2024
3e13f2c
Update src/token/erc1155/erc1155.cairo
ericnordelo Feb 22, 2024
43b8c67
fix: comments
ericnordelo Feb 22, 2024
991cc8d
Merge branch 'feat/erc1155-#572' of github.com:ericnordelo/cairo-cont…
ericnordelo Feb 22, 2024
71d6235
featL apply review updates
ericnordelo Feb 28, 2024
c77b3c1
feat: remove IAccount
ericnordelo Feb 29, 2024
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
163 changes: 52 additions & 111 deletions src/tests/mocks/erc1155_mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod DualCaseERC1155Mock {
use openzeppelin::token::erc1155::ERC1155Component;
use starknet::ContractAddress;

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

// ERC1155
#[abi(embed_v0)]
Expand All @@ -15,7 +15,6 @@ mod DualCaseERC1155Mock {
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
#[abi(embed_v0)]
impl ERC721Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;

impl ERC1155InternalImpl = ERC1155Component::InternalImpl<ContractState>;

// SRC5
Expand Down Expand Up @@ -48,11 +47,7 @@ mod DualCaseERC1155Mock {
uri: ByteArray
) {
self.erc1155.initializer(uri);

// mint
let token_ids = array![token_id].span();
let values = array![value].span();
self.erc1155.update(Zeroable::zero(), recipient, token_ids, values);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span());
}
}

Expand All @@ -62,16 +57,15 @@ mod SnakeERC1155Mock {
use openzeppelin::token::erc1155::ERC1155Component;
use starknet::ContractAddress;

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

// ERC1155
#[abi(embed_v0)]
impl ERC1155Impl = ERC1155Component::ERC1155Impl<ContractState>;
#[abi(embed_v0)]
impl ERC1155MetadataURIImpl =
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;

impl ERC1155InternalImpl = ERC1155Component::InternalImpl<ContractState>;

// SRC5
Expand Down Expand Up @@ -104,28 +98,25 @@ mod SnakeERC1155Mock {
uri: ByteArray
) {
self.erc1155.initializer(uri);

// mint
let token_ids = array![token_id].span();
let values = array![value].span();
self.erc1155.update(Zeroable::zero(), recipient, token_ids, values);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span());
}
}

#[starknet::contract]
mod CamelERC1155Mock {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc1155::ERC1155Component::{ERC1155Impl, ERC1155MetadataURIImpl};
use openzeppelin::token::erc1155::ERC1155Component;
use starknet::ContractAddress;

component!(path: SRC5Component, storage: src5, event: SRC5Event);
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
Expand Down Expand Up @@ -158,11 +149,7 @@ mod CamelERC1155Mock {
uri: ByteArray
) {
self.erc1155.initializer(uri);

// mint
let token_ids = array![token_id].span();
let values = array![value].span();
self.erc1155.update(Zeroable::zero(), recipient, token_ids, values);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span());
}
}

Expand All @@ -177,44 +164,24 @@ mod SnakeERC1155PanicMock {
#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn uri(self: @ContractState, token_id: u256) -> ByteArray {
panic!("Some error");
"3"
}

#[external(v0)]
fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
fn balance_of(self: @ContractState, account: ContractAddress, token_id: u256) -> u256 {
panic!("Some error");
u256 { low: 3, high: 3 }
}

#[external(v0)]
fn is_approved_for_all(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn set_approval_for_all(
ref self: ContractState, operator: ContractAddress, approved: bool
) {
panic!("Some error");
}

#[external(v0)]
fn transfer_from(
ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256
) {
fn balance_of_batch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
panic!("Some error");
array![u256 { low: 3, high: 3 }].span()
}

#[external(v0)]
Expand All @@ -223,19 +190,12 @@ mod SnakeERC1155PanicMock {
from: ContractAddress,
to: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
) {
panic!("Some error");
}

#[external(v0)]
fn balance_of_batch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
panic!("Some error");
array![u256 { low: 3, high: 3 }].span()
}

#[external(v0)]
fn safe_batch_transfer_from(
ref self: ContractState,
Expand All @@ -249,15 +209,25 @@ mod SnakeERC1155PanicMock {
}

#[external(v0)]
fn batch_transfer_from(
ref self: ContractState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_ids: Span<u256>,
values: Span<u256>
fn is_approved_for_all(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn set_approval_for_all(
ref self: ContractState, operator: ContractAddress, approved: bool
) {
panic!("Some error");
}

#[external(v0)]
fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
panic!("Some error");
false
}
}
}

Expand All @@ -272,54 +242,24 @@ mod CamelERC1155PanicMock {
#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn name(self: @ContractState) -> ByteArray {
panic!("Some error");
"3"
}

#[external(v0)]
fn symbol(self: @ContractState) -> ByteArray {
panic!("Some error");
"3"
}

#[external(v0)]
fn uri(self: @ContractState, tokenId: u256) -> ByteArray {
panic!("Some error");
"3"
}

#[external(v0)]
fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 {
fn balanceOf(self: @ContractState, account: ContractAddress, tokenId: u256) -> u256 {
panic!("Some error");
u256 { low: 3, high: 3 }
}

#[external(v0)]
fn isApprovedForAll(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) {
panic!("Some error");
}

#[external(v0)]
fn transferFrom(
ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u256
) {
fn balanceOfBatch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
panic!("Some error");
array![u256 { low: 3, high: 3 }].span()
}

#[external(v0)]
Expand All @@ -328,19 +268,12 @@ mod CamelERC1155PanicMock {
from: ContractAddress,
to: ContractAddress,
tokenId: u256,
value: u256,
data: Span<felt252>
) {
panic!("Some error");
}

#[external(v0)]
fn balanceOfBatch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
panic!("Some error");
array![u256 { low: 3, high: 3 }].span()
}

#[external(v0)]
fn safeBatchTransferFrom(
ref self: ContractState,
Expand All @@ -354,14 +287,22 @@ mod CamelERC1155PanicMock {
}

#[external(v0)]
fn batchTransferFrom(
ref self: ContractState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_ids: Span<u256>,
values: Span<u256>
) {
fn isApprovedForAll(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
panic!("Some error");
false
}

#[external(v0)]
fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) {
panic!("Some error");
}

#[external(v0)]
fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool {
panic!("Some error");
false
}
}
}
30 changes: 28 additions & 2 deletions src/tests/mocks/erc1155_receiver_mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,20 @@ mod SnakeERC1155ReceiverPanicMock {
value: u256,
data: Span<felt252>
) -> felt252 {
panic_with_felt252('Some error');
panic!("Some error");
3
}

#[external(v0)]
fn on_erc1155_batch_received(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
tokenIds: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252 {
panic!("Some error");
3
}
}
Expand All @@ -232,7 +245,20 @@ mod CamelERC1155ReceiverPanicMock {
value: u256,
data: Span<felt252>
) -> felt252 {
panic_with_felt252('Some error');
panic!("Some error");
3
}

#[external(v0)]
fn onERC1155BatchReceived(
self: @ContractState,
operator: ContractAddress,
from: ContractAddress,
tokenIds: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252 {
panic!("Some error");
3
}
}
1 change: 1 addition & 0 deletions src/tests/presets.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod test_account;
mod test_erc1155;
mod test_erc20;
mod test_erc721;
mod test_eth_account;
Loading
Loading