@jetthai/cuora 2.0.0-beta.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -112
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -98
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +8 -11
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +0 -1
  70. package/src/machine/game_v2_1.js +39 -126
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -459
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -80
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -133
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -155
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -133
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -603
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,270 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import cryptoBankFactory from '../src/machine/deposit/crypto_bank.js'
5
- import cryptoBankCashFactory from '../src/machine/deposit/crypto_bank_cash.js'
6
-
7
- test('crypto_bank actions/guards/services cover payment setup and submit payload', async () => {
8
- const sent = []
9
- const request = {
10
- config: { appSecret: 'secret' },
11
- send: async (req) => {
12
- sent.push(req)
13
- if (req.url === 'payment/v2/paymentDetail') {
14
- return [
15
- {
16
- category: 'cryptoBank',
17
- method: 'crypto_bank',
18
- minimum: 10,
19
- maximum: 1000,
20
- processing: [{ id: 1 }],
21
- optional: [100, 200],
22
- banks: [
23
- { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'A1' },
24
- { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'A2' },
25
- { cryptoName: 'ETH', symbol: 'ETH', network: 'ERC20', address: 'E1' },
26
- ],
27
- },
28
- ]
29
- }
30
- if (req.url === 'payment/v2/crypto_bank/crypto/expected/result') return { data: { rate: 1.2 } }
31
- if (req.url === 'payment/v2/crypto_bank/transaction') return { applyId: 88 }
32
- return {}
33
- },
34
- }
35
-
36
- const machine = cryptoBankFactory(request)
37
- const { actions, guards, services } = machine.options
38
-
39
- const setPayment = actions.setPayment.assignment(machine.initialState.context, {
40
- data: [
41
- {
42
- category: 'cryptoBank',
43
- method: 'crypto_bank',
44
- minimum: 10,
45
- maximum: 1000,
46
- processing: [{ id: 1 }],
47
- optional: [100, 200],
48
- banks: [
49
- { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'A1' },
50
- { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'A2' },
51
- { cryptoName: 'ETH', symbol: 'ETH', network: 'ERC20', address: 'E1' },
52
- ],
53
- },
54
- ],
55
- })
56
- assert.equal(setPayment.cryptos.length, 2)
57
- assert.equal(setPayment.selectedCrypto.label, 'USDT')
58
- assert.equal(setPayment.selectedAddress.value, 'A1')
59
- assert.equal(setPayment.processing.id, 1)
60
-
61
- assert.deepEqual(actions.setCrypto.assignment({ cryptoBank: { banks: [] } }, { data: { label: 'USDT' } }), {})
62
- assert.deepEqual(actions.setCrypto.assignment(setPayment, { data: { label: 'NOPE' } }), {})
63
-
64
- const setCrypto = actions.setCrypto.assignment(setPayment, { data: { label: 'ETH' } })
65
- assert.equal(setCrypto.selectedCrypto.label, 'ETH')
66
- assert.equal(setCrypto.selectedAddress.value, 'E1')
67
-
68
- assert.deepEqual(actions.setAddress.assignment({ cryptoBank: null, selectedCrypto: null }, { data: { value: 'A1' } }), {})
69
- const setAddress = actions.setAddress.assignment(setPayment, { data: { value: 'A2' } })
70
- assert.equal(setAddress.selectedCrypto.address, 'A2')
71
-
72
- assert.equal(actions.setAmount.assignment(machine.initialState.context, { data: '123' }).amount, '123')
73
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { bonus: 1 } } }).calculation, { bonus: 1 })
74
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { bonus: 2 } }).calculation, { bonus: 2 })
75
- assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
76
- assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 7 } }).result.applyId, 7)
77
- assert.equal(actions.setProofOptional.assignment(machine.initialState.context, { data: true }).proofOptional, true)
78
- assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: '2026-01-01 10:00:00' }).depositTime, '2026-01-01 10:00:00')
79
- assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'slip' }).receipt, 'slip')
80
- assert.equal(actions.setPromotion.assignment(machine.initialState.context, { data: { activityNo: 'A1' } }).promotion.activityNo, 'A1')
81
-
82
- assert.equal(
83
- guards.isCalculable({
84
- selectedCrypto: { value: 'crypto_bank' },
85
- selectedAddress: { value: 'A1' },
86
- cryptoBank: { minimum: 10, maximum: 100 },
87
- amount: '20',
88
- }),
89
- true
90
- )
91
- assert.equal(
92
- guards.isCalculable({ selectedCrypto: null, selectedAddress: { value: 'A1' }, cryptoBank: { minimum: 10, maximum: 100 }, amount: '20' }),
93
- null
94
- )
95
- assert.equal(
96
- guards.isSubmittable({
97
- selectedCrypto: { value: 'crypto_bank' },
98
- selectedAddress: { value: 'A1' },
99
- amount: '20',
100
- depositTime: 't',
101
- receipt: 'r',
102
- proofOptional: false,
103
- }),
104
- 'r'
105
- )
106
- assert.equal(
107
- guards.isSubmittable({
108
- selectedCrypto: { value: 'crypto_bank' },
109
- selectedAddress: { value: 'A1' },
110
- amount: '20',
111
- depositTime: 't',
112
- receipt: null,
113
- proofOptional: true,
114
- }),
115
- true
116
- )
117
- assert.equal(guards.isProcessing({ processing: { id: 1 } }).id, 1)
118
-
119
- const payments = await services.fetchPayments({}, {})
120
- assert.equal(Array.isArray(payments), true)
121
-
122
- const calculation = await services.fetchCalculation(
123
- { selectedCrypto: { value: 'crypto_bank', symbol: 'USDT' }, amount: 99, promotion: { activityNo: 'ACT1' } },
124
- {}
125
- )
126
- assert.equal(calculation.data.rate, 1.2)
127
-
128
- const submitted = await services.submitDeposit(
129
- {
130
- selectedCrypto: { value: 'crypto_bank', symbol: 'USDT', network: 'TRC20', address: 'A1' },
131
- amount: 77,
132
- promotion: { activityNo: 'ACT2' },
133
- depositTime: '2026-01-01 10:00:00',
134
- receipt: 'slip',
135
- },
136
- {}
137
- )
138
- assert.equal(submitted.applyId, 88)
139
-
140
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_bank/transaction')
141
- assert.equal(submitReq.params.promotionsNo, 'ACT2')
142
- assert.equal(submitReq.params.sourceAddress, 'A1')
143
- })
144
-
145
- test('crypto_bank_cash actions/guards/services cover init branches and submit rules', async () => {
146
- const sent = []
147
- const request = {
148
- send: async (req) => {
149
- sent.push(req)
150
- if (req.url === 'payment/v2/crypto_bank_cash/crypto/expected/result') return { data: { value: 22 } }
151
- if (req.url === 'payment/v2/crypto_bank_cash/transaction') return { applyId: 99 }
152
- return {}
153
- },
154
- }
155
-
156
- const machine = cryptoBankCashFactory(request, {
157
- paymentDetail: [
158
- {
159
- transferType: 'deposit',
160
- category: 'cryptoBank',
161
- method: 'crypto_bank_cash',
162
- minimum: 50,
163
- maximum: 5000,
164
- grandTotalEnable: 0,
165
- optional: [100, 200],
166
- banks: [
167
- { cryptoName: 'USDT', symbol: 'USDT', network: 'TRC20', address: 'CA1' },
168
- { cryptoName: 'USDT', symbol: 'USDT', network: 'ERC20', address: 'CA2' },
169
- ],
170
- },
171
- ],
172
- promotion: { promotionsNo: 'P1', minimumAmount: 120 },
173
- selectedAmount: 10,
174
- siteConfig: { bankDepositProofIsOptional: '1' },
175
- })
176
-
177
- const { actions, guards, services } = machine.options
178
-
179
- const init = actions.setInitData.assignment(machine.initialState.context, {})
180
- assert.equal(init.cryptos.length, 1)
181
- assert.equal(init.selectedCrypto.label, 'USDT')
182
- assert.equal(init.selectedAddress.value, 'CA1')
183
-
184
- const initMissing = actions.setInitData.assignment({ ...machine.initialState.context, paymentDetail: [] }, {})
185
- assert.equal(initMissing.cryptoBank, null)
186
- assert.deepEqual(initMissing.options, [])
187
-
188
- assert.deepEqual(actions.setCrypto.assignment({ cryptoBank: { banks: [] } }, { data: { label: 'USDT' } }), {})
189
- assert.deepEqual(actions.setCrypto.assignment(init, { data: { label: 'NOPE' } }), {})
190
- assert.equal(actions.setCrypto.assignment(init, { data: { label: 'USDT' } }).selectedAddress.value, 'CA1')
191
-
192
- assert.deepEqual(actions.setAddress.assignment({ cryptoBank: null, selectedCrypto: null }, { data: { value: 'CA1' } }), {})
193
- assert.equal(actions.setAddress.assignment(init, { data: { value: 'CA2' } }).selectedCrypto.address, 'CA2')
194
-
195
- assert.equal(actions.setAmount.assignment({ ...init, cryptoBank: { grandTotalEnable: 1 }, selectedAmount: '10' }, { data: '5' }).selectedAmount, 15)
196
- assert.equal(
197
- actions.setAmount.assignment({ ...init, cryptoBank: { grandTotalEnable: 0 }, selectedAmount: '10' }, { data: '5' }).selectedAmount,
198
- '5'
199
- )
200
- assert.equal(actions.inputAmount.assignment(machine.initialState.context, { data: 333 }).selectedAmount, 333)
201
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { bonus: 1 } } }).calculation, { bonus: 1 })
202
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { bonus: 2 } }).calculation, { bonus: 2 })
203
- assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
204
- assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
205
-
206
- const promo = actions.setPromotion.assignment({ ...init, selectedAmount: 10 }, { data: { promotionsNo: 'P2', minimumAmount: 200 } })
207
- assert.equal(promo.selectedAmount, 200)
208
- assert.equal(actions.setDepositTime.assignment(machine.initialState.context, { data: 't' }).depositTime, 't')
209
- assert.equal(actions.setReceipt.assignment(machine.initialState.context, { data: 'r' }).receipt, 'r')
210
-
211
- assert.equal(
212
- guards.isCalculable({
213
- selectedCrypto: { value: 'crypto_bank_cash' },
214
- selectedAddress: { value: 'CA1' },
215
- cryptoBank: { minimum: 50, maximum: 500 },
216
- selectedAmount: 100,
217
- }),
218
- true
219
- )
220
- assert.equal(
221
- guards.isCalculable({ selectedCrypto: null, selectedAddress: { value: 'CA1' }, cryptoBank: { minimum: 50, maximum: 500 }, selectedAmount: 100 }),
222
- null
223
- )
224
- assert.equal(
225
- guards.isSubmittable({
226
- selectedCrypto: { value: 'crypto_bank_cash' },
227
- selectedAddress: { value: 'CA1' },
228
- selectedAmount: 100,
229
- depositTime: 't',
230
- receipt: 'r',
231
- calculation: { ok: 1 },
232
- siteConfig: { bankDepositProofIsOptional: '1' },
233
- }),
234
- 'r'
235
- )
236
- assert.equal(
237
- guards.isSubmittable({
238
- selectedCrypto: { value: 'crypto_bank_cash' },
239
- selectedAddress: { value: 'CA1' },
240
- selectedAmount: 100,
241
- depositTime: null,
242
- receipt: null,
243
- calculation: { ok: 1 },
244
- siteConfig: { bankDepositProofIsOptional: '2' },
245
- }),
246
- true
247
- )
248
-
249
- const calc = await services.fetchCalculation(
250
- { selectedCrypto: { value: 'crypto_bank_cash', symbol: 'USDT' }, selectedAmount: 300, promotion: { promotionsNo: 'P3' } },
251
- {}
252
- )
253
- assert.equal(calc.data.value, 22)
254
-
255
- const submitted = await services.submitDeposit(
256
- {
257
- selectedCrypto: { value: 'crypto_bank_cash', symbol: 'USDT', network: 'TRC20', address: 'CA1' },
258
- selectedAmount: 500,
259
- promotion: { promotionsNo: 'P4' },
260
- depositTime: '2026-01-01 12:00:00',
261
- receipt: 'slip',
262
- },
263
- {}
264
- )
265
- assert.equal(submitted.applyId, 99)
266
-
267
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_bank_cash/transaction')
268
- assert.equal(submitReq.params.promotionsNo, 'P4')
269
- assert.equal(submitReq.params.sourceAddress, 'CA1')
270
- })
@@ -1,108 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import cryptoWayFactory from '../src/machine/deposit/crypto_way.js'
5
-
6
- test('crypto_way covers actions, guards and services including precise amount add', async () => {
7
- const sent = []
8
- const request = {
9
- config: { appSecret: 'secret' },
10
- send: async (req) => {
11
- sent.push(req)
12
- if (req.url === 'payment/v2/paymentDetail') {
13
- return [
14
- {
15
- category: 'cryptoWay',
16
- method: 'crypto_way',
17
- channel: 'USDT',
18
- cryptoOptional: ['USDT'],
19
- networkName: ['TRC20'],
20
- minimum: 50,
21
- maximum: 500,
22
- },
23
- {
24
- category: 'cryptoWay',
25
- method: 'crypto_way_eth',
26
- channel: 'ETH',
27
- cryptoOptional: ['ETH'],
28
- networkName: ['ERC20'],
29
- minimum: 80,
30
- maximum: 800,
31
- },
32
- { category: 'other', method: 'ignored' },
33
- ]
34
- }
35
- if (req.url === 'payment/v2/crypto_way/crypto/expected/result') {
36
- return { data: { expectedAmount: 777 } }
37
- }
38
- if (req.url === 'payment/v2/crypto_way/transaction') {
39
- return { applyId: 'TX-1' }
40
- }
41
- return {}
42
- },
43
- }
44
-
45
- const machine = cryptoWayFactory(request)
46
- const { actions, guards, services } = machine.options
47
- const initial = machine.initialState.context
48
-
49
- const fetched = await services.fetchPayments(initial)
50
- assert.equal(fetched.length, 3)
51
-
52
- const setPayment = actions.setPayment.assignment(initial, { data: fetched })
53
- assert.equal(setPayment.cryptos.length, 2)
54
- assert.equal(setPayment.selectedCrypto.label, 'USDT')
55
- assert.equal(setPayment.selectedCrypto.network, 'TRC20')
56
- assert.equal(setPayment.currentPayment.method, 'crypto_way')
57
-
58
- const setCrypto = actions.setCrypto.assignment(setPayment, { data: { label: 'ETH' } })
59
- assert.equal(setCrypto.selectedCrypto.label, 'ETH')
60
- assert.equal(setCrypto.amount, null)
61
- assert.equal(setCrypto.calculation, null)
62
-
63
- const setCryptoNotFound = actions.setCrypto.assignment(setPayment, { data: { label: 'NOPE' } })
64
- assert.equal(setCryptoNotFound.selectedCrypto, undefined)
65
-
66
- assert.equal(actions.setAmount.assignment(initial, { data: '123' }).amount, '123')
67
-
68
- const added = actions.inputAmount.assignment({ amount: '10.1' }, { data: '0.2' })
69
- assert.equal(added.amount, 10.3)
70
-
71
- assert.equal(actions.setAddress.assignment(initial, { data: '0xabc' }).sourceAddress, '0xabc')
72
-
73
- assert.equal(actions.setCalculation.assignment(initial, { data: { data: { a: 1 } } }).calculation.a, 1)
74
- assert.equal(actions.setCalculation.assignment(initial, { data: { b: 2 } }).calculation.b, 2)
75
- assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
76
- assert.equal(actions.setResult.assignment(initial, { data: { applyId: 'TX-2' } }).result.applyId, 'TX-2')
77
- assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'A-1' } }).promotion.activityNo, 'A-1')
78
-
79
- assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, amount: '60' }), true)
80
- assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, amount: '10' }), false)
81
- assert.equal(guards.isCalculable({ selectedCrypto: null, amount: '60' }), null)
82
-
83
- assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, amount: '1' }), '1')
84
- assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, amount: 0 }), 0)
85
-
86
- const calcResult = await services.fetchCalculation({
87
- selectedCrypto: { method: 'crypto_way', channel: 'USDT' },
88
- amount: 456,
89
- promotion: { activityNo: 'P-1' },
90
- })
91
- assert.equal(calcResult.data.expectedAmount, 777)
92
-
93
- const submitResult = await services.submitDeposit({
94
- selectedCrypto: { method: 'crypto_way', channel: 'USDT', network: 'TRC20' },
95
- amount: 321,
96
- })
97
- assert.equal(submitResult.applyId, 'TX-1')
98
-
99
- const calcReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way/crypto/expected/result')
100
- assert.equal(calcReq.params.amount, 456)
101
- assert.equal(calcReq.params.cryptoCurrency, 'USDT')
102
- assert.equal(calcReq.params.promotionsNo, 'P-1')
103
-
104
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way/transaction')
105
- assert.equal(submitReq.params.amount, 321)
106
- assert.equal(submitReq.params.cryptoCurrency, 'USDT')
107
- assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
108
- })
@@ -1,114 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import cryptoWayCashFactory from '../src/machine/deposit/crypto_way_cash.js'
5
-
6
- test('crypto_way_cash actions/guards/services cover amount, ttl and payload mapping', async () => {
7
- const sent = []
8
- const request = {
9
- send: async (req) => {
10
- sent.push(req)
11
- if (req.url === 'payment/v2/crypto_way_cash/crypto/expected/result') return { data: { bonus: 10 } }
12
- if (req.url === 'payment/v2/crypto_way_cash/transaction') return { applyId: 55, cdtime: 3000 }
13
- return {}
14
- },
15
- }
16
-
17
- const machine = cryptoWayCashFactory(request, {
18
- paymentDetail: [
19
- {
20
- category: 'cryptoWay',
21
- method: 'crypto_way_cash',
22
- channel: 'USDT',
23
- cryptoOptional: ['USDT'],
24
- networkName: ['TRC20'],
25
- optional: [100, 200],
26
- minimum: 50,
27
- maximum: 5000,
28
- grandTotalEnable: 1,
29
- },
30
- {
31
- category: 'cryptoWay',
32
- method: 'crypto_way_cash_eth',
33
- channel: 'ETH',
34
- cryptoOptional: ['ETH'],
35
- networkName: ['ERC20'],
36
- optional: [300],
37
- minimum: 80,
38
- maximum: 8000,
39
- grandTotalEnable: 0,
40
- },
41
- ],
42
- promotion: { promotionsNo: 'P1', minimumAmount: 100 },
43
- selectedAmount: 10,
44
- })
45
-
46
- const { actions, guards, services } = machine.options
47
-
48
- const init = actions.setInitData.assignment(machine.initialState.context, {})
49
- assert.equal(init.cryptos.length, 2)
50
- assert.equal(init.selectedCrypto.label, 'USDT')
51
- assert.equal(init.options.length, 2)
52
-
53
- const initEmpty = actions.setInitData.assignment({ ...machine.initialState.context, paymentDetail: [] }, {})
54
- assert.deepEqual(initEmpty.cryptos, [])
55
- assert.equal(initEmpty.selectedCrypto, undefined)
56
-
57
- assert.deepEqual(actions.setCrypto.assignment(init, { data: { label: 'NOPE' } }), {})
58
- const setCrypto = actions.setCrypto.assignment(init, { data: { label: 'ETH' } })
59
- assert.equal(setCrypto.selectedCrypto.label, 'ETH')
60
- assert.equal(setCrypto.options[0], 300)
61
-
62
- const amountPlus = actions.setAmount.assignment({ ...init, selectedAmount: '10.1', selectedCrypto: { grandTotalEnable: 1 } }, { data: '0.2' })
63
- assert.equal(amountPlus.selectedAmount, 10.3)
64
-
65
- const amountSet = actions.setAmount.assignment({ ...init, selectedCrypto: { grandTotalEnable: 0 } }, { data: '77' })
66
- assert.equal(amountSet.selectedAmount, '77')
67
-
68
- assert.equal(actions.inputAmount.assignment(machine.initialState.context, { data: '88' }).selectedAmount, '88')
69
- assert.equal(actions.setAddress.assignment(machine.initialState.context, { data: '0xabc' }).sourceAddress, '0xabc')
70
-
71
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { x: 1 } } }).calculation, { x: 1 })
72
- assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { y: 2 } }).calculation, { y: 2 })
73
- assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
74
-
75
- assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
76
-
77
- const promo = actions.setPromotion.assignment(
78
- { selectedCrypto: { minimum: 120 }, selectedAmount: 50 },
79
- { data: { promotionsNo: 'P2', minimumAmount: 200 } }
80
- )
81
- assert.equal(promo.selectedAmount, 200)
82
- assert.equal(promo.calculation, null)
83
-
84
- assert.equal(actions.setTtl.assignment(machine.initialState.context, { data: { cdtime: 3000 } }).ttl, 3000)
85
- assert.equal(actions.decreaseTtl.assignment({ ttl: 3000 }, {}).ttl, 2000)
86
- assert.equal(actions.decreaseTtl.assignment({ ttl: 500 }, {}).ttl, 0)
87
-
88
- assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, selectedAmount: '80' }), true)
89
- assert.equal(guards.isCalculable({ selectedCrypto: null, selectedAmount: '80' }), null)
90
- assert.deepEqual(guards.isSubmittable({ selectedCrypto: { method: 'x' }, selectedAmount: '1', calculation: { ok: 1 } }), { ok: 1 })
91
- assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, selectedAmount: '1', calculation: null }), null)
92
-
93
- const calc = await services.fetchCalculation(
94
- { selectedCrypto: { method: 'crypto_way_cash', channel: 'USDT' }, selectedAmount: 123, promotion: { promotionsNo: 'P3' } },
95
- {}
96
- )
97
- assert.equal(calc.data.bonus, 10)
98
-
99
- const submitted = await services.submitDeposit(
100
- {
101
- selectedCrypto: { method: 'crypto_way_cash', channel: 'USDT', network: 'TRC20' },
102
- selectedAmount: 456,
103
- sourceAddress: 'ADDR1',
104
- promotion: { promotionsNo: 'P4' },
105
- },
106
- {}
107
- )
108
- assert.equal(submitted.applyId, 55)
109
-
110
- const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way_cash/transaction')
111
- assert.equal(submitReq.params.cryptoCurrency, 'USDT')
112
- assert.equal(submitReq.params.sourceAddress, 'ADDR1')
113
- assert.equal(submitReq.params.promotionsNo, 'P4')
114
- })
@@ -1,137 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import machine from '../src/machine/index.js'
5
-
6
- function getRefName(value) {
7
- if (typeof value === 'string') {
8
- return value
9
- }
10
- if (value && typeof value === 'object' && typeof value.type === 'string') {
11
- return value.type
12
- }
13
- return null
14
- }
15
-
16
- function addActionRefs(targetSet, value) {
17
- if (!value) return
18
- if (Array.isArray(value)) {
19
- for (const item of value) {
20
- addActionRefs(targetSet, item)
21
- }
22
- return
23
- }
24
- const ref = getRefName(value)
25
- if (ref && !ref.startsWith('xstate.')) {
26
- targetSet.add(ref)
27
- }
28
- }
29
-
30
- function addGuardRef(targetSet, cond) {
31
- const ref = getRefName(cond)
32
- if (ref && !ref.startsWith('xstate.')) {
33
- targetSet.add(ref)
34
- }
35
- }
36
-
37
- function inspectTransitions(transitionLike, refs) {
38
- if (!transitionLike) return
39
- const transitions = Array.isArray(transitionLike) ? transitionLike : [transitionLike]
40
-
41
- for (const t of transitions) {
42
- if (!t || typeof t !== 'object') continue
43
- addActionRefs(refs.actions, t.actions)
44
- addGuardRef(refs.guards, t.cond)
45
- }
46
- }
47
-
48
- function walkStates(stateNodeConfig, refs) {
49
- addActionRefs(refs.actions, stateNodeConfig.entry)
50
- addActionRefs(refs.actions, stateNodeConfig.exit)
51
-
52
- if (stateNodeConfig.invoke) {
53
- const invokes = Array.isArray(stateNodeConfig.invoke) ? stateNodeConfig.invoke : [stateNodeConfig.invoke]
54
- for (const inv of invokes) {
55
- if (!inv || typeof inv !== 'object') continue
56
- const srcRef = getRefName(inv.src)
57
- if (srcRef && !srcRef.startsWith('xstate.')) {
58
- refs.services.add(srcRef)
59
- }
60
- inspectTransitions(inv.onDone, refs)
61
- inspectTransitions(inv.onError, refs)
62
- }
63
- }
64
-
65
- inspectTransitions(stateNodeConfig.always, refs)
66
-
67
- if (stateNodeConfig.on && typeof stateNodeConfig.on === 'object') {
68
- for (const t of Object.values(stateNodeConfig.on)) {
69
- inspectTransitions(t, refs)
70
- }
71
- }
72
-
73
- if (stateNodeConfig.after && typeof stateNodeConfig.after === 'object') {
74
- for (const [delayKey, transition] of Object.entries(stateNodeConfig.after)) {
75
- if (!/^\d+$/.test(delayKey)) {
76
- refs.delays.add(delayKey)
77
- }
78
- inspectTransitions(transition, refs)
79
- }
80
- }
81
-
82
- if (stateNodeConfig.states && typeof stateNodeConfig.states === 'object') {
83
- for (const child of Object.values(stateNodeConfig.states)) {
84
- walkStates(child, refs)
85
- }
86
- }
87
- }
88
-
89
- const requestStub = {
90
- config: {
91
- apiURL: 'https://api.example.com',
92
- apiVersion: 'v1',
93
- clientId: 'client',
94
- appSecret: 'secret',
95
- platform: 'web',
96
- version: '1.0.0',
97
- fpToken: 'fp-token',
98
- sentry: { captureException: () => {}, setTag: () => {} },
99
- defaultChannel: 'web',
100
- defaultSubchannel: 'home',
101
- socketURL: 'wss://socket.example.com',
102
- bucketName: 'bucket',
103
- },
104
- send: async () => ({}),
105
- }
106
-
107
- for (const [machineName, machineFactory] of Object.entries(machine)) {
108
- test(`machine definition refs are resolvable: ${machineName}`, () => {
109
- const m = machineFactory(requestStub, {})
110
- const refs = {
111
- actions: new Set(),
112
- guards: new Set(),
113
- services: new Set(),
114
- delays: new Set(),
115
- }
116
-
117
- walkStates(m.config, refs)
118
- inspectTransitions(m.config.on, refs)
119
- addActionRefs(refs.actions, m.config.entry)
120
- addActionRefs(refs.actions, m.config.exit)
121
-
122
- const definedActions = new Set(Object.keys(m.options.actions || {}))
123
- const definedGuards = new Set(Object.keys(m.options.guards || {}))
124
- const definedServices = new Set(Object.keys(m.options.services || {}))
125
- const definedDelays = new Set(Object.keys(m.options.delays || {}))
126
-
127
- const missingActions = [...refs.actions].filter((name) => !definedActions.has(name))
128
- const missingGuards = [...refs.guards].filter((name) => !definedGuards.has(name))
129
- const missingServices = [...refs.services].filter((name) => !definedServices.has(name))
130
- const missingDelays = [...refs.delays].filter((name) => !definedDelays.has(name))
131
-
132
- assert.deepEqual(missingActions, [], `missing actions in ${machineName}: ${missingActions.join(', ')}`)
133
- assert.deepEqual(missingGuards, [], `missing guards in ${machineName}: ${missingGuards.join(', ')}`)
134
- assert.deepEqual(missingServices, [], `missing services in ${machineName}: ${missingServices.join(', ')}`)
135
- assert.deepEqual(missingDelays, [], `missing delays in ${machineName}: ${missingDelays.join(', ')}`)
136
- })
137
- }