trac-msb 0.2.6 → 0.2.8
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 +9 -16
- package/docs/networking-dualstack-plan.md +75 -0
- package/docs/networking-layer-redesign.md +155 -0
- package/msb.mjs +11 -23
- package/package.json +2 -3
- package/rpc/{create_server.mjs → create_server.js} +2 -2
- package/rpc/{handlers.mjs → handlers.js} +5 -5
- package/rpc/routes/{index.mjs → index.js} +1 -1
- package/rpc/routes/{v1.mjs → v1.js} +1 -1
- package/rpc/{rpc_server.mjs → rpc_server.js} +1 -1
- package/rpc/rpc_services.js +4 -4
- package/src/config/config.js +137 -0
- package/src/config/env.js +61 -0
- package/src/core/network/Network.js +131 -72
- package/src/core/network/identity/NetworkWalletFactory.js +3 -4
- package/src/core/network/messaging/NetworkMessages.js +12 -11
- package/src/core/network/messaging/handlers/GetRequestHandler.js +5 -4
- package/src/core/network/messaging/handlers/ResponseHandler.js +4 -5
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +17 -19
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +44 -38
- package/src/core/network/messaging/handlers/TransferOperationHandler.js +29 -25
- package/src/core/network/messaging/handlers/base/BaseOperationHandler.js +20 -21
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +24 -20
- package/src/core/network/messaging/validators/AdminResponse.js +2 -2
- package/src/core/network/messaging/validators/CustomNodeResponse.js +2 -2
- package/src/core/network/messaging/validators/PartialBootstrapDeployment.js +3 -3
- package/src/core/network/messaging/validators/PartialRoleAccess.js +15 -12
- package/src/core/network/messaging/validators/PartialTransaction.js +9 -10
- package/src/core/network/messaging/validators/PartialTransfer.js +10 -7
- package/src/core/network/messaging/validators/ValidatorResponse.js +2 -2
- package/src/core/network/messaging/validators/base/BaseResponse.js +13 -5
- package/src/core/network/messaging/validators/base/PartialOperation.js +37 -21
- package/src/core/network/services/ConnectionManager.js +248 -62
- package/src/core/network/services/MessageOrchestrator.js +83 -0
- package/src/core/network/services/TransactionPoolService.js +9 -8
- package/src/core/network/services/ValidatorObserverService.js +95 -34
- package/src/core/state/State.js +136 -139
- 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 +153 -201
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +36 -32
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +39 -42
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +20 -20
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +29 -22
- package/src/utils/check.js +21 -17
- package/src/utils/cliCommands.js +11 -11
- package/src/utils/constants.js +2 -9
- 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 +10 -9
- 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 +9 -9
- 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/protobuf.fixtures.js +27 -26
- package/tests/helpers/StateNetworkFactory.js +3 -5
- package/tests/helpers/autobaseTestHelpers.js +48 -2
- package/tests/helpers/config.js +3 -0
- package/tests/helpers/setupApplyTests.js +89 -82
- package/tests/helpers/transactionPayloads.mjs +26 -12
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +10 -9
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +20 -19
- package/tests/integration/apply/addIndexer.test.js +23 -21
- package/tests/integration/apply/addWhitelist.test.js +9 -9
- package/tests/integration/apply/addWriter.test.js +33 -32
- package/tests/integration/apply/banValidator.test.js +16 -9
- package/tests/integration/apply/postTx/invalidSubValues.test.js +4 -4
- package/tests/integration/apply/postTx/postTx.test.js +7 -33
- package/tests/integration/apply/removeIndexer.test.js +11 -7
- package/tests/integration/apply/removeWriter.test.js +20 -19
- package/tests/integration/apply/transfer.test.js +18 -16
- package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +2 -1
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +9 -10
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +3 -2
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +25 -43
- package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +5 -4
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +4 -3
- package/tests/unit/network/ConnectionManager.test.js +41 -70
- package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +6 -6
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +8 -8
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +6 -5
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +24 -23
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +10 -16
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +45 -41
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +17 -16
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +3 -4
- 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 +23 -25
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +19 -18
- 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 +3 -4
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +2 -2
- 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 +11 -10
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +6 -7
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +35 -34
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +44 -43
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +26 -25
- 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/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/utils.test.js +0 -1
- package/src/core/state/utils/indexerEntry.js +0 -105
- package/src/utils/crypto.js +0 -11
- 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/{helpers.mjs → helpers.js} +0 -0
- /package/rpc/utils/{url.mjs → url.js} +0 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
buildRemoveIndexerPayloadWithTxValidity as buildRemoveIndexerPayloadWithTxValidityFromAddHelper,
|
|
15
15
|
assertAddIndexerSuccessState
|
|
16
16
|
} from '../addIndexer/addIndexerScenarioHelpers.js';
|
|
17
|
+
import { config } from '../../../../helpers/config.js';
|
|
17
18
|
|
|
18
19
|
export async function setupRemoveIndexerScenario(t, options = {}) {
|
|
19
20
|
const context = await setupAddIndexerScenario(t, options);
|
|
@@ -102,7 +103,7 @@ export async function applyWithoutIndexerMembership(context, invalidPayload) {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
const targetAddress = indexerPeer.wallet.address;
|
|
105
|
-
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddress);
|
|
106
|
+
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
|
|
106
107
|
if (!targetAddressBuffer) {
|
|
107
108
|
throw new Error('RemoveIndexer missing indexer membership scenario requires a decodable indexer address.');
|
|
108
109
|
}
|
|
@@ -277,7 +278,7 @@ async function assertWriterRegistry(t, base, writingKey, expectedAddress) {
|
|
|
277
278
|
const registryKey = EntryType.WRITER_ADDRESS + writingKey.toString('hex');
|
|
278
279
|
const entry = await base.view.get(registryKey);
|
|
279
280
|
t.ok(entry, 'writer registry entry exists after removeIndexer');
|
|
280
|
-
const addressBuffer = addressUtils.addressToBuffer(expectedAddress);
|
|
281
|
+
const addressBuffer = addressUtils.addressToBuffer(expectedAddress, config.addressPrefix);
|
|
281
282
|
t.ok(addressBuffer, 'indexer address encodes to buffer');
|
|
282
283
|
if (!entry?.value || !addressBuffer) return;
|
|
283
284
|
t.ok(
|
|
@@ -292,7 +293,7 @@ async function assertWriterIndexUpdates(t, base, lengthBefore, expectedAddress)
|
|
|
292
293
|
|
|
293
294
|
const indexEntry = await base.view.get(EntryType.WRITERS_INDEX + lengthBefore);
|
|
294
295
|
t.ok(indexEntry, 'writers index entry stored after removeIndexer');
|
|
295
|
-
const addressBuffer = addressUtils.addressToBuffer(expectedAddress);
|
|
296
|
+
const addressBuffer = addressUtils.addressToBuffer(expectedAddress, config.addressPrefix);
|
|
296
297
|
if (!indexEntry?.value || !addressBuffer) return;
|
|
297
298
|
t.ok(
|
|
298
299
|
b4a.equals(indexEntry.value, addressBuffer),
|
|
@@ -340,7 +341,7 @@ async function assertRemoveIndexerPayloadMetadata(t, base, payload, expectedAdmi
|
|
|
340
341
|
|
|
341
342
|
const requesterAddressBuffer = decodedOperation.address;
|
|
342
343
|
t.ok(requesterAddressBuffer, 'removeIndexer payload contains requester address');
|
|
343
|
-
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
344
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
|
|
344
345
|
t.ok(requesterAddress, 'removeIndexer requester address decodes');
|
|
345
346
|
if (requesterAddress) {
|
|
346
347
|
t.is(requesterAddress, expectedAdmin, 'removeIndexer payload signed by admin');
|
|
@@ -348,7 +349,7 @@ async function assertRemoveIndexerPayloadMetadata(t, base, payload, expectedAdmi
|
|
|
348
349
|
|
|
349
350
|
const targetAddressBuffer = decodedOperation?.aco?.ia;
|
|
350
351
|
t.ok(targetAddressBuffer, 'removeIndexer payload contains target indexer address');
|
|
351
|
-
const targetAddress = addressUtils.bufferToAddress(targetAddressBuffer);
|
|
352
|
+
const targetAddress = addressUtils.bufferToAddress(targetAddressBuffer, config.addressPrefix);
|
|
352
353
|
t.ok(targetAddress, 'removeIndexer target address decodes');
|
|
353
354
|
if (targetAddress) {
|
|
354
355
|
t.is(targetAddress, expectedTarget, 'removeIndexer payload nominates expected indexer');
|
|
@@ -15,6 +15,7 @@ import { toBalance, BALANCE_FEE, BALANCE_TO_STAKE } from '../../../../../src/cor
|
|
|
15
15
|
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
16
16
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
17
17
|
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
18
|
+
import { config } from '../../../../helpers/config.js';
|
|
18
19
|
|
|
19
20
|
export async function setupRemoveWriterScenario(t, options = {}) {
|
|
20
21
|
const context = await setupAddWriterScenario(t, options);
|
|
@@ -142,7 +143,7 @@ async function assertWriterStillPromoted(t, base, writerPeer, expected) {
|
|
|
142
143
|
'writer stake remains untouched'
|
|
143
144
|
);
|
|
144
145
|
|
|
145
|
-
const writerAddressBuffer = addressUtils.addressToBuffer(writerAddress);
|
|
146
|
+
const writerAddressBuffer = addressUtils.addressToBuffer(writerAddress, config.addressPrefix);
|
|
146
147
|
const writingKeyHex = writerPeer.base.local.key.toString('hex');
|
|
147
148
|
const registryKey = EntryType.WRITER_ADDRESS + writingKeyHex;
|
|
148
149
|
const registryEntry = await base.view.get(registryKey);
|
|
@@ -161,7 +162,7 @@ async function assertPayloadProcessedByValidator(t, payload, expectedValidatorAd
|
|
|
161
162
|
const validatorAddressBuffer = decodedOperation?.rao?.va;
|
|
162
163
|
t.ok(validatorAddressBuffer, 'removeWriter payload carries validator address');
|
|
163
164
|
if (!validatorAddressBuffer) return;
|
|
164
|
-
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer);
|
|
165
|
+
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
|
|
165
166
|
t.ok(validatorAddress, 'removeWriter payload validator address decodes');
|
|
166
167
|
if (!validatorAddress) return;
|
|
167
168
|
t.is(
|
|
@@ -179,13 +180,11 @@ export async function buildRemoveWriterPayloadWithTxValidity(context, mutatedTxV
|
|
|
179
180
|
}
|
|
180
181
|
const { readerPeer = selectWriterPeer(context), validatorPeer = context.adminBootstrap, writerKeyBuffer = null } = options;
|
|
181
182
|
const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
182
|
-
const partial = await PartialStateMessageOperations.assembleRemoveWriterMessage(
|
|
183
|
-
readerPeer.wallet,
|
|
183
|
+
const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleRemoveWriterMessage(
|
|
184
184
|
writerKey.toString('hex'),
|
|
185
185
|
mutatedTxValidity.toString('hex')
|
|
186
186
|
);
|
|
187
|
-
return CompleteStateMessageOperations.assembleRemoveWriterMessage(
|
|
188
|
-
validatorPeer.wallet,
|
|
187
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleRemoveWriterMessage(
|
|
189
188
|
partial.address,
|
|
190
189
|
b4a.from(partial.rao.tx, 'hex'),
|
|
191
190
|
mutatedTxValidity,
|
|
@@ -256,7 +255,7 @@ export async function applyWithWriterRegistryForeignAddress(context, invalidPayl
|
|
|
256
255
|
throw new Error('Foreign registry override requires a peer with an address.');
|
|
257
256
|
}
|
|
258
257
|
const foreignEntry = {
|
|
259
|
-
value: addressUtils.addressToBuffer(foreignAddress)
|
|
258
|
+
value: addressUtils.addressToBuffer(foreignAddress, config.addressPrefix)
|
|
260
259
|
};
|
|
261
260
|
await withWriterRegistryOverrideOnApply({
|
|
262
261
|
context,
|
|
@@ -13,6 +13,7 @@ import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
|
|
|
13
13
|
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
14
14
|
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
15
15
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
16
|
+
import { config } from '../../../../helpers/config.js';
|
|
16
17
|
|
|
17
18
|
export default function transferDoubleSpendAcrossValidatorsScenario() {
|
|
18
19
|
test('State.apply transfer prevents double spend across validators (distinct tx hashes)', async t => {
|
|
@@ -49,40 +50,40 @@ export default function transferDoubleSpendAcrossValidatorsScenario() {
|
|
|
49
50
|
const txValidityA = await deriveIndexerSequenceState(primaryValidator.base);
|
|
50
51
|
const txValidityB = await deriveIndexerSequenceState(secondaryValidator.base);
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
53
|
+
const partialA = await new PartialStateMessageOperations(senderPeer.wallet, config)
|
|
54
|
+
.assembleTransferOperationMessage(
|
|
55
|
+
recipientA.wallet.address,
|
|
56
|
+
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
57
|
+
b4a.toString(txValidityA, 'hex')
|
|
58
|
+
);
|
|
59
|
+
const partialB = await new PartialStateMessageOperations(senderPeer.wallet, config)
|
|
60
|
+
.assembleTransferOperationMessage(
|
|
61
|
+
recipientB.wallet.address,
|
|
62
|
+
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
63
|
+
b4a.toString(txValidityB, 'hex')
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const payloadA = await new CompleteStateMessageOperations(primaryValidator.wallet, config)
|
|
67
|
+
.assembleCompleteTransferOperationMessage(
|
|
68
|
+
partialA.address,
|
|
69
|
+
b4a.from(partialA.tro.tx, 'hex'),
|
|
70
|
+
b4a.from(partialA.tro.txv, 'hex'),
|
|
71
|
+
b4a.from(partialA.tro.in, 'hex'),
|
|
72
|
+
partialA.tro.to,
|
|
73
|
+
b4a.from(partialA.tro.am, 'hex'),
|
|
74
|
+
b4a.from(partialA.tro.is, 'hex')
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const payloadB = await new CompleteStateMessageOperations(secondaryValidator.wallet, config)
|
|
78
|
+
.assembleCompleteTransferOperationMessage(
|
|
79
|
+
partialB.address,
|
|
80
|
+
b4a.from(partialB.tro.tx, 'hex'),
|
|
81
|
+
b4a.from(partialB.tro.txv, 'hex'),
|
|
82
|
+
b4a.from(partialB.tro.in, 'hex'),
|
|
83
|
+
partialB.tro.to,
|
|
84
|
+
b4a.from(partialB.tro.am, 'hex'),
|
|
85
|
+
b4a.from(partialB.tro.is, 'hex')
|
|
86
|
+
);
|
|
86
87
|
|
|
87
88
|
// Apply first transfer successfully via primary validator.
|
|
88
89
|
await primaryValidator.base.append(payloadA);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
+
import PeerWallet from 'trac-wallet';
|
|
2
3
|
import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
3
4
|
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
4
5
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
@@ -15,10 +16,10 @@ import { toBalance, PERCENT_75, BALANCE_ZERO } from '../../../../../src/core/sta
|
|
|
15
16
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
16
17
|
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
17
18
|
import { ZERO_WK } from '../../../../../src/utils/buffer.js';
|
|
18
|
-
import { EntryType, OperationType
|
|
19
|
+
import { EntryType, OperationType } from '../../../../../src/utils/constants.js';
|
|
19
20
|
import { createMessage } from '../../../../../src/utils/buffer.js';
|
|
20
|
-
import { blake3Hash } from '../../../../../src/utils/crypto.js';
|
|
21
21
|
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
22
|
+
import { config } from '../../../../helpers/config.js';
|
|
22
23
|
|
|
23
24
|
export const DEFAULT_INITIAL_BALANCE = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
|
|
24
25
|
export const DEFAULT_TRANSFER_AMOUNT = bigIntTo16ByteBuffer(decimalStringToBigInt('2'));
|
|
@@ -122,23 +123,23 @@ export async function buildTransferPayload(
|
|
|
122
123
|
const resolvedTxValidity =
|
|
123
124
|
txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
126
|
+
const partial = await new PartialStateMessageOperations(senderPeer.wallet, config)
|
|
127
|
+
.assembleTransferOperationMessage(
|
|
128
|
+
recipientAddress,
|
|
129
|
+
b4a.toString(amount, 'hex'),
|
|
130
|
+
b4a.toString(resolvedTxValidity, 'hex')
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config)
|
|
134
|
+
.assembleCompleteTransferOperationMessage(
|
|
135
|
+
partial.address,
|
|
136
|
+
b4a.from(partial.tro.tx, 'hex'),
|
|
137
|
+
b4a.from(partial.tro.txv, 'hex'),
|
|
138
|
+
b4a.from(partial.tro.in, 'hex'),
|
|
139
|
+
partial.tro.to,
|
|
140
|
+
b4a.from(partial.tro.am, 'hex'),
|
|
141
|
+
b4a.from(partial.tro.is, 'hex')
|
|
142
|
+
);
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
export async function buildTransferPayloadWithTxValidity(
|
|
@@ -204,9 +205,9 @@ export async function assertTransferSuccessState(
|
|
|
204
205
|
t.ok(decodedPayload?.tro, 'transfer payload decodes');
|
|
205
206
|
if (!decodedPayload?.tro) return;
|
|
206
207
|
|
|
207
|
-
const senderAddress = addressUtils.bufferToAddress(decodedPayload.address);
|
|
208
|
-
const recipientAddress = addressUtils.bufferToAddress(decodedPayload.tro.to);
|
|
209
|
-
const validatorAddress = addressUtils.bufferToAddress(decodedPayload.tro.va);
|
|
208
|
+
const senderAddress = addressUtils.bufferToAddress(decodedPayload.address, config.addressPrefix);
|
|
209
|
+
const recipientAddress = addressUtils.bufferToAddress(decodedPayload.tro.to, config.addressPrefix);
|
|
210
|
+
const validatorAddress = addressUtils.bufferToAddress(decodedPayload.tro.va, config.addressPrefix);
|
|
210
211
|
|
|
211
212
|
const amount = toBalance(decodedPayload.tro.am);
|
|
212
213
|
const fee = toBalance(transactionUtils.FEE);
|
|
@@ -611,7 +612,7 @@ async function applyTransferSenderEntryOverride(context, invalidPayload, mutateE
|
|
|
611
612
|
}
|
|
612
613
|
|
|
613
614
|
const senderAddress = senderPeer.wallet.address;
|
|
614
|
-
const senderBuffer = addressUtils.addressToBuffer(senderAddress);
|
|
615
|
+
const senderBuffer = addressUtils.addressToBuffer(senderAddress, config.addressPrefix);
|
|
615
616
|
const base = node.base;
|
|
616
617
|
const originalApply = base._handlers.apply;
|
|
617
618
|
|
|
@@ -687,8 +688,8 @@ export async function mutateTransferAmountWithRehashedTx(t, validPayload) {
|
|
|
687
688
|
mutatedAmount[mutatedAmount.length - 1] ^= 0x01;
|
|
688
689
|
parent.am = mutatedAmount;
|
|
689
690
|
|
|
690
|
-
const message = createMessage(
|
|
691
|
-
const regeneratedTxHash = await
|
|
691
|
+
const message = createMessage(config.networkId, parent.txv, parent.to, parent.am, parent.in, OperationType.TRANSFER);
|
|
692
|
+
const regeneratedTxHash = await PeerWallet.blake3(message);
|
|
692
693
|
if (regeneratedTxHash?.length === parent.tx?.length) {
|
|
693
694
|
parent.tx = regeneratedTxHash;
|
|
694
695
|
}
|
|
@@ -735,14 +736,14 @@ export async function mutateTransferAmountInvalidWithRehash(t, validPayload, con
|
|
|
735
736
|
parent.am = b4a.alloc(1); // invalid length to break toBalance
|
|
736
737
|
|
|
737
738
|
const requesterMessage = createMessage(
|
|
738
|
-
|
|
739
|
+
config.networkId,
|
|
739
740
|
parent.txv,
|
|
740
741
|
parent.to,
|
|
741
742
|
parent.am,
|
|
742
743
|
parent.in,
|
|
743
744
|
OperationType.TRANSFER
|
|
744
745
|
);
|
|
745
|
-
const regeneratedTxHash = await
|
|
746
|
+
const regeneratedTxHash = await PeerWallet.blake3(requesterMessage);
|
|
746
747
|
if (regeneratedTxHash?.length === parent.tx?.length) {
|
|
747
748
|
parent.tx = regeneratedTxHash;
|
|
748
749
|
}
|
|
@@ -751,8 +752,8 @@ export async function mutateTransferAmountInvalidWithRehash(t, validPayload, con
|
|
|
751
752
|
parent.is = requesterWallet.sign(regeneratedTxHash);
|
|
752
753
|
}
|
|
753
754
|
if (validatorWallet && parent.vn) {
|
|
754
|
-
const validatorMessage = createMessage(
|
|
755
|
-
parent.vs = validatorWallet.sign(await
|
|
755
|
+
const validatorMessage = createMessage(config.networkId, parent.tx, parent.vn, OperationType.TRANSFER);
|
|
756
|
+
parent.vs = validatorWallet.sign(await PeerWallet.blake3(validatorMessage));
|
|
756
757
|
}
|
|
757
758
|
|
|
758
759
|
return safeEncodeApplyOperation(decoded);
|
|
@@ -772,8 +773,8 @@ export async function mutateTransferRecipientAddressWithRehash(t, validPayload,
|
|
|
772
773
|
}
|
|
773
774
|
parent.to = mutatedTo;
|
|
774
775
|
|
|
775
|
-
const message = createMessage(
|
|
776
|
-
const regeneratedTxHash = await
|
|
776
|
+
const message = createMessage(config.networkId, parent.txv, parent.to, parent.am, parent.in, OperationType.TRANSFER);
|
|
777
|
+
const regeneratedTxHash = await PeerWallet.blake3(message);
|
|
777
778
|
if (regeneratedTxHash?.length === parent.tx?.length) {
|
|
778
779
|
parent.tx = regeneratedTxHash;
|
|
779
780
|
}
|
|
@@ -782,8 +783,8 @@ export async function mutateTransferRecipientAddressWithRehash(t, validPayload,
|
|
|
782
783
|
parent.is = requesterWallet.sign(regeneratedTxHash);
|
|
783
784
|
}
|
|
784
785
|
if (validatorWallet && parent.vn) {
|
|
785
|
-
const validatorMessage = createMessage(
|
|
786
|
-
parent.vs = validatorWallet.sign(await
|
|
786
|
+
const validatorMessage = createMessage(config.networkId, parent.tx, parent.vn, OperationType.TRANSFER);
|
|
787
|
+
parent.vs = validatorWallet.sign(await PeerWallet.blake3(validatorMessage));
|
|
787
788
|
}
|
|
788
789
|
|
|
789
790
|
return safeEncodeApplyOperation(decoded);
|
|
@@ -804,8 +805,8 @@ export async function mutateTransferRecipientPublicKeyInvalidWithRehash(t, valid
|
|
|
804
805
|
}
|
|
805
806
|
parent.to = mutatedTo;
|
|
806
807
|
|
|
807
|
-
const message = createMessage(
|
|
808
|
-
const regeneratedTxHash = await
|
|
808
|
+
const message = createMessage(config.networkId, parent.txv, parent.to, parent.am, parent.in, OperationType.TRANSFER);
|
|
809
|
+
const regeneratedTxHash = await PeerWallet.blake3(message);
|
|
809
810
|
if (regeneratedTxHash?.length === parent.tx?.length) {
|
|
810
811
|
parent.tx = regeneratedTxHash;
|
|
811
812
|
}
|
|
@@ -814,8 +815,8 @@ export async function mutateTransferRecipientPublicKeyInvalidWithRehash(t, valid
|
|
|
814
815
|
parent.is = requesterWallet.sign(regeneratedTxHash);
|
|
815
816
|
}
|
|
816
817
|
if (validatorWallet && parent.vn) {
|
|
817
|
-
const validatorMessage = createMessage(
|
|
818
|
-
parent.vs = validatorWallet.sign(await
|
|
818
|
+
const validatorMessage = createMessage(config.networkId, parent.tx, parent.vn, OperationType.TRANSFER);
|
|
819
|
+
parent.vs = validatorWallet.sign(await PeerWallet.blake3(validatorMessage));
|
|
819
820
|
}
|
|
820
821
|
|
|
821
822
|
return safeEncodeApplyOperation(decoded);
|
|
@@ -841,14 +842,14 @@ export async function mutateTransferAmountToInvalidValue(t, validPayload, contex
|
|
|
841
842
|
parent.am = b4a.alloc(1); // forces toBalance(amount).value === null
|
|
842
843
|
|
|
843
844
|
const requesterMessage = createMessage(
|
|
844
|
-
|
|
845
|
+
config.networkId,
|
|
845
846
|
parent.txv,
|
|
846
847
|
parent.to,
|
|
847
848
|
parent.am,
|
|
848
849
|
parent.in,
|
|
849
850
|
OperationType.TRANSFER
|
|
850
851
|
);
|
|
851
|
-
const regeneratedTxHash = await
|
|
852
|
+
const regeneratedTxHash = await PeerWallet.blake3(requesterMessage);
|
|
852
853
|
if (regeneratedTxHash?.length === parent.tx?.length) {
|
|
853
854
|
parent.tx = regeneratedTxHash;
|
|
854
855
|
}
|
|
@@ -857,8 +858,8 @@ export async function mutateTransferAmountToInvalidValue(t, validPayload, contex
|
|
|
857
858
|
parent.is = requesterWallet.sign(regeneratedTxHash);
|
|
858
859
|
}
|
|
859
860
|
if (validatorWallet && parent.vn) {
|
|
860
|
-
const validatorMessage = createMessage(
|
|
861
|
-
parent.vs = validatorWallet.sign(await
|
|
861
|
+
const validatorMessage = createMessage(config.networkId, parent.tx, parent.vn, OperationType.TRANSFER);
|
|
862
|
+
parent.vs = validatorWallet.sign(await PeerWallet.blake3(validatorMessage));
|
|
862
863
|
}
|
|
863
864
|
|
|
864
865
|
return safeEncodeApplyOperation(decoded);
|
|
@@ -948,7 +949,7 @@ async function applyTransferRecipientEntryOverride(context, invalidPayload, muta
|
|
|
948
949
|
}
|
|
949
950
|
|
|
950
951
|
const recipientAddress = recipientPeer.wallet.address;
|
|
951
|
-
const recipientBuffer = addressUtils.addressToBuffer(recipientAddress);
|
|
952
|
+
const recipientBuffer = addressUtils.addressToBuffer(recipientAddress, config.addressPrefix);
|
|
952
953
|
const base = node.base;
|
|
953
954
|
const originalApply = base._handlers.apply;
|
|
954
955
|
|
|
@@ -992,7 +993,7 @@ async function applyTransferRecipientBalanceDecodeFailure(context, invalidPayloa
|
|
|
992
993
|
}
|
|
993
994
|
|
|
994
995
|
const targetAddress = recipientPeer.wallet.address;
|
|
995
|
-
const targetBuffer = addressUtils.addressToBuffer(targetAddress);
|
|
996
|
+
const targetBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
|
|
996
997
|
const originalDecode = nodeEntryUtils.decode;
|
|
997
998
|
let shouldMutateNextDecode = false;
|
|
998
999
|
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
safeDecodeApplyOperation,
|
|
26
26
|
safeEncodeApplyOperation
|
|
27
27
|
} from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
28
|
+
import { config } from '../../../../helpers/config.js';
|
|
28
29
|
|
|
29
30
|
const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
|
|
30
31
|
const DEFAULT_CONTENT_HASH = b4a.alloc(32, 0xab);
|
|
@@ -140,27 +141,27 @@ export async function buildTxOperationPayload(
|
|
|
140
141
|
) {
|
|
141
142
|
const resolvedTxValidity = txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
144
|
+
const partial = await new PartialStateMessageOperations(broadcasterPeer.wallet, config)
|
|
145
|
+
.assembleTransactionOperationMessage(
|
|
146
|
+
writerKeyBuffer.toString('hex'),
|
|
147
|
+
resolvedTxValidity.toString('hex'),
|
|
148
|
+
contentHash.toString('hex'),
|
|
149
|
+
externalBootstrap.toString('hex'),
|
|
150
|
+
msbBootstrap.toString('hex')
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config)
|
|
154
|
+
.assembleCompleteTransactionOperationMessage(
|
|
155
|
+
partial.address,
|
|
156
|
+
b4a.from(partial.txo.tx, 'hex'),
|
|
157
|
+
b4a.from(partial.txo.txv, 'hex'),
|
|
158
|
+
b4a.from(partial.txo.iw, 'hex'),
|
|
159
|
+
b4a.from(partial.txo.in, 'hex'),
|
|
160
|
+
b4a.from(partial.txo.ch, 'hex'),
|
|
161
|
+
b4a.from(partial.txo.is, 'hex'),
|
|
162
|
+
b4a.from(partial.txo.bs, 'hex'),
|
|
163
|
+
b4a.from(partial.txo.mbs, 'hex')
|
|
164
|
+
);
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
export async function buildTxOperationPayloadWithTxValidity(context, txValidity, options = {}) {
|
|
@@ -208,8 +209,8 @@ export async function assertTxOperationSuccessState(
|
|
|
208
209
|
t.ok(b4a.equals(msbBootstrap, context.txOperation?.msbBootstrap), 'payload MSB bootstrap matches network');
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
212
|
-
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer);
|
|
212
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
|
|
213
|
+
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
|
|
213
214
|
|
|
214
215
|
t.is(requesterAddress, broadcasterPeer.wallet.address, 'requester matches broadcaster');
|
|
215
216
|
t.is(validatorAddress, validatorPeer.wallet.address, 'validator matches selected peer');
|
|
@@ -309,10 +310,10 @@ export async function assertTxOperationSuccessState(
|
|
|
309
310
|
const deploymentKey = `${EntryType.DEPLOYMENT}${externalBootstrap.toString('hex')}`;
|
|
310
311
|
const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
|
|
311
312
|
t.ok(deploymentEntry, 'deployment entry remains present after tx');
|
|
312
|
-
const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value);
|
|
313
|
+
const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value, config.addressLength);
|
|
313
314
|
t.ok(decodedDeployment, 'deployment entry decodes after tx');
|
|
314
315
|
if (decodedDeployment?.address) {
|
|
315
|
-
const creatorAddress = addressUtils.bufferToAddress(decodedDeployment.address);
|
|
316
|
+
const creatorAddress = addressUtils.bufferToAddress(decodedDeployment.address, config.addressPrefix);
|
|
316
317
|
t.is(
|
|
317
318
|
creatorAddress,
|
|
318
319
|
creatorPeer.wallet.address,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
assertTxOperationFailureState
|
|
9
9
|
} from './txOperationScenarioHelpers.js';
|
|
10
10
|
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
11
|
+
import { config } from '../../../../helpers/config.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Builds a transferFeeTxOperation guard scenario that runs through the full apply path.
|
|
@@ -34,7 +35,7 @@ export function createTransferFeeGuardScenario({
|
|
|
34
35
|
applyInvalidPayload: async (context, invalidPayload) => {
|
|
35
36
|
const node = context.txOperation?.validatorPeer ?? context.peers?.[1];
|
|
36
37
|
const decoded = safeDecodeApplyOperation(invalidPayload);
|
|
37
|
-
const requesterAddressString = addressUtils.bufferToAddress(decoded?.address);
|
|
38
|
+
const requesterAddressString = addressUtils.bufferToAddress(decoded?.address, config.addressPrefix);
|
|
38
39
|
|
|
39
40
|
const patchResult = await applyPatch({ context, node, decoded, requesterAddressString });
|
|
40
41
|
const cleanup = typeof patchResult === 'function' ? patchResult : patchResult?.cleanup;
|
|
@@ -8,7 +8,6 @@ async function runStateTests() {
|
|
|
8
8
|
await import('./utils/adminEntry.test.js');
|
|
9
9
|
await import('./utils/balance.test.js');
|
|
10
10
|
await import('./utils/nodeEntry.test.js');
|
|
11
|
-
await import('./utils/indexerEntry.test.js');
|
|
12
11
|
await import('./utils/lengthEntry.test.js');
|
|
13
12
|
await import('./utils/roles.test.js');
|
|
14
13
|
// These tests are skipped temoporarily because the mock library sinon does not work with bare.
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { bech32m } from 'bech32';
|
|
3
|
-
import {
|
|
3
|
+
import { address as addressApi } from 'trac-crypto-api';
|
|
4
4
|
import { TOKEN_DECIMALS } from '../../../src/utils/constants.js';
|
|
5
5
|
|
|
6
6
|
export function randomBuffer(size) {
|
|
7
7
|
return b4a.from(Array.from({ length: size }, () => Math.floor(Math.random() * 256)));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function randomAddress(hrp
|
|
11
|
-
|
|
10
|
+
export function randomAddress(hrp) {
|
|
11
|
+
// Compute payload size so final string length equals addressApi.size(hrp)
|
|
12
|
+
const totalLen = addressApi.size(hrp); // expected address string length
|
|
13
|
+
const dataWordLen = totalLen - (hrp.length + 1 + 6); // data chars = total - hrp - sep - checksum
|
|
14
|
+
const dataBytesLen = Math.floor((dataWordLen * 5) / 8); // bytes that yield that many 5-bit words
|
|
15
|
+
const data = randomBuffer(dataBytesLen);
|
|
12
16
|
return bech32m.encode(hrp, bech32m.toWords(data));
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
import { TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
|
|
4
3
|
import { randomAddress } from '../stateTestUtils.js';
|
|
5
4
|
import addressUtils from '../../../../src/core/state/utils/address.js';
|
|
5
|
+
import { address as addressApi } from 'trac-crypto-api';
|
|
6
6
|
|
|
7
7
|
test('Convert bech32m address to and from buffer - Happy Path', t => {
|
|
8
8
|
const hrp = 'test';
|
|
@@ -14,8 +14,8 @@ test('Convert bech32m address to and from buffer - Happy Path', t => {
|
|
|
14
14
|
t.ok(b4a.isBuffer(addressBuffer), 'Address buffer should be a Buffer instance');
|
|
15
15
|
t.is(typeof reconstructedAddress, 'string', 'Reconstructed address should be a string');
|
|
16
16
|
t.is(address, reconstructedAddress, 'Reconstructed address should match original');
|
|
17
|
-
t.is(address.length,
|
|
18
|
-
t.is(addressBuffer.length,
|
|
17
|
+
t.is(address.length, addressApi.size(hrp), 'Address length should match expected size');
|
|
18
|
+
t.is(addressBuffer.length, addressApi.size(hrp), 'Address buffer length should match address length');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('isAddressValid returns false for wrong prefix', t => {
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
import { WRITER_BYTE_LENGTH
|
|
3
|
+
import { WRITER_BYTE_LENGTH } from '../../../../src/utils/constants.js';
|
|
4
4
|
import { randomAddress, randomBuffer } from '../stateTestUtils.js';
|
|
5
5
|
import addressUtils from '../../../../src/core/state/utils/address.js';
|
|
6
6
|
import adminEntryUtils from '../../../../src/core/state/utils/adminEntry.js';
|
|
7
|
+
import { config } from '../../../helpers/config.js';
|
|
7
8
|
|
|
8
|
-
const isAddressValid = addressUtils.isAddressValid;
|
|
9
|
+
const isAddressValid = address => addressUtils.isAddressValid(address, config.addressPrefix);
|
|
9
10
|
const addressToBuffer = addressUtils.addressToBuffer;
|
|
10
|
-
const encodeAdminEntry = adminEntryUtils.encode;
|
|
11
|
-
const decodeAdminEntry = adminEntryUtils.decode;
|
|
12
|
-
const ADMIN_ENTRY_SIZE =
|
|
11
|
+
const encodeAdminEntry = (address, wk) => adminEntryUtils.encode(address, wk, config.addressPrefix);
|
|
12
|
+
const decodeAdminEntry = entry => adminEntryUtils.decode(entry, config.addressPrefix);
|
|
13
|
+
const ADMIN_ENTRY_SIZE = config.addressLength + WRITER_BYTE_LENGTH;
|
|
13
14
|
|
|
14
15
|
test('Admin Entry - Encode and Decode - Happy Path', t => {
|
|
15
|
-
const address = randomAddress();
|
|
16
|
+
const address = randomAddress(config.addressPrefix);
|
|
16
17
|
const wk = randomBuffer(WRITER_BYTE_LENGTH);
|
|
17
18
|
|
|
18
|
-
const encoded = encodeAdminEntry(addressToBuffer(address), wk);
|
|
19
|
+
const encoded = encodeAdminEntry(addressToBuffer(address, config.addressPrefix), wk);
|
|
19
20
|
t.is(encoded.length, ADMIN_ENTRY_SIZE, "encoding has valid length");
|
|
20
21
|
|
|
21
22
|
const decoded = decodeAdminEntry(encoded);
|
|
@@ -26,8 +27,8 @@ test('Admin Entry - Encode and Decode - Happy Path', t => {
|
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
test('Admin Entry - Encode returns empty buffer on invalid input', t => {
|
|
29
|
-
const addrString = randomAddress();
|
|
30
|
-
const validAddress = addressToBuffer(addrString);
|
|
30
|
+
const addrString = randomAddress(config.addressPrefix);
|
|
31
|
+
const validAddress = addressToBuffer(addrString, config.addressPrefix);
|
|
31
32
|
const separatorIndex = addrString.indexOf('1');
|
|
32
33
|
const invalidAddress = validAddress.subarray(separatorIndex); // missing HRP
|
|
33
34
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import test from 'brittle'
|
|
2
|
-
|
|
3
2
|
import Check from '../../../../src/utils/check.js'
|
|
4
|
-
import {ACO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js'
|
|
3
|
+
import { ACO, not_allowed_data_types } from '../../../fixtures/check.fixtures.js'
|
|
5
4
|
import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest } from './common.test.js';
|
|
5
|
+
import { config } from '../../../helpers/config.js';
|
|
6
6
|
|
|
7
|
-
const check = new Check()
|
|
7
|
+
const check = new Check(config)
|
|
8
8
|
|
|
9
9
|
test('validateAdminControlOperation- happy paths for all operation types', t => {
|
|
10
10
|
const validInputs = [
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import test from 'brittle'
|
|
2
|
-
|
|
3
2
|
import Check from '../../../../src/utils/check.js'
|
|
4
3
|
import { BIO, not_allowed_data_types } from '../../../fixtures/check.fixtures.js'
|
|
5
4
|
import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest } from './common.test.js';
|
|
5
|
+
import { config } from '../../../helpers/config.js';
|
|
6
6
|
|
|
7
|
-
const check = new Check()
|
|
7
|
+
const check = new Check(config)
|
|
8
8
|
|
|
9
9
|
test('validateBalanceInitialization - happy path', t => {
|
|
10
10
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import test from 'brittle'
|
|
2
|
-
|
|
3
2
|
import Check from '../../../../src/utils/check.js';
|
|
4
3
|
import {BDO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js';
|
|
5
|
-
|
|
6
4
|
import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest, partialTypeCommonTests } from './common.test.js';
|
|
5
|
+
import { config } from '../../../helpers/config.js';
|
|
7
6
|
|
|
8
|
-
const check = new Check()
|
|
7
|
+
const check = new Check(config)
|
|
9
8
|
|
|
10
9
|
test('validateBootstrapDeployment - happy-path case', t => {
|
|
11
10
|
const partial_result = check.validateBootstrapDeploymentOperation(BDO.valid_partial_bootstrap_deployment)
|