trac-msb 0.2.8 → 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.
- package/msb.mjs +3 -3
- package/package.json +8 -3
- package/proto/network.proto +74 -0
- package/rpc/create_server.js +2 -2
- package/rpc/handlers.js +2 -2
- package/rpc/rpc_server.js +2 -2
- package/rpc/rpc_services.js +44 -3
- package/rpc/utils/helpers.js +1 -1
- package/src/config/env.js +2 -0
- package/src/core/network/Network.js +29 -61
- package/src/core/network/identity/NetworkWalletFactory.js +2 -2
- package/src/core/network/protocols/LegacyProtocol.js +67 -0
- package/src/core/network/protocols/NetworkMessages.js +48 -0
- package/src/core/network/protocols/ProtocolInterface.js +31 -0
- package/src/core/network/protocols/ProtocolSession.js +59 -0
- package/src/core/network/protocols/V1Protocol.js +64 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
- package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
- package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +1 -2
- package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
- package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
- package/src/core/network/{messaging → protocols/shared}/handlers/TransferOperationHandler.js +16 -15
- package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +7 -11
- package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +2 -2
- package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +5 -5
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +14 -12
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
- package/src/core/network/services/ConnectionManager.js +4 -4
- package/src/core/network/services/MessageOrchestrator.js +1 -1
- package/src/core/network/services/TransactionPoolService.js +1 -2
- package/src/core/network/services/TransactionRateLimiterService.js +5 -3
- package/src/core/state/State.js +1 -2
- package/src/index.js +153 -180
- package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
- package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
- package/src/messages/network/v1/networkMessageFactory.js +12 -0
- package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
- package/src/messages/state/ApplyStateMessageDirector.js +516 -0
- package/src/messages/state/applyStateMessageFactory.js +12 -0
- package/src/utils/buffer.js +53 -1
- package/src/utils/cli.js +0 -8
- package/src/utils/constants.js +34 -14
- package/src/utils/normalizers.js +84 -2
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +10 -0
- package/tests/acceptance/v1/rpc.test.mjs +1 -1
- package/tests/fixtures/networkV1.fixtures.js +84 -0
- package/tests/fixtures/protobuf.fixtures.js +83 -0
- package/tests/helpers/config.js +1 -1
- package/tests/helpers/setupApplyTests.js +53 -46
- package/tests/unit/messages/messages.test.js +12 -0
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +203 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
- package/tests/unit/network/ConnectionManager.test.js +6 -5
- package/tests/unit/network/networkModule.test.js +3 -2
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +9 -6
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +10 -7
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +53 -38
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +46 -35
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +13 -16
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +11 -12
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/common/commonScenarioHelper.js +15 -14
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +9 -4
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +19 -14
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +37 -29
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +11 -9
- package/tests/unit/unit.test.js +1 -1
- package/tests/unit/utils/buffer/buffer.test.js +62 -1
- package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
- package/docs/networking-dualstack-plan.md +0 -75
- package/docs/networking-layer-redesign.md +0 -155
- package/src/core/network/messaging/NetworkMessages.js +0 -64
- package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -113
- package/src/core/network/messaging/handlers/ResponseHandler.js +0 -107
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -114
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -149
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -98
- package/src/core/network/messaging/validators/AdminResponse.js +0 -58
- package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
- package/src/messages/base/StateBuilder.js +0 -25
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -425
- package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -296
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
- package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -138
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -69
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -126
- package/tests/integration/apply/addIndexer.test.js +0 -239
- package/tests/integration/apply/addWhitelist.test.js +0 -53
- package/tests/integration/apply/addWriter.test.js +0 -245
- package/tests/integration/apply/apply.test.js +0 -19
- package/tests/integration/apply/banValidator.test.js +0 -116
- package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
- package/tests/integration/apply/postTx/postTx.test.js +0 -196
- package/tests/integration/apply/removeIndexer.test.js +0 -132
- package/tests/integration/apply/removeWriter.test.js +0 -168
- package/tests/integration/apply/transfer.test.js +0 -83
- package/tests/integration/integration.test.js +0 -9
- package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
- package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -68
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -424
- package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
- package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -59
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -278
- package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
- /package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +0 -0
- /package/src/utils/{operations.js → applyOperations.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import applyOperations from './applyOperations.cjs';
|
|
2
|
+
import networkV1Operations from './network.cjs';
|
|
2
3
|
import b4a from 'b4a';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -48,3 +49,12 @@ export const normalizeIncomingMessage = (message) => {
|
|
|
48
49
|
|
|
49
50
|
return null;
|
|
50
51
|
};
|
|
52
|
+
|
|
53
|
+
export const encodeV1networkOperation = (payload) => {
|
|
54
|
+
return networkV1Operations.MessageHeader.encode(payload);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export const decodeV1networkOperation = (payload) => {
|
|
59
|
+
return networkV1Operations.MessageHeader.decode(payload);
|
|
60
|
+
}
|
|
@@ -58,7 +58,7 @@ const setupNetwork = async () => {
|
|
|
58
58
|
|
|
59
59
|
beforeAll(async () => {
|
|
60
60
|
const { admin, writer, reader } = await setupNetwork()
|
|
61
|
-
const server = createServer(reader.msb)
|
|
61
|
+
const server = createServer(reader.msb, reader.config)
|
|
62
62
|
toClose = admin.msb
|
|
63
63
|
Object.assign(testContext, {
|
|
64
64
|
writerMsb: writer.msb,
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
3
|
+
import { NetworkOperationType, ResultCode as NetworkResultCode } from '../../src/utils/constants.js';
|
|
4
|
+
|
|
5
|
+
const payloadValidatorConnectionRequest = {
|
|
6
|
+
type: NetworkOperationType.VALIDATOR_CONNECTION_REQUEST,
|
|
7
|
+
id: uuidv7(),
|
|
8
|
+
timestamp: 123,
|
|
9
|
+
validator_connection_request: {
|
|
10
|
+
issuer_address: 'trac1xm76l9qaujh7vqktk8302mw9sfrxau3l45w62hqfl4kasswt6yts0autkh',
|
|
11
|
+
nonce: b4a.from('00', 'hex'),
|
|
12
|
+
signature: b4a.from('01', 'hex')
|
|
13
|
+
},
|
|
14
|
+
capabilities: ['cap:a', 'cap:b']
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const payloadValidatorConnectionResponse = {
|
|
18
|
+
type: NetworkOperationType.VALIDATOR_CONNECTION_RESPONSE,
|
|
19
|
+
id: uuidv7(),
|
|
20
|
+
timestamp: 456,
|
|
21
|
+
validator_connection_response: {
|
|
22
|
+
issuer_address: 'trac1xm76l9qaujh7vqktk8302mw9sfrxau3l45w62hqfl4kasswt6yts0autkh',
|
|
23
|
+
nonce: b4a.from('02', 'hex'),
|
|
24
|
+
signature: b4a.from('03', 'hex'),
|
|
25
|
+
result: NetworkResultCode.OK
|
|
26
|
+
},
|
|
27
|
+
capabilities: ['cap:a']
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const payloadLivenessRequest = {
|
|
31
|
+
type: NetworkOperationType.LIVENESS_REQUEST,
|
|
32
|
+
id: uuidv7(),
|
|
33
|
+
timestamp: 789,
|
|
34
|
+
liveness_request: {
|
|
35
|
+
nonce: b4a.from('04', 'hex'),
|
|
36
|
+
signature: b4a.from('05', 'hex')
|
|
37
|
+
},
|
|
38
|
+
capabilities: []
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const payloadLivenessResponse = {
|
|
42
|
+
type: NetworkOperationType.LIVENESS_RESPONSE,
|
|
43
|
+
id: uuidv7(),
|
|
44
|
+
timestamp: 101112,
|
|
45
|
+
liveness_response: {
|
|
46
|
+
nonce: b4a.from('06', 'hex'),
|
|
47
|
+
signature: b4a.from('07', 'hex'),
|
|
48
|
+
result: NetworkResultCode.OK
|
|
49
|
+
},
|
|
50
|
+
capabilities: []
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const payloadBroadcastTransactionRequest = {
|
|
54
|
+
type: NetworkOperationType.BROADCAST_TRANSACTION_REQUEST,
|
|
55
|
+
id: uuidv7(),
|
|
56
|
+
timestamp: 131415,
|
|
57
|
+
broadcast_transaction_request: {
|
|
58
|
+
data: b4a.from('deadbeef', 'hex'),
|
|
59
|
+
nonce: b4a.from('08', 'hex'),
|
|
60
|
+
signature: b4a.from('09', 'hex')
|
|
61
|
+
},
|
|
62
|
+
capabilities: ['cap:a']
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const payloadBroadcastTransactionResponse = {
|
|
66
|
+
type: NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE,
|
|
67
|
+
id: uuidv7(),
|
|
68
|
+
timestamp: 161718,
|
|
69
|
+
broadcast_transaction_response: {
|
|
70
|
+
nonce: b4a.from('0a', 'hex'),
|
|
71
|
+
signature: b4a.from('0b', 'hex'),
|
|
72
|
+
result: NetworkResultCode.OK
|
|
73
|
+
},
|
|
74
|
+
capabilities: ['cap:b']
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default {
|
|
78
|
+
payloadValidatorConnectionRequest,
|
|
79
|
+
payloadValidatorConnectionResponse,
|
|
80
|
+
payloadLivenessRequest,
|
|
81
|
+
payloadLivenessResponse,
|
|
82
|
+
payloadBroadcastTransactionRequest,
|
|
83
|
+
payloadBroadcastTransactionResponse,
|
|
84
|
+
};
|
|
@@ -19,6 +19,22 @@ const validTransferOperation = {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const validPartialTransferOperation = {
|
|
23
|
+
type: OperationType.TRANSFER,
|
|
24
|
+
address: addressToBuffer('trac123z3gfpr2epjwww7ntm3m6ud2fhmq0tvts27p2f5mx3qkecsutlqfys769'),
|
|
25
|
+
tro: {
|
|
26
|
+
tx: b4a.from('c59f70942febb1de32fcb59febe84560416265d39f39b48fae676592910a98f4', 'hex'),
|
|
27
|
+
txv: b4a.from('eb59a3e756d1c9597e46b33bcea91e262f8f73e94c238bdf70854aa2e8c42608', 'hex'),
|
|
28
|
+
to: addressToBuffer('trac1mqktwme8fvklrds4hlhfy6lhmsu9qgfn3c3kuhz7c5zwjt8rc3dqj9tx7h'),
|
|
29
|
+
am: b4a.from('00000000000000015af1d78b58c40001', 'hex'),
|
|
30
|
+
in: b4a.from('863fef21f5146553b0396b2ee1a93a8dbfce240411b71ccdcfc504504a6b9b50', 'hex'),
|
|
31
|
+
is: b4a.from('06acd7faecd5159221259ebb1d7e98eccd7c6e2884de9de45097e6d9d8c37192602901c74dde6bb2f48f6f665edc84140627f6e9c42f774a0e9f55ef3b348e06', 'hex'),
|
|
32
|
+
va: null,
|
|
33
|
+
vn: null,
|
|
34
|
+
vs: null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
const validTransactionOperation = {
|
|
23
39
|
type: OperationType.TX,
|
|
24
40
|
address: addressToBuffer('trac1c232xtkvyg08zyeurn7l0wrarc4y36fzq5vhcdsgkxe6hdpzuslsm63dw8', config.addressPrefix),
|
|
@@ -37,6 +53,24 @@ const validTransactionOperation = {
|
|
|
37
53
|
}
|
|
38
54
|
};
|
|
39
55
|
|
|
56
|
+
const validPartialTransactionOperation = {
|
|
57
|
+
type: OperationType.TX,
|
|
58
|
+
address: addressToBuffer('trac1c232xtkvyg08zyeurn7l0wrarc4y36fzq5vhcdsgkxe6hdpzuslsm63dw8'),
|
|
59
|
+
txo: {
|
|
60
|
+
tx: b4a.from('6fb7f6e7f6970477977080f2b46cc837d48605e67691d30bf7511a1417d17ed7', 'hex'),
|
|
61
|
+
txv: b4a.from('6fb7f6e7f6970477977080f2b46cc837d48605e67691d30bf7511a1417d17ed7', 'hex'),
|
|
62
|
+
iw: b4a.from('79ef7be837aa9fd8a446a120e1bc1e6bdd99fb5393dc4fa8299d9d5043a7cd98', 'hex'),
|
|
63
|
+
ch: b4a.from('6ee7b29ce494875c1ea0dc0f9c2997d1aeeb8d21c67809950e145822989c8b2e', 'hex'),
|
|
64
|
+
bs: b4a.from('f68bac445eee3d9276be46aef58328a543e4b7ecc2b5c98c387c1b3ca1a7e85d', 'hex'),
|
|
65
|
+
mbs: b4a.from('5f3b9a6a516066de365e5e75a7ac0feb55ab7cd4a29facbb028a047fc3f3956e', 'hex'),
|
|
66
|
+
in: b4a.from('8bcef53a043f42ac7c17344f0c0d56af5b335e412d4042124f27733911169e4f', 'hex'),
|
|
67
|
+
is: b4a.from('d8626ea0552bf302921de3536e877796ef131368c9854119660c9c77a4196d4735d60bb87c6a89bbff7d5f8d72a70610d6ee73d62bc5144874cdf23f88e28a05', 'hex'),
|
|
68
|
+
va: null,
|
|
69
|
+
vn: null,
|
|
70
|
+
vs: null
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
40
74
|
const validAddIndexer = {
|
|
41
75
|
type: OperationType.ADD_INDEXER,
|
|
42
76
|
address: addressToBuffer('trac1jnafrn8xl3c59s4ml6jusufp2vzm6egkyenrcqvd907j8c9v5j2qnx7wvt', config.addressPrefix),
|
|
@@ -201,6 +235,50 @@ const validBalanceInitOperation = {
|
|
|
201
235
|
}
|
|
202
236
|
};
|
|
203
237
|
|
|
238
|
+
const validDisableInitialization = {
|
|
239
|
+
type: OperationType.DISABLE_INITIALIZATION,
|
|
240
|
+
address: addressToBuffer('trac18qq7h503y3326v6msgvq0jwc0e8jp4t4q53z9p9jvd98arj7mtpqfac04p'),
|
|
241
|
+
cao: {
|
|
242
|
+
tx: b4a.from('1bd4f96adeffba9c04943a82993c5b19660c3a5f572620d82a67464f381640e2', 'hex'),
|
|
243
|
+
txv: b4a.from('f24e61cf7941256b080be2133bccb520414c78021215edfcb781622da526c414', 'hex'),
|
|
244
|
+
iw: b4a.from('71c53657a8738b48772f0940398d4f4b01dc56cb32cd2fd84c30359f0cbb08f1', 'hex'),
|
|
245
|
+
in: b4a.from('0ad7fe36a35a27ea4df932b800200823a97d4db31bca247f43ad7523b0493645', 'hex'),
|
|
246
|
+
is: b4a.from('5b534be7a374148962c271d194c26cf5b1ad705ab218a87709a33fe74f9d1b811772447c939b17b2f803e3da7648f49b666b929fbb20e458ced952f147162c08', 'hex')
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const validPartialBootstrapDeployment = {
|
|
251
|
+
type: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
252
|
+
address: addressToBuffer('trac1c232xtkvyg08zyeurn7l0wrarc4y36fzq5vhcdsgkxe6hdpzuslsm63dw8'),
|
|
253
|
+
bdo: {
|
|
254
|
+
tx: b4a.from('6fb7f6e7f6970477977080f2b46cc837d48605e67691d30bf7511a1417d17ed7', 'hex'),
|
|
255
|
+
txv: b4a.from('eb59a3e756d1c9597e46b33bcea91e262f8f73e94c238bdf70854aa2e8c42608', 'hex'),
|
|
256
|
+
bs: b4a.from('f68bac445eee3d9276be46aef58328a543e4b7ecc2b5c98c387c1b3ca1a7e85d', 'hex'),
|
|
257
|
+
ic: b4a.from('79ef7be837aa9fd8a446a120e1bc1e6bdd99fb5393dc4fa8299d9d5043a7cd98', 'hex'),
|
|
258
|
+
in: b4a.from('8bcef53a043f42ac7c17344f0c0d56af5b335e412d4042124f27733911169e4f', 'hex'),
|
|
259
|
+
is: b4a.from('d8626ea0552bf302921de3536e877796ef131368c9854119660c9c77a4196d4735d60bb87c6a89bbff7d5f8d72a70610d6ee73d62bc5144874cdf23f88e28a05', 'hex'),
|
|
260
|
+
va: null,
|
|
261
|
+
vn: null,
|
|
262
|
+
vs: null
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const validCompleteBootstrapDeployment = {
|
|
267
|
+
type: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
268
|
+
address: addressToBuffer('trac1c232xtkvyg08zyeurn7l0wrarc4y36fzq5vhcdsgkxe6hdpzuslsm63dw8'),
|
|
269
|
+
bdo: {
|
|
270
|
+
tx: b4a.from('6fb7f6e7f6970477977080f2b46cc837d48605e67691d30bf7511a1417d17ed7', 'hex'),
|
|
271
|
+
txv: b4a.from('eb59a3e756d1c9597e46b33bcea91e262f8f73e94c238bdf70854aa2e8c42608', 'hex'),
|
|
272
|
+
bs: b4a.from('f68bac445eee3d9276be46aef58328a543e4b7ecc2b5c98c387c1b3ca1a7e85d', 'hex'),
|
|
273
|
+
ic: b4a.from('79ef7be837aa9fd8a446a120e1bc1e6bdd99fb5393dc4fa8299d9d5043a7cd98', 'hex'),
|
|
274
|
+
in: b4a.from('8bcef53a043f42ac7c17344f0c0d56af5b335e412d4042124f27733911169e4f', 'hex'),
|
|
275
|
+
is: b4a.from('d8626ea0552bf302921de3536e877796ef131368c9854119660c9c77a4196d4735d60bb87c6a89bbff7d5f8d72a70610d6ee73d62bc5144874cdf23f88e28a05', 'hex'),
|
|
276
|
+
va: addressToBuffer('trac1xvqvlzx4w2q2pfqrmycew87kq4rv0q0cewxk68ddvddgk2xm09cqvpc4jc'),
|
|
277
|
+
vn: b4a.from('9027192c6de13b683bc0c0fbcfe09c4e55d47c12c46b122d988f06c282a4be5e', 'hex'),
|
|
278
|
+
vs: b4a.from('8fb8a3ba30e00c347bca5a8554c47e167f63b248c87e1ea5532eebbad1bc036184fe8872ff65a9e63acfee68d2213a187466c13ff6687d3ab57e5209abd4fb01', 'hex')
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
204
282
|
|
|
205
283
|
const invalidPayloads = [
|
|
206
284
|
null,
|
|
@@ -286,12 +364,15 @@ const invalidPayloadWithMultipleOneOfKeys = {
|
|
|
286
364
|
|
|
287
365
|
export default {
|
|
288
366
|
validTransactionOperation,
|
|
367
|
+
validPartialTransactionOperation,
|
|
289
368
|
validAddIndexer,
|
|
290
369
|
validRemoveIndexer,
|
|
291
370
|
validAppendWhitelist,
|
|
292
371
|
validBanValidator,
|
|
293
372
|
validAddAdmin,
|
|
373
|
+
validDisableInitialization,
|
|
294
374
|
validTransferOperation,
|
|
375
|
+
validPartialTransferOperation,
|
|
295
376
|
validBalanceInitOperation,
|
|
296
377
|
validPartialAddWriter,
|
|
297
378
|
validCompleteAddWriter,
|
|
@@ -299,6 +380,8 @@ export default {
|
|
|
299
380
|
validPartialAdminRecovery,
|
|
300
381
|
validCompleteRemoveWriter,
|
|
301
382
|
validPartialRemoveWriter,
|
|
383
|
+
validPartialBootstrapDeployment,
|
|
384
|
+
validCompleteBootstrapDeployment,
|
|
302
385
|
invalidPayloads,
|
|
303
386
|
invalidPayloadWithMultipleOneOfKeys
|
|
304
387
|
};
|
package/tests/helpers/config.js
CHANGED
|
@@ -3,16 +3,13 @@ import {generateMnemonic, mnemonicToSeed} from 'bip39-mnemonic';
|
|
|
3
3
|
import b4a from 'b4a'
|
|
4
4
|
import PeerWallet from "trac-wallet"
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js'
|
|
7
|
-
import PartialStateMessageOperations from '../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
8
6
|
import {MainSettlementBus} from '../../src/index.js'
|
|
9
7
|
import { createConfig, ENV } from '../../src/config/env.js'
|
|
10
8
|
import fileUtils from '../../src/utils/fileUtils.js'
|
|
11
9
|
import {EntryType} from '../../src/utils/constants.js';
|
|
12
10
|
import {sleep} from '../../src/utils/helpers.js'
|
|
13
11
|
import {formatIndexersEntry} from '../../src/utils/helpers.js';
|
|
14
|
-
import
|
|
15
|
-
import CompleteStateMessageDirector from '../../src/messages/completeStateMessages/CompleteStateMessageDirector.js'
|
|
12
|
+
import { applyStateMessageFactory } from "../../src/messages/state/applyStateMessageFactory.js";
|
|
16
13
|
import { safeEncodeApplyOperation } from "../../src/utils/protobuf/operationHelpers.js"
|
|
17
14
|
import { $TNK } from '../../src/core/state/utils/balance.js';
|
|
18
15
|
import { EventType } from '../../src/utils/constants.js';
|
|
@@ -69,14 +66,13 @@ export const tick = () => new Promise(resolve => setImmediate(resolve));
|
|
|
69
66
|
|
|
70
67
|
export async function fundPeer(admin, toFund, amount) {
|
|
71
68
|
const txValidity = await admin.msb.state.getIndexerSequenceState()
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
69
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
70
|
+
.buildCompleteBalanceInitializationMessage(
|
|
71
|
+
admin.wallet.address,
|
|
72
|
+
toFund.wallet.address,
|
|
73
|
+
amount,
|
|
74
|
+
txValidity
|
|
75
|
+
);
|
|
80
76
|
|
|
81
77
|
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
82
78
|
await tick()
|
|
@@ -124,10 +120,10 @@ export async function initMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
|
124
120
|
export async function setupMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
125
121
|
const admin = await initMsbAdmin(keyPair, temporaryDirectory, options);
|
|
126
122
|
const txValidity = await admin.msb.state.getIndexerSequenceState();
|
|
127
|
-
const
|
|
128
|
-
.
|
|
123
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
124
|
+
.buildCompleteAddAdminMessage(admin.wallet.address, admin.msb.state.writingKey, txValidity);
|
|
129
125
|
|
|
130
|
-
await admin.msb.state.append(
|
|
126
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
131
127
|
await tick();
|
|
132
128
|
return admin;
|
|
133
129
|
}
|
|
@@ -137,22 +133,25 @@ export async function setupNodeAsWriter(admin, writerCandidate) {
|
|
|
137
133
|
await setupWhitelist(admin, [writerCandidate.wallet.address]); // ensure if is whitelisted
|
|
138
134
|
|
|
139
135
|
const validity = await admin.msb.getIndexerSequenceState()
|
|
140
|
-
const req = await
|
|
141
|
-
.
|
|
136
|
+
const req = await applyStateMessageFactory(writerCandidate.wallet, admin.config)
|
|
137
|
+
.buildPartialAddWriterMessage(
|
|
138
|
+
writerCandidate.wallet.address,
|
|
142
139
|
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
143
|
-
b4a.toString(validity, 'hex')
|
|
140
|
+
b4a.toString(validity, 'hex'),
|
|
141
|
+
'json'
|
|
142
|
+
);
|
|
144
143
|
|
|
145
144
|
await waitWritable(admin, writerCandidate, async () => {
|
|
146
|
-
const
|
|
147
|
-
.
|
|
145
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
146
|
+
.buildCompleteAddWriterMessage(
|
|
148
147
|
admin.wallet.address,
|
|
149
148
|
b4a.from(req.rao.tx, 'hex'),
|
|
150
149
|
b4a.from(req.rao.txv, 'hex'),
|
|
151
150
|
b4a.from(req.rao.iw, 'hex'),
|
|
152
151
|
b4a.from(req.rao.in, 'hex'),
|
|
153
152
|
b4a.from(req.rao.is, 'hex')
|
|
154
|
-
)
|
|
155
|
-
await admin.msb.state.append(
|
|
153
|
+
);
|
|
154
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
156
155
|
})
|
|
157
156
|
|
|
158
157
|
return writerCandidate;
|
|
@@ -172,22 +171,25 @@ export async function promoteToWriter(admin, writerCandidate) {
|
|
|
172
171
|
isIndexer: false,
|
|
173
172
|
})
|
|
174
173
|
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
175
|
-
const req = await
|
|
176
|
-
.
|
|
174
|
+
const req = await applyStateMessageFactory(writerCandidate.wallet, writerCandidate.config)
|
|
175
|
+
.buildPartialAddWriterMessage(
|
|
176
|
+
writerCandidate.wallet.address,
|
|
177
177
|
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
178
|
-
b4a.toString(validity, 'hex')
|
|
178
|
+
b4a.toString(validity, 'hex'),
|
|
179
|
+
'json'
|
|
180
|
+
);
|
|
179
181
|
|
|
180
182
|
await waitWritable(writerCandidate, writerCandidate, async () => {
|
|
181
|
-
const
|
|
182
|
-
.
|
|
183
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
184
|
+
.buildCompleteAddWriterMessage(
|
|
183
185
|
req.address,
|
|
184
186
|
b4a.from(req.rao.tx, 'hex'),
|
|
185
187
|
b4a.from(req.rao.txv, 'hex'),
|
|
186
188
|
b4a.from(req.rao.iw, 'hex'),
|
|
187
189
|
b4a.from(req.rao.in, 'hex'),
|
|
188
190
|
b4a.from(req.rao.is, 'hex')
|
|
189
|
-
)
|
|
190
|
-
await admin.msb.state.append(
|
|
191
|
+
);
|
|
192
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
191
193
|
})
|
|
192
194
|
|
|
193
195
|
return writerCandidate;
|
|
@@ -206,10 +208,10 @@ export async function setupMsbWriter(admin, peerName, peerKeyPair, temporaryDire
|
|
|
206
208
|
export async function setupMsbIndexer(indexerCandidate, admin) {
|
|
207
209
|
try {
|
|
208
210
|
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
209
|
-
const
|
|
210
|
-
.
|
|
211
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
212
|
+
.buildCompleteAddIndexerMessage(admin.wallet.address, indexerCandidate.wallet.address, validity);
|
|
211
213
|
|
|
212
|
-
await admin.msb.state.append(
|
|
214
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
213
215
|
await tick(); // wait for the request to be processed
|
|
214
216
|
|
|
215
217
|
const isIndexer = async () => {
|
|
@@ -260,10 +262,10 @@ export async function setupWhitelist(admin, whitelistAddresses) {
|
|
|
260
262
|
fileUtils.readAddressesFromWhitelistFile = async () => whitelistAddresses;
|
|
261
263
|
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
262
264
|
for (const address of whitelistAddresses) {
|
|
263
|
-
const
|
|
264
|
-
.
|
|
265
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
266
|
+
.buildCompleteAppendWhitelistMessage(admin.wallet.address, address, validity);
|
|
265
267
|
|
|
266
|
-
await admin.msb.state.append(
|
|
268
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
267
269
|
await sleep(100)
|
|
268
270
|
}
|
|
269
271
|
|
|
@@ -314,15 +316,17 @@ export async function initDirectoryStructure(peerName, keyPair, temporaryDirecto
|
|
|
314
316
|
export const deployExternalBootstrap = async (writer, externalNode) => {
|
|
315
317
|
const externalBootstrap = randomBytes(32).toString('hex');
|
|
316
318
|
const txValidity = await writer.msb.state.getIndexerSequenceState();
|
|
317
|
-
const payload = await
|
|
318
|
-
.
|
|
319
|
+
const payload = await applyStateMessageFactory(externalNode.msb.wallet, admin.config)
|
|
320
|
+
.buildPartialBootstrapDeploymentMessage(
|
|
321
|
+
externalNode.msb.wallet.address,
|
|
319
322
|
externalBootstrap,
|
|
320
323
|
randomBytes(32).toString('hex'),
|
|
321
|
-
txValidity.toString('hex')
|
|
324
|
+
txValidity.toString('hex'),
|
|
325
|
+
'json'
|
|
322
326
|
);
|
|
323
327
|
|
|
324
|
-
const
|
|
325
|
-
.
|
|
328
|
+
const rawPayload = await applyStateMessageFactory(writer.msb.wallet, admin.config)
|
|
329
|
+
.buildCompleteBootstrapDeploymentMessage(
|
|
326
330
|
payload.address,
|
|
327
331
|
b4a.from(payload.bdo.tx, 'hex'),
|
|
328
332
|
b4a.from(payload.bdo.txv, 'hex'),
|
|
@@ -331,7 +335,7 @@ export const deployExternalBootstrap = async (writer, externalNode) => {
|
|
|
331
335
|
b4a.from(payload.bdo.in, 'hex'),
|
|
332
336
|
b4a.from(payload.bdo.is, 'hex'),
|
|
333
337
|
)
|
|
334
|
-
await writer.msb.state.base.append(
|
|
338
|
+
await writer.msb.state.base.append(safeEncodeApplyOperation(rawPayload))
|
|
335
339
|
await tick()
|
|
336
340
|
await waitForHash(writer, payload.bdo.tx)
|
|
337
341
|
return externalBootstrap
|
|
@@ -353,17 +357,19 @@ export const generatePostTx = async (writer, externalNode, externalContractBoots
|
|
|
353
357
|
|
|
354
358
|
const contentHash = await PeerWallet.blake3(JSON.stringify(testObj));
|
|
355
359
|
const validity = await writer.msb.state.getIndexerSequenceState()
|
|
356
|
-
const tx = await
|
|
357
|
-
.
|
|
360
|
+
const tx = await applyStateMessageFactory(externalNode.wallet, admin.config)
|
|
361
|
+
.buildPartialTransactionOperationMessage(
|
|
362
|
+
externalNode.wallet.address,
|
|
358
363
|
peerWriterKey,
|
|
359
364
|
b4a.toString(validity, 'hex'),
|
|
360
365
|
b4a.toString(contentHash, 'hex'),
|
|
361
366
|
externalContractBootstrap,
|
|
362
|
-
b4a.toString(writer.msb.bootstrap, 'hex')
|
|
367
|
+
b4a.toString(writer.msb.bootstrap, 'hex'),
|
|
368
|
+
'json'
|
|
363
369
|
)
|
|
364
370
|
|
|
365
|
-
const
|
|
366
|
-
.
|
|
371
|
+
const postTxPayload = await applyStateMessageFactory(writer.wallet, admin.config)
|
|
372
|
+
.buildCompleteTransactionOperationMessage(
|
|
367
373
|
tx.address,
|
|
368
374
|
b4a.from(tx.txo.tx, 'hex'),
|
|
369
375
|
b4a.from(tx.txo.txv, 'hex'),
|
|
@@ -375,6 +381,7 @@ export const generatePostTx = async (writer, externalNode, externalContractBoots
|
|
|
375
381
|
b4a.from(tx.txo.mbs, 'hex')
|
|
376
382
|
);
|
|
377
383
|
|
|
384
|
+
const postTx = safeEncodeApplyOperation(postTxPayload);
|
|
378
385
|
return { postTx, txHash: tx.txo.tx };
|
|
379
386
|
}
|
|
380
387
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as test } from 'brittle';
|
|
2
|
+
|
|
3
|
+
async function runMsgUtilsTests() {
|
|
4
|
+
test.pause();
|
|
5
|
+
await import('./network/NetworkMessageBuilder.test.js');
|
|
6
|
+
await import('./network/NetworkMessageDirector.test.js');
|
|
7
|
+
await import('./state/applyStateMessageBuilder.complete.test.js');
|
|
8
|
+
await import('./state/applyStateMessageBuilder.partial.test.js');
|
|
9
|
+
test.resume();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
await runMsgUtilsTests();
|