1
1
use TokenTransferComponent :: TransferValidationTrait ;
2
2
use openzeppelin_testing :: events :: EventSpyExt ;
3
3
use snforge_std :: cheatcodes :: events :: EventSpy ;
4
- use snforge_std :: spy_events;
4
+ use snforge_std :: { spy_events, start_cheat_caller_address} ;
5
5
use starknet :: class_hash :: class_hash_const;
6
6
use starknet_ibc_apps :: transfer :: ERC20Contract ;
7
7
use starknet_ibc_apps :: transfer :: TokenTransferComponent :: {
@@ -12,7 +12,8 @@ use starknet_ibc_core::router::{AppContract, AppContractTrait};
12
12
use starknet_ibc_testkit :: configs :: {TransferAppConfigTrait , TransferAppConfig };
13
13
use starknet_ibc_testkit :: dummies :: CLASS_HASH ;
14
14
use starknet_ibc_testkit :: dummies :: {
15
- AMOUNT , SUPPLY , OWNER , NAME , SYMBOL , COSMOS , STARKNET , HOSTED_DENOM , EMPTY_MEMO
15
+ AMOUNT , SUPPLY , OWNER , SN_USER , CS_USER , NAME , SYMBOL , COSMOS , STARKNET , HOSTED_DENOM ,
16
+ EMPTY_MEMO
16
17
};
17
18
use starknet_ibc_testkit :: event_spy :: TransferEventSpyExt ;
18
19
use starknet_ibc_testkit :: handles :: {ERC20Handle , AppHandle };
@@ -79,21 +80,23 @@ fn test_missing_ibc_token_address() {
79
80
fn test_escrow_ok () {
80
81
let (ics20 , mut erc20 , cfg , mut spy ) = setup ();
81
82
82
- // Owner approves the amount of allowance for the `TransferApp` contract.
83
- erc20 . approve (OWNER (), ics20 . address, cfg . amount);
83
+ start_cheat_caller_address (ics20 . address, SN_USER ());
84
84
85
- let msg_transfer = cfg . dummy_msg_transfer (cfg . native_denom. clone (), STARKNET (), COSMOS ());
85
+ // User approves the amount of allowance for the `TransferApp` contract.
86
+ erc20 . approve (SN_USER (), ics20 . address, cfg . amount);
87
+
88
+ let msg_transfer = cfg . dummy_msg_transfer (cfg . native_denom. clone (), CS_USER ());
86
89
87
90
call_contract (ics20 . address, selector! (" send_transfer_internal" ), @ msg_transfer );
88
91
89
92
// Assert the `SendEvent` emitted.
90
93
spy
91
94
. assert_send_event (
92
- ics20 . address, STARKNET (), COSMOS (), cfg . native_denom. clone (), cfg . amount
95
+ ics20 . address, SN_USER (), CS_USER (), cfg . native_denom. clone (), cfg . amount
93
96
);
94
97
95
98
// Check the balance of the sender.
96
- erc20 . assert_balance (OWNER (), SUPPLY - cfg . amount);
99
+ erc20 . assert_balance (SN_USER (), SUPPLY - cfg . amount);
97
100
98
101
// Check the balance of the transfer contract.
99
102
erc20 . assert_balance (ics20 . address, cfg . amount);
@@ -103,15 +106,19 @@ fn test_escrow_ok() {
103
106
fn test_unescrow_ok () {
104
107
let (ics20 , mut erc20 , cfg , mut spy ) = setup ();
105
108
106
- // Owner approves the amount of allowance for the `TransferApp` contract.
107
- erc20 . approve (OWNER (), ics20 . address, cfg . amount);
109
+ start_cheat_caller_address (ics20 . address, SN_USER ());
110
+
111
+ // User approves the amount of allowance for the `TransferApp` contract.
112
+ erc20 . approve (SN_USER (), ics20 . address, cfg . amount);
108
113
109
- let msg_transfer = cfg . dummy_msg_transfer (cfg . native_denom. clone (), STARKNET (), COSMOS ());
114
+ let msg_transfer = cfg . dummy_msg_transfer (cfg . native_denom. clone (), CS_USER ());
110
115
111
116
call_contract (ics20 . address, selector! (" send_transfer_internal" ), @ msg_transfer );
112
117
113
118
spy . drop_all_events ();
114
119
120
+ start_cheat_caller_address (ics20 . address, OWNER ());
121
+
115
122
let prefixed_denom = cfg . prefix_native_denom ();
116
123
117
124
let recv_packet = cfg . dummy_packet (prefixed_denom . clone (), COSMOS (), STARKNET ());
@@ -120,12 +127,12 @@ fn test_unescrow_ok() {
120
127
ics20 . on_recv_packet (recv_packet );
121
128
122
129
// Assert the `RecvEvent` emitted.
123
- spy . assert_recv_event (ics20 . address, COSMOS (), STARKNET (), prefixed_denom , cfg . amount, true );
130
+ spy . assert_recv_event (ics20 . address, CS_USER (), SN_USER (), prefixed_denom , cfg . amount, true );
124
131
125
132
erc20 . assert_balance (ics20 . address, 0 );
126
133
127
134
// Check the balance of the recipient.
128
- erc20 . assert_balance (OWNER (), SUPPLY );
135
+ erc20 . assert_balance (SN_USER (), SUPPLY );
129
136
}
130
137
131
138
#[test]
@@ -147,7 +154,7 @@ fn test_mint_ok() {
147
154
// Assert the `RecvEvent` emitted.
148
155
spy
149
156
. assert_recv_event (
150
- ics20 . address, COSMOS (), STARKNET (), prefixed_denom . clone (), cfg . amount, true
157
+ ics20 . address, CS_USER (), SN_USER (), prefixed_denom . clone (), cfg . amount, true
151
158
);
152
159
153
160
spy . drop_all_events ();
@@ -158,13 +165,13 @@ fn test_mint_ok() {
158
165
// Assert the `RecvEvent` emitted.
159
166
spy
160
167
. assert_recv_event (
161
- ics20 . address, COSMOS (), STARKNET (), prefixed_denom . clone (), cfg . amount, true
168
+ ics20 . address, CS_USER (), SN_USER (), prefixed_denom . clone (), cfg . amount, true
162
169
);
163
170
164
171
let erc20 : ERC20Contract = token_address . into ();
165
172
166
173
// Check the balance of the receiver.
167
- erc20 . assert_balance (OWNER (), cfg . amount * 2 );
174
+ erc20 . assert_balance (SN_USER (), cfg . amount * 2 );
168
175
169
176
// Check the total supply of the ERC20 contract.
170
177
erc20 . assert_total_supply (cfg . amount * 2 );
@@ -183,30 +190,35 @@ fn test_burn_ok() {
183
190
184
191
let token_address = ics20 . ibc_token_address (prefixed_denom . key ());
185
192
186
- let erc20 : ERC20Contract = token_address . into ();
193
+ let mut erc20 : ERC20Contract = token_address . into ();
187
194
188
195
spy . drop_all_events ();
189
196
190
- let msg_transfer = cfg . dummy_msg_transfer (prefixed_denom . clone (), STARKNET (), COSMOS ());
197
+ start_cheat_caller_address (ics20 . address, SN_USER ());
198
+
199
+ // User approves the amount of allowance for the `TransferApp` contract.
200
+ erc20 . approve (SN_USER (), ics20 . address, cfg . amount);
201
+
202
+ let msg_transfer = cfg . dummy_msg_transfer (prefixed_denom . clone (), CS_USER ());
191
203
192
204
call_contract (ics20 . address, selector! (" send_transfer_internal" ), @ msg_transfer );
193
205
194
206
// Assert the `SendEvent` emitted.
195
- spy . assert_send_event (ics20 . address, STARKNET (), COSMOS (), prefixed_denom , cfg . amount);
207
+ spy . assert_send_event (ics20 . address, SN_USER (), CS_USER (), prefixed_denom , cfg . amount);
196
208
197
209
// Check the balance of the sender.
198
- erc20 . assert_balance (OWNER (), 0 );
210
+ erc20 . assert_balance (SN_USER (), 0 );
199
211
200
212
// Check the balance of the `TransferApp` contract.
201
213
erc20 . assert_balance (ics20 . address, 0 );
202
214
203
- // Chekck the total supply of the ERC20 contract.
215
+ // Check the total supply of the ERC20 contract.
204
216
erc20 . assert_total_supply (0 );
205
217
}
206
218
207
219
#[test]
208
220
#[should_panic(expected: ' ICS20: missing token address' )]
209
221
fn test_burn_non_existence_ibc_token () {
210
222
let state = setup_component ();
211
- state . burn_validate (OWNER (), HOSTED_DENOM (), AMOUNT , EMPTY_MEMO ());
223
+ state . burn_validate (SN_USER (), HOSTED_DENOM (), AMOUNT , EMPTY_MEMO ());
212
224
}
0 commit comments