@bsv/wallet-toolbox 1.3.2 → 1.3.4

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 (329) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/docs/client.md +97 -28
  3. package/docs/services.md +2 -1
  4. package/docs/setup.md +404 -14
  5. package/docs/storage.md +720 -42
  6. package/docs/wallet.md +97 -28
  7. package/out/src/CWIStyleWalletManager.d.ts.map +1 -1
  8. package/out/src/CWIStyleWalletManager.js +12 -5
  9. package/out/src/CWIStyleWalletManager.js.map +1 -1
  10. package/out/src/Setup.d.ts +2 -69
  11. package/out/src/Setup.d.ts.map +1 -1
  12. package/out/src/Setup.js.map +1 -1
  13. package/out/src/SetupClient.d.ts +126 -0
  14. package/out/src/SetupClient.d.ts.map +1 -0
  15. package/out/src/SetupClient.js +220 -0
  16. package/out/src/SetupClient.js.map +1 -0
  17. package/out/src/SetupWallet.d.ts +100 -0
  18. package/out/src/SetupWallet.d.ts.map +1 -0
  19. package/out/src/{storage/schema/tables/Certificate.js → SetupWallet.js} +1 -1
  20. package/out/src/SetupWallet.js.map +1 -0
  21. package/out/src/index.all.d.ts +2 -0
  22. package/out/src/index.all.d.ts.map +1 -1
  23. package/out/src/index.all.js +2 -0
  24. package/out/src/index.all.js.map +1 -1
  25. package/out/src/index.client.d.ts +1 -0
  26. package/out/src/index.client.d.ts.map +1 -1
  27. package/out/src/index.client.js +1 -0
  28. package/out/src/index.client.js.map +1 -1
  29. package/out/src/monitor/Monitor.d.ts.map +1 -1
  30. package/out/src/monitor/Monitor.js +4 -0
  31. package/out/src/monitor/Monitor.js.map +1 -1
  32. package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
  33. package/out/src/monitor/MonitorDaemon.js +0 -3
  34. package/out/src/monitor/MonitorDaemon.js.map +1 -1
  35. package/out/src/monitor/tasks/TaskUnFail.d.ts.map +1 -1
  36. package/out/src/monitor/tasks/TaskUnFail.js +1 -2
  37. package/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
  38. package/out/src/sdk/WalletServices.interfaces.d.ts +9 -0
  39. package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  40. package/out/src/services/Services.d.ts +2 -1
  41. package/out/src/services/Services.d.ts.map +1 -1
  42. package/out/src/services/Services.js +8 -0
  43. package/out/src/services/Services.js.map +1 -1
  44. package/out/src/services/__tests/postBeef.test.js +1 -1
  45. package/out/src/services/__tests/postBeef.test.js.map +1 -1
  46. package/out/src/storage/StorageIdb.d.ts +203 -0
  47. package/out/src/storage/StorageIdb.d.ts.map +1 -0
  48. package/out/src/storage/StorageIdb.js +2289 -0
  49. package/out/src/storage/StorageIdb.js.map +1 -0
  50. package/out/src/storage/StorageKnex.d.ts +6 -6
  51. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  52. package/out/src/storage/StorageKnex.js +9 -29
  53. package/out/src/storage/StorageKnex.js.map +1 -1
  54. package/out/src/storage/StorageProvider.d.ts +3 -1
  55. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  56. package/out/src/storage/StorageProvider.js +22 -0
  57. package/out/src/storage/StorageProvider.js.map +1 -1
  58. package/out/src/storage/StorageReader.d.ts +1 -1
  59. package/out/src/storage/StorageReader.d.ts.map +1 -1
  60. package/out/src/storage/StorageReader.js +5 -0
  61. package/out/src/storage/StorageReader.js.map +1 -1
  62. package/out/src/storage/__test/StorageIdb.test.d.ts +2 -0
  63. package/out/src/storage/__test/StorageIdb.test.d.ts.map +1 -0
  64. package/out/src/storage/__test/StorageIdb.test.js +16 -0
  65. package/out/src/storage/__test/StorageIdb.test.js.map +1 -0
  66. package/out/src/storage/methods/ListActionsSpecOp.d.ts +16 -0
  67. package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -0
  68. package/out/src/storage/methods/ListActionsSpecOp.js +40 -0
  69. package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -0
  70. package/out/src/storage/methods/ListOutputsSpecOp.d.ts +26 -0
  71. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -0
  72. package/out/src/storage/methods/ListOutputsSpecOp.js +71 -0
  73. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -0
  74. package/out/src/storage/methods/listActionsIdb.d.ts +5 -0
  75. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -0
  76. package/out/src/storage/methods/listActionsIdb.js +155 -0
  77. package/out/src/storage/methods/listActionsIdb.js.map +1 -0
  78. package/out/src/storage/methods/{listActions.d.ts → listActionsKnex.d.ts} +1 -1
  79. package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -0
  80. package/out/src/storage/methods/{listActions.js → listActionsKnex.js} +3 -34
  81. package/out/src/storage/methods/listActionsKnex.js.map +1 -0
  82. package/out/src/storage/methods/listOutputsIdb.d.ts +5 -0
  83. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -0
  84. package/out/src/storage/methods/listOutputsIdb.js +181 -0
  85. package/out/src/storage/methods/listOutputsIdb.js.map +1 -0
  86. package/out/src/storage/methods/{listOutputs.d.ts → listOutputsKnex.d.ts} +1 -1
  87. package/out/src/storage/methods/listOutputsKnex.d.ts.map +1 -0
  88. package/out/src/storage/methods/{listOutputs.js → listOutputsKnex.js} +7 -76
  89. package/out/src/storage/methods/listOutputsKnex.js.map +1 -0
  90. package/out/src/storage/methods/purgeDataIdb.d.ts +4 -0
  91. package/out/src/storage/methods/purgeDataIdb.d.ts.map +1 -0
  92. package/out/src/storage/methods/purgeDataIdb.js +9 -0
  93. package/out/src/storage/methods/purgeDataIdb.js.map +1 -0
  94. package/out/src/storage/methods/reviewStatus.d.ts +11 -0
  95. package/out/src/storage/methods/reviewStatus.d.ts.map +1 -1
  96. package/out/src/storage/methods/reviewStatus.js +11 -0
  97. package/out/src/storage/methods/reviewStatus.js.map +1 -1
  98. package/out/src/storage/methods/reviewStatusIdb.d.ts +20 -0
  99. package/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -0
  100. package/out/src/storage/methods/reviewStatusIdb.js +35 -0
  101. package/out/src/storage/methods/reviewStatusIdb.js.map +1 -0
  102. package/out/src/storage/schema/StorageIdbSchema.d.ts +133 -0
  103. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -0
  104. package/out/src/storage/schema/{tables/CertificateField.js → StorageIdbSchema.js} +1 -1
  105. package/out/src/storage/schema/StorageIdbSchema.js.map +1 -0
  106. package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js +1 -0
  107. package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js.map +1 -1
  108. package/out/src/storage/schema/tables/{Certificate.d.ts → TableCertificate.d.ts} +1 -1
  109. package/out/src/storage/schema/tables/TableCertificate.d.ts.map +1 -0
  110. package/out/src/storage/schema/tables/TableCertificate.js +3 -0
  111. package/out/src/storage/schema/tables/TableCertificate.js.map +1 -0
  112. package/out/src/storage/schema/tables/{CertificateField.d.ts → TableCertificateField.d.ts} +1 -1
  113. package/out/src/storage/schema/tables/TableCertificateField.d.ts.map +1 -0
  114. package/out/src/storage/schema/tables/TableCertificateField.js +3 -0
  115. package/out/src/storage/schema/tables/TableCertificateField.js.map +1 -0
  116. package/out/src/storage/schema/tables/{Commission.d.ts → TableCommission.d.ts} +1 -1
  117. package/out/src/storage/schema/tables/TableCommission.d.ts.map +1 -0
  118. package/out/src/storage/schema/tables/TableCommission.js +3 -0
  119. package/out/src/storage/schema/tables/TableCommission.js.map +1 -0
  120. package/out/src/storage/schema/tables/{MonitorEvent.d.ts → TableMonitorEvent.d.ts} +1 -1
  121. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts.map +1 -0
  122. package/out/src/storage/schema/tables/TableMonitorEvent.js +3 -0
  123. package/out/src/storage/schema/tables/TableMonitorEvent.js.map +1 -0
  124. package/out/src/storage/schema/tables/{Output.d.ts → TableOutput.d.ts} +1 -1
  125. package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -0
  126. package/out/src/storage/schema/tables/{Output.js → TableOutput.js} +1 -1
  127. package/out/src/storage/schema/tables/TableOutput.js.map +1 -0
  128. package/out/src/storage/schema/tables/{OutputBasket.d.ts → TableOutputBasket.d.ts} +1 -1
  129. package/out/src/storage/schema/tables/TableOutputBasket.d.ts.map +1 -0
  130. package/out/src/storage/schema/tables/TableOutputBasket.js +3 -0
  131. package/out/src/storage/schema/tables/TableOutputBasket.js.map +1 -0
  132. package/out/src/storage/schema/tables/{OutputTag.d.ts → TableOutputTag.d.ts} +1 -1
  133. package/out/src/storage/schema/tables/TableOutputTag.d.ts.map +1 -0
  134. package/out/src/storage/schema/tables/{MonitorEvent.js → TableOutputTag.js} +1 -1
  135. package/out/src/storage/schema/tables/TableOutputTag.js.map +1 -0
  136. package/out/src/storage/schema/tables/{OutputTagMap.d.ts → TableOutputTagMap.d.ts} +1 -1
  137. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts.map +1 -0
  138. package/out/src/storage/schema/tables/TableOutputTagMap.js +3 -0
  139. package/out/src/storage/schema/tables/TableOutputTagMap.js.map +1 -0
  140. package/out/src/storage/schema/tables/{ProvenTx.d.ts → TableProvenTx.d.ts} +1 -1
  141. package/out/src/storage/schema/tables/TableProvenTx.d.ts.map +1 -0
  142. package/out/src/storage/schema/tables/{Commission.js → TableProvenTx.js} +1 -1
  143. package/out/src/storage/schema/tables/TableProvenTx.js.map +1 -0
  144. package/out/src/storage/schema/tables/{ProvenTxReq.d.ts → TableProvenTxReq.d.ts} +1 -1
  145. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts.map +1 -0
  146. package/out/src/storage/schema/tables/TableProvenTxReq.js +3 -0
  147. package/out/src/storage/schema/tables/TableProvenTxReq.js.map +1 -0
  148. package/out/src/storage/schema/tables/TableSettings.d.ts +1 -1
  149. package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
  150. package/out/src/storage/schema/tables/{SyncState.d.ts → TableSyncState.d.ts} +1 -1
  151. package/out/src/storage/schema/tables/TableSyncState.d.ts.map +1 -0
  152. package/out/src/storage/schema/tables/TableSyncState.js +3 -0
  153. package/out/src/storage/schema/tables/TableSyncState.js.map +1 -0
  154. package/out/src/storage/schema/tables/{Transaction.d.ts → TableTransaction.d.ts} +1 -1
  155. package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -0
  156. package/out/src/storage/schema/tables/{Transaction.js → TableTransaction.js} +1 -1
  157. package/out/src/storage/schema/tables/TableTransaction.js.map +1 -0
  158. package/out/src/storage/schema/tables/{TxLabel.d.ts → TableTxLabel.d.ts} +1 -1
  159. package/out/src/storage/schema/tables/TableTxLabel.d.ts.map +1 -0
  160. package/out/src/storage/schema/tables/{OutputBasket.js → TableTxLabel.js} +1 -1
  161. package/out/src/storage/schema/tables/TableTxLabel.js.map +1 -0
  162. package/out/src/storage/schema/tables/{TxLabelMap.d.ts → TableTxLabelMap.d.ts} +1 -1
  163. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts.map +1 -0
  164. package/out/src/storage/schema/tables/TableTxLabelMap.js +3 -0
  165. package/out/src/storage/schema/tables/TableTxLabelMap.js.map +1 -0
  166. package/out/src/storage/schema/tables/{User.d.ts → TableUser.d.ts} +1 -1
  167. package/out/src/storage/schema/tables/TableUser.d.ts.map +1 -0
  168. package/out/src/storage/schema/tables/{SyncState.js → TableUser.js} +1 -1
  169. package/out/src/storage/schema/tables/TableUser.js.map +1 -0
  170. package/out/src/storage/schema/tables/index.d.ts +15 -15
  171. package/out/src/storage/schema/tables/index.d.ts.map +1 -1
  172. package/out/src/storage/schema/tables/index.js +15 -15
  173. package/out/src/storage/schema/tables/index.js.map +1 -1
  174. package/out/test/Wallet/local/localWallet2.man.test.js +4 -0
  175. package/out/test/Wallet/local/localWallet2.man.test.js.map +1 -1
  176. package/out/test/Wallet/support/operations.man.test.d.ts +2 -0
  177. package/out/test/Wallet/support/operations.man.test.d.ts.map +1 -0
  178. package/out/test/Wallet/support/{opers1.man.test.js → operations.man.test.js} +41 -6
  179. package/out/test/Wallet/support/operations.man.test.js.map +1 -0
  180. package/out/test/storage/find.test.js +1 -1
  181. package/out/test/storage/find.test.js.map +1 -1
  182. package/out/test/storage/idb/allocateChange.test.d.ts +2 -0
  183. package/out/test/storage/idb/allocateChange.test.d.ts.map +1 -0
  184. package/out/test/storage/idb/allocateChange.test.js +110 -0
  185. package/out/test/storage/idb/allocateChange.test.js.map +1 -0
  186. package/out/test/storage/idb/count.test.d.ts +2 -0
  187. package/out/test/storage/idb/count.test.d.ts.map +1 -0
  188. package/out/test/storage/idb/count.test.js +129 -0
  189. package/out/test/storage/idb/count.test.js.map +1 -0
  190. package/out/test/storage/idb/find.test.d.ts +2 -0
  191. package/out/test/storage/idb/find.test.d.ts.map +1 -0
  192. package/out/test/storage/idb/find.test.js +131 -0
  193. package/out/test/storage/idb/find.test.js.map +1 -0
  194. package/out/test/storage/idb/idbSpeed.test.d.ts +2 -0
  195. package/out/test/storage/idb/idbSpeed.test.d.ts.map +1 -0
  196. package/out/test/storage/idb/idbSpeed.test.js +29 -0
  197. package/out/test/storage/idb/idbSpeed.test.js.map +1 -0
  198. package/out/test/storage/idb/insert.test.d.ts +2 -0
  199. package/out/test/storage/idb/insert.test.d.ts.map +1 -0
  200. package/out/test/storage/idb/insert.test.js +242 -0
  201. package/out/test/storage/idb/insert.test.js.map +1 -0
  202. package/out/test/storage/idb/transactionAbort.test.d.ts +2 -0
  203. package/out/test/storage/idb/transactionAbort.test.d.ts.map +1 -0
  204. package/out/test/storage/idb/transactionAbort.test.js +97 -0
  205. package/out/test/storage/idb/transactionAbort.test.js.map +1 -0
  206. package/out/test/storage/idb/update.test.d.ts +2 -0
  207. package/out/test/storage/idb/update.test.d.ts.map +1 -0
  208. package/out/test/storage/idb/update.test.js +902 -0
  209. package/out/test/storage/idb/update.test.js.map +1 -0
  210. package/out/test/storage/update.test.js +2 -2
  211. package/out/test/storage/update.test.js.map +1 -1
  212. package/out/test/utils/TestUtilsWalletStorage.d.ts +24 -1
  213. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
  214. package/out/test/utils/TestUtilsWalletStorage.js +147 -3
  215. package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
  216. package/out/test/wallet/list/listActions.test.d.ts +1 -1
  217. package/out/test/wallet/list/listActions.test.d.ts.map +1 -1
  218. package/out/test/wallet/list/listActions.test.js +9 -3
  219. package/out/test/wallet/list/listActions.test.js.map +1 -1
  220. package/out/test/wallet/list/listOutputs.test.d.ts +1 -1
  221. package/out/test/wallet/list/listOutputs.test.d.ts.map +1 -1
  222. package/out/test/wallet/list/listOutputs.test.js +34 -219
  223. package/out/test/wallet/list/listOutputs.test.js.map +1 -1
  224. package/out/tsconfig.all.tsbuildinfo +1 -1
  225. package/package.json +3 -1
  226. package/src/CWIStyleWalletManager.ts +12 -5
  227. package/src/Setup.ts +1 -71
  228. package/src/SetupClient.ts +312 -0
  229. package/src/SetupWallet.ts +105 -0
  230. package/src/index.all.ts +2 -0
  231. package/src/index.client.ts +1 -0
  232. package/src/monitor/Monitor.ts +4 -0
  233. package/src/monitor/MonitorDaemon.ts +0 -1
  234. package/src/monitor/tasks/TaskUnFail.ts +3 -4
  235. package/src/sdk/WalletServices.interfaces.ts +10 -0
  236. package/src/services/Services.ts +13 -1
  237. package/src/services/__tests/postBeef.test.ts +1 -1
  238. package/src/storage/StorageIdb.ts +2298 -0
  239. package/src/storage/StorageKnex.ts +7 -32
  240. package/src/storage/StorageProvider.ts +28 -0
  241. package/src/storage/StorageReader.ts +5 -1
  242. package/src/storage/__test/StorageIdb.test.ts +15 -0
  243. package/src/storage/methods/ListActionsSpecOp.ts +68 -0
  244. package/src/storage/methods/ListOutputsSpecOp.ts +125 -0
  245. package/src/storage/methods/listActionsIdb.ts +181 -0
  246. package/src/storage/methods/{listActions.ts → listActionsKnex.ts} +2 -64
  247. package/src/storage/methods/listOutputsIdb.ts +199 -0
  248. package/src/storage/methods/{listOutputs.ts → listOutputsKnex.ts} +9 -133
  249. package/src/storage/methods/purgeDataIdb.ts +15 -0
  250. package/src/storage/methods/reviewStatus.ts +11 -0
  251. package/src/storage/methods/reviewStatusIdb.ts +43 -0
  252. package/src/storage/schema/StorageIdbSchema.ts +150 -0
  253. package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +2 -0
  254. package/src/storage/schema/tables/TableSettings.ts +1 -1
  255. package/src/storage/schema/tables/index.ts +15 -15
  256. package/test/Wallet/local/localWallet2.man.test.ts +5 -0
  257. package/test/Wallet/support/{opers1.man.test.ts → operations.man.test.ts} +43 -14
  258. package/test/storage/find.test.ts +1 -1
  259. package/test/storage/idb/allocateChange.test.ts +251 -0
  260. package/test/storage/idb/count.test.ts +158 -0
  261. package/test/storage/idb/find.test.ts +177 -0
  262. package/test/storage/idb/idbSpeed.test.ts +34 -0
  263. package/test/storage/idb/insert.test.ts +268 -0
  264. package/test/storage/idb/transactionAbort.test.ts +108 -0
  265. package/test/storage/idb/update.test.ts +1000 -0
  266. package/test/storage/update.test.ts +2 -2
  267. package/test/utils/TestUtilsWalletStorage.ts +188 -4
  268. package/test/wallet/list/listActions.test.ts +15 -5
  269. package/test/wallet/list/listOutputs.test.ts +29 -214
  270. package/out/src/storage/methods/listActions.d.ts.map +0 -1
  271. package/out/src/storage/methods/listActions.js.map +0 -1
  272. package/out/src/storage/methods/listOutputs.d.ts.map +0 -1
  273. package/out/src/storage/methods/listOutputs.js.map +0 -1
  274. package/out/src/storage/schema/tables/Certificate.d.ts.map +0 -1
  275. package/out/src/storage/schema/tables/Certificate.js.map +0 -1
  276. package/out/src/storage/schema/tables/CertificateField.d.ts.map +0 -1
  277. package/out/src/storage/schema/tables/CertificateField.js.map +0 -1
  278. package/out/src/storage/schema/tables/Commission.d.ts.map +0 -1
  279. package/out/src/storage/schema/tables/Commission.js.map +0 -1
  280. package/out/src/storage/schema/tables/MonitorEvent.d.ts.map +0 -1
  281. package/out/src/storage/schema/tables/MonitorEvent.js.map +0 -1
  282. package/out/src/storage/schema/tables/Output.d.ts.map +0 -1
  283. package/out/src/storage/schema/tables/Output.js.map +0 -1
  284. package/out/src/storage/schema/tables/OutputBasket.d.ts.map +0 -1
  285. package/out/src/storage/schema/tables/OutputBasket.js.map +0 -1
  286. package/out/src/storage/schema/tables/OutputTag.d.ts.map +0 -1
  287. package/out/src/storage/schema/tables/OutputTag.js +0 -3
  288. package/out/src/storage/schema/tables/OutputTag.js.map +0 -1
  289. package/out/src/storage/schema/tables/OutputTagMap.d.ts.map +0 -1
  290. package/out/src/storage/schema/tables/OutputTagMap.js +0 -3
  291. package/out/src/storage/schema/tables/OutputTagMap.js.map +0 -1
  292. package/out/src/storage/schema/tables/ProvenTx.d.ts.map +0 -1
  293. package/out/src/storage/schema/tables/ProvenTx.js +0 -3
  294. package/out/src/storage/schema/tables/ProvenTx.js.map +0 -1
  295. package/out/src/storage/schema/tables/ProvenTxReq.d.ts.map +0 -1
  296. package/out/src/storage/schema/tables/ProvenTxReq.js +0 -3
  297. package/out/src/storage/schema/tables/ProvenTxReq.js.map +0 -1
  298. package/out/src/storage/schema/tables/SyncState.d.ts.map +0 -1
  299. package/out/src/storage/schema/tables/SyncState.js.map +0 -1
  300. package/out/src/storage/schema/tables/Transaction.d.ts.map +0 -1
  301. package/out/src/storage/schema/tables/Transaction.js.map +0 -1
  302. package/out/src/storage/schema/tables/TxLabel.d.ts.map +0 -1
  303. package/out/src/storage/schema/tables/TxLabel.js +0 -3
  304. package/out/src/storage/schema/tables/TxLabel.js.map +0 -1
  305. package/out/src/storage/schema/tables/TxLabelMap.d.ts.map +0 -1
  306. package/out/src/storage/schema/tables/TxLabelMap.js +0 -3
  307. package/out/src/storage/schema/tables/TxLabelMap.js.map +0 -1
  308. package/out/src/storage/schema/tables/User.d.ts.map +0 -1
  309. package/out/src/storage/schema/tables/User.js +0 -3
  310. package/out/src/storage/schema/tables/User.js.map +0 -1
  311. package/out/test/Wallet/support/opers1.man.test.d.ts +0 -2
  312. package/out/test/Wallet/support/opers1.man.test.d.ts.map +0 -1
  313. package/out/test/Wallet/support/opers1.man.test.js.map +0 -1
  314. package/unlock-migrations.sh +0 -41
  315. /package/src/storage/schema/tables/{Certificate.ts → TableCertificate.ts} +0 -0
  316. /package/src/storage/schema/tables/{CertificateField.ts → TableCertificateField.ts} +0 -0
  317. /package/src/storage/schema/tables/{Commission.ts → TableCommission.ts} +0 -0
  318. /package/src/storage/schema/tables/{MonitorEvent.ts → TableMonitorEvent.ts} +0 -0
  319. /package/src/storage/schema/tables/{Output.ts → TableOutput.ts} +0 -0
  320. /package/src/storage/schema/tables/{OutputBasket.ts → TableOutputBasket.ts} +0 -0
  321. /package/src/storage/schema/tables/{OutputTag.ts → TableOutputTag.ts} +0 -0
  322. /package/src/storage/schema/tables/{OutputTagMap.ts → TableOutputTagMap.ts} +0 -0
  323. /package/src/storage/schema/tables/{ProvenTx.ts → TableProvenTx.ts} +0 -0
  324. /package/src/storage/schema/tables/{ProvenTxReq.ts → TableProvenTxReq.ts} +0 -0
  325. /package/src/storage/schema/tables/{SyncState.ts → TableSyncState.ts} +0 -0
  326. /package/src/storage/schema/tables/{Transaction.ts → TableTransaction.ts} +0 -0
  327. /package/src/storage/schema/tables/{TxLabel.ts → TableTxLabel.ts} +0 -0
  328. /package/src/storage/schema/tables/{TxLabelMap.ts → TableTxLabelMap.ts} +0 -0
  329. /package/src/storage/schema/tables/{User.ts → TableUser.ts} +0 -0
@@ -0,0 +1,902 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const TestUtilsWalletStorage_1 = require("../../utils/TestUtilsWalletStorage");
4
+ const index_client_1 = require("../../../src/index.client");
5
+ const TestUtilsWalletStorage_2 = require("../../utils/TestUtilsWalletStorage");
6
+ const StorageIdb_1 = require("../../../src/storage/StorageIdb");
7
+ require("fake-indexeddb/auto");
8
+ (0, TestUtilsWalletStorage_2.setLogging)(false);
9
+ describe('update tests', () => {
10
+ jest.setTimeout(99999999);
11
+ const chain = 'test';
12
+ const env = TestUtilsWalletStorage_1._tu.getEnv(chain);
13
+ let setups = [];
14
+ beforeEach(async () => {
15
+ const options = index_client_1.StorageProvider.createStorageBaseOptions(chain);
16
+ const storage = new StorageIdb_1.StorageIdb(options);
17
+ await storage.dropAllData();
18
+ await storage.migrate('idb update tests', '1'.repeat(64));
19
+ await storage.makeAvailable();
20
+ const setup = await TestUtilsWalletStorage_1._tu.createTestSetup1(storage);
21
+ setups = [{ setup, storage }];
22
+ });
23
+ afterEach(async () => {
24
+ for (const { storage } of setups) {
25
+ await storage.destroy();
26
+ }
27
+ });
28
+ test('0_update ProvenTx', async () => {
29
+ for (const { storage } of setups) {
30
+ const records = await storage.findProvenTxs({ partial: {} });
31
+ const time = new Date('2001-01-02T12:00:00.000Z');
32
+ for (const record of records) {
33
+ await storage.updateProvenTx(record.provenTxId, {
34
+ blockHash: 'fred',
35
+ updated_at: time
36
+ });
37
+ const t = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
38
+ partial: { provenTxId: record.provenTxId }
39
+ }));
40
+ expect(t.provenTxId).toBe(record.provenTxId);
41
+ expect(t.blockHash).toBe('fred');
42
+ expect(t.updated_at.getTime()).toBe(time.getTime());
43
+ }
44
+ }
45
+ });
46
+ test('1_update ProvenTx', async () => {
47
+ const primaryKey = 'provenTxId';
48
+ for (const { storage } of setups) {
49
+ const referenceTime = new Date();
50
+ const records = await storage.findProvenTxs({ partial: {} });
51
+ for (const record of records) {
52
+ try {
53
+ const testValues = {
54
+ provenTxId: record.provenTxId,
55
+ txid: 'mockTxid',
56
+ created_at: new Date('2024-12-30T23:00:00Z'),
57
+ updated_at: new Date('2024-12-30T23:05:00Z'),
58
+ blockHash: 'mockBlockHash',
59
+ height: 12345,
60
+ index: 1,
61
+ merklePath: [1, 2, 3, 4],
62
+ merkleRoot: '1234',
63
+ rawTx: [4, 3, 2, 1]
64
+ };
65
+ await (0, TestUtilsWalletStorage_2.updateTable)(storage.updateProvenTx.bind(storage), record[primaryKey], testValues);
66
+ const updatedTx = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
67
+ partial: { [primaryKey]: record[primaryKey] }
68
+ }));
69
+ (0, TestUtilsWalletStorage_2.verifyValues)(updatedTx, testValues, referenceTime);
70
+ for (const [key, value] of Object.entries(testValues)) {
71
+ if (key === primaryKey) {
72
+ continue;
73
+ }
74
+ if (typeof value === 'string') {
75
+ const validString = `valid${key}`;
76
+ const r1 = await storage.updateProvenTx(record[primaryKey], {
77
+ [key]: validString
78
+ });
79
+ expect(r1).toBe(1);
80
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
81
+ partial: { [primaryKey]: record[primaryKey] }
82
+ }));
83
+ expect(updatedRow[key]).toBe(validString);
84
+ }
85
+ if (typeof value === 'number') {
86
+ const validNumber = value + 1;
87
+ const r1 = await storage.updateProvenTx(record[primaryKey], {
88
+ [key]: validNumber
89
+ });
90
+ expect(r1).toBe(1);
91
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
92
+ partial: { [primaryKey]: record[primaryKey] }
93
+ }));
94
+ expect(updatedRow[key]).toBe(validNumber);
95
+ }
96
+ if (value instanceof Date) {
97
+ const validDate = new Date('2024-12-31T00:00:00Z');
98
+ const r1 = await storage.updateProvenTx(record[primaryKey], {
99
+ [key]: validDate
100
+ });
101
+ expect(r1).toBe(1);
102
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
103
+ partial: { [primaryKey]: record[primaryKey] }
104
+ }));
105
+ expect(new Date(updatedRow[key]).toISOString()).toBe(validDate.toISOString());
106
+ }
107
+ if (Array.isArray(value)) {
108
+ const validArray = value.map(v => v + 1);
109
+ const r1 = await storage.updateProvenTx(record[primaryKey], {
110
+ [key]: validArray
111
+ });
112
+ expect(r1).toBe(1);
113
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findProvenTxs({
114
+ partial: { [primaryKey]: record[primaryKey] }
115
+ }));
116
+ expect(updatedRow[key]).toEqual(validArray);
117
+ }
118
+ }
119
+ }
120
+ catch (error) {
121
+ console.error(`Error updating or verifying ProvenTx record with ${primaryKey}=${record[primaryKey]}:`, error.message);
122
+ throw error;
123
+ }
124
+ }
125
+ }
126
+ });
127
+ test('2_update ProvenTxReq', async () => {
128
+ const primaryKey = 'provenTxReqId';
129
+ for (const { storage } of setups) {
130
+ const records = await storage.findProvenTxReqs({ partial: {} });
131
+ for (const record of records) {
132
+ try {
133
+ const testValues = {
134
+ provenTxReqId: record.provenTxReqId,
135
+ provenTxId: 1,
136
+ batch: `batch-001`,
137
+ status: 'completed',
138
+ txid: `mockTxid-${Date.now()}`,
139
+ created_at: new Date('2024-12-30T23:00:00Z'),
140
+ updated_at: new Date('2024-12-30T23:05:00Z'),
141
+ attempts: 3,
142
+ history: JSON.stringify({ validated: true, timestamp: Date.now() }),
143
+ inputBEEF: [5, 6, 7, 8],
144
+ notified: true,
145
+ notify: JSON.stringify({ email: 'test@example.com', sent: true }),
146
+ rawTx: [1, 2, 3, 4]
147
+ };
148
+ const r1 = await storage.updateProvenTxReq(record[primaryKey], testValues);
149
+ expect(r1).toBe(1);
150
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findProvenTxReqs({
151
+ partial: { [primaryKey]: record[primaryKey] }
152
+ }));
153
+ for (const [key, value] of Object.entries(testValues)) {
154
+ const actualValue = updatedRow[key];
155
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
156
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
157
+ if (normalizedActual && normalizedExpected) {
158
+ expect(normalizedActual).toBe(normalizedExpected);
159
+ continue;
160
+ }
161
+ if (typeof value === 'string' && value.startsWith('{') && value.endsWith('}')) {
162
+ expect(JSON.parse(actualValue)).toStrictEqual(JSON.parse(value));
163
+ continue;
164
+ }
165
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
166
+ expect(actualValue).toBe(value);
167
+ continue;
168
+ }
169
+ if (typeof actualValue === 'object' && (actualValue === null || actualValue === void 0 ? void 0 : actualValue.type) === 'Buffer') {
170
+ const actualArray = actualValue.data || actualValue;
171
+ const expectedArray = Buffer.isBuffer(value) || Array.isArray(value) ? Array.from(value) : value;
172
+ expect(actualArray).toStrictEqual(expectedArray);
173
+ continue;
174
+ }
175
+ expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value));
176
+ }
177
+ }
178
+ catch (error) {
179
+ console.error(`Error updating or verifying ProvenTxReq record with ${primaryKey}=${record[primaryKey]}:`, error.message);
180
+ throw error;
181
+ }
182
+ }
183
+ }
184
+ });
185
+ test('3_update User', async () => {
186
+ const primaryKey = 'userId';
187
+ for (const { storage } of setups) {
188
+ const records = await storage.findUsers({ partial: {} });
189
+ for (const record of records) {
190
+ try {
191
+ const testValues = {
192
+ userId: record.userId,
193
+ identityKey: `mockUpdatedIdentityKey-${record[primaryKey]}`,
194
+ created_at: new Date('2024-12-30T23:00:00Z'),
195
+ updated_at: new Date('2024-12-30T23:05:00Z'),
196
+ activeStorage: storage.getSettings().storageIdentityKey
197
+ };
198
+ const updateResult = await storage.updateUser(record[primaryKey], testValues);
199
+ expect(updateResult).toBe(1);
200
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findUsers({
201
+ partial: { [primaryKey]: record[primaryKey] }
202
+ }));
203
+ for (const [key, value] of Object.entries(testValues)) {
204
+ const actualValue = updatedRow[key];
205
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
206
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
207
+ if (normalizedActual && normalizedExpected) {
208
+ expect(normalizedActual).toBe(normalizedExpected);
209
+ continue;
210
+ }
211
+ expect(actualValue).toBe(value);
212
+ }
213
+ }
214
+ catch (error) {
215
+ console.error(`Error updating or verifying User record with ${primaryKey}=${record[primaryKey]}:`, error.message);
216
+ throw error;
217
+ }
218
+ }
219
+ }
220
+ });
221
+ test('4_update Certificate', async () => {
222
+ for (const { storage } of setups) {
223
+ const primaryKey = 'certificateId';
224
+ const records = await storage.findCertificates({ partial: {} });
225
+ for (const record of records) {
226
+ try {
227
+ const testValues = {
228
+ certificateId: record.certificateId,
229
+ userId: 1,
230
+ certifier: `mockCertifier${record.certificateId}`,
231
+ serialNumber: `mockSerialNumber${record.certificateId}`,
232
+ type: `mockType${record.certificateId}`,
233
+ created_at: new Date('2024-12-30T23:00:00Z'),
234
+ updated_at: new Date('2024-12-30T23:05:00Z'),
235
+ isDeleted: false,
236
+ revocationOutpoint: 'mockRevocationOutpoint',
237
+ signature: 'mockSignature',
238
+ subject: 'mockSubject'
239
+ };
240
+ const r1 = await storage.updateCertificate(record[primaryKey], testValues);
241
+ expect(r1).toBe(1);
242
+ const updatedRow = (0, index_client_1.verifyOne)(await storage.findCertificates({
243
+ partial: { [primaryKey]: record[primaryKey] }
244
+ }));
245
+ for (const [key, value] of Object.entries(testValues)) {
246
+ const actualValue = updatedRow[key];
247
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
248
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
249
+ if (normalizedActual && normalizedExpected) {
250
+ expect(normalizedActual).toBe(normalizedExpected);
251
+ continue;
252
+ }
253
+ if (typeof value === 'string' && value.startsWith('{') && value.endsWith('}')) {
254
+ expect(JSON.parse(actualValue)).toStrictEqual(JSON.parse(value));
255
+ continue;
256
+ }
257
+ if (typeof actualValue === 'boolean') {
258
+ if (value === 1 || value) {
259
+ expect(actualValue).toBe(true);
260
+ }
261
+ else if (value === 0 || value === false) {
262
+ expect(actualValue).toBe(false);
263
+ }
264
+ else {
265
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
266
+ }
267
+ continue;
268
+ }
269
+ if (typeof value === 'string' || typeof value === 'number') {
270
+ expect(actualValue).toBe(value);
271
+ continue;
272
+ }
273
+ if (typeof actualValue === 'object' && (actualValue === null || actualValue === void 0 ? void 0 : actualValue.type) === 'Buffer') {
274
+ const actualArray = actualValue.data || actualValue;
275
+ const expectedArray = Buffer.isBuffer(value) || Array.isArray(value) ? Array.from(value) : value;
276
+ expect(actualArray).toStrictEqual(expectedArray);
277
+ continue;
278
+ }
279
+ expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value));
280
+ }
281
+ }
282
+ catch (error) {
283
+ console.error(`Error updating or verifying Certificate record with ${primaryKey}=${record[primaryKey]}:`, error.message);
284
+ throw error;
285
+ }
286
+ }
287
+ }
288
+ });
289
+ test('5_update CertificateField', async () => {
290
+ var _a;
291
+ const primaryKey = 'certificateId';
292
+ for (const { storage } of setups) {
293
+ const records = await storage.findCertificateFields({
294
+ partial: { fieldName: 'bob' }
295
+ });
296
+ for (const record of records) {
297
+ try {
298
+ const testValues = {
299
+ certificateId: record.certificateId,
300
+ userId: (_a = record.userId) !== null && _a !== void 0 ? _a : 1,
301
+ created_at: new Date('2024-12-30T23:00:00Z'),
302
+ updated_at: new Date('2024-12-30T23:05:00Z'),
303
+ fieldName: record.fieldName || 'defaultFieldName',
304
+ fieldValue: 'your uncle',
305
+ masterKey: 'key'
306
+ };
307
+ const updateResult = await storage.updateCertificateField(record.certificateId, testValues.fieldName, testValues);
308
+ expect(updateResult).toBe(1);
309
+ const updatedRecords = await storage.findCertificateFields({
310
+ partial: {
311
+ certificateId: record.certificateId,
312
+ fieldName: testValues.fieldName
313
+ }
314
+ });
315
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated CertificateField with certificateId=${record.certificateId}, fieldName=${testValues.fieldName} was not unique or missing.`);
316
+ for (const [key, value] of Object.entries(testValues)) {
317
+ const actualValue = updatedRow[key];
318
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
319
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
320
+ if (normalizedActual && normalizedExpected) {
321
+ expect(normalizedActual).toBe(normalizedExpected);
322
+ continue;
323
+ }
324
+ expect(actualValue).toBe(value);
325
+ }
326
+ }
327
+ catch (error) {
328
+ console.error(`Error updating or verifying CertificateField record with certificateId=${record[primaryKey]}:`, error.message);
329
+ throw error;
330
+ }
331
+ }
332
+ }
333
+ });
334
+ test('6_update OutputBasket', async () => {
335
+ var _a;
336
+ const primaryKey = 'basketId';
337
+ for (const { storage } of setups) {
338
+ const records = await storage.findOutputBaskets({ partial: {} });
339
+ for (const record of records) {
340
+ try {
341
+ const testValues = {
342
+ basketId: record.basketId,
343
+ userId: (_a = record.userId) !== null && _a !== void 0 ? _a : 1,
344
+ created_at: new Date('2024-12-30T23:00:00Z'),
345
+ updated_at: new Date('2024-12-30T23:05:00Z'),
346
+ name: record.name || 'defaultName',
347
+ numberOfDesiredUTXOs: 99,
348
+ minimumDesiredUTXOValue: 5000,
349
+ isDeleted: false
350
+ };
351
+ const updateResult = await storage.updateOutputBasket(record.basketId, testValues);
352
+ expect(updateResult).toBe(1);
353
+ const updatedRecords = await storage.findOutputBaskets({
354
+ partial: { basketId: record.basketId, name: testValues.name }
355
+ });
356
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated OutputBasket with basketId=${record.basketId}, name=${testValues.name} was not unique or missing.`);
357
+ for (const [key, value] of Object.entries(testValues)) {
358
+ const actualValue = updatedRow[key];
359
+ if (typeof actualValue === 'boolean') {
360
+ if (value === 1 || value === true) {
361
+ expect(actualValue).toBe(true);
362
+ }
363
+ else if (value === 0 || value === false) {
364
+ expect(actualValue).toBe(false);
365
+ }
366
+ else {
367
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
368
+ }
369
+ continue;
370
+ }
371
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
372
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
373
+ if (normalizedActual && normalizedExpected) {
374
+ expect(normalizedActual).toBe(normalizedExpected);
375
+ continue;
376
+ }
377
+ expect(actualValue).toBe(value);
378
+ }
379
+ }
380
+ catch (error) {
381
+ console.error(`Error updating or verifying OutputBasket record with basketId=${record[primaryKey]}:`, error.message);
382
+ throw error;
383
+ }
384
+ }
385
+ }
386
+ });
387
+ test('7_update Transaction', async () => {
388
+ var _a;
389
+ const primaryKey = 'transactionId';
390
+ for (const { storage } of setups) {
391
+ const records = await storage.findTransactions({ partial: {} });
392
+ for (const record of records) {
393
+ try {
394
+ const testValues = {
395
+ transactionId: record.transactionId,
396
+ userId: (_a = record.userId) !== null && _a !== void 0 ? _a : 1,
397
+ provenTxId: 1,
398
+ reference: `updated_reference_string_${record.transactionId}==`,
399
+ status: 'confirmed',
400
+ txid: `updated_txid_example_${record.transactionId}`,
401
+ created_at: new Date('2024-12-30T23:00:00Z'),
402
+ updated_at: new Date('2024-12-30T23:05:00Z'),
403
+ description: 'Updated transaction description',
404
+ isOutgoing: false,
405
+ lockTime: 600000000,
406
+ satoshis: 20000,
407
+ version: 2
408
+ };
409
+ const updateResult = await storage.updateTransaction(record.transactionId, testValues);
410
+ expect(updateResult).toBe(1);
411
+ const updatedRecords = await storage.findTransactions({
412
+ partial: { transactionId: record.transactionId }
413
+ });
414
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated Transaction with transactionId=${record.transactionId} was not unique or missing.`);
415
+ for (const [key, value] of Object.entries(testValues)) {
416
+ const actualValue = updatedRow[key];
417
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
418
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
419
+ if (normalizedActual && normalizedExpected) {
420
+ expect(normalizedActual).toBe(normalizedExpected);
421
+ continue;
422
+ }
423
+ expect(actualValue).toBe(value);
424
+ }
425
+ }
426
+ catch (error) {
427
+ console.error(`Error updating or verifying Transaction record with transactionId=${record[primaryKey]}:`, error.message);
428
+ throw error;
429
+ }
430
+ }
431
+ }
432
+ });
433
+ test('7a updateTransactionStatus', async () => {
434
+ const { activeStorage: storage } = await TestUtilsWalletStorage_1._tu.createLegacyWalletSQLiteCopy('updateTransactionStatus6a');
435
+ let tx = (0, index_client_1.verifyOne)(await storage.findTransactions({
436
+ partial: { status: 'unproven' },
437
+ paged: { limit: 1 }
438
+ }));
439
+ expect(tx.status).toBe('unproven');
440
+ await storage.updateTransactionStatus('completed', tx.transactionId);
441
+ tx = (0, index_client_1.verifyOne)(await storage.findTransactions({
442
+ partial: { transactionId: tx.transactionId }
443
+ }));
444
+ expect(tx.status).toBe('completed');
445
+ await storage.destroy();
446
+ });
447
+ test('8_update Commission', async () => {
448
+ var _a, _b;
449
+ const primaryKey = 'commissionId';
450
+ for (const { storage } of setups) {
451
+ const records = await storage.findCommissions({ partial: {} });
452
+ for (const record of records) {
453
+ try {
454
+ const testValues = {
455
+ commissionId: record.commissionId,
456
+ userId: (_a = record.userId) !== null && _a !== void 0 ? _a : 1,
457
+ transactionId: (_b = record.transactionId) !== null && _b !== void 0 ? _b : 1,
458
+ created_at: new Date('2024-12-30T23:00:00Z'),
459
+ updated_at: new Date('2024-12-30T23:05:00Z'),
460
+ satoshis: 300,
461
+ keyOffset: `updated_key_offset_${record.commissionId}`,
462
+ isRedeemed: true,
463
+ lockingScript: [1, 2, 3, 4]
464
+ };
465
+ const updateResult = await storage.updateCommission(record.commissionId, testValues);
466
+ expect(updateResult).toBe(1);
467
+ const updatedRecords = await storage.findCommissions({
468
+ partial: { commissionId: record.commissionId }
469
+ });
470
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated Commission with commissionId=${record.commissionId} was not unique or missing.`);
471
+ for (const [key, value] of Object.entries(testValues)) {
472
+ const actualValue = updatedRow[key];
473
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
474
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
475
+ if (normalizedActual && normalizedExpected) {
476
+ expect(normalizedActual).toBe(normalizedExpected);
477
+ continue;
478
+ }
479
+ if (Buffer.isBuffer(actualValue) || Array.isArray(actualValue)) {
480
+ expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value));
481
+ continue;
482
+ }
483
+ expect(actualValue).toBe(value);
484
+ }
485
+ }
486
+ catch (error) {
487
+ console.error(`Error updating or verifying Commission record with commissionId=${record[primaryKey]}:`, error.message);
488
+ throw error;
489
+ }
490
+ }
491
+ }
492
+ });
493
+ test('9_update Output', async () => {
494
+ var _a;
495
+ const primaryKey = 'outputId';
496
+ for (const { storage } of setups) {
497
+ const records = await storage.findOutputs({ partial: {} });
498
+ for (const record of records) {
499
+ if (!record.transactionId)
500
+ record.transactionId = 1;
501
+ if (!record.basketId)
502
+ record.basketId = 1;
503
+ if (!record.userId || !record.transactionId || !record.basketId) {
504
+ throw new Error(`Missing required foreign keys for record ${JSON.stringify(record)}`);
505
+ }
506
+ }
507
+ for (const record of records) {
508
+ const existingRecords = await storage.findOutputs({ partial: {} });
509
+ const usedCombinations = new Set(existingRecords.map(r => `${r.transactionId}-${r.vout}-${r.userId}`));
510
+ let testTransactionId = record.transactionId;
511
+ let testVout = record.vout + 1;
512
+ let testUserId = record.userId;
513
+ while (usedCombinations.has(`${testTransactionId}-${testVout}-${testUserId}`)) {
514
+ testVout += 1;
515
+ }
516
+ try {
517
+ const testValues = {
518
+ outputId: record.outputId,
519
+ basketId: (_a = record.basketId) !== null && _a !== void 0 ? _a : 1,
520
+ transactionId: testTransactionId,
521
+ userId: testUserId,
522
+ vout: testVout,
523
+ created_at: new Date('2024-12-30T23:00:00Z'),
524
+ updated_at: new Date('2024-12-30T23:05:00Z'),
525
+ change: true,
526
+ customInstructions: 'Updated instructions',
527
+ derivationPrefix: 'updated_prefix==',
528
+ derivationSuffix: 'updated_suffix==',
529
+ lockingScript: [0x01, 0x02, 0x03, 0x04],
530
+ providedBy: 'you',
531
+ purpose: 'updated_purpose',
532
+ satoshis: 3000,
533
+ scriptLength: 150,
534
+ scriptOffset: 5,
535
+ senderIdentityKey: 'updated_sender_key',
536
+ sequenceNumber: 10,
537
+ spendingDescription: 'Updated spending description',
538
+ spendable: false,
539
+ spentBy: 3,
540
+ txid: 'updated_txid',
541
+ type: 'updated_type',
542
+ outputDescription: 'outputDescription'
543
+ };
544
+ const updateResult = await storage.updateOutput(record.outputId, testValues);
545
+ expect(updateResult).toBe(1);
546
+ const updatedRecords = await storage.findOutputs({
547
+ partial: { outputId: record.outputId }
548
+ });
549
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated Output with outputId=${record.outputId} was not unique or missing.`);
550
+ for (const [key, value] of Object.entries(testValues)) {
551
+ const actualValue = updatedRow[key];
552
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
553
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
554
+ if (normalizedActual && normalizedExpected) {
555
+ expect(normalizedActual).toBe(normalizedExpected);
556
+ continue;
557
+ }
558
+ if (Buffer.isBuffer(actualValue) || Array.isArray(actualValue)) {
559
+ expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value));
560
+ continue;
561
+ }
562
+ expect(actualValue).toBe(value);
563
+ }
564
+ }
565
+ catch (error) {
566
+ console.error(`Error updating or verifying Output record with outputId=${record[primaryKey]}:`, error.message);
567
+ throw error;
568
+ }
569
+ }
570
+ }
571
+ });
572
+ test('10_update OutputTag', async () => {
573
+ const primaryKey = 'outputTagId';
574
+ for (const { storage } of setups) {
575
+ const records = await storage.findOutputTags({ partial: {} });
576
+ for (const record of records) {
577
+ if (!record.userId)
578
+ record.userId = 1;
579
+ if (!record.tag)
580
+ record.tag = `default_tag_${record.outputTagId}`;
581
+ if (!record.userId || !record.tag) {
582
+ throw new Error(`Missing required fields for record ${JSON.stringify(record)}`);
583
+ }
584
+ }
585
+ for (const record of records) {
586
+ const uniqueTag = `updated_tag_${record.outputTagId}`;
587
+ const testValues = {
588
+ outputTagId: record.outputTagId,
589
+ userId: record.userId,
590
+ tag: uniqueTag,
591
+ created_at: new Date('2024-12-30T23:00:00Z'),
592
+ updated_at: new Date('2024-12-30T23:05:00Z'),
593
+ isDeleted: false
594
+ };
595
+ try {
596
+ const updateResult = await storage.updateOutputTag(record.outputTagId, testValues);
597
+ expect(updateResult).toBe(1);
598
+ const updatedRecords = await storage.findOutputTags({
599
+ partial: { outputTagId: record.outputTagId }
600
+ });
601
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated OutputTag with outputTagId=${record.outputTagId} was not unique or missing.`);
602
+ for (const [key, value] of Object.entries(testValues)) {
603
+ const actualValue = updatedRow[key];
604
+ if (typeof actualValue === 'boolean') {
605
+ if (value === 1 || value === true) {
606
+ expect(actualValue).toBe(true);
607
+ }
608
+ else if (value === 0 || value === false) {
609
+ expect(actualValue).toBe(false);
610
+ }
611
+ else {
612
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
613
+ }
614
+ continue;
615
+ }
616
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
617
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
618
+ if (normalizedActual && normalizedExpected) {
619
+ expect(normalizedActual).toBe(normalizedExpected);
620
+ continue;
621
+ }
622
+ expect(actualValue).toBe(value);
623
+ }
624
+ }
625
+ catch (error) {
626
+ console.error(`Error updating or verifying OutputTag record with outputTagId=${record[primaryKey]}:`, error.message);
627
+ throw error;
628
+ }
629
+ }
630
+ }
631
+ });
632
+ test('11_update OutputTagMap', async () => {
633
+ const primaryKey = ['outputTagId', 'outputId'];
634
+ for (const { storage } of setups) {
635
+ const records = await storage.findOutputTagMaps({ partial: {} });
636
+ for (const record of records) {
637
+ if (!record.outputTagId)
638
+ throw new Error(`Missing outputTagId for record: ${JSON.stringify(record)}`);
639
+ if (!record.outputId)
640
+ throw new Error(`Missing outputId for record: ${JSON.stringify(record)}`);
641
+ try {
642
+ const testValues = {
643
+ outputTagId: record.outputTagId,
644
+ outputId: record.outputId,
645
+ created_at: new Date('2024-12-30T23:00:00Z'),
646
+ updated_at: new Date('2024-12-30T23:05:00Z'),
647
+ isDeleted: false
648
+ };
649
+ const updateResult = await storage.updateOutputTagMap(record.outputId, record.outputTagId, testValues);
650
+ expect(updateResult).toBe(1);
651
+ const updatedRecords = await storage.findOutputTagMaps({
652
+ partial: {
653
+ outputTagId: record.outputTagId,
654
+ outputId: record.outputId
655
+ }
656
+ });
657
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated OutputTagMap with outputTagId=${record.outputTagId} and outputId=${record.outputId} was not unique or missing.`);
658
+ for (const [key, value] of Object.entries(testValues)) {
659
+ const actualValue = updatedRow[key];
660
+ if (typeof actualValue === 'boolean') {
661
+ if (value === 1 || value === true) {
662
+ expect(actualValue).toBe(true);
663
+ }
664
+ else if (value === 0 || value === false) {
665
+ expect(actualValue).toBe(false);
666
+ }
667
+ else {
668
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
669
+ }
670
+ continue;
671
+ }
672
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
673
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
674
+ if (normalizedActual && normalizedExpected) {
675
+ expect(normalizedActual).toBe(normalizedExpected);
676
+ continue;
677
+ }
678
+ expect(actualValue).toBe(value);
679
+ }
680
+ }
681
+ catch (error) {
682
+ console.error(`Error updating or verifying OutputTagMap record with outputTagId=${record.outputTagId} and outputId=${record.outputId}:`, error.message);
683
+ throw error;
684
+ }
685
+ }
686
+ }
687
+ });
688
+ test('12_update TxLabel', async () => {
689
+ const primaryKey = 'txLabelId';
690
+ for (const { storage } of setups) {
691
+ const records = await storage.findTxLabels({ partial: {} });
692
+ for (const record of records) {
693
+ if (!record.userId) {
694
+ throw new Error(`Missing required foreign key userId for record ${JSON.stringify(record)}`);
695
+ }
696
+ }
697
+ for (const record of records) {
698
+ const uniqueLabel = `unique_label_${record.txLabelId}`;
699
+ const testValues = {
700
+ txLabelId: record.txLabelId,
701
+ userId: record.userId,
702
+ label: uniqueLabel,
703
+ isDeleted: false,
704
+ created_at: new Date('2024-12-30T23:00:00Z'),
705
+ updated_at: new Date('2024-12-30T23:05:00Z')
706
+ };
707
+ const existingLabel = await storage.findTxLabels({
708
+ partial: { label: testValues.label, userId: testValues.userId }
709
+ });
710
+ if (existingLabel.length > 0) {
711
+ continue;
712
+ }
713
+ const updateResult = await storage.updateTxLabel(record.txLabelId, testValues);
714
+ expect(updateResult).toBe(1);
715
+ const updatedRecords = await storage.findTxLabels({
716
+ partial: { txLabelId: record.txLabelId }
717
+ });
718
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated TxLabel with txLabelId=${record.txLabelId} was not unique or missing.`);
719
+ for (const [key, value] of Object.entries(testValues)) {
720
+ const actualValue = updatedRow[key];
721
+ if (typeof actualValue === 'boolean') {
722
+ if (value === 1 || value === true) {
723
+ expect(actualValue).toBe(true);
724
+ }
725
+ else if (value === 0 || value === false) {
726
+ expect(actualValue).toBe(false);
727
+ }
728
+ else {
729
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
730
+ }
731
+ continue;
732
+ }
733
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
734
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
735
+ if (normalizedActual && normalizedExpected) {
736
+ expect(normalizedActual).toBe(normalizedExpected);
737
+ continue;
738
+ }
739
+ expect(actualValue).toBe(value);
740
+ }
741
+ }
742
+ }
743
+ });
744
+ test('13_update TxLabelMap', async () => {
745
+ const primaryKeyTransaction = 'transactionId';
746
+ const primaryKeyLabel = 'txLabelId';
747
+ for (const { storage, setup } of setups) {
748
+ const records = await storage.findTxLabelMaps({ partial: {} });
749
+ for (const record of records) {
750
+ if (!record.transactionId || !record.txLabelId) {
751
+ throw new Error(`Missing required foreign keys for record ${JSON.stringify(record)}`);
752
+ }
753
+ }
754
+ for (const record of records) {
755
+ const testValues = {
756
+ transactionId: record.transactionId,
757
+ txLabelId: record.txLabelId,
758
+ created_at: new Date('2024-12-30T23:00:00Z'),
759
+ updated_at: new Date('2024-12-30T23:05:00Z'),
760
+ isDeleted: false
761
+ };
762
+ const existingRecord = await storage.findTxLabelMaps({
763
+ partial: {
764
+ transactionId: testValues.transactionId,
765
+ txLabelId: testValues.txLabelId
766
+ }
767
+ });
768
+ if (existingRecord.length > 0) {
769
+ continue;
770
+ }
771
+ try {
772
+ const updateResult = await storage.updateTxLabelMap(record.transactionId, record.txLabelId, testValues);
773
+ expect(updateResult).toBe(1);
774
+ const updatedRecords = await storage.findTxLabelMaps({
775
+ partial: {
776
+ transactionId: record.transactionId,
777
+ txLabelId: record.txLabelId
778
+ }
779
+ });
780
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated TxLabelMap with transactionId=${record[primaryKeyTransaction]} and txLabelId=${record[primaryKeyLabel]} was not unique or missing.`);
781
+ for (const [key, value] of Object.entries(testValues)) {
782
+ const actualValue = updatedRow[key];
783
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
784
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
785
+ if (normalizedActual && normalizedExpected) {
786
+ expect(normalizedActual).toBe(normalizedExpected);
787
+ continue;
788
+ }
789
+ expect(actualValue).toBe(value);
790
+ }
791
+ }
792
+ catch (error) {
793
+ console.error(`Error updating or verifying TxLabelMap record with transactionId=${record[primaryKeyTransaction]} and txLabelId=${record[primaryKeyLabel]}:`, error.message);
794
+ throw error;
795
+ }
796
+ }
797
+ }
798
+ });
799
+ test('14_update MonitorEvent', async () => {
800
+ const primaryKey = 'id';
801
+ for (const { storage, setup } of setups) {
802
+ const records = await storage.findMonitorEvents({ partial: {} });
803
+ for (const record of records) {
804
+ try {
805
+ const testValues = {
806
+ id: record.id,
807
+ created_at: new Date('2024-12-30T23:00:00Z'),
808
+ updated_at: new Date('2024-12-30T23:05:00Z'),
809
+ event: 'updated_event',
810
+ details: 'Updated details'
811
+ };
812
+ const updateResult = await storage.updateMonitorEvent(record.id, testValues);
813
+ expect(updateResult).toBe(1);
814
+ const updatedRecords = await storage.findMonitorEvents({
815
+ partial: { id: record.id }
816
+ });
817
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated MonitorEvent with id=${record.id} was not unique or missing.`);
818
+ for (const [key, value] of Object.entries(testValues)) {
819
+ const actualValue = updatedRow[key];
820
+ const normalizedActual = (0, TestUtilsWalletStorage_2.normalizeDate)(actualValue);
821
+ const normalizedExpected = (0, TestUtilsWalletStorage_2.normalizeDate)(value);
822
+ if (normalizedActual && normalizedExpected) {
823
+ expect(normalizedActual).toBe(normalizedExpected);
824
+ continue;
825
+ }
826
+ expect(actualValue).toBe(value);
827
+ }
828
+ }
829
+ catch (error) {
830
+ console.error(`Error updating or verifying MonitorEvent record with id=${record[primaryKey]}:`, error.message);
831
+ throw error;
832
+ }
833
+ }
834
+ }
835
+ });
836
+ test('15_update SyncState', async () => {
837
+ const primaryKey = 'syncStateId';
838
+ for (const { storage } of setups) {
839
+ const records = await storage.findSyncStates({ partial: {} });
840
+ for (const record of records) {
841
+ if (!record.userId) {
842
+ throw new Error(`Missing required foreign key userId for record ${JSON.stringify(record)}`);
843
+ }
844
+ }
845
+ for (const record of records) {
846
+ const testValues = {
847
+ syncStateId: record.syncStateId,
848
+ userId: record.userId,
849
+ refNum: 'test_refNum',
850
+ created_at: new Date('2025-01-01T00:00:00.000Z'),
851
+ updated_at: new Date('2025-01-01T00:00:00.000Z'),
852
+ errorLocal: 'Example local error',
853
+ errorOther: 'Example other error',
854
+ init: false,
855
+ satoshis: 1000,
856
+ status: 'success',
857
+ storageIdentityKey: 'test_identity_key',
858
+ storageName: 'test_storage',
859
+ syncMap: '{}',
860
+ when: new Date('2025-01-01T02:00:00.000Z')
861
+ };
862
+ const updateResult = await storage.updateSyncState(record.syncStateId, testValues);
863
+ expect(updateResult).toBe(1);
864
+ const updatedRecords = await storage.findSyncStates({
865
+ partial: { syncStateId: record.syncStateId }
866
+ });
867
+ const updatedRow = (0, index_client_1.verifyOne)(updatedRecords, `Updated SyncState with syncStateId=${record.syncStateId} was not unique or missing.`);
868
+ for (const [key, value] of Object.entries(testValues)) {
869
+ const actualValue = updatedRow[key];
870
+ if (typeof actualValue === 'boolean') {
871
+ if (value === 1 || value === true) {
872
+ expect(actualValue).toBe(true);
873
+ }
874
+ else if (value === 0 || value === false) {
875
+ expect(actualValue).toBe(false);
876
+ }
877
+ else {
878
+ throw new Error(`Unexpected value for expectedValue: ${value}. Must be 0 or 1.`);
879
+ }
880
+ continue;
881
+ }
882
+ if (typeof actualValue === 'object' && actualValue.constructor.name === 'Date') {
883
+ const actualDate = new Date(actualValue);
884
+ const expectedDate = new Date(value);
885
+ expect(actualDate.getTime()).toBe(expectedDate.getTime());
886
+ continue;
887
+ }
888
+ if (value === undefined || value === null) {
889
+ expect(actualValue).toBeNull();
890
+ continue;
891
+ }
892
+ if (key === 'refNum') {
893
+ expect(actualValue).toBe('test_refNum');
894
+ continue;
895
+ }
896
+ expect(actualValue).toStrictEqual(value);
897
+ }
898
+ }
899
+ }
900
+ });
901
+ });
902
+ //# sourceMappingURL=update.test.js.map