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

chore: refactor tests and configure writers #15

Merged
merged 1 commit into from
Aug 28, 2023
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
1 change: 1 addition & 0 deletions src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mod test_box_nft;
mod test_briq_token;
mod test_set_nft;
mod test_briq_factory;
mod test_world_config;
19 changes: 18 additions & 1 deletion src/tests/test_attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::Serde;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::deploy_default_world;
use briq_protocol::tests::test_utils::{DEFAULT_OWNER, deploy_default_world, impersonate};

use dojo_erc::erc721::interface::IERC721DispatcherTrait;

Expand Down Expand Up @@ -72,3 +72,20 @@ fn test_create_collection_collision() {
world.execute('create_collection', (calldata));
}
}


#[test]
#[available_gas(30000000)]
#[should_panic]
fn test_create_collection_with_non_world_admin() {
let DefaultWorld{world, .. } = deploy_default_world();

impersonate(DEFAULT_OWNER());

let mut calldata: Array<felt252> = ArrayTrait::new();
CreateCollectionData {
collection_id: 1, params: 2, admin_or_system: starknet::contract_address_const::<0xfafa>()
}
.serialize(ref calldata);
world.execute('create_collection', (calldata));
}
24 changes: 11 additions & 13 deletions src/tests/test_box_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use result::ResultTrait;
use array::ArrayTrait;
use serde::Serde;

use starknet::testing::{set_caller_address, set_contract_address};
use starknet::ContractAddress;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{WORLD_ADMIN, DefaultWorld, deploy_default_world, mint_briqs};
use briq_protocol::tests::test_utils::{
WORLD_ADMIN, DEFAULT_OWNER, DefaultWorld, deploy_default_world, mint_briqs, impersonate
};

use dojo_erc::erc721::interface::IERC721DispatcherTrait;
use dojo_erc::erc1155::interface::IERC1155DispatcherTrait;
Expand All @@ -22,9 +23,6 @@ use debug::PrintTrait;

use briq_protocol::world_config::get_world_config;

fn default_owner() -> ContractAddress {
starknet::contract_address_const::<0xcafe>()
}

#[test]
#[available_gas(300000000)]
Expand All @@ -38,31 +36,31 @@ fn test_mint_and_unbox() {
WORLD_ADMIN().into(),
get_world_config(world).box.into(),
0,
default_owner().into(),
DEFAULT_OWNER().into(),
1,
0x1,
1,
1
])
);

set_contract_address(default_owner());
impersonate(DEFAULT_OWNER());

assert(briq_token.balance_of(default_owner(), 1) == 0, 'bad balance');
assert(briq_token.balance_of(DEFAULT_OWNER(), 1) == 0, 'bad balance');
assert(
booklet
.balance_of(default_owner(), 0x1000000000000000000000000000000000000000000000001) == 0,
.balance_of(DEFAULT_OWNER(), 0x1000000000000000000000000000000000000000000000001) == 0,
'bad balance 1'
);
assert(box_nft.balance_of(default_owner(), 1) == 1, 'bad balance 2');
assert(box_nft.balance_of(DEFAULT_OWNER(), 1) == 1, 'bad balance 2');

world.execute('box_unboxing', (array![0x1,]));

assert(briq_token.balance_of(default_owner(), 1) == 434, 'bad balance 2.5');
assert(briq_token.balance_of(DEFAULT_OWNER(), 1) == 434, 'bad balance 2.5');
assert(
booklet
.balance_of(default_owner(), 0x1000000000000000000000000000000000000000000000001) == 1,
.balance_of(DEFAULT_OWNER(), 0x1000000000000000000000000000000000000000000000001) == 1,
'bad balance 3'
);
assert(box_nft.balance_of(default_owner(), 1) == 0, 'bad balance 4');
assert(box_nft.balance_of(DEFAULT_OWNER(), 1) == 0, 'bad balance 4');
}
12 changes: 3 additions & 9 deletions src/tests/test_briq_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use starknet::info::get_block_timestamp;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{WORLD_ADMIN, DefaultWorld, deploy_default_world, mint_briqs};
use briq_protocol::tests::test_utils::{WORLD_ADMIN,ETH_ADDRESS, DefaultWorld, deploy_default_world, mint_briqs};

use dojo_erc::erc_common::utils::system_calldata;

Expand All @@ -26,19 +26,13 @@ use briq_protocol::felt_math::{FeltOrd, FeltDiv};

use debug::PrintTrait;

fn default_owner() -> ContractAddress {
starknet::contract_address_const::<0xcafe>()
}

fn eth_address() -> ContractAddress {
starknet::contract_address_const::<0xeeee>()
}

fn init_briq_factory(world: IWorldDispatcher, t: felt252, surge_t: felt252,) -> BriqFactoryStore {
world
.execute(
'BriqFactoryInitialize',
system_calldata(BriqFactoryInitializeParams { t, surge_t, buy_token: eth_address() })
system_calldata(BriqFactoryInitializeParams { t, surge_t, buy_token: ETH_ADDRESS() })
);
BriqFactoryTrait::get_briq_factory(world)
}
Expand All @@ -49,7 +43,7 @@ fn test_briq_factory_init() {
let DefaultWorld{world, .. } = deploy_default_world();
let briq_factory = init_briq_factory(world, DECIMALS(), DECIMALS());

assert(briq_factory.buy_token == eth_address(), 'invalid buy_token');
assert(briq_factory.buy_token == ETH_ADDRESS(), 'invalid buy_token');
assert(briq_factory.surge_t == DECIMALS(), 'invalid surge_t');
assert(briq_factory.last_stored_t == DECIMALS(), 'invalid last_stored_t');
}
Expand Down
Loading
Loading