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

Added Test for TM ERC721 #46

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Test
on: [push, pull_request]

env:
SCARB_VERSION: 2.4.0
SNFORGE_VERSION: 0.13.0
SCARB_VERSION: 2.4.3
SNFORGE_VERSION: 0.13.1

jobs:
check:
Expand Down
7 changes: 6 additions & 1 deletion flex_marketplace/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use core::fmt::{Display, Error, Formatter, Debug};
use starknet::contract_address_to_felt252;

impl DisplayContractAddress of Display<starknet::ContractAddress> {
fn fmt(self: @starknet::ContractAddress, ref f: Formatter) -> Result<(), Error> {
write!(f, "{}", *self)
write!(f, "{}", contract_address_to_felt252(*self))
}
}

Expand Down Expand Up @@ -49,3 +50,7 @@ mod marketplace {
mod transfer_manager_ERC1155;
mod transfer_selector_NFT;
}

mod mocks {
mod erc721;
}
27 changes: 27 additions & 0 deletions flex_marketplace/src/mocks/erc721.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#[starknet::interface]
trait IER721CamelOnly<TState> {
fn transferFrom(
ref self: TState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_id: u256
);
}

#[starknet::contract]
mod ERC721 {
use starknet::{ContractAddress, get_caller_address};

#[storage]
struct Storage {}

#[external(v0)]
impl IERC721CamelOnlyImpl of super::IER721CamelOnly<ContractState> {
fn transferFrom(
ref self: ContractState,
from: starknet::ContractAddress,
to: starknet::ContractAddress,
token_id: u256
) {}
}
}
49 changes: 36 additions & 13 deletions flex_marketplace/tests/transfer_manager_erc721_test.cairo
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
use tests::utils::{setup, initialize_test};
use snforge_std::{start_prank, stop_prank, PrintTrait, CheatTarget};
use tests::utils::{
setup, initialize_test, deploy_mock_nft, ACCOUNT1, ACCOUNT2, OWNER, ZERO_ADDRESS
};
use flex::marketplace::transfer_manager_ERC721::{
ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait
};

const TOKEN_ID: u256 = 1;

#[test]
fn test_transfer_non_fungible_token_success() {
let dsp = setup();
initialize_test(dsp);
// TODO
let collection = deploy_mock_nft();

start_prank(
CheatTarget::One(dsp.transfer_manager_erc721.contract_address),
dsp.marketplace.contract_address
);
dsp
.transfer_manager_erc721
.transfer_non_fungible_token(collection, ACCOUNT1(), ACCOUNT2(), TOKEN_ID, 1);
}

#[test]
#[should_panic()]
#[should_panic(expected: ("TransferManagerNFT: caller 0 is not MarketPlace",))]
fn test_transfer_non_fungible_token_fails_caller_not_marketplace() {
let dsp = setup();
initialize_test(dsp);
assert(false, '');
// TODO
let collection = deploy_mock_nft();

start_prank(CheatTarget::One(dsp.transfer_manager_erc721.contract_address), ZERO_ADDRESS());
dsp
.transfer_manager_erc721
.transfer_non_fungible_token(collection, ACCOUNT1(), ACCOUNT2(), TOKEN_ID, 1);
}

#[test]
fn test_update_marketplace_success() {
let dsp = setup();
initialize_test(dsp);
// TODO
}
let collection = deploy_mock_nft();
let new_marketplace = starknet::contract_address_const::<'new_marketplace'>();

start_prank(
CheatTarget::One(dsp.transfer_manager_erc721.contract_address),
dsp.marketplace.contract_address
);
dsp.transfer_manager_erc721.update_marketplace(new_marketplace);

// TESTS VIEWSqs
#[test]
fn test_get_marketplace() {
let dsp = setup();
initialize_test(dsp);
// TODO
let actual_marketplace = dsp.transfer_manager_erc721.get_marketplace();

assert(actual_marketplace == new_marketplace, 'update marketplace failed');
}

9 changes: 9 additions & 0 deletions flex_marketplace/tests/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use flex::marketplace::{
TransferSelectorNFT, ITransferSelectorNFTDispatcher, ITransferSelectorNFTDispatcherTrait
},
};
use flex::mocks::erc721::ERC721;

const HASH_DOMAIN: felt252 = 'HASH_DOMAIN';
const FEE_LIMIT: u128 = 1_000;
Expand Down Expand Up @@ -71,6 +72,9 @@ fn ACCOUNT4() -> ContractAddress {
fn PROXY_ADMIN() -> ContractAddress {
contract_address_const::<'PROXY_ADMIN'>()
}
fn ZERO_ADDRESS() -> ContractAddress {
contract_address_const::<0>()
}

fn setup() -> Dispatchers {
let contract = declare('MarketPlace');
Expand Down Expand Up @@ -155,6 +159,11 @@ fn initialize_test(dsp: Dispatchers) {
dsp.transfer_manager_erc1155.initializer(dsp.marketplace.contract_address, OWNER());
}

fn deploy_mock_nft() -> ContractAddress {
let contract = declare('ERC721');
contract.deploy(@array![]).expect('failed ERC721')
}

#[test]
fn deploy_test() {
let dsp = setup();
Expand Down
Loading