trac-msb 0.2.7 → 0.2.9

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 (187) hide show
  1. package/.github/workflows/publish.yml +8 -16
  2. package/msb.mjs +13 -25
  3. package/package.json +8 -4
  4. package/proto/network.proto +74 -0
  5. package/rpc/{create_server.mjs → create_server.js} +4 -4
  6. package/rpc/{handlers.mjs → handlers.js} +7 -7
  7. package/rpc/routes/{index.mjs → index.js} +1 -1
  8. package/rpc/routes/{v1.mjs → v1.js} +1 -1
  9. package/rpc/rpc_server.js +10 -0
  10. package/rpc/rpc_services.js +48 -7
  11. package/rpc/utils/{helpers.mjs → helpers.js} +1 -1
  12. package/src/config/config.js +137 -0
  13. package/src/config/env.js +63 -0
  14. package/src/core/network/Network.js +133 -119
  15. package/src/core/network/identity/NetworkWalletFactory.js +5 -6
  16. package/src/core/network/protocols/LegacyProtocol.js +67 -0
  17. package/src/core/network/protocols/NetworkMessages.js +48 -0
  18. package/src/core/network/protocols/ProtocolInterface.js +31 -0
  19. package/src/core/network/protocols/ProtocolSession.js +59 -0
  20. package/src/core/network/protocols/V1Protocol.js +64 -0
  21. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
  22. package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
  23. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  24. package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +2 -2
  25. package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +13 -6
  26. package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
  27. package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
  28. package/src/core/network/protocols/shared/handlers/TransferOperationHandler.js +57 -0
  29. package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +21 -26
  30. package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +3 -3
  31. package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +15 -12
  32. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +10 -11
  33. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +10 -7
  34. package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +40 -22
  35. package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
  36. package/src/core/network/services/ConnectionManager.js +13 -19
  37. package/src/core/network/services/MessageOrchestrator.js +10 -22
  38. package/src/core/network/services/TransactionPoolService.js +10 -10
  39. package/src/core/network/services/TransactionRateLimiterService.js +5 -3
  40. package/src/core/network/services/ValidatorObserverService.js +46 -21
  41. package/src/core/state/State.js +137 -141
  42. package/src/core/state/utils/address.js +18 -16
  43. package/src/core/state/utils/adminEntry.js +17 -16
  44. package/src/core/state/utils/deploymentEntry.js +15 -15
  45. package/src/core/state/utils/transaction.js +3 -95
  46. package/src/index.js +250 -325
  47. package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
  48. package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
  49. package/src/messages/network/v1/networkMessageFactory.js +12 -0
  50. package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
  51. package/src/messages/state/ApplyStateMessageDirector.js +516 -0
  52. package/src/messages/state/applyStateMessageFactory.js +12 -0
  53. package/src/utils/buffer.js +53 -1
  54. package/src/utils/check.js +21 -17
  55. package/src/utils/cli.js +0 -8
  56. package/src/utils/cliCommands.js +11 -11
  57. package/src/utils/constants.js +36 -24
  58. package/src/utils/fileUtils.js +1 -4
  59. package/src/utils/helpers.js +9 -20
  60. package/src/utils/migrationUtils.js +2 -2
  61. package/src/utils/normalizers.js +94 -11
  62. package/src/utils/protobuf/network.cjs +840 -0
  63. package/src/utils/protobuf/operationHelpers.js +10 -0
  64. package/tests/acceptance/v1/account/account.test.mjs +2 -2
  65. package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
  66. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
  67. package/tests/acceptance/v1/rpc.test.mjs +10 -10
  68. package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
  69. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
  70. package/tests/fixtures/check.fixtures.js +42 -42
  71. package/tests/fixtures/networkV1.fixtures.js +84 -0
  72. package/tests/fixtures/protobuf.fixtures.js +110 -26
  73. package/tests/helpers/StateNetworkFactory.js +3 -5
  74. package/tests/helpers/autobaseTestHelpers.js +1 -2
  75. package/tests/helpers/config.js +3 -0
  76. package/tests/helpers/setupApplyTests.js +113 -99
  77. package/tests/helpers/transactionPayloads.mjs +26 -12
  78. package/tests/unit/messages/messages.test.js +12 -0
  79. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
  80. package/tests/unit/messages/network/NetworkMessageDirector.test.js +203 -0
  81. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
  82. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
  83. package/tests/unit/network/ConnectionManager.test.js +10 -7
  84. package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
  85. package/tests/unit/network/networkModule.test.js +3 -2
  86. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
  87. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +11 -8
  88. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +11 -7
  89. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -20
  90. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +57 -48
  91. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
  92. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +72 -57
  93. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
  94. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +12 -14
  95. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +18 -13
  96. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
  97. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
  98. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +27 -30
  99. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
  100. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +24 -21
  101. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
  102. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
  103. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
  104. package/tests/unit/state/apply/common/commonScenarioHelper.js +16 -16
  105. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +10 -5
  106. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
  107. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
  108. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
  109. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
  110. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
  111. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +16 -9
  112. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
  113. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +23 -19
  114. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +45 -36
  115. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +48 -45
  116. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +32 -29
  117. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
  118. package/tests/unit/state/stateModule.test.js +0 -1
  119. package/tests/unit/state/stateTestUtils.js +7 -3
  120. package/tests/unit/state/utils/address.test.js +3 -3
  121. package/tests/unit/state/utils/adminEntry.test.js +10 -9
  122. package/tests/unit/unit.test.js +1 -1
  123. package/tests/unit/utils/buffer/buffer.test.js +62 -1
  124. package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
  125. package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
  126. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
  127. package/tests/unit/utils/check/common.test.js +7 -6
  128. package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
  129. package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
  130. package/tests/unit/utils/check/transactionOperation.test.js +3 -3
  131. package/tests/unit/utils/check/transferOperation.test.js +3 -3
  132. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
  133. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
  134. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
  135. package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
  136. package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
  137. package/tests/unit/utils/utils.test.js +0 -1
  138. package/rpc/rpc_server.mjs +0 -10
  139. package/src/core/network/messaging/NetworkMessages.js +0 -63
  140. package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -112
  141. package/src/core/network/messaging/handlers/ResponseHandler.js +0 -108
  142. package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -116
  143. package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -143
  144. package/src/core/network/messaging/handlers/TransferOperationHandler.js +0 -52
  145. package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -94
  146. package/src/core/network/messaging/validators/AdminResponse.js +0 -58
  147. package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
  148. package/src/core/state/utils/indexerEntry.js +0 -105
  149. package/src/messages/base/StateBuilder.js +0 -25
  150. package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -421
  151. package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
  152. package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -299
  153. package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
  154. package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
  155. package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -131
  156. package/src/utils/crypto.js +0 -11
  157. package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -68
  158. package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -125
  159. package/tests/integration/apply/addIndexer.test.js +0 -237
  160. package/tests/integration/apply/addWhitelist.test.js +0 -53
  161. package/tests/integration/apply/addWriter.test.js +0 -244
  162. package/tests/integration/apply/apply.test.js +0 -19
  163. package/tests/integration/apply/banValidator.test.js +0 -109
  164. package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
  165. package/tests/integration/apply/postTx/postTx.test.js +0 -222
  166. package/tests/integration/apply/removeIndexer.test.js +0 -128
  167. package/tests/integration/apply/removeWriter.test.js +0 -167
  168. package/tests/integration/apply/transfer.test.js +0 -81
  169. package/tests/integration/integration.test.js +0 -9
  170. package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
  171. package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -16
  172. package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -69
  173. package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -16
  174. package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -442
  175. package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
  176. package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
  177. package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -58
  178. package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -277
  179. package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
  180. package/tests/unit/state/utils/indexerEntry.test.js +0 -83
  181. package/tests/unit/state/utils/transaction.test.js +0 -97
  182. package/tests/unit/utils/crypto/createHash.test.js +0 -15
  183. /package/rpc/{constants.mjs → constants.js} +0 -0
  184. /package/rpc/{cors.mjs → cors.js} +0 -0
  185. /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
  186. /package/rpc/utils/{url.mjs → url.js} +0 -0
  187. /package/src/utils/{operations.js → applyOperations.js} +0 -0
@@ -1,277 +0,0 @@
1
- import b4a from 'b4a';
2
- import {OperationType} from "../../src/utils/constants.js";
3
- import {bufferToAddress, isAddressValid} from "../../src/core/state/utils/address.js";
4
- import {errorMessageIncludes} from "../utils/regexHelper.js"
5
-
6
- export async function messageOperationsEkoTest(t, fnName, assembler, wallet, writingKey, opType, msgValueLength, expectedMessageAddress) {
7
- console.log('address:', expectedMessageAddress)
8
- t.test(`${fnName} - Happy Path`, async (k) => {
9
- const msg = await assembler(wallet, writingKey);
10
- k.ok(msg, 'Message should be created');
11
- k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
12
- k.is(Object.keys(msg.eko).length, msgValueLength, `Message value should have ${msgValueLength} keys`);
13
-
14
- k.is(msg.type, opType, `Message type should be ${opType}`);
15
-
16
- if (msg.type === OperationType.ADD_WRITER || msg.type === OperationType.REMOVE_WRITER || msg.type === OperationType.ADD_ADMIN) {
17
- k.ok(b4a.equals(msg.eko.wk, writingKey), 'Message wk should be the writing key');
18
- }
19
-
20
- k.ok(bufferToAddress(msg.address) === expectedMessageAddress, 'Message key should be the the expected one');
21
- k.ok(isAddressValid(msg.address), 'Message address should be a valid address');
22
-
23
- k.is(msg.eko.nonce.length, 32, 'Message nonce should be 32 bytes long');
24
- k.ok(b4a.isBuffer(msg.eko.nonce), 'Message nonce should be a buffer');
25
- k.is(msg.eko.sig.length, 64, 'Message signature should be 64 bytes long');
26
- k.ok(b4a.isBuffer(msg.eko.sig), 'Message signature should be a buffer');
27
- });
28
-
29
- t.test(`${fnName} - Invalid wallet - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
30
- const wallet = {
31
- address: 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką'
32
- }
33
- await k.exception(
34
- async () => await assembler(wallet, writingKey),
35
- errorMessageIncludes('Wallet should have a valid TRAC address')
36
- );
37
- });
38
-
39
- t.test(`${fnName} - Invalid wallet instance - trac address is to short`, async (k) => {
40
- const wallet = {
41
- address: 'trac1y6kkq48fgu3ur'
42
- }
43
- await k.exception(
44
- async () => await assembler(wallet, writingKey),
45
- errorMessageIncludes('Wallet should have a valid TRAC address')
46
- );
47
- });
48
-
49
- t.test(`${fnName} - Invalid wallet instance - invalid prefix`, async (k) => {
50
- const wallet = {
51
- address: 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk'
52
- }
53
- await k.exception(
54
- async () => await assembler(wallet, writingKey),
55
- errorMessageIncludes('Wallet should have a valid TRAC address')
56
- );
57
- });
58
-
59
- t.test(`${fnName} - Invalid wallet instance - empty string`, async (k) => {
60
- const wallet = {
61
- address: ''
62
- }
63
- await k.exception(
64
- async () => await assembler(wallet, writingKey),
65
- errorMessageIncludes('Wallet should have a valid TRAC address')
66
- );
67
- });
68
-
69
- t.test(`${fnName} - Invalid wallet instance - null Wallet `, async (k) => {
70
- await k.exception(
71
- async () => await assembler(null, writingKey),
72
- errorMessageIncludes('Wallet must be a valid wallet object')
73
- );
74
- });
75
-
76
- t.test(`${fnName} - Invalid wallet instance - undefined Wallet`, async (k) => {
77
- await k.exception(
78
- async () => await assembler(undefined, writingKey),
79
- errorMessageIncludes('Wallet must be a valid wallet object')
80
- );
81
- });
82
- //
83
- // //TODO: fix - works on node, but not on bare.
84
- //
85
- //
86
- // t.test(`${fnName} - Invalid writing key - not hex`, async (k) => {
87
- // try {
88
- // const invalidHexKey = b4a.from("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdeg", 'hex');
89
- // await k.exception(
90
- // async () => await assembler(wallet, invalidHexKey),
91
- // errorMessageIncludes('Writer key must be a 32 length buffer')
92
- // );
93
- // } catch (error) {
94
- // k.pass('Invalid hex string was rejected');
95
- // }
96
- // });
97
-
98
-
99
- t.test(`${fnName} - Invalid writing key - invalid length`, async (k) => {
100
- await k.exception(
101
- async () => await assembler(
102
- wallet,
103
- b4a.from("1234567890a", 'hex')
104
- ),
105
- errorMessageIncludes('Writer key must be a 32 length buffer')
106
- );
107
- });
108
-
109
-
110
- t.test(`${fnName} - Invalid writing key - empty buffer`, async (k) => {
111
- await k.exception(
112
- async () => await assembler(
113
- wallet,
114
- b4a.alloc(0)
115
- ),
116
- errorMessageIncludes('Writer key must be a 32 length buffer')
117
- );
118
- });
119
-
120
- t.test(`${fnName} - Null writing key`, async (k) => {
121
- await k.exception(
122
- async () => await assembler(
123
- wallet,
124
- null
125
- ),
126
- errorMessageIncludes('Writer key must be a 32 length buffer')
127
- );
128
- });
129
-
130
-
131
- t.test(`${fnName} - undefined writing key`, async (k) => {
132
- await k.exception(
133
- async () => await assembler(
134
- wallet,
135
- undefined
136
- ),
137
- errorMessageIncludes('Writer key must be a 32 length buffer')
138
- );
139
- });
140
-
141
- }
142
-
143
- export async function messageOperationsBkoTest(t, fnName, assembler, wallet, writingKey, opType, msgValueLength, expectedMessageAddress) {
144
-
145
- t.test(`${fnName} - Happy Path`, async (k) => {
146
- const msg = await assembler(wallet, expectedMessageAddress);
147
-
148
- k.ok(msg, 'Message should be created');
149
- k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
150
- k.is(Object.keys(msg.bko).length, msgValueLength, `Message value should have ${msgValueLength} keys`);
151
-
152
-
153
- k.is(msg.type, opType, `Message type should be ${opType}`);
154
-
155
- k.ok(bufferToAddress(msg.address) === expectedMessageAddress, 'Message address should be the the expected one');
156
- k.is(msg.bko.nonce.length, 32, 'Message nonce should be 32 bytes long');
157
- k.ok(b4a.isBuffer(msg.bko.nonce), 'Message nonce should be a buffer');
158
- k.is(msg.bko.sig.length, 64, 'Message signature should be 64 bytes long');
159
- k.ok(b4a.isBuffer(msg.bko.sig), 'Message signature should be a buffer');
160
- });
161
-
162
- t.test(`${fnName} - Invalid wallet instance - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
163
- const invalidWallet = {
164
- address: 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką'
165
- }
166
-
167
- await k.exception(
168
- async () => await assembler(invalidWallet, expectedMessageAddress),
169
- errorMessageIncludes('Wallet should have a valid TRAC address')
170
- );
171
- });
172
-
173
- t.test(`${fnName} - Invalid wallet instance - trac address is to short`, async (k) => {
174
- const wallet = {
175
- address: 'trac1y6kkq48fgu3ur'
176
- }
177
- await k.exception(
178
- async () => await assembler(wallet, expectedMessageAddress),
179
- errorMessageIncludes('Wallet should have a valid TRAC address')
180
- );
181
- });
182
-
183
- t.test(`${fnName} - Invalid wallet instance - invalid prefix`, async (k) => {
184
- const wallet = {
185
- address: 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk'
186
- }
187
- await k.exception(
188
- async () => await assembler(wallet, expectedMessageAddress),
189
- errorMessageIncludes('Wallet should have a valid TRAC address')
190
- );
191
- });
192
-
193
-
194
- t.test(`${fnName} - Invalid wallet instance - empty string`, async (k) => {
195
- const wallet = {
196
- address: ''
197
- }
198
- await k.exception(
199
- async () => await assembler(wallet, expectedMessageAddress),
200
- errorMessageIncludes('Wallet should have a valid TRAC address')
201
- );
202
- });
203
-
204
- t.test(`${fnName} - Invalid wallet instance - Null Wallet`, async (k) => {
205
- await k.exception(
206
- async () => await assembler(null, expectedMessageAddress),
207
- errorMessageIncludes('Wallet must be a valid wallet object')
208
- );
209
- });
210
-
211
- t.test(`${fnName} - Invalid wallet instance - undefined Wallet`, async (k) => {
212
- await k.exception(
213
- async () => await assembler(undefined, expectedMessageAddress),
214
- errorMessageIncludes('Wallet must be a valid wallet object')
215
- );
216
- });
217
-
218
- t.test(`${fnName} - Address parameter - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
219
-
220
- const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
221
-
222
- await k.exception(
223
- async () => await assembler(wallet, invalid),
224
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
225
- );
226
- });
227
-
228
- t.test(`${fnName} - Address parameter - trac address is to short`, async (k) => {
229
- const invalid = 'trac1y6kkq48fgu3ur';
230
-
231
- await k.exception(
232
- async () => await assembler(wallet, invalid),
233
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
234
- );
235
- });
236
-
237
- t.test(`${fnName} - Address parameter - invalid prefix`, async (k) => {
238
- const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
239
-
240
- await k.exception(
241
- async () => await assembler(wallet, invalid),
242
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
243
- );
244
- });
245
-
246
-
247
- t.test(`${fnName} - Address parameter - empty string`, async (k) => {
248
- const invalid = '';
249
-
250
- await k.exception(
251
- async () => await assembler(wallet, invalid),
252
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
253
- );
254
- });
255
-
256
- t.test(`${fnName} - Address parameter - Null`, async (k) => {
257
-
258
- await k.exception(
259
- async () => await assembler(wallet, null),
260
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
261
- );
262
- });
263
-
264
- t.test(`${fnName} - Address parameter - undefined`, async (k) => {
265
- await k.exception(
266
- async () => await assembler(wallet, undefined),
267
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
268
- );
269
- });
270
-
271
- t.test(`${fnName} - Address parameter - address is the same as wallet address`, async (k) => {
272
- await k.exception(
273
- async () => await assembler(wallet, wallet.address),
274
- errorMessageIncludes('Address must not be the same as the wallet address for basic operations')
275
- );
276
- });
277
- }
@@ -1,19 +0,0 @@
1
- import { default as test } from 'brittle';
2
-
3
- async function runMsgUtilsTests() {
4
- test.pause();
5
- await import('./assembleAdminMessage.test.js');
6
- await import('./assembleAddWriterMessage.test.js');
7
- await import('./assembleRemoveWriterMessage.test.js');
8
- await import('./assembleAddIndexerMessage.test.js');
9
- await import('./assembleRemoveIndexerMessage.test.js');
10
- await import('./assembleBanWriterMessage.test.js');
11
- await import('./assembleWhitelistMessages.test.js');
12
- await import('./assembleWhitelistMessages.test.js');
13
- await import('./assemblePostTransaction.test.js');
14
-
15
- // TODO: Implement mocked tests for MessageOperations.verifyEventMessage
16
- test.resume();
17
- }
18
-
19
- await runMsgUtilsTests();
@@ -1,83 +0,0 @@
1
- import { test } from 'brittle';
2
- import b4a from 'b4a';
3
- import { TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
4
- import { randomBuffer } from '../stateTestUtils.js';
5
- import indexerEntryUtils, { append } from '../../../../src/core/state/utils/indexerEntry.js';
6
-
7
- const appendIndexer = indexerEntryUtils.append;
8
- const removeIndexer = indexerEntryUtils.remove;
9
-
10
- // Test append()
11
- test('Indexer Entry - Append creates new entry if none exists', t => {
12
- const addr = randomBuffer(TRAC_ADDRESS_SIZE);
13
- const entry = appendIndexer(addr, null);
14
- t.is(entry[0], 1, 'count should be 1');
15
- t.ok(b4a.equals(entry.subarray(1), addr), 'address should match');
16
- });
17
-
18
- test('Indexer Entry - Append to existing entry', t => {
19
- const addr1 = randomBuffer(TRAC_ADDRESS_SIZE);
20
- const addr2 = randomBuffer(TRAC_ADDRESS_SIZE);
21
- let entry = appendIndexer(addr1, null);
22
- entry = appendIndexer(addr2, entry);
23
- t.is(entry[0], 2, 'count should be 2');
24
- t.ok(b4a.equals(entry.subarray(1, 1 + TRAC_ADDRESS_SIZE), addr1), 'first address matches');
25
- t.ok(b4a.equals(entry.subarray(1 + TRAC_ADDRESS_SIZE), addr2), 'second address matches');
26
- });
27
-
28
- test('Indexer Entry - Append returns empty buffer if address is invalid', t => {
29
- const addr = b4a.alloc(5); // invalid size
30
- const entry = appendIndexer(addr, null);
31
- t.ok(b4a.equals(entry, b4a.alloc(0)), 'should return empty buffer if address is invalid');
32
- });
33
-
34
- // Test remove()
35
- test('Indexer Entry - Removes address from entry', t => {
36
- const addr1 = randomBuffer(TRAC_ADDRESS_SIZE);
37
- const addr2 = randomBuffer(TRAC_ADDRESS_SIZE);
38
- let entry = appendIndexer(addr1, null);
39
- entry = appendIndexer(addr2, entry);
40
-
41
- const updated = removeIndexer(addr1, entry);
42
- t.is(updated[0], 1, 'count should be 1 after removal');
43
- t.ok(b4a.equals(updated.subarray(1), addr2), 'remaining address should be addr2');
44
- });
45
-
46
- test('Indexer Entry - Remove returns empty buffer if address not found', t => {
47
- const addr1 = randomBuffer(TRAC_ADDRESS_SIZE);
48
- const addr2 = randomBuffer(TRAC_ADDRESS_SIZE);
49
- const addr3 = randomBuffer(TRAC_ADDRESS_SIZE);
50
- let entry = appendIndexer(addr1, null);
51
- entry = appendIndexer(addr2, entry);
52
-
53
- const updated = removeIndexer(addr3, entry);
54
- t.ok(b4a.equals(updated, b4a.alloc(0)), 'entry should be empty if address not found');
55
- });
56
-
57
- test('Indexer Entry - Remove returns empty buffer on invalid entry', t => {
58
- const addr = randomBuffer(TRAC_ADDRESS_SIZE);
59
- const invalidEntry = b4a.alloc(5); // too short
60
- const updated = removeIndexer(addr, invalidEntry);
61
- t.ok(b4a.equals(updated, b4a.alloc(0)), 'should return empty buffer if invalid');
62
- });
63
-
64
- test('Indexer Entry - Remove returns empty buffer on invalid address', t => {
65
- const addr1 = randomBuffer(TRAC_ADDRESS_SIZE);
66
- let entry = appendIndexer(addr1, null);
67
- const invalidAddr = b4a.alloc(5);
68
- const updated = removeIndexer(invalidAddr, entry);
69
- t.ok(b4a.equals(updated, b4a.alloc(0)), 'should return empty buffer if address invalid');
70
- });
71
-
72
- test('Indexer Entry - Remove doesn\'t throw an error when count is bigger than the number of indexers', t => {
73
- const addr1 = randomBuffer(TRAC_ADDRESS_SIZE);
74
- const addr2 = randomBuffer(TRAC_ADDRESS_SIZE);
75
- const addr3 = randomBuffer(TRAC_ADDRESS_SIZE);
76
- let entry = appendIndexer(addr1, null);
77
- entry = appendIndexer(addr2, entry);
78
-
79
- // Remove an indexer and set the count to a higher value
80
- entry[0] = 3;
81
- const updated = removeIndexer(addr3, entry);
82
- t.ok(b4a.equals(updated, b4a.alloc(0)), 'entry should be unchanged if count is too high');
83
- });
@@ -1,97 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
- import transaction from '../../../src/core/state/utils/transaction.js';
4
-
5
- const { generateTxBuffer, TRANSACTION_TOTAL_SIZE, generateBootstrapDeploymentTxBuffer, BOOTSTRAP_DEPLOYMENT_SIZE } = transaction;
6
- import { OperationType, BOOTSTRAP_BYTE_LENGTH, NONCE_BYTE_LENGTH } from '../../../src/utils/constants.js';
7
-
8
- function buf(size, fill = 0) {
9
- return b4a.alloc(size, fill);
10
- }
11
-
12
- test('generateTxBuffer returns a 32-byte hash for valid input', async t => {
13
- const bootstrap = buf(8, 0x01);
14
- const msb_bootstrap = buf(8, 0x02);
15
- const validator_address = buf(20, 0x03);
16
- const local_writer_key = buf(32, 0x04);
17
- const local_address = buf(20, 0x05);
18
- const content_hash = buf(32, 0x06);
19
- const nonce = buf(8, 0x07);
20
-
21
- const total = bootstrap.length + msb_bootstrap.length + validator_address.length + local_writer_key.length + local_address.length + content_hash.length + nonce.length;
22
- t.is(total, TRANSACTION_TOTAL_SIZE, 'sum of buffer sizes matches TRANSACTION_TOTAL_SIZE');
23
-
24
- const hash = await generateTxBuffer(bootstrap, msb_bootstrap, validator_address, local_writer_key, local_address, content_hash, nonce);
25
- t.ok(b4a.isBuffer(hash));
26
- t.is(hash.length, 32, 'hash should be 32 bytes (sha256)');
27
- });
28
-
29
- test('generateTxBuffer returns empty buffer on error', async t => {
30
- const bootstrap = buf(1, 0x01); // too small
31
- const msb_bootstrap = buf(8, 0x02);
32
- const validator_address = buf(20, 0x03);
33
- const local_writer_key = buf(32, 0x04);
34
- const local_address = buf(20, 0x05);
35
- const content_hash = buf(32, 0x06);
36
- const nonce = buf(8, 0x07);
37
-
38
- const hash = await generateTxBuffer(bootstrap, msb_bootstrap, validator_address, local_writer_key, local_address, content_hash, nonce);
39
- t.ok(b4a.isBuffer(hash));
40
- t.is(hash.length, 0, 'should return empty buffer on error');
41
- });
42
-
43
- test('generateBootstrapDeploymentTxBuffer returns a 32-byte hash for valid input', async t => {
44
- const bootstrap = buf(BOOTSTRAP_BYTE_LENGTH, 0x01);
45
- const incoming_nonce = buf(NONCE_BYTE_LENGTH, 0x02);
46
- const opType = OperationType.BOOTSTRAP_DEPLOYMENT;
47
-
48
- const hash = await generateBootstrapDeploymentTxBuffer(bootstrap, incoming_nonce, opType);
49
- t.ok(b4a.isBuffer(hash));
50
- t.is(hash.length, 32, 'hash should be 32 bytes (sha256)');
51
- });
52
-
53
- test('generateBootstrapDeploymentTxBuffer returns empty buffer on error (bad bootstrap size)', async t => {
54
- const bootstrap = buf(1, 0x01); // too small
55
- const incoming_nonce = buf(NONCE_BYTE_LENGTH, 0x02);
56
- const opType = OperationType.BOOTSTRAP_DEPLOYMENT;
57
-
58
- const hash = await generateBootstrapDeploymentTxBuffer(bootstrap, incoming_nonce, opType);
59
- t.ok(b4a.isBuffer(hash));
60
- t.is(hash.length, 0, 'should return empty buffer on error');
61
- });
62
-
63
- test('generateBootstrapDeploymentTxBuffer returns empty buffer on error (bad nonce size)', async t => {
64
- const bootstrap = buf(BOOTSTRAP_BYTE_LENGTH, 0x01);
65
- const incoming_nonce = buf(1, 0x02); // too small
66
- const opType = OperationType.BOOTSTRAP_DEPLOYMENT;
67
-
68
- const hash = await generateBootstrapDeploymentTxBuffer(bootstrap, incoming_nonce, opType);
69
- t.ok(b4a.isBuffer(hash));
70
- t.is(hash.length, 0, 'should return empty buffer on error');
71
- });
72
-
73
- test('generateBootstrapDeploymentTxBuffer returns empty buffer on error (bad opType buffer)', async t => {
74
- const bootstrap = buf(BOOTSTRAP_BYTE_LENGTH, 0x01);
75
- const incoming_nonce = buf(NONCE_BYTE_LENGTH, 0x02);
76
- // simulate opTypeBuffer of wrong size by passing undefined (should fail internally)
77
- const hash = await generateBootstrapDeploymentTxBuffer(bootstrap, incoming_nonce, undefined);
78
- t.ok(b4a.isBuffer(hash));
79
- t.is(hash.length, 0, 'should return empty buffer on error');
80
- });
81
-
82
- test('generateBootstrapDeploymentTxBuffer output buffer size is correct before hashing', async t => {
83
- const bootstrap = buf(BOOTSTRAP_BYTE_LENGTH, 0x01);
84
- const incoming_nonce = buf(NONCE_BYTE_LENGTH, 0x02);
85
- const opType = OperationType.BOOTSTRAP_DEPLOYMENT;
86
-
87
- const opTypeBuffer = b4a.alloc(4);
88
- opTypeBuffer.writeUInt32BE(opType, 0);
89
- const tx = b4a.alloc(BOOTSTRAP_DEPLOYMENT_SIZE);
90
- let offset = 0;
91
- bootstrap.copy(tx, offset);
92
- offset += bootstrap.length;
93
- incoming_nonce.copy(tx, offset);
94
- offset += incoming_nonce.length;
95
- opTypeBuffer.copy(tx, offset);
96
- t.is(tx.length, BOOTSTRAP_DEPLOYMENT_SIZE, 'buffer size should match BOOTSTRAP_DEPLOYMENT_SIZE');
97
- });
@@ -1,15 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
- import { blake3Hash} from '../../../../src/utils/crypto.js';
4
-
5
- test('blake3', async (t) => {
6
- t.test('blake3Hash', async (k) => {
7
- const hash = await blake3Hash('test');
8
- const expectedResult = b4a.from("4878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215", 'hex');
9
- k.ok(b4a.isBuffer(hash), 'Hash should be a buffer');
10
- k.ok(hash.length === 32, 'Hash should be 32 bytes long');
11
- k.ok(hash.equals(expectedResult), 'Hash result should be the expected one');
12
- k.ok(hash.equals(await blake3Hash('test')), 'Hash should be the same for the same input');
13
- k.ok(!hash.equals(await blake3Hash('Test')), 'Hash should be different for different inputs');
14
- });
15
- });
File without changes
File without changes
File without changes
File without changes