trac-msb 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +8 -16
- package/msb.mjs +13 -25
- package/package.json +8 -4
- package/proto/network.proto +74 -0
- package/rpc/{create_server.mjs → create_server.js} +4 -4
- package/rpc/{handlers.mjs → handlers.js} +7 -7
- package/rpc/routes/{index.mjs → index.js} +1 -1
- package/rpc/routes/{v1.mjs → v1.js} +1 -1
- package/rpc/rpc_server.js +10 -0
- package/rpc/rpc_services.js +48 -7
- package/rpc/utils/{helpers.mjs → helpers.js} +1 -1
- package/src/config/config.js +137 -0
- package/src/config/env.js +63 -0
- package/src/core/network/Network.js +133 -119
- package/src/core/network/identity/NetworkWalletFactory.js +5 -6
- 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/ValidatorResponse.js +2 -2
- package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +13 -6
- 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/protocols/shared/handlers/TransferOperationHandler.js +57 -0
- package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +21 -26
- package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +3 -3
- package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +15 -12
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +10 -11
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +10 -7
- package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +40 -22
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
- package/src/core/network/services/ConnectionManager.js +13 -19
- package/src/core/network/services/MessageOrchestrator.js +10 -22
- package/src/core/network/services/TransactionPoolService.js +10 -10
- package/src/core/network/services/TransactionRateLimiterService.js +5 -3
- package/src/core/network/services/ValidatorObserverService.js +46 -21
- package/src/core/state/State.js +137 -141
- package/src/core/state/utils/address.js +18 -16
- package/src/core/state/utils/adminEntry.js +17 -16
- package/src/core/state/utils/deploymentEntry.js +15 -15
- package/src/core/state/utils/transaction.js +3 -95
- package/src/index.js +250 -325
- 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/check.js +21 -17
- package/src/utils/cli.js +0 -8
- package/src/utils/cliCommands.js +11 -11
- package/src/utils/constants.js +36 -24
- package/src/utils/fileUtils.js +1 -4
- package/src/utils/helpers.js +9 -20
- package/src/utils/migrationUtils.js +2 -2
- package/src/utils/normalizers.js +94 -11
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +10 -0
- package/tests/acceptance/v1/account/account.test.mjs +2 -2
- package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
- package/tests/acceptance/v1/rpc.test.mjs +10 -10
- package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
- package/tests/fixtures/check.fixtures.js +42 -42
- package/tests/fixtures/networkV1.fixtures.js +84 -0
- package/tests/fixtures/protobuf.fixtures.js +110 -26
- package/tests/helpers/StateNetworkFactory.js +3 -5
- package/tests/helpers/autobaseTestHelpers.js +1 -2
- package/tests/helpers/config.js +3 -0
- package/tests/helpers/setupApplyTests.js +113 -99
- package/tests/helpers/transactionPayloads.mjs +26 -12
- 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 +10 -7
- package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
- 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 +11 -8
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +11 -7
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -20
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +57 -48
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +72 -57
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +12 -14
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +18 -13
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +27 -30
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +24 -21
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/commonScenarioHelper.js +16 -16
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +10 -5
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +16 -9
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +23 -19
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +45 -36
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +48 -45
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +32 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
- package/tests/unit/state/stateModule.test.js +0 -1
- package/tests/unit/state/stateTestUtils.js +7 -3
- package/tests/unit/state/utils/address.test.js +3 -3
- package/tests/unit/state/utils/adminEntry.test.js +10 -9
- package/tests/unit/unit.test.js +1 -1
- package/tests/unit/utils/buffer/buffer.test.js +62 -1
- package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
- package/tests/unit/utils/check/common.test.js +7 -6
- package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
- package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
- package/tests/unit/utils/check/transactionOperation.test.js +3 -3
- package/tests/unit/utils/check/transferOperation.test.js +3 -3
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
- package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
- package/tests/unit/utils/utils.test.js +0 -1
- package/rpc/rpc_server.mjs +0 -10
- package/src/core/network/messaging/NetworkMessages.js +0 -63
- package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -112
- package/src/core/network/messaging/handlers/ResponseHandler.js +0 -108
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -116
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -143
- package/src/core/network/messaging/handlers/TransferOperationHandler.js +0 -52
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -94
- package/src/core/network/messaging/validators/AdminResponse.js +0 -58
- package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
- package/src/core/state/utils/indexerEntry.js +0 -105
- package/src/messages/base/StateBuilder.js +0 -25
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -421
- package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -299
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
- package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -131
- package/src/utils/crypto.js +0 -11
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -68
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -125
- package/tests/integration/apply/addIndexer.test.js +0 -237
- package/tests/integration/apply/addWhitelist.test.js +0 -53
- package/tests/integration/apply/addWriter.test.js +0 -244
- package/tests/integration/apply/apply.test.js +0 -19
- package/tests/integration/apply/banValidator.test.js +0 -109
- package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
- package/tests/integration/apply/postTx/postTx.test.js +0 -222
- package/tests/integration/apply/removeIndexer.test.js +0 -128
- package/tests/integration/apply/removeWriter.test.js +0 -167
- package/tests/integration/apply/transfer.test.js +0 -81
- 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 -16
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -69
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -16
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -442
- 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 -58
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -277
- package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
- package/tests/unit/state/utils/indexerEntry.test.js +0 -83
- package/tests/unit/state/utils/transaction.test.js +0 -97
- package/tests/unit/utils/crypto/createHash.test.js +0 -15
- /package/rpc/{constants.mjs → constants.js} +0 -0
- /package/rpc/{cors.mjs → cors.js} +0 -0
- /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
- /package/rpc/utils/{url.mjs → url.js} +0 -0
- /package/src/utils/{operations.js → applyOperations.js} +0 -0
|
@@ -1,442 +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 {generatePostTx, randomBytes} from "../../helpers/setupApplyTests.js";
|
|
11
|
-
|
|
12
|
-
const msgTxoLength = 10;
|
|
13
|
-
const opType = OperationType.TX;
|
|
14
|
-
test('assemblePostTxMessage - ....', async (k) => {
|
|
15
|
-
await fixtures.initAll();
|
|
16
|
-
const nonAdminWallet = fixtures.walletNonAdmin;
|
|
17
|
-
const peerWallet = fixtures.walletPeer;
|
|
18
|
-
const validatorAddress = nonAdminWallet.address;
|
|
19
|
-
const txHash = randomBytes(32);
|
|
20
|
-
const incomingAddress = peerWallet.address;
|
|
21
|
-
|
|
22
|
-
const incomingWriterKey = randomBytes(32);
|
|
23
|
-
const incomingNonce = randomBytes(32);
|
|
24
|
-
const contentHash = randomBytes(32);
|
|
25
|
-
const incomingSignature = randomBytes(64);
|
|
26
|
-
const externalBootstrap = randomBytes(32);
|
|
27
|
-
const msbBootstrap = randomBytes(32);
|
|
28
|
-
|
|
29
|
-
const decodedPostTx = safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
30
|
-
nonAdminWallet,
|
|
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), 'Message validator address should be a valid address');
|
|
48
|
-
k.ok(isAddressValid(decodedPostTx.txo.ia), 'Message incoming address should be a valid address');
|
|
49
|
-
|
|
50
|
-
k.ok(bufferToAddress(decodedPostTx.txo.ia) === incomingAddress, 'Message incoming address should be the address of the peer wallet');
|
|
51
|
-
k.ok(bufferToAddress(decodedPostTx.address) === 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 CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
80
|
-
invalidWallet,
|
|
81
|
-
validatorAddress,
|
|
82
|
-
txHash,
|
|
83
|
-
incomingAddress,
|
|
84
|
-
incomingWriterKey,
|
|
85
|
-
incomingNonce,
|
|
86
|
-
contentHash,
|
|
87
|
-
incomingSignature,
|
|
88
|
-
externalBootstrap,
|
|
89
|
-
msbBootstrap
|
|
90
|
-
),
|
|
91
|
-
errorMessageIncludes('Wallet should have a valid TRAC address')
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
k.test(`assemblePostTxMessage - Invalid wallet instance - invalid prefix`, async (k) => {
|
|
96
|
-
const invalidWallet = {
|
|
97
|
-
address: 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk'
|
|
98
|
-
}
|
|
99
|
-
await k.exception(
|
|
100
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
101
|
-
invalidWallet,
|
|
102
|
-
validatorAddress,
|
|
103
|
-
txHash,
|
|
104
|
-
incomingAddress,
|
|
105
|
-
incomingWriterKey,
|
|
106
|
-
incomingNonce,
|
|
107
|
-
contentHash,
|
|
108
|
-
incomingSignature,
|
|
109
|
-
externalBootstrap,
|
|
110
|
-
msbBootstrap
|
|
111
|
-
),
|
|
112
|
-
errorMessageIncludes('Wallet should have a valid TRAC address')
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
k.test(`assemblePostTxMessage - Invalid wallet instance - empty string`, async (k) => {
|
|
117
|
-
const invalidWallet = {
|
|
118
|
-
address: ''
|
|
119
|
-
}
|
|
120
|
-
await k.exception(
|
|
121
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
122
|
-
invalidWallet,
|
|
123
|
-
validatorAddress,
|
|
124
|
-
txHash,
|
|
125
|
-
incomingAddress,
|
|
126
|
-
incomingWriterKey,
|
|
127
|
-
incomingNonce,
|
|
128
|
-
contentHash,
|
|
129
|
-
incomingSignature,
|
|
130
|
-
externalBootstrap,
|
|
131
|
-
msbBootstrap
|
|
132
|
-
),
|
|
133
|
-
errorMessageIncludes('Wallet should have a valid TRAC address')
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
k.test(`assemblePostTxMessage - Invalid wallet instance - null Wallet `, async (k) => {
|
|
138
|
-
await k.exception(
|
|
139
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
140
|
-
null,
|
|
141
|
-
validatorAddress,
|
|
142
|
-
txHash,
|
|
143
|
-
incomingAddress,
|
|
144
|
-
incomingWriterKey,
|
|
145
|
-
incomingNonce,
|
|
146
|
-
contentHash,
|
|
147
|
-
incomingSignature,
|
|
148
|
-
externalBootstrap,
|
|
149
|
-
msbBootstrap
|
|
150
|
-
),
|
|
151
|
-
errorMessageIncludes('Wallet must be a valid wallet object')
|
|
152
|
-
);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
k.test(`assemblePostTxMessage - Invalid wallet instance - undefined Wallet`, async (k) => {
|
|
156
|
-
await k.exception(
|
|
157
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
158
|
-
undefined,
|
|
159
|
-
validatorAddress,
|
|
160
|
-
txHash,
|
|
161
|
-
incomingAddress,
|
|
162
|
-
incomingWriterKey,
|
|
163
|
-
incomingNonce,
|
|
164
|
-
contentHash,
|
|
165
|
-
incomingSignature,
|
|
166
|
-
externalBootstrap,
|
|
167
|
-
msbBootstrap
|
|
168
|
-
),
|
|
169
|
-
errorMessageIncludes('Wallet must be a valid wallet object')
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
k.test(`assemblePostTxMessage - Address parameter (validator address) - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
|
|
174
|
-
|
|
175
|
-
const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
|
|
176
|
-
|
|
177
|
-
await k.exception(
|
|
178
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
179
|
-
nonAdminWallet,
|
|
180
|
-
invalid,
|
|
181
|
-
txHash,
|
|
182
|
-
incomingAddress,
|
|
183
|
-
incomingWriterKey,
|
|
184
|
-
incomingNonce,
|
|
185
|
-
contentHash,
|
|
186
|
-
incomingSignature,
|
|
187
|
-
externalBootstrap,
|
|
188
|
-
msbBootstrap
|
|
189
|
-
),
|
|
190
|
-
errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
k.test(`assemblePostTxMessage - Address parameter (validator address) - trac address is to short`, async (k) => {
|
|
195
|
-
const invalid = 'trac1y6kkq48fgu3ur';
|
|
196
|
-
|
|
197
|
-
await k.exception(
|
|
198
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
199
|
-
nonAdminWallet,
|
|
200
|
-
invalid,
|
|
201
|
-
txHash,
|
|
202
|
-
incomingAddress,
|
|
203
|
-
incomingWriterKey,
|
|
204
|
-
incomingNonce,
|
|
205
|
-
contentHash,
|
|
206
|
-
incomingSignature,
|
|
207
|
-
externalBootstrap,
|
|
208
|
-
msbBootstrap
|
|
209
|
-
),
|
|
210
|
-
errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
k.test(`assemblePostTxMessage- Address parameter (validator address) - invalid prefix`, async (k) => {
|
|
215
|
-
const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
|
|
216
|
-
|
|
217
|
-
await k.exception(
|
|
218
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
219
|
-
nonAdminWallet,
|
|
220
|
-
invalid,
|
|
221
|
-
txHash,
|
|
222
|
-
incomingAddress,
|
|
223
|
-
incomingWriterKey,
|
|
224
|
-
incomingNonce,
|
|
225
|
-
contentHash,
|
|
226
|
-
incomingSignature,
|
|
227
|
-
externalBootstrap,
|
|
228
|
-
msbBootstrap
|
|
229
|
-
), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
k.test(`assemblePostTxMessage - Address parameter (validator address) - empty string`, async (k) => {
|
|
235
|
-
const invalid = '';
|
|
236
|
-
|
|
237
|
-
await k.exception(
|
|
238
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
239
|
-
nonAdminWallet,
|
|
240
|
-
invalid,
|
|
241
|
-
txHash,
|
|
242
|
-
incomingAddress,
|
|
243
|
-
incomingWriterKey,
|
|
244
|
-
incomingNonce,
|
|
245
|
-
contentHash,
|
|
246
|
-
incomingSignature,
|
|
247
|
-
externalBootstrap,
|
|
248
|
-
msbBootstrap
|
|
249
|
-
), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
250
|
-
);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
k.test(`assemblePostTxMessage - Address parameter (validator address) - Null`, async (k) => {
|
|
254
|
-
|
|
255
|
-
await k.exception(
|
|
256
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
257
|
-
nonAdminWallet,
|
|
258
|
-
null,
|
|
259
|
-
txHash,
|
|
260
|
-
incomingAddress,
|
|
261
|
-
incomingWriterKey,
|
|
262
|
-
incomingNonce,
|
|
263
|
-
contentHash,
|
|
264
|
-
incomingSignature,
|
|
265
|
-
externalBootstrap,
|
|
266
|
-
msbBootstrap
|
|
267
|
-
), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
268
|
-
);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
k.test(`assemblePostTxMessage - Address parameter (validator address) - undefined`, async (k) => {
|
|
272
|
-
await k.exception(
|
|
273
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
274
|
-
nonAdminWallet,
|
|
275
|
-
undefined,
|
|
276
|
-
txHash,
|
|
277
|
-
incomingAddress,
|
|
278
|
-
incomingWriterKey,
|
|
279
|
-
incomingNonce,
|
|
280
|
-
contentHash,
|
|
281
|
-
incomingSignature,
|
|
282
|
-
externalBootstrap,
|
|
283
|
-
msbBootstrap
|
|
284
|
-
), errorMessageIncludes('Address field must be a valid TRAC bech32m address with length 63')
|
|
285
|
-
);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
k.test(`assemblePostTxMessage - Address parameter (incoming address) - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
|
|
289
|
-
const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
|
|
290
|
-
await k.exception(
|
|
291
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
292
|
-
nonAdminWallet,
|
|
293
|
-
validatorAddress, // correct validator address
|
|
294
|
-
txHash,
|
|
295
|
-
invalid, // invalid incoming address
|
|
296
|
-
incomingWriterKey,
|
|
297
|
-
incomingNonce,
|
|
298
|
-
contentHash,
|
|
299
|
-
incomingSignature,
|
|
300
|
-
externalBootstrap,
|
|
301
|
-
msbBootstrap
|
|
302
|
-
),
|
|
303
|
-
errorMessageIncludes('Incoming address must be a 63 length string')
|
|
304
|
-
);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
k.test(`assemblePostTxMessage - Address parameter (incoming address) - trac address is to short`, async (k) => {
|
|
308
|
-
const invalid = 'trac1y6kkq48fgu3ur';
|
|
309
|
-
await k.exception(
|
|
310
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
311
|
-
nonAdminWallet,
|
|
312
|
-
validatorAddress,
|
|
313
|
-
txHash,
|
|
314
|
-
invalid,
|
|
315
|
-
incomingWriterKey,
|
|
316
|
-
incomingNonce,
|
|
317
|
-
contentHash,
|
|
318
|
-
incomingSignature,
|
|
319
|
-
externalBootstrap,
|
|
320
|
-
msbBootstrap
|
|
321
|
-
),
|
|
322
|
-
errorMessageIncludes('Incoming address must be a 63 length string')
|
|
323
|
-
);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
k.test(`assemblePostTxMessage- Address parameter (incoming address) - invalid prefix`, async (k) => {
|
|
327
|
-
const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
|
|
328
|
-
await k.exception(
|
|
329
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
330
|
-
nonAdminWallet,
|
|
331
|
-
validatorAddress,
|
|
332
|
-
txHash,
|
|
333
|
-
invalid,
|
|
334
|
-
incomingWriterKey,
|
|
335
|
-
incomingNonce,
|
|
336
|
-
contentHash,
|
|
337
|
-
incomingSignature,
|
|
338
|
-
externalBootstrap,
|
|
339
|
-
msbBootstrap
|
|
340
|
-
), errorMessageIncludes('Incoming address must be a 63 length string')
|
|
341
|
-
);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
k.test(`assemblePostTxMessage - Address parameter (incoming address) - empty string`, async (k) => {
|
|
345
|
-
const invalid = '';
|
|
346
|
-
await k.exception(
|
|
347
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
348
|
-
nonAdminWallet,
|
|
349
|
-
validatorAddress,
|
|
350
|
-
txHash,
|
|
351
|
-
invalid,
|
|
352
|
-
incomingWriterKey,
|
|
353
|
-
incomingNonce,
|
|
354
|
-
contentHash,
|
|
355
|
-
incomingSignature,
|
|
356
|
-
externalBootstrap,
|
|
357
|
-
msbBootstrap
|
|
358
|
-
), errorMessageIncludes('Incoming address must be a 63 length string')
|
|
359
|
-
);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
k.test(`assemblePostTxMessage - Address parameter (incoming address) - Null`, async (k) => {
|
|
363
|
-
await k.exception(
|
|
364
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
365
|
-
nonAdminWallet,
|
|
366
|
-
validatorAddress,
|
|
367
|
-
txHash,
|
|
368
|
-
null,
|
|
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
|
-
k.test(`assemblePostTxMessage - Address parameter (incoming address) - undefined`, async (k) => {
|
|
380
|
-
await k.exception(
|
|
381
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
382
|
-
nonAdminWallet,
|
|
383
|
-
validatorAddress,
|
|
384
|
-
txHash,
|
|
385
|
-
undefined,
|
|
386
|
-
incomingWriterKey,
|
|
387
|
-
incomingNonce,
|
|
388
|
-
contentHash,
|
|
389
|
-
incomingSignature,
|
|
390
|
-
externalBootstrap,
|
|
391
|
-
msbBootstrap
|
|
392
|
-
), errorMessageIncludes('Incoming address must be a 63 length string')
|
|
393
|
-
);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
const invalidBufferCases = [
|
|
397
|
-
{ name: 'empty buffer', value: b4a.alloc(0) },
|
|
398
|
-
{ name: 'null', value: null },
|
|
399
|
-
{ name: 'undefined', value: undefined },
|
|
400
|
-
];
|
|
401
|
-
const bufferParams = [
|
|
402
|
-
{ key: 'msbBootstrap', error: 'MSB bootstrap must be a 32-byte buffer.' },
|
|
403
|
-
{ key: 'externalBootstrap', error: 'Bootstrap key must be a 32-byte buffer.' },
|
|
404
|
-
{ key: 'incomingSignature', error: 'Incoming signature must be a 64-byte buffer.' },
|
|
405
|
-
{ key: 'contentHash', error: 'Content hash must be a 32-byte buffer.' },
|
|
406
|
-
{ key: 'incomingNonce', error: 'Incoming nonce must be a 32-byte buffer.' },
|
|
407
|
-
{ key: 'incomingWriterKey', error: 'Incoming writer key must be a 32-byte buffer.' },
|
|
408
|
-
{ key: 'txHash', error: 'Transaction hash must be a 32-byte buffer.' },
|
|
409
|
-
];
|
|
410
|
-
for (const param of bufferParams) {
|
|
411
|
-
for (const invalid of invalidBufferCases) {
|
|
412
|
-
k.test(`assemblePostTxMessage - ${param.key} - ${invalid.name}`, async (k) => {
|
|
413
|
-
const args = {
|
|
414
|
-
msbBootstrap,
|
|
415
|
-
externalBootstrap,
|
|
416
|
-
incomingSignature,
|
|
417
|
-
contentHash,
|
|
418
|
-
incomingNonce,
|
|
419
|
-
incomingWriterKey,
|
|
420
|
-
txHash
|
|
421
|
-
};
|
|
422
|
-
args[param.key] = invalid.value;
|
|
423
|
-
await k.exception(
|
|
424
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
425
|
-
nonAdminWallet,
|
|
426
|
-
validatorAddress,
|
|
427
|
-
args.txHash,
|
|
428
|
-
incomingAddress,
|
|
429
|
-
args.incomingWriterKey,
|
|
430
|
-
args.incomingNonce,
|
|
431
|
-
args.contentHash,
|
|
432
|
-
args.incomingSignature,
|
|
433
|
-
args.externalBootstrap,
|
|
434
|
-
args.msbBootstrap
|
|
435
|
-
),
|
|
436
|
-
errorMessageIncludes(param.error)
|
|
437
|
-
);
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
})
|
|
@@ -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
|
-
|
|
8
|
-
const testName = 'assembleRemoveIndexerMessage';
|
|
9
|
-
test(testName, async (t) => {
|
|
10
|
-
await initAll();
|
|
11
|
-
const assembler = async (wallet,address) => {
|
|
12
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleRemoveIndexerMessage(wallet,address));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.REMOVE_INDEXER, 2, walletNonAdmin.address);
|
|
16
|
-
});
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
const testName = 'assembleRemoveWriterMessage';
|
|
10
|
-
test(testName, async (t) => {
|
|
11
|
-
await initAll();
|
|
12
|
-
const assembler = async (wallet, writingKey) => {
|
|
13
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleRemoveWriterMessage(wallet, writingKey));
|
|
14
|
-
}
|
|
15
|
-
await messageOperationsEkoTest(t, testName, assembler, walletNonAdmin, writingKeyNonAdmin, OperationType.REMOVE_WRITER, 3, walletNonAdmin.address);
|
|
16
|
-
});
|
|
17
|
-
|
|
@@ -1,58 +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
|
-
|
|
11
|
-
// MOCK SETUP
|
|
12
|
-
const whitelistAddresses = [
|
|
13
|
-
'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk',
|
|
14
|
-
];
|
|
15
|
-
const originalReadAddressesFromWhitelistFile = fileUtils.readAddressesFromWhitelistFile;
|
|
16
|
-
|
|
17
|
-
test('assembleWhitelistMessages', async (t) => {
|
|
18
|
-
fileUtils.readAddressesFromWhitelistFile = async () => whitelistAddresses;
|
|
19
|
-
|
|
20
|
-
await fixtures.initAll();
|
|
21
|
-
const walletAdmin = fixtures.walletAdmin;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
t.test('assembleWhitelistMessages - Happy Path', async (k) => {
|
|
25
|
-
const mapMsg = await CompleteStateMessageOperations.assembleAppendWhitelistMessages(walletAdmin);
|
|
26
|
-
const msg = mapMsg.get(whitelistAddresses[0])
|
|
27
|
-
k.ok(msg, 'Message should be created');
|
|
28
|
-
k.ok(msg.length > 0, 'Message should be an array with at least one element');
|
|
29
|
-
const decodedMsg = safeDecodeApplyOperation(msg);
|
|
30
|
-
k.is(Object.keys(decodedMsg).length, 3, 'Message should have 3 keys');
|
|
31
|
-
k.is(Object.keys(decodedMsg.bko).length, 2, 'Message value should have 2 keys');
|
|
32
|
-
k.is(decodedMsg.type, OperationType.APPEND_WHITELIST, 'Message type should be APPEND_WHITELIST');
|
|
33
|
-
|
|
34
|
-
k.is(bufferToAddress(decodedMsg.address) , whitelistAddresses[0], 'Message address should be the address in the file');
|
|
35
|
-
k.is(decodedMsg.bko.nonce.length, 32, 'Message nonce should be 32 bytes long');
|
|
36
|
-
k.ok(b4a.isBuffer(decodedMsg.bko.nonce), 'Message nonce should be a buffer');
|
|
37
|
-
k.is(decodedMsg.bko.sig.length, 64, 'Message signature should be 64 bytes long');
|
|
38
|
-
k.ok(b4a.isBuffer(decodedMsg.bko.sig), 'Message signature should be a buffer');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
t.test('assembleWhitelistMessages - Should return null when wallet is invalid', async (k) => {
|
|
42
|
-
await k.exception(
|
|
43
|
-
async () => await CompleteStateMessageOperations.assembleAppendWhitelistMessages(null),
|
|
44
|
-
errorMessageIncludes('Wallet must be a valid wallet object')
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
t.test('assembleWhitelistMessages - Empty object', async (k) => {
|
|
50
|
-
await k.exception(
|
|
51
|
-
async () => await CompleteStateMessageOperations.assembleAppendWhitelistMessages({}),
|
|
52
|
-
errorMessageIncludes('Wallet should have a valid TRAC address.')
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
fileUtils.readAddressesFromWhitelistFile = originalReadAddressesFromWhitelistFile;
|
|
58
|
-
});
|