@@ -28,22 +28,26 @@ func TestGuard_SendPublicPayment_PerTransactionValue(t *testing.T) {
28
28
limit .SendLimits [currency_lib .USD ].PerTransaction - 1 ,
29
29
limit .SendLimits [currency_lib .USD ].PerTransaction ,
30
30
} {
31
- intentRecord := makeSendPublicPaymentIntent (t , owner , acceptableValue , time .Now ())
31
+ for _ , isWithdraw := range []bool {true , false } {
32
+ intentRecord := makeSendPublicPaymentIntent (t , owner , acceptableValue , isWithdraw , time .Now ())
32
33
33
- allow , err := env .guard .AllowMoneyMovement (env .ctx , intentRecord )
34
- require .NoError (t , err )
35
- assert .True (t , allow )
34
+ allow , err := env .guard .AllowMoneyMovement (env .ctx , intentRecord )
35
+ require .NoError (t , err )
36
+ assert .True (t , allow )
37
+ }
36
38
}
37
39
38
40
for _ , unacceptableValue := range []float64 {
39
41
limit .SendLimits [currency_lib .USD ].PerTransaction + 1 ,
40
42
limit .SendLimits [currency_lib .USD ].PerTransaction * 10 ,
41
43
} {
42
- intentRecord := makeSendPublicPaymentIntent (t , owner , unacceptableValue , time .Now ())
44
+ for _ , isWithdraw := range []bool {true , false } {
45
+ intentRecord := makeSendPublicPaymentIntent (t , owner , unacceptableValue , isWithdraw , time .Now ())
43
46
44
- allow , err := env .guard .AllowMoneyMovement (env .ctx , intentRecord )
45
- require .NoError (t , err )
46
- assert .False (t , allow )
47
+ allow , err := env .guard .AllowMoneyMovement (env .ctx , intentRecord )
48
+ require .NoError (t , err )
49
+ assert .Equal (t , isWithdraw , allow )
50
+ }
47
51
}
48
52
}
49
53
@@ -87,20 +91,29 @@ func TestGuard_SendPublicPayment_DailyUsdLimit(t *testing.T) {
87
91
},
88
92
} {
89
93
owner := testutil .NewRandomAccount (t )
90
- intentRecord := makeSendPublicPaymentIntent (t , owner , 1 , time .Now ())
94
+ giveIntentRecord := makeSendPublicPaymentIntent (t , owner , 1 , false , time .Now ())
95
+ withdrawIntentRecord := makeSendPublicPaymentIntent (t , owner , 1 , true , time .Now ())
91
96
92
- // Sanity check the intent for $1 USD is allowed
93
- allow , err := env .guard .AllowMoneyMovement (env .ctx , intentRecord )
97
+ // Sanity check the intents for $1 USD is allowed
98
+ allow , err := env .guard .AllowMoneyMovement (env .ctx , giveIntentRecord )
99
+ require .NoError (t , err )
100
+ assert .True (t , allow )
101
+ allow , err = env .guard .AllowMoneyMovement (env .ctx , withdrawIntentRecord )
94
102
require .NoError (t , err )
95
103
assert .True (t , allow )
96
104
97
105
// Save an intent to bring the user up to the desired consumed daily USD value
98
- require .NoError (t , env .data .SaveIntent (env .ctx , makeSendPublicPaymentIntent (t , owner , tc .consumedUsdValue , tc .at )))
106
+ require .NoError (t , env .data .SaveIntent (env .ctx , makeSendPublicPaymentIntent (t , owner , tc .consumedUsdValue , false , tc .at )))
99
107
100
- // Check whether we allow the $1 USD intent
101
- allow , err = env .guard .AllowMoneyMovement (env .ctx , intentRecord )
108
+ // Check whether we allow the $1 USD give intent
109
+ allow , err = env .guard .AllowMoneyMovement (env .ctx , giveIntentRecord )
102
110
require .NoError (t , err )
103
111
assert .Equal (t , tc .expected , allow )
112
+
113
+ // Check whether we allow the $1 USD withdraw intent
114
+ allow , err = env .guard .AllowMoneyMovement (env .ctx , withdrawIntentRecord )
115
+ require .NoError (t , err )
116
+ assert .True (t , allow )
104
117
}
105
118
}
106
119
@@ -145,7 +158,7 @@ func setupAmlTest(t *testing.T) (env amlTestEnv) {
145
158
return env
146
159
}
147
160
148
- func makeSendPublicPaymentIntent (t * testing.T , owner * common.Account , usdMarketValue float64 , at time.Time ) * intent.Record {
161
+ func makeSendPublicPaymentIntent (t * testing.T , owner * common.Account , usdMarketValue float64 , isWithdraw bool , at time.Time ) * intent.Record {
149
162
return & intent.Record {
150
163
IntentId : testutil .NewRandomAccount (t ).PublicKey ().ToBase58 (),
151
164
IntentType : intent .SendPublicPayment ,
@@ -159,6 +172,8 @@ func makeSendPublicPaymentIntent(t *testing.T, owner *common.Account, usdMarketV
159
172
ExchangeCurrency : currency_lib .USD ,
160
173
NativeAmount : usdMarketValue ,
161
174
UsdMarketValue : usdMarketValue ,
175
+
176
+ IsWithdrawal : isWithdraw ,
162
177
},
163
178
164
179
InitiatorOwnerAccount : owner .PublicKey ().ToBase58 (),
0 commit comments