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