@@ -9,14 +9,14 @@ import (
9
9
"github.com/stretchr/testify/assert"
10
10
"github.com/stretchr/testify/require"
11
11
12
- "github.com/code-payments/code-server/pkg/currency"
13
- "github.com/code-payments/code-server/pkg/kin"
14
- "github.com/code-payments/code-server/pkg/pointer"
15
- "github.com/code-payments/code-server/pkg/testutil"
16
12
code_data "github.com/code-payments/code-server/pkg/code/data"
17
13
"github.com/code-payments/code-server/pkg/code/data/action"
18
14
"github.com/code-payments/code-server/pkg/code/data/fulfillment"
19
15
"github.com/code-payments/code-server/pkg/code/data/intent"
16
+ "github.com/code-payments/code-server/pkg/currency"
17
+ "github.com/code-payments/code-server/pkg/kin"
18
+ "github.com/code-payments/code-server/pkg/pointer"
19
+ "github.com/code-payments/code-server/pkg/testutil"
20
20
)
21
21
22
22
func TestOpenAccountsIntentHandler_RemainInStatePending (t * testing.T ) {
@@ -69,22 +69,35 @@ func TestSendPrivatePaymentIntentHandler_RemainInStatePending(t *testing.T) {
69
69
env := setupIntentHandlerTestEnv (t )
70
70
71
71
intentHandler := env .handlersByType [intent .SendPrivatePayment ]
72
- intentRecord := env .createIntent (t , intent .SendPrivatePayment )
73
72
74
- require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord .IntentId ))
75
- env .assertIntentState (t , intentRecord .IntentId , intent .StatePending )
73
+ intentRecord1 := env .createIntent (t , intent .SendPrivatePayment )
74
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord1 .IntentId ))
75
+ env .assertIntentState (t , intentRecord1 .IntentId , intent .StatePending )
76
76
77
- env .confirmFirstActionOfType (t , intentRecord .IntentId , action .PrivateTransfer )
78
- require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord .IntentId ))
79
- env .assertIntentState (t , intentRecord .IntentId , intent .StatePending )
77
+ env .confirmFirstActionOfType (t , intentRecord1 .IntentId , action .PrivateTransfer )
78
+ env .confirmAllActionsOfType (t , intentRecord1 .IntentId , action .NoPrivacyTransfer )
79
+ env .confirmFirstActionOfType (t , intentRecord1 .IntentId , action .NoPrivacyWithdraw )
80
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord1 .IntentId ))
81
+ env .assertIntentState (t , intentRecord1 .IntentId , intent .StatePending )
80
82
81
- env .confirmFirstActionOfType (t , intentRecord . IntentId , action . NoPrivacyTransfer )
82
- require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord .IntentId ))
83
- env .assertIntentState (t , intentRecord .IntentId , intent .StatePending )
83
+ intentRecord2 := env .createIntent (t , intent . SendPrivatePayment )
84
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord2 .IntentId ))
85
+ env .assertIntentState (t , intentRecord2 .IntentId , intent .StatePending )
84
86
85
- env .confirmFirstActionOfType (t , intentRecord .IntentId , action .NoPrivacyWithdraw )
86
- require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord .IntentId ))
87
- env .assertIntentState (t , intentRecord .IntentId , intent .StatePending )
87
+ env .confirmAllActionsOfType (t , intentRecord2 .IntentId , action .PrivateTransfer )
88
+ env .confirmFirstActionOfType (t , intentRecord2 .IntentId , action .NoPrivacyTransfer )
89
+ env .confirmFirstActionOfType (t , intentRecord2 .IntentId , action .NoPrivacyWithdraw )
90
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord2 .IntentId ))
91
+ env .assertIntentState (t , intentRecord2 .IntentId , intent .StatePending )
92
+
93
+ intentRecord3 := env .createIntent (t , intent .SendPrivatePayment )
94
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord2 .IntentId ))
95
+ env .assertIntentState (t , intentRecord3 .IntentId , intent .StatePending )
96
+
97
+ env .confirmAllActionsOfType (t , intentRecord3 .IntentId , action .PrivateTransfer )
98
+ env .confirmAllActionsOfType (t , intentRecord3 .IntentId , action .NoPrivacyTransfer )
99
+ require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord3 .IntentId ))
100
+ env .assertIntentState (t , intentRecord3 .IntentId , intent .StatePending )
88
101
}
89
102
90
103
func TestSendPrivatePaymentIntentHandler_TransitionToStateConfirmed (t * testing.T ) {
@@ -114,25 +127,33 @@ func TestSendPrivatePaymentIntentHandler_SchedulerPollingOptimizations(t *testin
114
127
env .assertIntentState (t , intentRecord1 .IntentId , intent .StatePending )
115
128
env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 2 , false )
116
129
env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 3 , false )
130
+ env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 4 , false )
131
+ env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 5 , false )
117
132
118
133
env .scheduleAllFulfillmentsOfType (t , intentRecord1 .IntentId , fulfillment .TransferWithCommitment )
119
134
require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord1 .IntentId ))
120
135
env .assertIntentState (t , intentRecord1 .IntentId , intent .StatePending )
121
136
env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 2 , true )
122
137
env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 3 , true )
138
+ env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 4 , true )
139
+ env .assertSchedulerPollingState (t , intentRecord1 .IntentId , 5 , true )
123
140
124
141
intentRecord2 := env .createIntent (t , intent .SendPrivatePayment )
125
142
126
143
require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord2 .IntentId ))
127
144
env .assertIntentState (t , intentRecord2 .IntentId , intent .StatePending )
128
145
env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 2 , false )
129
146
env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 3 , false )
147
+ env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 4 , false )
148
+ env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 5 , false )
130
149
131
150
env .confirmAllFulfillmentsOfType (t , intentRecord2 .IntentId , fulfillment .TransferWithCommitment )
132
151
require .NoError (t , intentHandler .OnActionUpdated (env .ctx , intentRecord2 .IntentId ))
133
152
env .assertIntentState (t , intentRecord2 .IntentId , intent .StatePending )
134
153
env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 2 , true )
135
154
env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 3 , true )
155
+ env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 4 , true )
156
+ env .assertSchedulerPollingState (t , intentRecord2 .IntentId , 5 , true )
136
157
}
137
158
138
159
func TestSendPrivatePaymentIntentHandler_TransitionToStateFailed (t * testing.T ) {
@@ -523,6 +544,32 @@ func (e *intentHandlerTestEnv) createIntent(t *testing.T, intentType intent.Type
523
544
IntentType : intentType ,
524
545
525
546
ActionId : 3 ,
547
+ ActionType : action .NoPrivacyTransfer ,
548
+
549
+ Source : tempOutgoing ,
550
+ Destination : pointer .String (testutil .NewRandomAccount (t ).PublicKey ().ToBase58 ()),
551
+ Quantity : & feeAmount ,
552
+
553
+ State : action .StatePending ,
554
+ },
555
+ & action.Record {
556
+ Intent : intentRecord .IntentId ,
557
+ IntentType : intentType ,
558
+
559
+ ActionId : 4 ,
560
+ ActionType : action .NoPrivacyTransfer ,
561
+
562
+ Source : tempOutgoing ,
563
+ Destination : pointer .String (testutil .NewRandomAccount (t ).PublicKey ().ToBase58 ()),
564
+ Quantity : & feeAmount ,
565
+
566
+ State : action .StatePending ,
567
+ },
568
+ & action.Record {
569
+ Intent : intentRecord .IntentId ,
570
+ IntentType : intentType ,
571
+
572
+ ActionId : 5 ,
526
573
ActionType : action .NoPrivacyWithdraw ,
527
574
528
575
Source : tempOutgoing ,
@@ -535,7 +582,7 @@ func (e *intentHandlerTestEnv) createIntent(t *testing.T, intentType intent.Type
535
582
Intent : intentRecord .IntentId ,
536
583
IntentType : intentType ,
537
584
538
- ActionId : 4 ,
585
+ ActionId : 6 ,
539
586
ActionType : action .OpenAccount ,
540
587
541
588
Source : newTempOutgoing ,
@@ -546,7 +593,7 @@ func (e *intentHandlerTestEnv) createIntent(t *testing.T, intentType intent.Type
546
593
Intent : intentRecord .IntentId ,
547
594
IntentType : intentType ,
548
595
549
- ActionId : 5 ,
596
+ ActionId : 7 ,
550
597
ActionType : action .CloseDormantAccount ,
551
598
552
599
Source : newTempOutgoing ,
0 commit comments