trac-msb 0.2.8 → 0.2.10

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 (151) hide show
  1. package/.github/workflows/acceptance-tests.yml +7 -11
  2. package/.github/workflows/lint-pr-title.yml +26 -0
  3. package/.github/workflows/unit-tests.yml +2 -8
  4. package/CODE_OF_CONDUCT.md +128 -0
  5. package/README.md +33 -18
  6. package/docker-compose.yml +1 -0
  7. package/docs/trac_network_http_api.openapi.yaml +889 -0
  8. package/msb.mjs +5 -22
  9. package/package.json +14 -10
  10. package/proto/network.proto +74 -0
  11. package/rpc/create_server.js +2 -2
  12. package/rpc/handlers.js +165 -92
  13. package/rpc/routes/v1.js +3 -1
  14. package/rpc/rpc_server.js +4 -4
  15. package/rpc/rpc_services.js +62 -25
  16. package/rpc/utils/helpers.js +83 -52
  17. package/src/config/args.js +46 -0
  18. package/src/config/config.js +78 -5
  19. package/src/config/env.js +70 -3
  20. package/src/core/network/Network.js +34 -70
  21. package/src/core/network/identity/NetworkWalletFactory.js +2 -2
  22. package/src/core/network/protocols/LegacyProtocol.js +67 -0
  23. package/src/core/network/protocols/NetworkMessages.js +48 -0
  24. package/src/core/network/protocols/ProtocolInterface.js +31 -0
  25. package/src/core/network/protocols/ProtocolSession.js +59 -0
  26. package/src/core/network/protocols/V1Protocol.js +64 -0
  27. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
  28. package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
  29. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  30. package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +2 -3
  31. package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
  32. package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
  33. package/src/core/network/{messaging → protocols/shared}/handlers/TransferOperationHandler.js +17 -16
  34. package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +10 -15
  35. package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +2 -2
  36. package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +5 -5
  37. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +4 -4
  38. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +4 -4
  39. package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +14 -12
  40. package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
  41. package/src/core/network/services/ConnectionManager.js +5 -5
  42. package/src/core/network/services/MessageOrchestrator.js +2 -2
  43. package/src/core/network/services/TransactionPoolService.js +5 -6
  44. package/src/core/network/services/TransactionRateLimiterService.js +12 -13
  45. package/src/core/network/services/ValidatorObserverService.js +5 -6
  46. package/src/core/state/State.js +3 -5
  47. package/src/index.js +156 -181
  48. package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
  49. package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
  50. package/src/messages/network/v1/networkMessageFactory.js +12 -0
  51. package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
  52. package/src/messages/state/ApplyStateMessageDirector.js +516 -0
  53. package/src/messages/state/applyStateMessageFactory.js +12 -0
  54. package/src/utils/buffer.js +53 -1
  55. package/src/utils/check.js +1 -1
  56. package/src/utils/cli.js +0 -8
  57. package/src/utils/constants.js +33 -30
  58. package/src/utils/fileUtils.js +13 -0
  59. package/src/utils/normalizers.js +84 -2
  60. package/src/utils/protobuf/network.cjs +840 -0
  61. package/src/utils/protobuf/operationHelpers.js +10 -0
  62. package/src/utils/type.js +26 -0
  63. package/tests/acceptance/v1/balance/balance.test.mjs +1 -2
  64. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +26 -30
  65. package/tests/acceptance/v1/health/health.test.mjs +33 -0
  66. package/tests/acceptance/v1/rpc.test.mjs +4 -3
  67. package/tests/acceptance/v1/tx/tx.test.mjs +27 -16
  68. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +26 -12
  69. package/tests/fixtures/check.fixtures.js +33 -32
  70. package/tests/fixtures/networkV1.fixtures.js +85 -0
  71. package/tests/fixtures/protobuf.fixtures.js +109 -25
  72. package/tests/helpers/StateNetworkFactory.js +2 -2
  73. package/tests/helpers/address.js +6 -0
  74. package/tests/helpers/autobaseTestHelpers.js +2 -1
  75. package/tests/helpers/config.js +2 -1
  76. package/tests/helpers/setupApplyTests.js +59 -56
  77. package/tests/unit/messages/messages.test.js +12 -0
  78. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
  79. package/tests/unit/messages/network/NetworkMessageDirector.test.js +201 -0
  80. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
  81. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
  82. package/tests/unit/network/ConnectionManager.test.js +6 -5
  83. package/tests/unit/network/networkModule.test.js +3 -2
  84. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
  85. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +9 -6
  86. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +10 -7
  87. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -21
  88. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +53 -38
  89. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +46 -35
  90. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +13 -16
  91. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +17 -11
  92. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +11 -12
  93. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +9 -7
  94. package/tests/unit/state/apply/common/commonScenarioHelper.js +15 -14
  95. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +9 -4
  96. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +17 -11
  97. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +19 -14
  98. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +37 -29
  99. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +9 -7
  100. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +11 -9
  101. package/tests/unit/unit.test.js +1 -1
  102. package/tests/unit/utils/buffer/buffer.test.js +62 -1
  103. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +4 -3
  104. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +3 -2
  105. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +3 -2
  106. package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
  107. package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
  108. package/tests/unit/utils/type/type.test.js +25 -0
  109. package/tests/unit/utils/utils.test.js +1 -0
  110. package/docs/networking-dualstack-plan.md +0 -75
  111. package/docs/networking-layer-redesign.md +0 -155
  112. package/src/core/network/messaging/NetworkMessages.js +0 -64
  113. package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -113
  114. package/src/core/network/messaging/handlers/ResponseHandler.js +0 -107
  115. package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -114
  116. package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -149
  117. package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -98
  118. package/src/core/network/messaging/validators/AdminResponse.js +0 -58
  119. package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
  120. package/src/messages/base/StateBuilder.js +0 -25
  121. package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -425
  122. package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
  123. package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -296
  124. package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
  125. package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
  126. package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -138
  127. package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -69
  128. package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -126
  129. package/tests/integration/apply/addIndexer.test.js +0 -239
  130. package/tests/integration/apply/addWhitelist.test.js +0 -53
  131. package/tests/integration/apply/addWriter.test.js +0 -245
  132. package/tests/integration/apply/apply.test.js +0 -19
  133. package/tests/integration/apply/banValidator.test.js +0 -116
  134. package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
  135. package/tests/integration/apply/postTx/postTx.test.js +0 -196
  136. package/tests/integration/apply/removeIndexer.test.js +0 -132
  137. package/tests/integration/apply/removeWriter.test.js +0 -168
  138. package/tests/integration/apply/transfer.test.js +0 -83
  139. package/tests/integration/integration.test.js +0 -9
  140. package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
  141. package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -17
  142. package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -68
  143. package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -17
  144. package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -424
  145. package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
  146. package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
  147. package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -59
  148. package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -278
  149. package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
  150. /package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +0 -0
  151. /package/src/utils/{operations.js → applyOperations.js} +0 -0
@@ -1,68 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
4
- import {default as fixtures} from '../fixtures/assembleMessage.fixtures.js';
5
- import {OperationType} from "../../src/utils/constants.js";
6
- import {bufferToAddress} from "../../src/core/state/utils/address.js";
7
- import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
8
- import {isAddressValid} from "../../src/core/state/utils/address.js";
9
- import {errorMessageIncludes} from "../utils/regexHelper.js";
10
- import { config } from '../../helpers/config.js';
11
-
12
- test('assembleAdminMessage', async (t) => {
13
- await fixtures.initAll();
14
-
15
- const walletAdmin = fixtures.walletAdmin;
16
- const writingKeyAdmin = fixtures.writingKeyAdmin;
17
- const writingKeyNonAdmin = fixtures.writingKeyNonAdmin;
18
-
19
-
20
- t.test('assembleAdminMessage - setup admin', async (k) => {
21
- const msg = safeDecodeApplyOperation(await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(writingKeyAdmin));
22
-
23
- k.ok(msg, 'Message should be created');
24
- k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
25
- k.is(Object.keys(msg.eko).length, 3, 'Message value have 3 keys');
26
- k.is(msg.type, OperationType.ADD_ADMIN, 'Message type should be ADD_ADMIN');
27
- k.is(bufferToAddress(msg.address, config.addressPrefix), walletAdmin.address, 'Message address should be the public key of the wallet');
28
-
29
- k.ok(isAddressValid(msg.address, config.addressPrefix), 'Message address should be a valid address');
30
-
31
- k.ok(b4a.equals(msg.eko.wk, writingKeyAdmin), 'Message wk should be the writing key');
32
- k.is(msg.eko.nonce.length, 32, 'Message nonce should be 32 bytes long');
33
- k.ok(b4a.isBuffer(msg.eko.nonce), 'Message nonce should be a buffer');
34
- k.is(msg.eko.sig.length, 64, 'Message signature should be 64 bytes long')
35
- k.ok(b4a.isBuffer(msg.eko.sig), 'Message signature should be a buffer');
36
- });
37
-
38
- t.test('assembleAdminMessage - admin recovery message', async (k) => {
39
- const msg = safeDecodeApplyOperation(await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(writingKeyNonAdmin));
40
-
41
- k.ok(msg, 'Message should be created');
42
- k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
43
- k.is(Object.keys(msg.eko).length, 3, 'Message value have 3 keys');
44
- k.is(msg.type, OperationType.ADD_ADMIN, 'Message type should be ADD_ADMIN');
45
-
46
- k.is(bufferToAddress(msg.address, config.addressPrefix), walletAdmin.address, 'Message address should be address of the wallet');
47
- k.ok(isAddressValid(msg.address, config.addressPrefix), 'Message address should be a valid address');
48
-
49
- k.ok(b4a.equals(msg.eko.wk, writingKeyNonAdmin), 'Message wk should be the writing key');
50
- k.is(msg.eko.sig.length, 64, 'Message signature should be 64 bytes long')
51
- k.ok(b4a.isBuffer(msg.eko.sig), 'Message signature should be a buffer');
52
-
53
- });
54
-
55
- t.test('assembleAdminMessage - writer key is null', async (k) => {
56
- await k.exception(
57
- async () => await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(null),
58
- errorMessageIncludes('Writer key must be a 32 length buffer')
59
- );
60
- });
61
-
62
- t.test("assembleAdminMessage - admin wallet is null", async (k) => {
63
- await k.exception(
64
- async () => await new CompleteStateMessageOperations(null, config).assembleAddAdminMessage(writingKeyAdmin),
65
- errorMessageIncludes('Wallet must be a valid wallet object')
66
- );
67
- });
68
- });
@@ -1,17 +0,0 @@
1
- import test from 'brittle';
2
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
- import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
4
- import { writingKeyNonAdmin, walletNonAdmin, initAll, walletAdmin } from '../fixtures/assembleMessage.fixtures.js';
5
- import { messageOperationsBkoTest } from './commonsStateMessageOperationsTest.js';
6
- import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
7
- import { config } from '../../helpers/config.js';
8
-
9
- const testName = 'assembleBanWriterMessage';
10
- test(testName, async (t) => {
11
- await initAll();
12
- const assembler = async (wallet,address) => {
13
- return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleBanWriterMessage(address));
14
- }
15
- await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.BAN_VALIDATOR, 2, walletNonAdmin.address);
16
-
17
- });
@@ -1,424 +0,0 @@
1
- import test from 'brittle';
2
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
- import {default as fixtures} from '../fixtures/assembleMessage.fixtures.js';
4
- import {OperationType} from "../../src/utils/constants.js";
5
- import {bufferToAddress} from "../../src/core/state/utils/address.js";
6
- import b4a from 'b4a';
7
- import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
8
- import {isAddressValid} from "../../src/core/state/utils/address.js";
9
- import {errorMessageIncludes} from "../utils/regexHelper.js";
10
- import {randomBytes} from "../../helpers/setupApplyTests.js";
11
- import { config } from '../../helpers/config.js';
12
-
13
- const msgTxoLength = 10;
14
- const opType = OperationType.TX;
15
- test('assemblePostTxMessage - ....', async (k) => {
16
- await fixtures.initAll();
17
- const nonAdminWallet = fixtures.walletNonAdmin;
18
- const peerWallet = fixtures.walletPeer;
19
- const validatorAddress = nonAdminWallet.address;
20
- const txHash = randomBytes(32);
21
- const incomingAddress = peerWallet.address;
22
-
23
- const incomingWriterKey = randomBytes(32);
24
- const incomingNonce = randomBytes(32);
25
- const contentHash = randomBytes(32);
26
- const incomingSignature = randomBytes(64);
27
- const externalBootstrap = randomBytes(32);
28
- const msbBootstrap = randomBytes(32);
29
-
30
- const decodedPostTx = safeDecodeApplyOperation(await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
31
- validatorAddress,
32
- txHash,
33
- incomingAddress,
34
- incomingWriterKey,
35
- incomingNonce,
36
- contentHash,
37
- incomingSignature,
38
- externalBootstrap,
39
- msbBootstrap
40
- ));
41
- k.ok(decodedPostTx, 'Message should be created');
42
- k.is(Object.keys(decodedPostTx).length, 3, 'Message should have 3 keys');
43
- k.is(Object.keys(decodedPostTx.txo).length, msgTxoLength, `Message value should have ${msgTxoLength} keys`);
44
-
45
- k.is(decodedPostTx.type, opType, `Message type should be ${opType}`);
46
-
47
- k.ok(isAddressValid(decodedPostTx.address, config.addressPrefix), 'Message validator address should be a valid address');
48
- k.ok(isAddressValid(decodedPostTx.txo.ia, config.addressPrefix), 'Message incoming address should be a valid address');
49
-
50
- k.ok(bufferToAddress(decodedPostTx.txo.ia, config.addressPrefix) === incomingAddress, 'Message incoming address should be the address of the peer wallet');
51
- k.ok(bufferToAddress(decodedPostTx.address, config.addressPrefix) === validatorAddress, 'Message validator address should be the address of the non-admin wallet');
52
-
53
- k.ok(b4a.isBuffer(decodedPostTx.txo.tx), 'tx should be a buffer');
54
- k.is(decodedPostTx.txo.tx.length, 32, 'tx should be 32 bytes long');
55
- k.ok(b4a.isBuffer(decodedPostTx.txo.ia), 'ia should be a buffer');
56
- k.is(decodedPostTx.txo.ia.length, 63, 'ia should be 63 bytes long');
57
- k.ok(b4a.isBuffer(decodedPostTx.txo.iw), 'iw should be a buffer');
58
- k.is(decodedPostTx.txo.iw.length, 32, 'iw should be 32 bytes long');
59
- k.ok(b4a.isBuffer(decodedPostTx.txo.in), 'in should be a buffer');
60
- k.is(decodedPostTx.txo.in.length, 32, 'in should be 32 bytes long');
61
- k.ok(b4a.isBuffer(decodedPostTx.txo.ch), 'ch should be a buffer');
62
- k.is(decodedPostTx.txo.ch.length, 32, 'ch should be 32 bytes long');
63
- k.ok(b4a.isBuffer(decodedPostTx.txo.is), 'is should be a buffer');
64
- k.is(decodedPostTx.txo.is.length, 64, 'is should be 64 bytes long');
65
- k.ok(b4a.isBuffer(decodedPostTx.txo.bs), 'bs should be a buffer');
66
- k.is(decodedPostTx.txo.bs.length, 32, 'bs should be 32 bytes long');
67
- k.ok(b4a.isBuffer(decodedPostTx.txo.mbs), 'mbs should be a buffer');
68
- k.is(decodedPostTx.txo.mbs.length, 32, 'mbs should be 32 bytes long');
69
- k.ok(b4a.isBuffer(decodedPostTx.txo.vs), 'vs should be a buffer');
70
- k.is(decodedPostTx.txo.vs.length, 64, 'vs should be 64 bytes long');
71
- k.ok(b4a.isBuffer(decodedPostTx.txo.vn), 'vn should be a buffer');
72
- k.is(decodedPostTx.txo.vn.length, 32, 'vn should be 32 bytes long');
73
-
74
- k.test(`assemblePostTxMessage - Invalid wallet instance - trac address is to short`, async (k) => {
75
- const invalidWallet = {
76
- address: 'trac1y6kkq48fgu3ur'
77
- }
78
- await k.exception(
79
- async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
80
- validatorAddress,
81
- txHash,
82
- incomingAddress,
83
- incomingWriterKey,
84
- incomingNonce,
85
- contentHash,
86
- incomingSignature,
87
- externalBootstrap,
88
- msbBootstrap
89
- ),
90
- errorMessageIncludes('Wallet should have a valid TRAC address')
91
- );
92
- });
93
-
94
- k.test(`assemblePostTxMessage - Invalid wallet instance - invalid prefix`, async (k) => {
95
- const invalidWallet = {
96
- address: 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk'
97
- }
98
- await k.exception(
99
- async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
100
- validatorAddress,
101
- txHash,
102
- incomingAddress,
103
- incomingWriterKey,
104
- incomingNonce,
105
- contentHash,
106
- incomingSignature,
107
- externalBootstrap,
108
- msbBootstrap
109
- ),
110
- errorMessageIncludes('Wallet should have a valid TRAC address')
111
- );
112
- });
113
-
114
- k.test(`assemblePostTxMessage - Invalid wallet instance - empty string`, async (k) => {
115
- const invalidWallet = {
116
- address: ''
117
- }
118
- await k.exception(
119
- async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
120
- validatorAddress,
121
- txHash,
122
- incomingAddress,
123
- incomingWriterKey,
124
- incomingNonce,
125
- contentHash,
126
- incomingSignature,
127
- externalBootstrap,
128
- msbBootstrap
129
- ),
130
- errorMessageIncludes('Wallet should have a valid TRAC address')
131
- );
132
- });
133
-
134
- k.test(`assemblePostTxMessage - Invalid wallet instance - null Wallet `, async (k) => {
135
- await k.exception(
136
- async () => await new CompleteStateMessageOperations(null, config).assembleCompleteTransactionOperationMessage(
137
- validatorAddress,
138
- txHash,
139
- incomingAddress,
140
- incomingWriterKey,
141
- incomingNonce,
142
- contentHash,
143
- incomingSignature,
144
- externalBootstrap,
145
- msbBootstrap
146
- ),
147
- errorMessageIncludes('Wallet must be a valid wallet object')
148
- );
149
- });
150
-
151
- k.test(`assemblePostTxMessage - Invalid wallet instance - undefined Wallet`, async (k) => {
152
- await k.exception(
153
- async () => await new CompleteStateMessageOperations(undefined, config).assembleCompleteTransactionOperationMessage(
154
- validatorAddress,
155
- txHash,
156
- incomingAddress,
157
- incomingWriterKey,
158
- incomingNonce,
159
- contentHash,
160
- incomingSignature,
161
- externalBootstrap,
162
- msbBootstrap
163
- ),
164
- errorMessageIncludes('Wallet must be a valid wallet object')
165
- );
166
- });
167
-
168
- k.test(`assemblePostTxMessage - Address parameter (validator address) - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
169
-
170
- const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
171
-
172
- await k.exception(
173
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
174
- invalid,
175
- txHash,
176
- incomingAddress,
177
- incomingWriterKey,
178
- incomingNonce,
179
- contentHash,
180
- incomingSignature,
181
- externalBootstrap,
182
- msbBootstrap
183
- ),
184
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
185
- );
186
- });
187
-
188
- k.test(`assemblePostTxMessage - Address parameter (validator address) - trac address is to short`, async (k) => {
189
- const invalid = 'trac1y6kkq48fgu3ur';
190
-
191
- await k.exception(
192
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
193
- invalid,
194
- txHash,
195
- incomingAddress,
196
- incomingWriterKey,
197
- incomingNonce,
198
- contentHash,
199
- incomingSignature,
200
- externalBootstrap,
201
- msbBootstrap
202
- ),
203
- errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
204
- );
205
- });
206
-
207
- k.test(`assemblePostTxMessage- Address parameter (validator address) - invalid prefix`, async (k) => {
208
- const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
209
-
210
- await k.exception(
211
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
212
- invalid,
213
- txHash,
214
- incomingAddress,
215
- incomingWriterKey,
216
- incomingNonce,
217
- contentHash,
218
- incomingSignature,
219
- externalBootstrap,
220
- msbBootstrap
221
- ), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
222
- );
223
- });
224
-
225
-
226
- k.test(`assemblePostTxMessage - Address parameter (validator address) - empty string`, async (k) => {
227
- const invalid = '';
228
-
229
- await k.exception(
230
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
231
- invalid,
232
- txHash,
233
- incomingAddress,
234
- incomingWriterKey,
235
- incomingNonce,
236
- contentHash,
237
- incomingSignature,
238
- externalBootstrap,
239
- msbBootstrap
240
- ), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
241
- );
242
- });
243
-
244
- k.test(`assemblePostTxMessage - Address parameter (validator address) - Null`, async (k) => {
245
-
246
- await k.exception(
247
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
248
- null,
249
- txHash,
250
- incomingAddress,
251
- incomingWriterKey,
252
- incomingNonce,
253
- contentHash,
254
- incomingSignature,
255
- externalBootstrap,
256
- msbBootstrap
257
- ), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
258
- );
259
- });
260
-
261
- k.test(`assemblePostTxMessage - Address parameter (validator address) - undefined`, async (k) => {
262
- await k.exception(
263
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
264
- undefined,
265
- txHash,
266
- incomingAddress,
267
- incomingWriterKey,
268
- incomingNonce,
269
- contentHash,
270
- incomingSignature,
271
- externalBootstrap,
272
- msbBootstrap
273
- ), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
274
- );
275
- });
276
-
277
- k.test(`assemblePostTxMessage - Address parameter (incoming address) - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
278
- const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
279
- await k.exception(
280
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
281
- validatorAddress, // correct validator address
282
- txHash,
283
- invalid, // invalid incoming address
284
- incomingWriterKey,
285
- incomingNonce,
286
- contentHash,
287
- incomingSignature,
288
- externalBootstrap,
289
- msbBootstrap
290
- ),
291
- errorMessageIncludes('Incoming address must be a 63 length string')
292
- );
293
- });
294
-
295
- k.test(`assemblePostTxMessage - Address parameter (incoming address) - trac address is to short`, async (k) => {
296
- const invalid = 'trac1y6kkq48fgu3ur';
297
- await k.exception(
298
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
299
- validatorAddress,
300
- txHash,
301
- invalid,
302
- incomingWriterKey,
303
- incomingNonce,
304
- contentHash,
305
- incomingSignature,
306
- externalBootstrap,
307
- msbBootstrap
308
- ),
309
- errorMessageIncludes('Incoming address must be a 63 length string')
310
- );
311
- });
312
-
313
- k.test(`assemblePostTxMessage- Address parameter (incoming address) - invalid prefix`, async (k) => {
314
- const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
315
- await k.exception(
316
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
317
- validatorAddress,
318
- txHash,
319
- invalid,
320
- incomingWriterKey,
321
- incomingNonce,
322
- contentHash,
323
- incomingSignature,
324
- externalBootstrap,
325
- msbBootstrap
326
- ), errorMessageIncludes('Incoming address must be a 63 length string')
327
- );
328
- });
329
-
330
- k.test(`assemblePostTxMessage - Address parameter (incoming address) - empty string`, async (k) => {
331
- const invalid = '';
332
- await k.exception(
333
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
334
- validatorAddress,
335
- txHash,
336
- invalid,
337
- incomingWriterKey,
338
- incomingNonce,
339
- contentHash,
340
- incomingSignature,
341
- externalBootstrap,
342
- msbBootstrap
343
- ), errorMessageIncludes('Incoming address must be a 63 length string')
344
- );
345
- });
346
-
347
- k.test(`assemblePostTxMessage - Address parameter (incoming address) - Null`, async (k) => {
348
- await k.exception(
349
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
350
- validatorAddress,
351
- txHash,
352
- null,
353
- incomingWriterKey,
354
- incomingNonce,
355
- contentHash,
356
- incomingSignature,
357
- externalBootstrap,
358
- msbBootstrap
359
- ), errorMessageIncludes('Incoming address must be a 63 length string')
360
- );
361
- });
362
-
363
- k.test(`assemblePostTxMessage - Address parameter (incoming address) - undefined`, async (k) => {
364
- await k.exception(
365
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
366
- validatorAddress,
367
- txHash,
368
- undefined,
369
- incomingWriterKey,
370
- incomingNonce,
371
- contentHash,
372
- incomingSignature,
373
- externalBootstrap,
374
- msbBootstrap
375
- ), errorMessageIncludes('Incoming address must be a 63 length string')
376
- );
377
- });
378
-
379
- const invalidBufferCases = [
380
- { name: 'empty buffer', value: b4a.alloc(0) },
381
- { name: 'null', value: null },
382
- { name: 'undefined', value: undefined },
383
- ];
384
- const bufferParams = [
385
- { key: 'msbBootstrap', error: 'MSB bootstrap must be a 32-byte buffer.' },
386
- { key: 'externalBootstrap', error: 'Bootstrap key must be a 32-byte buffer.' },
387
- { key: 'incomingSignature', error: 'Incoming signature must be a 64-byte buffer.' },
388
- { key: 'contentHash', error: 'Content hash must be a 32-byte buffer.' },
389
- { key: 'incomingNonce', error: 'Incoming nonce must be a 32-byte buffer.' },
390
- { key: 'incomingWriterKey', error: 'Incoming writer key must be a 32-byte buffer.' },
391
- { key: 'txHash', error: 'Transaction hash must be a 32-byte buffer.' },
392
- ];
393
- for (const param of bufferParams) {
394
- for (const invalid of invalidBufferCases) {
395
- k.test(`assemblePostTxMessage - ${param.key} - ${invalid.name}`, async (k) => {
396
- const args = {
397
- msbBootstrap,
398
- externalBootstrap,
399
- incomingSignature,
400
- contentHash,
401
- incomingNonce,
402
- incomingWriterKey,
403
- txHash
404
- };
405
- args[param.key] = invalid.value;
406
- await k.exception(
407
- async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
408
- validatorAddress,
409
- args.txHash,
410
- incomingAddress,
411
- args.incomingWriterKey,
412
- args.incomingNonce,
413
- args.contentHash,
414
- args.incomingSignature,
415
- args.externalBootstrap,
416
- args.msbBootstrap
417
- ),
418
- errorMessageIncludes(param.error)
419
- );
420
- });
421
- }
422
- }
423
-
424
- })
@@ -1,19 +0,0 @@
1
- import test from 'brittle';
2
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
- import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
4
- import { writingKeyNonAdmin, walletNonAdmin, initAll ,walletAdmin} from '../fixtures/assembleMessage.fixtures.js';
5
- import { messageOperationsBkoTest } from './commonsStateMessageOperationsTest.js';
6
- import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
7
- import { config } from '../../helpers/config.js';
8
-
9
- const testName = 'assembleRemoveIndexerMessage';
10
- test(testName, async (t) => {
11
- await initAll();
12
- const assembler = async (wallet,address) => {
13
- return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleRemoveIndexerMessage(address));
14
- }
15
-
16
- await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.REMOVE_INDEXER, 2, walletNonAdmin.address);
17
- });
18
-
19
-
@@ -1,17 +0,0 @@
1
- import test from 'brittle';
2
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
- import {OperationType} from '../../src/utils/protobuf/applyOperations.cjs';
4
- import {initAll, walletNonAdmin, writingKeyNonAdmin} from '../fixtures/assembleMessage.fixtures.js';
5
- import {messageOperationsEkoTest} from './commonsStateMessageOperationsTest.js';
6
- import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
7
- import { config } from '../../helpers/config.js';
8
-
9
- const testName = 'assembleRemoveWriterMessage';
10
- test(testName, async (t) => {
11
- await initAll();
12
- const assembler = async (wallet, writingKey) => {
13
- return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleRemoveWriterMessage(writingKey));
14
- }
15
- await messageOperationsEkoTest(t, testName, assembler, walletNonAdmin, writingKeyNonAdmin, OperationType.REMOVE_WRITER, 3, walletNonAdmin.address);
16
- });
17
-
@@ -1,59 +0,0 @@
1
- import test from 'brittle';
2
- import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
3
- import { default as fixtures } from '../fixtures/assembleMessage.fixtures.js';
4
- import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
5
- import b4a from 'b4a';
6
- import fileUtils from "../../src/utils/fileUtils.js";
7
- import CompleteStateMessageOperations from "../../src/messages/completeStateMessages/CompleteStateMessageOperations.js";
8
- import {bufferToAddress} from "../../src/core/state/utils/address.js";
9
- import {errorMessageIncludes} from "../utils/regexHelper.js";
10
- import { config } from '../../helpers/config.js'
11
-
12
- // MOCK SETUP
13
- const whitelistAddresses = [
14
- 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk',
15
- ];
16
- const originalReadAddressesFromWhitelistFile = fileUtils.readAddressesFromWhitelistFile;
17
-
18
- test('assembleWhitelistMessages', async (t) => {
19
- fileUtils.readAddressesFromWhitelistFile = async () => whitelistAddresses;
20
-
21
- await fixtures.initAll();
22
- const walletAdmin = fixtures.walletAdmin;
23
-
24
-
25
- t.test('assembleWhitelistMessages - Happy Path', async (k) => {
26
- const mapMsg = await new CompleteStateMessageOperations(walletAdmin, config).assembleAppendWhitelistMessages();
27
- const msg = mapMsg.get(whitelistAddresses[0])
28
- k.ok(msg, 'Message should be created');
29
- k.ok(msg.length > 0, 'Message should be an array with at least one element');
30
- const decodedMsg = safeDecodeApplyOperation(msg);
31
- k.is(Object.keys(decodedMsg).length, 3, 'Message should have 3 keys');
32
- k.is(Object.keys(decodedMsg.bko).length, 2, 'Message value should have 2 keys');
33
- k.is(decodedMsg.type, OperationType.APPEND_WHITELIST, 'Message type should be APPEND_WHITELIST');
34
-
35
- k.is(bufferToAddress(decodedMsg.address, config.addressPrefix) , whitelistAddresses[0], 'Message address should be the address in the file');
36
- k.is(decodedMsg.bko.nonce.length, 32, 'Message nonce should be 32 bytes long');
37
- k.ok(b4a.isBuffer(decodedMsg.bko.nonce), 'Message nonce should be a buffer');
38
- k.is(decodedMsg.bko.sig.length, 64, 'Message signature should be 64 bytes long');
39
- k.ok(b4a.isBuffer(decodedMsg.bko.sig), 'Message signature should be a buffer');
40
- });
41
-
42
- t.test('assembleWhitelistMessages - Should return null when wallet is invalid', async (k) => {
43
- await k.exception(
44
- async () => await new CompleteStateMessageOperations(null, config).assembleAppendWhitelistMessages(),
45
- errorMessageIncludes('Wallet must be a valid wallet object')
46
- );
47
- });
48
-
49
-
50
- t.test('assembleWhitelistMessages - Empty object', async (k) => {
51
- await k.exception(
52
- async () => await new CompleteStateMessageOperations({}, config).assembleAppendWhitelistMessages(),
53
- errorMessageIncludes('Wallet should have a valid TRAC address.')
54
- );
55
-
56
- });
57
-
58
- fileUtils.readAddressesFromWhitelistFile = originalReadAddressesFromWhitelistFile;
59
- });