Skip to content

Commit

Permalink
Merge pull request #61 from Realkayzee/main
Browse files Browse the repository at this point in the history
End To End Test For Creating And Accepting Offer
  • Loading branch information
0xandee authored Mar 8, 2024
2 parents fc1e94a + eb8cac3 commit 020f313
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 49 deletions.
4 changes: 1 addition & 3 deletions flex_marketplace/src/marketplace/marketplace.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,7 @@ mod MarketPlace {
}

currency_erc20
.transferFrom(
from, recipient, (amount - protocol_fee_amount - royalty_amount).into()
);
.transferFrom(from, to, (amount - protocol_fee_amount - royalty_amount).into());
}

fn transfer_non_fungible_token(
Expand Down
89 changes: 50 additions & 39 deletions flex_marketplace/src/mocks/erc721.cairo
Original file line number Diff line number Diff line change
@@ -1,71 +1,82 @@
#[starknet::interface]
trait IER721CamelOnly<TState> {
fn transferFrom(
ref self: TState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_id: u256
);
}
use starknet::ContractAddress;

#[starknet::interface]
trait IERC2981<TContractState> {
fn royaltyInfo(
ref self: TContractState, tokenId: u256, salePrice: u128
) -> (starknet::ContractAddress, u128);
trait IERC721<TContractState> {
fn mint(ref self: TContractState, recipient: ContractAddress);
fn approve(ref self: TContractState, to: ContractAddress, token_id: u256);
fn balance_of(self: @TContractState, account: ContractAddress) -> u256;
}


#[starknet::contract]
mod ERC721 {
use starknet::{ContractAddress, get_caller_address};
use openzeppelin::token::erc721::interface::IERC721;
use openzeppelin::token::erc721::erc721::ERC721Component::InternalTrait;
use starknet::ContractAddress;
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::ERC721Component;

component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: ERC721Component, storage: erc721, event: ERC721Event);

#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;
#[abi(embed_v0)]
impl SRC5CamelImpl = SRC5Component::SRC5CamelImpl<ContractState>;
impl SRC5InternalImpl = SRC5Component::InternalImpl<ContractState>;
const NAME: felt252 = 'FLEX TOKEN';
const SYMBOL: felt252 = 'FLX';
const TOKEN_URI: felt252 = '';

#[storage]
struct Storage {
id: u256,
#[substorage(v0)]
erc721: ERC721Component::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage,
src5: SRC5Component::Storage
}

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

#[abi(embed_v0)]
impl ERC721CamelOnlyImpl = ERC721Component::ERC721CamelOnlyImpl<ContractState>;
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;

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

#[constructor]
fn constructor(ref self: ContractState,) {
self.src5.register_interface(0x80ac58cd);
fn constructor(ref self: ContractState) {
self.erc721.initializer(NAME, SYMBOL);
}

#[external(v0)]
impl IERC721CamelOnlyImpl of super::IER721CamelOnly<ContractState> {
fn transferFrom(
ref self: ContractState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_id: u256
) {}
}
#[abi(embed_v0)]
impl ERC721 of super::IERC721<ContractState> {
fn mint(ref self: ContractState, recipient: ContractAddress) {
self._mint_with_uri(recipient);
}

fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) {
self.erc721._approve(to, token_id);
}

fn RECIPIENT() -> starknet::ContractAddress {
starknet::contract_address_const::<'RECIPIENT'>()
fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
self.erc721.balance_of(account)
}
}

#[external(v0)]
impl IERC2981Impl of super::IERC2981<ContractState> {
fn royaltyInfo(
ref self: ContractState, tokenId: u256, salePrice: u128
) -> (starknet::ContractAddress, u128) {
(RECIPIENT(), 5000)
#[generate_trait]
impl Private of PrivateTrait {
fn _mint_with_uri(ref self: ContractState, recipient: ContractAddress) {
let token_id = self.id.read() + 1;
self.id.write(token_id);

self.erc721._mint(recipient, token_id);
self.erc721._set_token_uri(token_id, TOKEN_URI);
}
}
}
8 changes: 5 additions & 3 deletions flex_marketplace/src/mocks/strategy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod Strategy {
use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};
use starknet::ContractAddress;

const E18: u128 = 1_000_000_000_000_000_000;

#[storage]
struct Storage {}

Expand All @@ -39,12 +41,12 @@ mod Strategy {
maker_bid: super::MakerOrder,
extra_params: Array<felt252>
) -> (bool, u256, u128) {
(true, 1, 1)
(true, 1, E18)
}
fn canExecuteTakerBid(
self: @ContractState, taker_bid: super::TakerOrder, maker_ask: super::MakerOrder
) -> (bool, u256, u128) {
(true, 1, 1)
(true, 1, E18)
}
}

Expand All @@ -56,7 +58,7 @@ mod Strategy {
fn canExecuteAuctionSale(
self: @ContractState, maker_ask: MakerOrder, maker_bid: MakerOrder
) -> (bool, u256, u128) {
(true, 1, 1)
(true, 1, E18)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions flex_marketplace/tests/integration.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod create_and_accept_offer;
mod utils;
Loading

0 comments on commit 020f313

Please sign in to comment.