-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtest_coloniznft.cairo
132 lines (115 loc) · 5.15 KB
/
test_coloniznft.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use core::num::traits::zero::Zero;
use core::starknet::SyscallResultTrait;
use core::traits::TryInto;
use starknet::ContractAddress;
use snforge_std::{
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait,
DeclareResultTrait
};
use openzeppelin_token::erc721::interface::{ERC721ABIDispatcher, ERC721ABIDispatcherTrait};
use coloniz::interfaces::IColonizNFT::{IColonizNFTDispatcher, IColonizNFTDispatcherTrait};
use coloniz::base::constants::types::{
ProfileVariants, AccessoryVariants, FaceVariants, ClothVariants, BackgroundVariants,
BodyVariants, ToolVariants
};
const ADMIN: felt252 = 'ADMIN';
const USER_ONE: felt252 = 'BOB';
fn __setup__() -> ContractAddress {
let nft_contract = declare("ColonizNFT").unwrap().contract_class();
let mut calldata: Array<felt252> = array![ADMIN];
let (nft_contract_address, _) = nft_contract.deploy(@calldata).unwrap_syscall();
(nft_contract_address)
}
#[test]
fn test_metadata() {
let nft_contract_address = __setup__();
let dispatcher = ERC721ABIDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let nft_name = dispatcher.name();
let nft_symbol = dispatcher.symbol();
assert(nft_name == "Coloniz", 'invalid name');
assert(nft_symbol == "CLZ:PROFILE", 'invalid symbol');
stop_cheat_caller_address(nft_contract_address);
}
#[test]
fn test_last_minted_id_on_init_is_zero() {
let nft_contract_address = __setup__();
let dispatcher = IColonizNFTDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let last_minted_id = dispatcher.get_last_minted_id();
assert(last_minted_id.is_zero(), 'last minted id not zero');
stop_cheat_caller_address(nft_contract_address);
}
#[test]
fn test_mint_coloniz_nft() {
let nft_contract_address = __setup__();
let dispatcher = IColonizNFTDispatcher { contract_address: nft_contract_address };
let erc721_dispatcher = ERC721ABIDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let profile_variant = ProfileVariants {
body: BodyVariants::BODY1,
tool: ToolVariants::TOOL1,
background: BackgroundVariants::BACKGROUND1,
cloth: ClothVariants::CLOTH1,
face: FaceVariants::FACE1,
accessory: AccessoryVariants::ACCESSORY1
};
dispatcher.mint_coloniznft(USER_ONE.try_into().unwrap(), profile_variant);
let balance = erc721_dispatcher.balance_of(USER_ONE.try_into().unwrap());
assert(balance == 1, 'nft not minted');
stop_cheat_caller_address(nft_contract_address);
}
#[test]
#[should_panic(expected: ('coloniz: user already minted!',))]
fn test_mint_coloniz_nft_twice_for_the_same_user() {
let nft_contract_address = __setup__();
let dispatcher = IColonizNFTDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let profile_variant = ProfileVariants {
body: BodyVariants::BODY1,
tool: ToolVariants::TOOL1,
background: BackgroundVariants::BACKGROUND1,
cloth: ClothVariants::CLOTH1,
face: FaceVariants::FACE1,
accessory: AccessoryVariants::ACCESSORY1
};
dispatcher.mint_coloniznft(USER_ONE.try_into().unwrap(), profile_variant);
dispatcher.mint_coloniznft(USER_ONE.try_into().unwrap(), profile_variant);
stop_cheat_caller_address(nft_contract_address);
}
#[test]
fn test_get_last_minted_id_after_minting() {
let nft_contract_address = __setup__();
let dispatcher = IColonizNFTDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let profile_variant = ProfileVariants {
body: BodyVariants::BODY1,
tool: ToolVariants::TOOL1,
background: BackgroundVariants::BACKGROUND1,
cloth: ClothVariants::CLOTH1,
face: FaceVariants::FACE1,
accessory: AccessoryVariants::ACCESSORY1
};
dispatcher.mint_coloniznft(USER_ONE.try_into().unwrap(), profile_variant);
let last_minted_id = dispatcher.get_last_minted_id();
assert(last_minted_id == 1, 'invalid last minted id');
stop_cheat_caller_address(nft_contract_address);
}
#[test]
fn test_get_user_token_id_after_minting() {
let nft_contract_address = __setup__();
let dispatcher = IColonizNFTDispatcher { contract_address: nft_contract_address };
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let profile_variant = ProfileVariants {
body: BodyVariants::BODY1,
tool: ToolVariants::TOOL1,
background: BackgroundVariants::BACKGROUND1,
cloth: ClothVariants::CLOTH1,
face: FaceVariants::FACE1,
accessory: AccessoryVariants::ACCESSORY1
};
dispatcher.mint_coloniznft(USER_ONE.try_into().unwrap(), profile_variant);
let user_token_id = dispatcher.get_user_token_id(USER_ONE.try_into().unwrap());
assert(user_token_id == 1, 'invalid user token id');
stop_cheat_caller_address(nft_contract_address);
}