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,6 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
+
import PeerWallet from 'trac-wallet';
|
|
2
3
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
3
|
-
import
|
|
4
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
4
5
|
import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
5
6
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
6
7
|
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
@@ -10,14 +11,13 @@ import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../
|
|
|
10
11
|
import {
|
|
11
12
|
setupAddWriterScenario,
|
|
12
13
|
selectWriterPeer,
|
|
13
|
-
promotePeerToWriter
|
|
14
|
-
applyWithStakeEntryMutation
|
|
14
|
+
promotePeerToWriter
|
|
15
15
|
} from '../addWriter/addWriterScenarioHelpers.js';
|
|
16
16
|
import { setupAdminAndWhitelistedReaderNetwork } from '../common/commonScenarioHelper.js';
|
|
17
17
|
import { applyWithRequesterEntryRemoval } from '../addWriter/addWriterScenarioHelpers.js';
|
|
18
18
|
import { createMessage } from '../../../../../src/utils/buffer.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { OperationType } from '../../../../../src/utils/constants.js';
|
|
20
|
+
import { config } from '../../../../helpers/config.js';
|
|
21
21
|
|
|
22
22
|
export async function setupBanValidatorScenario(
|
|
23
23
|
t,
|
|
@@ -62,10 +62,9 @@ export async function buildBanValidatorPayload(
|
|
|
62
62
|
/* cover tests */
|
|
63
63
|
) {
|
|
64
64
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
65
|
-
return
|
|
66
|
-
adminPeer.wallet,
|
|
67
|
-
|
|
68
|
-
txValidity
|
|
65
|
+
return safeEncodeApplyOperation(
|
|
66
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
67
|
+
.buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
|
|
69
68
|
);
|
|
70
69
|
}
|
|
71
70
|
|
|
@@ -74,10 +73,9 @@ export async function buildBanValidatorPayloadWithTxValidity(
|
|
|
74
73
|
mutatedTxValidity,
|
|
75
74
|
{ adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
|
|
76
75
|
) {
|
|
77
|
-
return
|
|
78
|
-
adminPeer.wallet,
|
|
79
|
-
|
|
80
|
-
mutatedTxValidity
|
|
76
|
+
return safeEncodeApplyOperation(
|
|
77
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
78
|
+
.buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, mutatedTxValidity)
|
|
81
79
|
);
|
|
82
80
|
}
|
|
83
81
|
|
|
@@ -154,8 +152,8 @@ export async function assertBanValidatorSuccessState(
|
|
|
154
152
|
const licenseId = lengthEntryUtils.decodeBE(decodedAfter.license);
|
|
155
153
|
const licenseIndexEntry = await adminPeer.base.view.get(`${EntryType.LICENSE_INDEX}${licenseId}`);
|
|
156
154
|
t.ok(licenseIndexEntry, 'license index entry persists after banValidator');
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
if (licenseIndexEntry?.value) {
|
|
156
|
+
const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address, config.addressPrefix);
|
|
159
157
|
t.ok(
|
|
160
158
|
b4a.equals(licenseIndexEntry.value, validatorAddressBuffer),
|
|
161
159
|
'license index still maps to validator address'
|
|
@@ -167,8 +165,8 @@ export async function assertBanValidatorSuccessState(
|
|
|
167
165
|
const registryKey = EntryType.WRITER_ADDRESS + decodedBefore.wk.toString('hex');
|
|
168
166
|
const registryEntry = await adminPeer.base.view.get(registryKey);
|
|
169
167
|
t.ok(registryEntry, 'writer registry entry persists after banValidator');
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
if (registryEntry?.value) {
|
|
169
|
+
const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address, config.addressPrefix);
|
|
172
170
|
t.ok(
|
|
173
171
|
b4a.equals(registryEntry.value, validatorAddressBuffer),
|
|
174
172
|
'writer registry maps writing key to validator address'
|
|
@@ -305,13 +303,13 @@ export async function applyInvalidTargetAddressPayload(context, validPayload) {
|
|
|
305
303
|
decoded.aco.ia = invalidAddress;
|
|
306
304
|
|
|
307
305
|
const message = createMessage(
|
|
308
|
-
|
|
306
|
+
config.networkId,
|
|
309
307
|
decoded.aco.txv,
|
|
310
308
|
decoded.aco.ia,
|
|
311
309
|
decoded.aco.in,
|
|
312
310
|
OperationType.BAN_VALIDATOR
|
|
313
311
|
);
|
|
314
|
-
const newHash = await
|
|
312
|
+
const newHash = await PeerWallet.blake3(message);
|
|
315
313
|
decoded.aco.tx = newHash;
|
|
316
314
|
decoded.aco.is = adminPeer.wallet.sign(newHash);
|
|
317
315
|
|
|
@@ -337,15 +335,14 @@ export async function applyInvalidIndexerSequenceStatePayload(context, validPayl
|
|
|
337
335
|
}
|
|
338
336
|
|
|
339
337
|
export async function promoteValidatorToIndexer(
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
context,
|
|
339
|
+
{ adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
|
|
342
340
|
) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
341
|
+
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
342
|
+
const payload = safeEncodeApplyOperation(
|
|
343
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
344
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
|
|
345
|
+
);
|
|
349
346
|
|
|
350
347
|
await adminPeer.base.append(payload);
|
|
351
348
|
await adminPeer.base.update();
|
|
@@ -420,7 +417,7 @@ export async function applyWithBanValidatorRoleDecodeFailure(context, invalidPay
|
|
|
420
417
|
export async function applyWithBanValidatorWithdrawFailure(context, invalidPayload) {
|
|
421
418
|
const targetPeer = context.banValidatorScenario?.validatorPeer ?? selectWriterPeer(context);
|
|
422
419
|
const targetAddress = targetPeer.wallet.address;
|
|
423
|
-
|
|
420
|
+
const targetBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
|
|
424
421
|
const adminPeer = context.adminBootstrap;
|
|
425
422
|
const base = adminPeer.base;
|
|
426
423
|
const originalApply = base._handlers.apply;
|
|
@@ -481,13 +478,13 @@ async function assertBanValidatorPayloadMetadata(t, base, payload, { adminAddres
|
|
|
481
478
|
t.ok(decodedPayload, 'banValidator payload decodes');
|
|
482
479
|
if (!decodedPayload) return;
|
|
483
480
|
|
|
484
|
-
|
|
481
|
+
const requesterAddress = addressUtils.bufferToAddress(decodedPayload.address, config.addressPrefix);
|
|
485
482
|
t.ok(requesterAddress, 'banValidator requester address decodes');
|
|
486
483
|
if (requesterAddress) {
|
|
487
484
|
t.is(requesterAddress, adminAddress, 'banValidator payload signed by admin');
|
|
488
485
|
}
|
|
489
486
|
|
|
490
|
-
|
|
487
|
+
const targetAddressDecoded = addressUtils.bufferToAddress(decodedPayload?.aco?.ia, config.addressPrefix);
|
|
491
488
|
t.ok(targetAddressDecoded, 'banValidator target address decodes');
|
|
492
489
|
if (targetAddressDecoded) {
|
|
493
490
|
t.is(targetAddressDecoded, targetAddress, 'banValidator payload targets expected validator');
|
|
@@ -9,6 +9,7 @@ import { initializeBalances, whitelistAddress } from '../common/commonScenarioHe
|
|
|
9
9
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
10
10
|
import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
|
|
11
11
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
12
|
+
import { config } from '../../../../helpers/config.js';
|
|
12
13
|
|
|
13
14
|
async function setupDuplicateBootstrapScenario(t) {
|
|
14
15
|
const context = await setupBootstrapDeploymentScenario(t, { nodes: 4 });
|
|
@@ -73,7 +74,7 @@ async function assertDuplicateBootstrapState(t, context, validPayload, invalidPa
|
|
|
73
74
|
const deploymentKey = `deployment/${bootstrapHex}`;
|
|
74
75
|
const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
|
|
75
76
|
t.ok(deploymentEntry, 'deployment entry still stored');
|
|
76
|
-
const decodedDeployment = deploymentEntry ? deploymentEntryUtils.decode(deploymentEntry.value) : null;
|
|
77
|
+
const decodedDeployment = deploymentEntry ? deploymentEntryUtils.decode(deploymentEntry.value, config.addressLength) : null;
|
|
77
78
|
t.ok(decodedDeployment, 'deployment entry decodes');
|
|
78
79
|
if (decodedDeployment?.txHash) {
|
|
79
80
|
t.is(decodedDeployment.txHash.toString('hex'), firstTxHex, 'deployment entry keeps original tx hash');
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
2
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
4
3
|
import { deriveIndexerSequenceState } from '../../../../helpers/autobaseTestHelpers.js';
|
|
5
4
|
import {
|
|
6
5
|
setupAdminNetwork,
|
|
@@ -19,6 +18,7 @@ import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
|
19
18
|
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
20
19
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
21
20
|
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
21
|
+
import { config } from '../../../../helpers/config.js';
|
|
22
22
|
|
|
23
23
|
const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
|
|
24
24
|
|
|
@@ -108,23 +108,26 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
|
|
|
108
108
|
context.bootstrapDeployment?.txValidity ??
|
|
109
109
|
(await deriveIndexerSequenceState(validatorPeer.base));
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
const partial = await applyStateMessageFactory(deployerPeer.wallet, config)
|
|
112
|
+
.buildPartialBootstrapDeploymentMessage(
|
|
113
|
+
deployerPeer.wallet.address,
|
|
114
|
+
externalBootstrap.toString('hex'),
|
|
115
|
+
channel.toString('hex'),
|
|
116
|
+
txValidity.toString('hex'),
|
|
117
|
+
'json'
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
121
|
+
.buildCompleteBootstrapDeploymentMessage(
|
|
120
122
|
partial.address,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
b4a.from(partial.bdo.tx, 'hex'),
|
|
124
|
+
b4a.from(partial.bdo.txv, 'hex'),
|
|
125
|
+
b4a.from(partial.bdo.bs, 'hex'),
|
|
126
|
+
b4a.from(partial.bdo.ic, 'hex'),
|
|
127
|
+
b4a.from(partial.bdo.in, 'hex'),
|
|
128
|
+
b4a.from(partial.bdo.is, 'hex')
|
|
129
|
+
);
|
|
130
|
+
return safeEncodeApplyOperation(payload);
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
export async function buildBootstrapDeploymentPayloadWithTxValidity(context, txValidity, options = {}) {
|
|
@@ -173,8 +176,8 @@ export async function assertBootstrapDeploymentSuccessState(
|
|
|
173
176
|
t.ok(validatorAddressBuffer, 'payload carries validator address');
|
|
174
177
|
t.ok(txHashBuffer, 'payload exposes tx hash');
|
|
175
178
|
|
|
176
|
-
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
177
|
-
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer);
|
|
179
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
|
|
180
|
+
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
|
|
178
181
|
|
|
179
182
|
if (requesterAddress) {
|
|
180
183
|
t.is(requesterAddress, deployerPeer.wallet.address, 'payload signed by expected requester');
|
|
@@ -329,7 +332,7 @@ async function assertDeploymentEntry(
|
|
|
329
332
|
const deploymentKey = `${EntryType.DEPLOYMENT}${bootstrapBuffer.toString('hex')}`;
|
|
330
333
|
const deploymentEntry = await base.view.get(deploymentKey);
|
|
331
334
|
t.ok(deploymentEntry, 'deployment entry stored');
|
|
332
|
-
const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value);
|
|
335
|
+
const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value, config.addressLength);
|
|
333
336
|
t.ok(decodedDeployment?.txHash, 'deployment entry decodes');
|
|
334
337
|
if (!decodedDeployment || !decodedDeployment.txHash) return;
|
|
335
338
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
3
3
|
import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
4
|
-
import { EntryType
|
|
4
|
+
import { EntryType } from '../../../../../../src/utils/constants.js';
|
|
5
5
|
import addressUtils from '../../../../../../src/core/state/utils/address.js';
|
|
6
|
+
import { config } from '../../../../../helpers/config.js'
|
|
6
7
|
|
|
7
8
|
export default class AdminConsistencyMismatchScenario extends OperationValidationScenarioBase {
|
|
8
9
|
constructor({
|
|
@@ -39,8 +40,8 @@ async function applyWithMutatedAdminEntry(context, payload) {
|
|
|
39
40
|
throw new Error('Admin consistency scenario requires a reader peer with a wallet.');
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const alternateAddressBuffer = addressUtils.addressToBuffer(reader.wallet.address);
|
|
43
|
-
if (!alternateAddressBuffer || alternateAddressBuffer.length !==
|
|
43
|
+
const alternateAddressBuffer = addressUtils.addressToBuffer(reader.wallet.address, config.addressPrefix);
|
|
44
|
+
if (!alternateAddressBuffer || alternateAddressBuffer.length !== config.addressLength) {
|
|
44
45
|
throw new Error('Failed to derive alternate admin address buffer.');
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -85,7 +86,7 @@ function patchAdminEntryMismatch(base, alternateAddressBuffer) {
|
|
|
85
86
|
|
|
86
87
|
mutatedOnce = true;
|
|
87
88
|
const mutated = b4a.from(adminEntry.value);
|
|
88
|
-
alternateAddressBuffer.copy(mutated, 0, 0,
|
|
89
|
+
alternateAddressBuffer.copy(mutated, 0, 0, config.addressLength);
|
|
89
90
|
|
|
90
91
|
return {
|
|
91
92
|
...adminEntry,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
3
3
|
import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
4
|
-
import { EntryType
|
|
4
|
+
import { EntryType } from '../../../../../../src/utils/constants.js';
|
|
5
|
+
import { config } from '../../../../../helpers/config.js';
|
|
5
6
|
|
|
6
7
|
const ADMIN_KEY_BUFFER = b4a.from(EntryType.ADMIN);
|
|
7
8
|
|
|
@@ -97,12 +98,12 @@ function patchAdminEntryAddress(base) {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
function mutateAdminAddress(value) {
|
|
100
|
-
if (!b4a.isBuffer(value) || value.length <
|
|
101
|
+
if (!b4a.isBuffer(value) || value.length < config.addressLength) {
|
|
101
102
|
return value;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
const mutated = b4a.from(value);
|
|
105
|
-
const lastIndex =
|
|
106
|
+
const lastIndex = config.addressLength - 1;
|
|
106
107
|
const asciiP = 'p'.charCodeAt(0);
|
|
107
108
|
const asciiQ = 'q'.charCodeAt(0);
|
|
108
109
|
mutated[lastIndex] = mutated[lastIndex] === asciiP ? asciiQ : asciiP;
|
|
@@ -4,6 +4,7 @@ import nodeEntryUtils from '../../../../../../../src/core/state/utils/nodeEntry.
|
|
|
4
4
|
import addressUtils from '../../../../../../../src/core/state/utils/address.js';
|
|
5
5
|
import { BALANCE_ZERO } from '../../../../../../../src/core/state/utils/balance.js';
|
|
6
6
|
import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
|
|
7
|
+
import { config } from '../../../../../../helpers/config.js'
|
|
7
8
|
|
|
8
9
|
export default class RequesterBalanceScenarioBase extends OperationValidationScenarioBase {
|
|
9
10
|
constructor({
|
|
@@ -76,7 +77,7 @@ function createApplyInvalidPayload({
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
const targetAddressString = peer.wallet.address;
|
|
79
|
-
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
|
|
80
|
+
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
|
|
80
81
|
|
|
81
82
|
const originalDecode = nodeEntryUtils.decode;
|
|
82
83
|
let shouldFailNextSub = false;
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
deriveIndexerSequenceState,
|
|
6
6
|
eventFlush
|
|
7
7
|
} from '../../../../helpers/autobaseTestHelpers.js';
|
|
8
|
-
import
|
|
8
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
9
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
9
10
|
import { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
|
|
10
11
|
import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
|
|
12
|
+
import { config } from '../../../../helpers/config.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Boots a network with an initialized admin node and returns the shared context.
|
|
@@ -58,14 +60,16 @@ export async function initializeBalances(context, recipients) {
|
|
|
58
60
|
if (!adminNode || !Array.isArray(recipients) || recipients.length === 0) return;
|
|
59
61
|
|
|
60
62
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
61
|
-
const
|
|
62
|
-
adminNode.wallet,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
for (const [recipientAddress, balanceBuffer] of recipients) {
|
|
64
|
+
const payload = await applyStateMessageFactory(adminNode.wallet, config)
|
|
65
|
+
.buildCompleteBalanceInitializationMessage(
|
|
66
|
+
adminNode.wallet.address,
|
|
67
|
+
recipientAddress,
|
|
68
|
+
balanceBuffer,
|
|
69
|
+
txValidity
|
|
70
|
+
);
|
|
71
|
+
const encoded = safeEncodeApplyOperation(payload);
|
|
72
|
+
await adminNode.base.append(encoded);
|
|
69
73
|
await adminNode.base.update();
|
|
70
74
|
await eventFlush();
|
|
71
75
|
}
|
|
@@ -76,13 +80,9 @@ export async function whitelistAddress(context, address) {
|
|
|
76
80
|
if (!adminNode || !address) return;
|
|
77
81
|
|
|
78
82
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
79
|
-
const payload = await
|
|
80
|
-
adminNode.wallet,
|
|
81
|
-
|
|
82
|
-
address
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
await adminNode.base.append(payload);
|
|
83
|
+
const payload = await applyStateMessageFactory(adminNode.wallet, config)
|
|
84
|
+
.buildCompleteAppendWhitelistMessage(adminNode.wallet.address, address, txValidity);
|
|
85
|
+
await adminNode.base.append(safeEncodeApplyOperation(payload));
|
|
86
86
|
await adminNode.base.update();
|
|
87
87
|
await eventFlush();
|
|
88
88
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { eventFlush, deriveIndexerSequenceState } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
2
2
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
3
|
-
import
|
|
3
|
+
import { applyStateMessageFactory } from '../../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
4
|
+
import { safeEncodeApplyOperation } from '../../../../../../src/utils/protobuf/operationHelpers.js';
|
|
5
|
+
import { config } from '../../../../../helpers/config.js';
|
|
4
6
|
|
|
5
7
|
export default class InitializationDisabledScenario extends OperationValidationScenarioBase {
|
|
6
8
|
constructor({
|
|
@@ -33,10 +35,13 @@ async function disableInitializationAndApply(context, invalidPayload) {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
36
|
-
const disablePayload =
|
|
37
|
-
adminNode.wallet,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const disablePayload = safeEncodeApplyOperation(
|
|
39
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
40
|
+
.buildCompleteDisableInitializationMessage(
|
|
41
|
+
adminNode.wallet.address,
|
|
42
|
+
adminNode.base.local.key,
|
|
43
|
+
txValidity
|
|
44
|
+
)
|
|
40
45
|
);
|
|
41
46
|
|
|
42
47
|
await adminNode.base.append(disablePayload);
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
safeDecodeApplyOperation,
|
|
4
4
|
safeEncodeApplyOperation
|
|
5
5
|
} from '../../../../../../src/utils/protobuf/operationHelpers.js';
|
|
6
|
-
import
|
|
6
|
+
import PeerWallet from 'trac-wallet';
|
|
7
7
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
8
8
|
|
|
9
9
|
export default class InvalidHashValidationScenario extends OperationValidationScenarioBase {
|
|
@@ -32,7 +32,7 @@ async function defaultMutateHash(t, validPayload) {
|
|
|
32
32
|
const decodedPayload = safeDecodeApplyOperation(validPayload);
|
|
33
33
|
t.ok(decodedPayload, 'fixtures decode');
|
|
34
34
|
|
|
35
|
-
const invalidHash = await
|
|
35
|
+
const invalidHash = await PeerWallet.blake3(validPayload);
|
|
36
36
|
|
|
37
37
|
switch (true) {
|
|
38
38
|
case Boolean(decodedPayload.cao?.tx):
|
|
@@ -2,6 +2,7 @@ import b4a from 'b4a';
|
|
|
2
2
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
3
3
|
import addressUtils from '../../../../../../src/core/state/utils/address.js';
|
|
4
4
|
import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
5
|
+
import { config } from '../../../../../helpers/config.js'
|
|
5
6
|
|
|
6
7
|
export default class RequesterNodeEntryBufferMissingScenario extends OperationValidationScenarioBase {
|
|
7
8
|
constructor({
|
|
@@ -26,7 +27,7 @@ export default class RequesterNodeEntryBufferMissingScenario extends OperationVa
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const targetAddressString = peer.wallet.address;
|
|
29
|
-
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
|
|
30
|
+
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
|
|
30
31
|
|
|
31
32
|
const originalApply = node.base._handlers.apply;
|
|
32
33
|
node.base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
|
|
@@ -2,6 +2,7 @@ import b4a from 'b4a';
|
|
|
2
2
|
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
3
3
|
import addressUtils from '../../../../../../src/core/state/utils/address.js';
|
|
4
4
|
import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
5
|
+
import { config } from '../../../../../helpers/config.js'
|
|
5
6
|
|
|
6
7
|
export default class RequesterNodeEntryDecodeFailureScenario extends OperationValidationScenarioBase {
|
|
7
8
|
constructor({
|
|
@@ -26,7 +27,7 @@ export default class RequesterNodeEntryDecodeFailureScenario extends OperationVa
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const targetAddressString = peer.wallet.address;
|
|
29
|
-
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
|
|
30
|
+
const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
|
|
30
31
|
|
|
31
32
|
const originalApply = node.base._handlers.apply;
|
|
32
33
|
node.base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
|
package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js
CHANGED
|
@@ -3,6 +3,7 @@ import OperationValidationScenarioBase from '../../base/OperationValidationScena
|
|
|
3
3
|
import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobuf/operationHelpers.js';
|
|
4
4
|
import addressUtils from '../../../../../../../src/core/state/utils/address.js';
|
|
5
5
|
import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
|
|
6
|
+
import { config } from '../../../../../../helpers/config.js'
|
|
6
7
|
|
|
7
8
|
export const ValidatorEntryMutation = {
|
|
8
9
|
DELETE: Symbol('validator-entry-delete')
|
|
@@ -178,7 +179,7 @@ function extractValidatorAddress(payloadBuffer, path) {
|
|
|
178
179
|
return null;
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
const addressString = addressUtils.bufferToAddress(value);
|
|
182
|
+
const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
|
|
182
183
|
if (!addressString) {
|
|
183
184
|
return null;
|
|
184
185
|
}
|
|
@@ -5,6 +5,7 @@ import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobu
|
|
|
5
5
|
import addressUtils from '../../../../../../../src/core/state/utils/address.js';
|
|
6
6
|
import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
|
|
7
7
|
import { BALANCE_ZERO } from '../../../../../../../src/core/state/utils/balance.js';
|
|
8
|
+
import { config } from '../../../../../../helpers/config.js'
|
|
8
9
|
|
|
9
10
|
const DEFAULT_VALIDATOR_ADDRESS_PATH = ['rao', 'va'];
|
|
10
11
|
const VALIDATOR_ENTRY_MARK = Symbol('validator-entry-mark');
|
|
@@ -285,7 +286,7 @@ function extractValidatorAddress(payloadBuffer, path) {
|
|
|
285
286
|
return null;
|
|
286
287
|
}
|
|
287
288
|
|
|
288
|
-
const addressString = addressUtils.bufferToAddress(value);
|
|
289
|
+
const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
|
|
289
290
|
if (!addressString) {
|
|
290
291
|
return null;
|
|
291
292
|
}
|
package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js
CHANGED
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
deriveIndexerSequenceState,
|
|
7
7
|
eventFlush
|
|
8
8
|
} from '../../../../helpers/autobaseTestHelpers.js';
|
|
9
|
-
import
|
|
9
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
10
10
|
import { AUTOBASE_VALUE_ENCODING, EntryType } from '../../../../../src/utils/constants.js';
|
|
11
11
|
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
12
12
|
import { safeWriteUInt32BE } from '../../../../../src/utils/buffer.js';
|
|
13
13
|
import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
|
|
14
|
+
import { config } from '../../../../helpers/config.js';
|
|
14
15
|
|
|
15
16
|
export async function setupDisableInitializationScenario(t) {
|
|
16
17
|
const context = await setupStateNetwork({
|
|
@@ -54,19 +55,25 @@ export async function buildDisableInitializationPayload(context) {
|
|
|
54
55
|
const adminNode = context.adminBootstrap;
|
|
55
56
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
56
57
|
|
|
57
|
-
return
|
|
58
|
-
adminNode.wallet,
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
return safeEncodeApplyOperation(
|
|
59
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
60
|
+
.buildCompleteDisableInitializationMessage(
|
|
61
|
+
adminNode.wallet.address,
|
|
62
|
+
adminNode.base.local.key,
|
|
63
|
+
txValidity
|
|
64
|
+
)
|
|
61
65
|
);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
export async function buildDisableInitializationPayloadWithTxValidity(context, txValidity) {
|
|
65
69
|
const adminNode = context.adminBootstrap;
|
|
66
|
-
return
|
|
67
|
-
adminNode.wallet,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
return safeEncodeApplyOperation(
|
|
71
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
72
|
+
.buildCompleteDisableInitializationMessage(
|
|
73
|
+
adminNode.wallet.address,
|
|
74
|
+
adminNode.base.local.key,
|
|
75
|
+
txValidity
|
|
76
|
+
)
|
|
70
77
|
);
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -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');
|