trac-msb 0.2.11 → 0.2.12

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 (114) hide show
  1. package/.github/workflows/acceptance-tests.yml +38 -0
  2. package/.github/workflows/lint-pr-title.yml +26 -0
  3. package/.github/workflows/publish.yml +33 -0
  4. package/.github/workflows/unit-tests.yml +34 -0
  5. package/package.json +5 -10
  6. package/proto/network.proto +74 -0
  7. package/rpc/rpc_services.js +4 -22
  8. package/scripts/generate-protobufs.js +12 -37
  9. package/src/config/config.js +5 -26
  10. package/src/config/env.js +11 -25
  11. package/src/core/network/Network.js +36 -73
  12. package/src/core/network/protocols/LegacyProtocol.js +11 -21
  13. package/src/core/network/protocols/NetworkMessages.js +17 -38
  14. package/src/core/network/protocols/ProtocolInterface.js +2 -14
  15. package/src/core/network/protocols/ProtocolSession.js +17 -144
  16. package/src/core/network/protocols/V1Protocol.js +18 -37
  17. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +19 -25
  18. package/src/core/network/protocols/legacy/handlers/{LegacyGetRequestHandler.js → GetRequestHandler.js} +6 -6
  19. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  20. package/src/core/network/protocols/{legacy/handlers/LegacyRoleOperationHandler.js → shared/handlers/RoleOperationHandler.js} +11 -18
  21. package/src/core/network/protocols/{legacy/handlers/LegacySubnetworkOperationHandler.js → shared/handlers/SubnetworkOperationHandler.js} +17 -28
  22. package/src/core/network/protocols/{legacy/handlers/LegacyTransferOperationHandler.js → shared/handlers/TransferOperationHandler.js} +11 -17
  23. package/src/core/network/protocols/{legacy/handlers/BaseStateOperationHandler.js → shared/handlers/base/BaseOperationHandler.js} +12 -23
  24. package/src/core/network/protocols/shared/validators/{PartialBootstrapDeploymentValidator.js → PartialBootstrapDeployment.js} +4 -9
  25. package/src/core/network/protocols/shared/validators/{PartialRoleAccessValidator.js → PartialRoleAccess.js} +17 -51
  26. package/src/core/network/protocols/shared/validators/{PartialTransactionValidator.js → PartialTransaction.js} +7 -21
  27. package/src/core/network/protocols/shared/validators/{PartialTransferValidator.js → PartialTransfer.js} +9 -26
  28. package/src/core/network/protocols/shared/validators/{PartialOperationValidator.js → base/PartialOperation.js} +25 -47
  29. package/src/core/network/protocols/v1/NetworkMessageRouter.js +7 -91
  30. package/src/core/network/services/ConnectionManager.js +94 -146
  31. package/src/core/network/services/MessageOrchestrator.js +27 -151
  32. package/src/core/network/services/TransactionPoolService.js +18 -129
  33. package/src/core/network/services/TransactionRateLimiterService.js +34 -52
  34. package/src/core/network/services/ValidatorObserverService.js +26 -18
  35. package/src/core/state/State.js +19 -70
  36. package/src/index.js +4 -5
  37. package/src/messages/network/v1/NetworkMessageBuilder.js +79 -59
  38. package/src/messages/network/v1/NetworkMessageDirector.js +50 -16
  39. package/src/utils/Scheduler.js +8 -0
  40. package/src/utils/constants.js +5 -71
  41. package/src/utils/helpers.js +1 -10
  42. package/src/utils/normalizers.js +0 -38
  43. package/src/utils/protobuf/network.cjs +840 -0
  44. package/src/utils/protobuf/operationHelpers.js +3 -24
  45. package/tests/acceptance/v1/account/account.test.mjs +2 -8
  46. package/tests/acceptance/v1/tx/tx.test.mjs +1 -23
  47. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +6 -34
  48. package/tests/fixtures/networkV1.fixtures.js +28 -2
  49. package/tests/helpers/transactionPayloads.mjs +2 -2
  50. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +79 -239
  51. package/tests/unit/messages/network/NetworkMessageDirector.test.js +77 -223
  52. package/tests/unit/network/ConnectionManager.test.js +191 -0
  53. package/tests/unit/network/networkModule.test.js +1 -4
  54. package/tests/unit/unit.test.js +2 -2
  55. package/tests/unit/utils/protobuf/operationHelpers.test.js +4 -2
  56. package/tests/unit/utils/utils.test.js +0 -1
  57. package/proto/network/v1/enums/message_type.proto +0 -16
  58. package/proto/network/v1/enums/result_code.proto +0 -84
  59. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  60. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  61. package/proto/network/v1/messages/liveness_request.proto +0 -8
  62. package/proto/network/v1/messages/liveness_response.proto +0 -11
  63. package/proto/network/v1/network_message.proto +0 -22
  64. package/src/core/network/protocols/connectionPolicies.js +0 -88
  65. package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +0 -23
  66. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  67. package/src/core/network/protocols/v1/V1ProtocolError.js +0 -91
  68. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +0 -65
  69. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +0 -389
  70. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +0 -87
  71. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +0 -211
  72. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +0 -26
  73. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +0 -276
  74. package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +0 -15
  75. package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +0 -17
  76. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +0 -210
  77. package/src/core/network/services/PendingRequestService.js +0 -172
  78. package/src/core/network/services/TransactionCommitService.js +0 -149
  79. package/src/core/network/services/ValidatorHealthCheckService.js +0 -127
  80. package/src/utils/deepEqualApplyPayload.js +0 -40
  81. package/src/utils/logger.js +0 -25
  82. package/src/utils/protobuf/networkV1.generated.cjs +0 -2460
  83. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  84. package/tests/unit/network/ProtocolSession.test.js +0 -127
  85. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  86. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  87. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  88. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  89. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  90. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  91. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  92. package/tests/unit/network/services/services.test.js +0 -17
  93. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  94. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  95. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  96. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  97. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  98. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  99. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  100. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  101. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  102. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  103. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  104. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  105. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  106. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  107. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  108. package/tests/unit/network/v1/v1.test.js +0 -19
  109. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  110. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  111. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  112. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  113. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  114. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
@@ -1,193 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
- import V1LivenessOperationHandler from '../../../../../src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js';
4
- import V1LivenessRequest from '../../../../../src/core/network/protocols/v1/validators/V1LivenessRequest.js';
5
- import V1LivenessResponse from '../../../../../src/core/network/protocols/v1/validators/V1LivenessResponse.js';
6
- import { ResultCode } from '../../../../../src/utils/constants.js';
7
- import {V1ProtocolError} from '../../../../../src/core/network/protocols/v1/V1ProtocolError.js';
8
-
9
- // Backup original validators
10
- const originalReqValidate = V1LivenessRequest.prototype.validate;
11
- const originalResValidate = V1LivenessResponse.prototype.validate;
12
-
13
- const mockConfig = {
14
- hrp: 'trac',
15
- addressPrefix: 'trac',
16
- networkId: 1,
17
- disableRateLimit: true,
18
- network: { hrp: 'trac' }
19
- };
20
-
21
- // Minimal wallet required so constructor does not break
22
- const mockWallet = {
23
- getPublicKey: () => b4a.alloc(33, 2),
24
- sign: () => b4a.alloc(64),
25
- address: 'trac123z3gfpr2epjwww7ntm3m6ud2fhmq0tvts27p2f5mx3qkecsutlqfys769',
26
- networkId: 1
27
- };
28
-
29
- class MockConnection {
30
- constructor() {
31
- this.remotePublicKey = b4a.alloc(32);
32
- this.ended = false;
33
- this.sentPayload = null;
34
- this.flushCalled = false;
35
- this.protocolSession = {
36
- sendAndForget: () => {}
37
- };
38
- }
39
-
40
- async flush() {
41
- this.flushCalled = true;
42
- return true;
43
- }
44
-
45
- end() {
46
- this.ended = true;
47
- }
48
- }
49
-
50
- const mockRateLimiter = {
51
- v1HandleRateLimit: () => {}
52
- };
53
-
54
- test('handleRequest: request validation and response send -> covers success and error branches', async (t) => {
55
-
56
- // -------- SUCCESS FLOW (does not validate real payload) --------
57
- {
58
- V1LivenessRequest.prototype.validate = async () => {};
59
-
60
- const handler = new V1LivenessOperationHandler(
61
- mockWallet,
62
- mockRateLimiter,
63
- {},
64
- mockConfig
65
- );
66
-
67
- handler.displayError = () => {};
68
-
69
- const conn = new MockConnection();
70
-
71
- await handler.handleRequest({ id: 'msg-success' }, conn);
72
-
73
- // Real factory is not being asserted
74
- t.pass('Success path executed');
75
- }
76
-
77
- // -------- VALIDATION ERROR + endConnection true --------
78
- {
79
- V1LivenessRequest.prototype.validate = async () => {
80
- throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Validation Fail', true);
81
- };
82
-
83
- const handler = new V1LivenessOperationHandler(
84
- mockWallet,
85
- mockRateLimiter,
86
- {},
87
- mockConfig
88
- );
89
-
90
- handler.displayError = () => {};
91
-
92
- const conn = new MockConnection();
93
-
94
- await handler.handleRequest({ id: 'msg-end' }, conn);
95
-
96
- t.ok(conn.ended);
97
- t.ok(conn.flushCalled);
98
- }
99
-
100
- // -------- VALIDATION ERROR without endConnection --------
101
- {
102
- V1LivenessRequest.prototype.validate = async () => {
103
- throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Validation Fail No End', false);
104
- };
105
-
106
- const handler = new V1LivenessOperationHandler(
107
- mockWallet,
108
- mockRateLimiter,
109
- {},
110
- mockConfig
111
- );
112
-
113
- handler.displayError = () => {};
114
-
115
- const conn = new MockConnection();
116
-
117
- await handler.handleRequest({ id: 'msg-no-end' }, conn);
118
-
119
- t.absent(conn.ended);
120
- t.absent(conn.flushCalled);
121
- }
122
-
123
- // -------- SEND FAILURE (second catch block) --------
124
- {
125
- V1LivenessRequest.prototype.validate = async () => {};
126
-
127
- const handler = new V1LivenessOperationHandler(
128
- mockWallet,
129
- mockRateLimiter,
130
- {},
131
- mockConfig
132
- );
133
-
134
- handler.displayError = () => {};
135
-
136
- const conn = new MockConnection();
137
-
138
- conn.protocolSession.sendAndForget = () => {
139
- throw new Error('send fail');
140
- };
141
-
142
- await handler.handleRequest({ id: 'msg-send-fail' }, conn);
143
-
144
- t.ok(conn.ended);
145
- }
146
- });
147
-
148
- test('handleResponse: resolvePendingResponse result handling -> covers success and delegated error branches', async (t) => {
149
-
150
- const handler = new V1LivenessOperationHandler(
151
- mockWallet,
152
- mockRateLimiter,
153
- {},
154
- mockConfig
155
- );
156
-
157
- // resolvePendingResponse success path
158
- {
159
- let extractorCalled = false;
160
-
161
- handler.resolvePendingResponse = async (msg, conn, val, extractor) => {
162
- extractor({ liveness_response: { result: 1 } });
163
- extractorCalled = true;
164
- };
165
-
166
- await handler.handleResponse({ id: 'msg-1' }, new MockConnection());
167
-
168
- t.ok(extractorCalled);
169
- }
170
-
171
- // resolvePendingResponse error path
172
- {
173
- handler.resolvePendingResponse = async () => {
174
- throw new Error('Fail');
175
- };
176
-
177
- let handled = false;
178
-
179
- handler.handlePendingResponseError = () => {
180
- handled = true;
181
- };
182
-
183
- await handler.handleResponse({ id: 'msg-2' }, new MockConnection());
184
-
185
- t.ok(handled);
186
- }
187
- });
188
-
189
- test('validators cleanup: restore original validator methods', async (t) => {
190
- V1LivenessRequest.prototype.validate = originalReqValidate;
191
- V1LivenessResponse.prototype.validate = originalResValidate;
192
- t.pass();
193
- });
@@ -1,15 +0,0 @@
1
- // Aggregator for V1 handlers unit tests
2
-
3
- import { default as test } from 'brittle';
4
-
5
- async function runTests() {
6
- test.pause();
7
-
8
- await import('./handlers/V1BaseOperationHandler.test.js');
9
- await import('./handlers/V1BroadcastTransactionOperationHandler.test.js');
10
- await import('./handlers/V1LivenessOperationHandler.test.js');
11
-
12
- test.resume();
13
- }
14
-
15
- await runTests();
@@ -1,19 +0,0 @@
1
- import { default as test } from 'brittle';
2
-
3
- async function runTests() {
4
- test.pause();
5
- await import('./v1.handlers.test.js');
6
- await import('./V1BaseOperation.test.js');
7
- await import('./V1LivenessRequest.test.js');
8
- await import('./V1LivenessResponse.test.js');
9
- await import('./V1BroadcastTransactionRequest.test.js');
10
- await import('./V1ResultCode.test.js');
11
- await import('./connectionPolicies.test.js');
12
- await import('./V1BroadcastTransactionResponse.test.js');
13
- await import('./V1ValidationSchema.test.js');
14
- await import('./V1BroadcastTransactionOperationHandler.test.js');
15
- await import('./NetworkMessageRouterV1.test.js');
16
- test.resume();
17
- }
18
-
19
- await runTests();
@@ -1,119 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
-
4
- import V1ValidationSchema from '../../../../../src/core/network/protocols/v1/validators/V1ValidationSchema.js';
5
- import {
6
- NetworkOperationType,
7
- NONCE_BYTE_LENGTH,
8
- SIGNATURE_BYTE_LENGTH,
9
- MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE
10
- } from '../../../../../src/utils/constants.js';
11
- import {not_allowed_data_types} from '../../../../fixtures/check.fixtures.js';
12
-
13
- import {
14
- fieldsBufferLengthTest,
15
- fieldsNonZeroBufferTest,
16
- headerFieldValueValidationTests,
17
- topLevelValidationTests,
18
- valueLevelValidationTests,
19
- } from './common.test.js';
20
-
21
- const v = new V1ValidationSchema();
22
-
23
- const bytes = (len, fill = 1) => b4a.alloc(len, fill);
24
-
25
- const validFixture = {
26
- type: NetworkOperationType.BROADCAST_TRANSACTION_REQUEST,
27
- id: 'test-id',
28
- timestamp: Date.now(),
29
- broadcast_transaction_request: {
30
- data: bytes(16, 1),
31
- nonce: bytes(NONCE_BYTE_LENGTH, 2),
32
- signature: bytes(SIGNATURE_BYTE_LENGTH, 3),
33
- },
34
- capabilities: ['cap:a'],
35
- };
36
-
37
- const topFields = ['type', 'id', 'timestamp', 'broadcast_transaction_request', 'capabilities'];
38
- const valueFields = ['data', 'nonce', 'signature'];
39
- const requiredLengths = {
40
- nonce: NONCE_BYTE_LENGTH,
41
- signature: SIGNATURE_BYTE_LENGTH,
42
- };
43
-
44
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - happy path', t => {
45
- t.ok(v.validateV1BroadcastTransactionRequest(validFixture), 'valid BROADCAST_TRANSACTION_REQUEST should pass');
46
- });
47
-
48
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - top level validation', t => {
49
- topLevelValidationTests(
50
- t,
51
- v.validateV1BroadcastTransactionRequest.bind(v),
52
- validFixture,
53
- 'broadcast_transaction_request',
54
- not_allowed_data_types,
55
- topFields,
56
- NetworkOperationType.BROADCAST_TRANSACTION_REQUEST
57
- );
58
- });
59
-
60
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - header field values', t => {
61
- headerFieldValueValidationTests(t, v.validateV1BroadcastTransactionRequest.bind(v), validFixture);
62
- });
63
-
64
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - payload validation', t => {
65
- valueLevelValidationTests(
66
- t,
67
- v.validateV1BroadcastTransactionRequest.bind(v),
68
- validFixture,
69
- 'broadcast_transaction_request',
70
- valueFields,
71
- not_allowed_data_types,
72
- {
73
- skipInvalidType: (field, invalidType) => field === 'data' && b4a.isBuffer(invalidType),
74
- }
75
- );
76
- });
77
-
78
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - data size limits', t => {
79
- const min = structuredClone(validFixture);
80
- min.broadcast_transaction_request.data = bytes(1, 1);
81
- t.ok(v.validateV1BroadcastTransactionRequest(min), 'data length 1 should pass');
82
-
83
- const max = structuredClone(validFixture);
84
- max.broadcast_transaction_request.data = bytes(MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE, 1);
85
- t.ok(v.validateV1BroadcastTransactionRequest(max), `data length ${MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE} should pass`);
86
-
87
- const tooLarge = structuredClone(validFixture);
88
- tooLarge.broadcast_transaction_request.data = bytes(MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE + 1, 1);
89
- t.absent(v.validateV1BroadcastTransactionRequest(tooLarge), `data length ${MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE + 1} should fail`);
90
-
91
- const empty = structuredClone(validFixture);
92
- empty.broadcast_transaction_request.data = bytes(0, 0);
93
- t.absent(v.validateV1BroadcastTransactionRequest(empty), 'data length 0 should fail');
94
-
95
- const zeroFilled = structuredClone(validFixture);
96
- zeroFilled.broadcast_transaction_request.data = bytes(16, 0);
97
- t.ok(v.validateV1BroadcastTransactionRequest(zeroFilled), 'zero-filled data should pass (allowZero)');
98
- });
99
-
100
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - buffer lengths', t => {
101
- fieldsBufferLengthTest(
102
- t,
103
- v.validateV1BroadcastTransactionRequest.bind(v),
104
- validFixture,
105
- 'broadcast_transaction_request',
106
- requiredLengths
107
- );
108
- });
109
-
110
- test('V1ValidationSchema.validateV1BroadcastTransactionRequest - non-zero buffers', t => {
111
- fieldsNonZeroBufferTest(
112
- t,
113
- v.validateV1BroadcastTransactionRequest.bind(v),
114
- validFixture,
115
- 'broadcast_transaction_request',
116
- ['nonce', 'signature']
117
- );
118
- });
119
-
@@ -1,136 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
-
4
- import V1ValidationSchema from '../../../../../src/core/network/protocols/v1/validators/V1ValidationSchema.js';
5
- import {
6
- NetworkOperationType,
7
- NONCE_BYTE_LENGTH,
8
- ResultCode,
9
- SIGNATURE_BYTE_LENGTH,
10
- } from '../../../../../src/utils/constants.js';
11
- import {not_allowed_data_types} from '../../../../fixtures/check.fixtures.js';
12
-
13
- import {
14
- assertNoThrowAndAbsent,
15
- fieldsBufferLengthTest,
16
- fieldsNonZeroBufferTest,
17
- headerFieldValueValidationTests,
18
- topLevelValidationTests,
19
- valueLevelValidationTests,
20
- } from './common.test.js';
21
-
22
- const v = new V1ValidationSchema();
23
-
24
- const validFixture = {
25
- type: NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE,
26
- id: 'test-id',
27
- timestamp: Date.now(),
28
- broadcast_transaction_response: {
29
- nonce: b4a.alloc(NONCE_BYTE_LENGTH, 1),
30
- signature: b4a.alloc(SIGNATURE_BYTE_LENGTH, 2),
31
- proof: b4a.from('deadbeef', 'hex'),
32
- timestamp: Date.now(),
33
- result: ResultCode.OK,
34
- },
35
- capabilities: ['cap:a'],
36
- };
37
-
38
- const topFields = ['type', 'id', 'timestamp', 'broadcast_transaction_response', 'capabilities'];
39
- const valueFields = ['nonce', 'signature', 'result'];
40
- const requiredLengths = {
41
- nonce: NONCE_BYTE_LENGTH,
42
- signature: SIGNATURE_BYTE_LENGTH,
43
- };
44
-
45
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - happy path', t => {
46
- t.ok(v.validateV1BroadcastTransactionResponse(validFixture), 'valid BROADCAST_TRANSACTION_RESPONSE should pass');
47
- });
48
-
49
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - payload/type mismatch (request payload + response type)', t => {
50
- const op = structuredClone(validFixture);
51
- delete op.broadcast_transaction_response;
52
- op.broadcast_transaction_request = {
53
- data: b4a.alloc(16, 1),
54
- nonce: b4a.alloc(NONCE_BYTE_LENGTH, 2),
55
- signature: b4a.alloc(SIGNATURE_BYTE_LENGTH, 3),
56
- };
57
-
58
- assertNoThrowAndAbsent(
59
- t,
60
- v.validateV1BroadcastTransactionResponse.bind(v),
61
- op,
62
- 'broadcast_transaction_request payload with type=BROADCAST_TRANSACTION_RESPONSE'
63
- );
64
- });
65
-
66
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - top level validation', t => {
67
- topLevelValidationTests(
68
- t,
69
- v.validateV1BroadcastTransactionResponse.bind(v),
70
- validFixture,
71
- 'broadcast_transaction_response',
72
- not_allowed_data_types,
73
- topFields,
74
- NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE
75
- );
76
- });
77
-
78
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - header field values', t => {
79
- headerFieldValueValidationTests(t, v.validateV1BroadcastTransactionResponse.bind(v), validFixture);
80
- });
81
-
82
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - payload validation', t => {
83
- valueLevelValidationTests(
84
- t,
85
- v.validateV1BroadcastTransactionResponse.bind(v),
86
- validFixture,
87
- 'broadcast_transaction_response',
88
- valueFields,
89
- not_allowed_data_types,
90
- {
91
- skipInvalidType: (field, invalidType) => field === 'result' && typeof invalidType === 'number',
92
- }
93
- );
94
- });
95
-
96
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - result value validation', t => {
97
- const negative = structuredClone(validFixture);
98
- negative.broadcast_transaction_response.result = -1;
99
- t.absent(v.validateV1BroadcastTransactionResponse(negative), 'negative result should fail');
100
-
101
- const nonInteger = structuredClone(validFixture);
102
- nonInteger.broadcast_transaction_response.result = 1.1;
103
- t.absent(v.validateV1BroadcastTransactionResponse(nonInteger), 'non-integer result should fail');
104
-
105
- const nan = structuredClone(validFixture);
106
- nan.broadcast_transaction_response.result = NaN;
107
- t.absent(v.validateV1BroadcastTransactionResponse(nan), 'result NaN should fail');
108
-
109
- const infinity = structuredClone(validFixture);
110
- infinity.broadcast_transaction_response.result = Infinity;
111
- t.absent(v.validateV1BroadcastTransactionResponse(infinity), 'result Infinity should fail');
112
-
113
- const unknownCode = structuredClone(validFixture);
114
- unknownCode.broadcast_transaction_response.result = Math.max(...Object.values(ResultCode)) + 1;
115
- t.absent(v.validateV1BroadcastTransactionResponse(unknownCode), 'unknown result code should fail');
116
- });
117
-
118
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - buffer lengths', t => {
119
- fieldsBufferLengthTest(
120
- t,
121
- v.validateV1BroadcastTransactionResponse.bind(v),
122
- validFixture,
123
- 'broadcast_transaction_response',
124
- requiredLengths
125
- );
126
- });
127
-
128
- test('V1ValidationSchema.validateV1BroadcastTransactionResponse - non-zero buffers', t => {
129
- fieldsNonZeroBufferTest(
130
- t,
131
- v.validateV1BroadcastTransactionResponse.bind(v),
132
- validFixture,
133
- 'broadcast_transaction_response',
134
- ['nonce', 'signature']
135
- );
136
- });