@@ -30,31 +30,70 @@ fn test_transfers() {
3030
3131 mollusk. process_and_validate_instruction_chain (
3232 & [
33- system_instruction:: transfer ( & alice, & bob, alice_to_bob) ,
34- system_instruction:: transfer ( & bob, & carol, bob_to_carol) ,
35- system_instruction:: transfer ( & bob, & dave, bob_to_dave) ,
33+ (
34+ // 0: Alice to Bob
35+ & system_instruction:: transfer ( & alice, & bob, alice_to_bob) ,
36+ & [
37+ Check :: success ( ) ,
38+ Check :: account ( & alice)
39+ . lamports ( starting_lamports - alice_to_bob) // Alice pays
40+ . build ( ) ,
41+ Check :: account ( & bob)
42+ . lamports ( starting_lamports + alice_to_bob) // Bob receives
43+ . build ( ) ,
44+ Check :: account ( & carol)
45+ . lamports ( starting_lamports) // Unchanged
46+ . build ( ) ,
47+ Check :: account ( & dave)
48+ . lamports ( starting_lamports) // Unchanged
49+ . build ( ) ,
50+ ] ,
51+ ) ,
52+ (
53+ // 1: Bob to Carol
54+ & system_instruction:: transfer ( & bob, & carol, bob_to_carol) ,
55+ & [
56+ Check :: success ( ) ,
57+ Check :: account ( & alice)
58+ . lamports ( starting_lamports - alice_to_bob) // Unchanged
59+ . build ( ) ,
60+ Check :: account ( & bob)
61+ . lamports ( starting_lamports + alice_to_bob - bob_to_carol) // Bob pays
62+ . build ( ) ,
63+ Check :: account ( & carol)
64+ . lamports ( starting_lamports + bob_to_carol) // Carol receives
65+ . build ( ) ,
66+ Check :: account ( & dave)
67+ . lamports ( starting_lamports) // Unchanged
68+ . build ( ) ,
69+ ] ,
70+ ) ,
71+ (
72+ // 2: Bob to Dave
73+ & system_instruction:: transfer ( & bob, & dave, bob_to_dave) ,
74+ & [
75+ Check :: success ( ) ,
76+ Check :: account ( & alice)
77+ . lamports ( starting_lamports - alice_to_bob) // Unchanged
78+ . build ( ) ,
79+ Check :: account ( & bob)
80+ . lamports ( starting_lamports + alice_to_bob - bob_to_carol - bob_to_dave) // Bob pays
81+ . build ( ) ,
82+ Check :: account ( & carol)
83+ . lamports ( starting_lamports + bob_to_carol) // Unchanged
84+ . build ( ) ,
85+ Check :: account ( & dave)
86+ . lamports ( starting_lamports + bob_to_dave) // Dave receives
87+ . build ( ) ,
88+ ] ,
89+ ) ,
3690 ] ,
3791 & [
3892 ( alice, system_account_with_lamports ( starting_lamports) ) ,
3993 ( bob, system_account_with_lamports ( starting_lamports) ) ,
4094 ( carol, system_account_with_lamports ( starting_lamports) ) ,
4195 ( dave, system_account_with_lamports ( starting_lamports) ) ,
4296 ] ,
43- & [
44- Check :: success ( ) ,
45- Check :: account ( & alice)
46- . lamports ( starting_lamports - alice_to_bob)
47- . build ( ) ,
48- Check :: account ( & bob)
49- . lamports ( starting_lamports + alice_to_bob - bob_to_carol - bob_to_dave)
50- . build ( ) ,
51- Check :: account ( & carol)
52- . lamports ( starting_lamports + bob_to_carol)
53- . build ( ) ,
54- Check :: account ( & dave)
55- . lamports ( starting_lamports + bob_to_dave)
56- . build ( ) ,
57- ] ,
5897 ) ;
5998}
6099
@@ -117,15 +156,27 @@ fn test_mixed() {
117156
118157 mollusk. process_and_validate_instruction_chain (
119158 & [
120- ix_transfer_to_1,
121- ix_transfer_to_2,
122- ix_allocate_1,
123- ix_allocate_2,
124- ix_assign_1,
125- ix_assign_2,
126- ix_write_data_to_1,
127- ix_write_data_to_2,
128- ix_close_1,
159+ ( & ix_transfer_to_1, & [ ] ) ,
160+ ( & ix_transfer_to_2, & [ ] ) ,
161+ ( & ix_allocate_1, & [ ] ) ,
162+ ( & ix_allocate_2, & [ ] ) ,
163+ ( & ix_assign_1, & [ ] ) ,
164+ ( & ix_assign_2, & [ ] ) ,
165+ ( & ix_write_data_to_1, & [ ] ) ,
166+ ( & ix_write_data_to_2, & [ ] ) ,
167+ (
168+ & ix_close_1,
169+ // Just check the final result.
170+ & [
171+ Check :: success ( ) ,
172+ Check :: account ( & target1) . closed ( ) . build ( ) ,
173+ Check :: account ( & target2)
174+ . data ( data)
175+ . lamports ( lamports)
176+ . owner ( & program_id)
177+ . build ( ) ,
178+ ] ,
179+ ) ,
129180 ] ,
130181 & [
131182 ( payer, system_account_with_lamports ( lamports * 4 ) ) ,
@@ -134,14 +185,5 @@ fn test_mixed() {
134185 ( incinerator:: id ( ) , Account :: default ( ) ) ,
135186 keyed_account_for_system_program ( ) ,
136187 ] ,
137- & [
138- Check :: success ( ) ,
139- Check :: account ( & target1) . closed ( ) . build ( ) ,
140- Check :: account ( & target2)
141- . data ( data)
142- . lamports ( lamports)
143- . owner ( & program_id)
144- . build ( ) ,
145- ] ,
146188 ) ;
147189}
0 commit comments