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
|
@@ -3,15 +3,14 @@ import sinon from 'sinon';
|
|
|
3
3
|
import b4a from 'b4a';
|
|
4
4
|
|
|
5
5
|
import PeerWallet from 'trac-wallet';
|
|
6
|
-
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
7
|
-
|
|
8
6
|
import NetworkWalletFactory, { EphemeralWallet } from '../../../src/core/network/identity/NetworkWalletFactory.js';
|
|
9
7
|
import { errorMessageIncludes } from '../../helpers/regexHelper.js';
|
|
10
8
|
import { testKeyPair1, testKeyPair2 } from '../../fixtures/apply.fixtures.js';
|
|
9
|
+
import { config } from '../../helpers/config.js';
|
|
11
10
|
|
|
12
11
|
test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
|
|
13
12
|
const publicKey = b4a.from(testKeyPair2.publicKey, 'hex');
|
|
14
|
-
const address = PeerWallet.encodeBech32m(
|
|
13
|
+
const address = PeerWallet.encodeBech32m(config.addressPrefix, publicKey);
|
|
15
14
|
const signResult = b4a.from('abcd', 'hex');
|
|
16
15
|
const wallet = {
|
|
17
16
|
publicKey,
|
|
@@ -20,7 +19,7 @@ test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
|
|
|
20
19
|
verify: sinon.stub().returns(true)
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
const provider = NetworkWalletFactory.provide({ wallet, enableWallet: true });
|
|
22
|
+
const provider = NetworkWalletFactory.provide({ wallet, enableWallet: true, networkPrefix: config.addressPrefix });
|
|
24
23
|
const message = b4a.from('00112233', 'hex');
|
|
25
24
|
const signature = provider.sign(message);
|
|
26
25
|
|
|
@@ -39,7 +38,7 @@ test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
|
|
|
39
38
|
test('NetworkWalletFactory.provide requires both public and secret keys when wallet disabled', async t => {
|
|
40
39
|
const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
|
|
41
40
|
await t.exception(
|
|
42
|
-
() => NetworkWalletFactory.provide({ enableWallet: false, keyPair: { publicKey } }),
|
|
41
|
+
() => NetworkWalletFactory.provide({ enableWallet: false, keyPair: { publicKey }, networkPrefix: config.addressPrefix }),
|
|
43
42
|
errorMessageIncludes('keyPair with publicKey and secretKey is required')
|
|
44
43
|
);
|
|
45
44
|
});
|
|
@@ -50,7 +49,8 @@ test('NetworkWalletFactory.provide rejects non-buffer inputs', async t => {
|
|
|
50
49
|
() =>
|
|
51
50
|
NetworkWalletFactory.provide({
|
|
52
51
|
enableWallet: false,
|
|
53
|
-
keyPair: { publicKey: 'not-a-buffer', secretKey }
|
|
52
|
+
keyPair: { publicKey: 'not-a-buffer', secretKey },
|
|
53
|
+
networkPrefix: config.addressPrefix
|
|
54
54
|
}),
|
|
55
55
|
errorMessageIncludes('must be a Buffer')
|
|
56
56
|
);
|
|
@@ -65,7 +65,7 @@ test('NetworkWalletFactory.provide propagates invalid public key length errors',
|
|
|
65
65
|
NetworkWalletFactory.provide({
|
|
66
66
|
enableWallet: false,
|
|
67
67
|
keyPair: { publicKey: invalidPublicKey, secretKey },
|
|
68
|
-
networkPrefix:
|
|
68
|
+
networkPrefix: config.addressPrefix
|
|
69
69
|
}),
|
|
70
70
|
errorMessageIncludes('Invalid public key')
|
|
71
71
|
);
|
|
@@ -79,14 +79,14 @@ test('NetworkWalletFactory.provide derives address and signs payloads from keyPa
|
|
|
79
79
|
const provider = NetworkWalletFactory.provide({
|
|
80
80
|
enableWallet: false,
|
|
81
81
|
keyPair,
|
|
82
|
-
networkPrefix:
|
|
82
|
+
networkPrefix: config.addressPrefix
|
|
83
83
|
});
|
|
84
84
|
const message = b4a.from('123455555', 'hex');
|
|
85
85
|
const signature = provider.sign(message);
|
|
86
86
|
|
|
87
87
|
t.is(
|
|
88
88
|
provider.address,
|
|
89
|
-
PeerWallet.encodeBech32m(
|
|
89
|
+
PeerWallet.encodeBech32m(config.addressPrefix, provider.publicKey)
|
|
90
90
|
);
|
|
91
91
|
t.ok(PeerWallet.verify(signature, message, provider.publicKey));
|
|
92
92
|
t.ok(provider.verify(signature, message));
|
|
@@ -104,7 +104,7 @@ test('NetworkWalletFactory handles falsy address derivation results', async t =>
|
|
|
104
104
|
NetworkWalletFactory.provide({
|
|
105
105
|
enableWallet: false,
|
|
106
106
|
keyPair,
|
|
107
|
-
networkPrefix:
|
|
107
|
+
networkPrefix: config.addressPrefix
|
|
108
108
|
}),
|
|
109
109
|
errorMessageIncludes('failed to derive address')
|
|
110
110
|
);
|
|
@@ -124,7 +124,7 @@ test('NetworkWalletFactory propagates encoder exceptions', async t => {
|
|
|
124
124
|
NetworkWalletFactory.provide({
|
|
125
125
|
enableWallet: false,
|
|
126
126
|
keyPair,
|
|
127
|
-
networkPrefix:
|
|
127
|
+
networkPrefix: config.addressPrefix
|
|
128
128
|
}),
|
|
129
129
|
errorMessageIncludes('test exception')
|
|
130
130
|
);
|
|
@@ -137,12 +137,12 @@ test('EphemeralWallet exposes wallet like interface', async t => {
|
|
|
137
137
|
publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
|
|
138
138
|
secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
|
|
139
139
|
};
|
|
140
|
-
const wallet = new EphemeralWallet(keyPair,
|
|
140
|
+
const wallet = new EphemeralWallet(keyPair, config.addressPrefix);
|
|
141
141
|
const message = b4a.from('feedface', 'hex');
|
|
142
142
|
const signature = wallet.sign(message);
|
|
143
143
|
|
|
144
144
|
t.alike(wallet.publicKey, keyPair.publicKey);
|
|
145
|
-
t.is(wallet.address, PeerWallet.encodeBech32m(
|
|
145
|
+
t.is(wallet.address, PeerWallet.encodeBech32m(config.addressPrefix, keyPair.publicKey));
|
|
146
146
|
t.ok(PeerWallet.verify(signature, message, wallet.publicKey));
|
|
147
147
|
t.ok(wallet.verify(signature, message));
|
|
148
148
|
});
|
|
@@ -150,7 +150,7 @@ test('EphemeralWallet exposes wallet like interface', async t => {
|
|
|
150
150
|
test('EphemeralWallet requires both public and secret keys', async t => {
|
|
151
151
|
const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
|
|
152
152
|
await t.exception(
|
|
153
|
-
() => new EphemeralWallet({ publicKey },
|
|
153
|
+
() => new EphemeralWallet({ publicKey }, config.addressPrefix),
|
|
154
154
|
errorMessageIncludes('keyPair with publicKey and secretKey is required')
|
|
155
155
|
);
|
|
156
156
|
});
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
7
7
|
import { toTerm } from '../../../../../src/core/state/utils/balance.js';
|
|
8
8
|
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
9
|
-
|
|
10
9
|
import { setupAddAdminScenario, assertAdminState } from './addAdminScenarioHelpers.js';
|
|
10
|
+
import { config } from '../../../../helpers/config.js';
|
|
11
11
|
|
|
12
12
|
export default function addAdminHappyPathScenario() {
|
|
13
13
|
test('State.apply addAdmin bootstraps admin node - happy path', async t => {
|
|
@@ -17,11 +17,11 @@ export default function addAdminHappyPathScenario() {
|
|
|
17
17
|
const reader = readerNodes[0];
|
|
18
18
|
|
|
19
19
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const addAdminPayload = await new CompleteStateMessageOperations(adminNode.wallet, config)
|
|
21
|
+
.assembleAddAdminMessage(
|
|
22
|
+
adminNode.base.local.key,
|
|
23
|
+
txValidity
|
|
24
|
+
);
|
|
25
25
|
|
|
26
26
|
await adminNode.base.append(addAdminPayload);
|
|
27
27
|
await adminNode.base.update();
|
|
@@ -17,12 +17,12 @@ import {
|
|
|
17
17
|
ADMIN_INITIAL_BALANCE,
|
|
18
18
|
ADMIN_INITIAL_STAKED_BALANCE
|
|
19
19
|
} from '../../../../../src/utils/constants.js';
|
|
20
|
-
import { createSignature } from '../../../../helpers/createTestSignature.js';
|
|
21
20
|
import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
|
|
22
21
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
23
22
|
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
24
23
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
25
24
|
import { safeWriteUInt32BE } from '../../../../../src/utils/buffer.js';
|
|
25
|
+
import { config } from '../../../../helpers/config.js';
|
|
26
26
|
|
|
27
27
|
export async function setupAddAdminScenario(t) {
|
|
28
28
|
const context = await setupStateNetwork({
|
|
@@ -42,11 +42,11 @@ export async function setupAddAdminScenario(t) {
|
|
|
42
42
|
export async function buildAddAdminRequesterPayload(context) {
|
|
43
43
|
const adminNode = context.adminBootstrap;
|
|
44
44
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
return new CompleteStateMessageOperations(adminNode.wallet, config)
|
|
46
|
+
.assembleAddAdminMessage(
|
|
47
|
+
adminNode.base.local.key,
|
|
48
|
+
txValidity
|
|
49
|
+
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export async function assertAddAdminRequesterFailureState(t, context) {
|
|
@@ -103,7 +103,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
|
|
|
103
103
|
const adminEntryRecord = await base.view.get(EntryType.ADMIN);
|
|
104
104
|
t.ok(adminEntryRecord, 'admin entry should exist');
|
|
105
105
|
|
|
106
|
-
const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value);
|
|
106
|
+
const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value, config.addressPrefix);
|
|
107
107
|
t.ok(decodedAdminEntry, 'admin entry decodes');
|
|
108
108
|
t.is(decodedAdminEntry.address, wallet.address, 'admin entry stores wallet address');
|
|
109
109
|
t.ok(b4a.equals(decodedAdminEntry.wk, writingKey), 'admin entry stores writing key');
|
|
@@ -126,7 +126,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
|
|
|
126
126
|
'admin license id assigned'
|
|
127
127
|
);
|
|
128
128
|
|
|
129
|
-
const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address);
|
|
129
|
+
const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address, config.addressPrefix);
|
|
130
130
|
t.ok(adminAddressBuffer.length > 0, 'admin address encoded as buffer');
|
|
131
131
|
const writerRegistry = await base.view.get(EntryType.WRITER_ADDRESS + writingKey.toString('hex'));
|
|
132
132
|
t.ok(writerRegistry, 'writer registry entry exists');
|
|
@@ -23,6 +23,7 @@ import addAdminEntryExistsScenario from './adminEntryExistsScenario.js';
|
|
|
23
23
|
import addAdminNonBootstrapNodeScenario from './nonBootstrapNodeScenario.js';
|
|
24
24
|
import addAdminNodeEntryInitializationFailureScenario from './nodeEntryInitializationFailureScenario.js';
|
|
25
25
|
import addAdminEntryEncodingFailureScenario from './adminEntryEncodingFailureScenario.js';
|
|
26
|
+
import { config } from '../../../../helpers/config.js';
|
|
26
27
|
|
|
27
28
|
// happy path
|
|
28
29
|
addAdminHappyPathScenario();
|
|
@@ -128,11 +129,11 @@ new TransactionValidityMismatchScenario({
|
|
|
128
129
|
assertStateUnchanged: assertAddAdminRequesterFailureState,
|
|
129
130
|
rebuildPayloadWithTxValidity: ({ context, mutatedTxValidity }) => {
|
|
130
131
|
const adminNode = context.adminBootstrap;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
return new CompleteStateMessageOperations(adminNode.wallet, config)
|
|
133
|
+
.assembleAddAdminMessage(
|
|
134
|
+
adminNode.base.local.key,
|
|
135
|
+
mutatedTxValidity
|
|
136
|
+
);
|
|
136
137
|
},
|
|
137
138
|
expectedLogs: ['Transaction was not executed.']
|
|
138
139
|
}).performScenario();
|
|
@@ -12,6 +12,7 @@ import transactionUtils from '../../../../../src/core/state/utils/transaction.js
|
|
|
12
12
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
13
13
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
14
14
|
import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
|
|
15
|
+
import { config } from '../../../../helpers/config.js';
|
|
15
16
|
|
|
16
17
|
export function selectIndexerCandidatePeer(context, offset = 0) {
|
|
17
18
|
return selectWriterPeer(context, offset);
|
|
@@ -50,11 +51,11 @@ export async function buildAddIndexerPayload(
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
return new CompleteStateMessageOperations(adminPeer.wallet, config)
|
|
55
|
+
.assembleAddIndexerMessage(
|
|
56
|
+
writerPeer.wallet.address,
|
|
57
|
+
txValidity
|
|
58
|
+
);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
export async function applyWithIndexerRoleUpdateFailure(context, invalidPayload) {
|
|
@@ -98,11 +99,11 @@ export async function buildAddIndexerPayloadWithTxValidity(
|
|
|
98
99
|
throw new Error('buildAddIndexerPayloadWithTxValidity requires an admin peer.');
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
return new CompleteStateMessageOperations(adminPeer.wallet, config)
|
|
103
|
+
.assembleAddIndexerMessage(
|
|
104
|
+
writerPeer.wallet.address,
|
|
105
|
+
mutatedTxValidity
|
|
106
|
+
);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export function ensureIndexerRegistration(base, writingKey) {
|
|
@@ -146,11 +147,11 @@ export async function buildRemoveIndexerPayload(
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
return new CompleteStateMessageOperations(adminPeer.wallet, config)
|
|
151
|
+
.assembleRemoveIndexerMessage(
|
|
152
|
+
indexerPeer.wallet.address,
|
|
153
|
+
txValidity
|
|
154
|
+
);
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
export async function buildRemoveIndexerPayloadWithTxValidity(
|
|
@@ -168,11 +169,11 @@ export async function buildRemoveIndexerPayloadWithTxValidity(
|
|
|
168
169
|
throw new Error('buildRemoveIndexerPayloadWithTxValidity requires an admin peer.');
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
return new CompleteStateMessageOperations(adminPeer.wallet, config)
|
|
173
|
+
.assembleRemoveIndexerMessage(
|
|
174
|
+
indexerPeer.wallet.address,
|
|
175
|
+
mutatedTxValidity
|
|
176
|
+
);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
export async function assertAddIndexerSuccessState(
|
|
@@ -299,7 +300,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
|
|
|
299
300
|
|
|
300
301
|
const requesterAddressBuffer = decodedOperation.address;
|
|
301
302
|
t.ok(requesterAddressBuffer, 'addIndexer payload contains requester address');
|
|
302
|
-
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
303
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
|
|
303
304
|
t.ok(requesterAddress, 'addIndexer requester address decodes');
|
|
304
305
|
if (requesterAddress) {
|
|
305
306
|
t.is(requesterAddress, expectedAdminAddress, 'addIndexer payload signed by admin');
|
|
@@ -307,7 +308,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
|
|
|
307
308
|
|
|
308
309
|
const candidateAddressBuffer = decodedOperation?.aco?.ia;
|
|
309
310
|
t.ok(candidateAddressBuffer, 'addIndexer payload contains candidate address');
|
|
310
|
-
const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer);
|
|
311
|
+
const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer, config.addressPrefix);
|
|
311
312
|
t.ok(candidateAddress, 'addIndexer candidate address decodes');
|
|
312
313
|
if (candidateAddress) {
|
|
313
314
|
t.is(candidateAddress, expectedCandidate, 'addIndexer payload nominates expected writer');
|
|
@@ -403,7 +404,7 @@ export async function applyWithPretenderRoleMutation(context, invalidPayload, ro
|
|
|
403
404
|
if (typeof key === 'string' ? key !== address : true) {
|
|
404
405
|
// string path comparison; buffer path is unlikely for address entries here
|
|
405
406
|
if (b4a.isBuffer(key)) {
|
|
406
|
-
const addrBuf = addressUtils.addressToBuffer(address);
|
|
407
|
+
const addrBuf = addressUtils.addressToBuffer(address, config.addressPrefix);
|
|
407
408
|
if (!addrBuf || !b4a.equals(addrBuf, key)) {
|
|
408
409
|
return originalGet(key);
|
|
409
410
|
}
|
|
@@ -4,7 +4,6 @@ import CompleteStateMessageOperations from '../../../../../src/messages/complete
|
|
|
4
4
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
5
5
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
6
6
|
import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
7
|
-
import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
|
|
8
7
|
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
9
8
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
10
9
|
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
@@ -17,6 +16,7 @@ import {
|
|
|
17
16
|
} from '../../../../../src/core/state/utils/balance.js';
|
|
18
17
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
19
18
|
import { setupAdminAndWhitelistedReaderNetwork } from '../common/commonScenarioHelper.js';
|
|
19
|
+
import { config } from '../../../../helpers/config.js';
|
|
20
20
|
|
|
21
21
|
const DEFAULT_WRITER_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
|
|
22
22
|
const STAKE_ENTRY_MARK = Symbol('stake-entry-mark');
|
|
@@ -105,14 +105,12 @@ export async function buildAddWriterPayload(
|
|
|
105
105
|
) {
|
|
106
106
|
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
107
107
|
const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
108
|
-
const partial = await PartialStateMessageOperations.assembleAddWriterMessage(
|
|
109
|
-
readerPeer.wallet,
|
|
108
|
+
const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleAddWriterMessage(
|
|
110
109
|
writingKey.toString('hex'),
|
|
111
110
|
txValidity.toString('hex')
|
|
112
111
|
);
|
|
113
112
|
|
|
114
|
-
return CompleteStateMessageOperations.assembleAddWriterMessage(
|
|
115
|
-
validatorPeer.wallet,
|
|
113
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleAddWriterMessage(
|
|
116
114
|
partial.address,
|
|
117
115
|
b4a.from(partial.rao.tx, 'hex'),
|
|
118
116
|
b4a.from(partial.rao.txv, 'hex'),
|
|
@@ -136,14 +134,12 @@ export async function buildAddWriterPayloadWithTxValidity(
|
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
139
|
-
const partial = await PartialStateMessageOperations.assembleAddWriterMessage(
|
|
140
|
-
readerPeer.wallet,
|
|
137
|
+
const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleAddWriterMessage(
|
|
141
138
|
writingKey.toString('hex'),
|
|
142
139
|
mutatedTxValidity.toString('hex')
|
|
143
140
|
);
|
|
144
141
|
|
|
145
|
-
return CompleteStateMessageOperations.assembleAddWriterMessage(
|
|
146
|
-
validatorPeer.wallet,
|
|
142
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleAddWriterMessage(
|
|
147
143
|
partial.address,
|
|
148
144
|
b4a.from(partial.rao.tx, 'hex'),
|
|
149
145
|
mutatedTxValidity,
|
|
@@ -163,14 +159,12 @@ export async function buildRemoveWriterPayload(
|
|
|
163
159
|
) {
|
|
164
160
|
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
165
161
|
const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
166
|
-
const partial = await PartialStateMessageOperations.assembleRemoveWriterMessage(
|
|
167
|
-
readerPeer.wallet,
|
|
162
|
+
const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleRemoveWriterMessage(
|
|
168
163
|
writerKey.toString('hex'),
|
|
169
164
|
txValidity.toString('hex')
|
|
170
165
|
);
|
|
171
166
|
|
|
172
|
-
return CompleteStateMessageOperations.assembleRemoveWriterMessage(
|
|
173
|
-
validatorPeer.wallet,
|
|
167
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleRemoveWriterMessage(
|
|
174
168
|
partial.address,
|
|
175
169
|
b4a.from(partial.rao.tx, 'hex'),
|
|
176
170
|
b4a.from(partial.rao.txv, 'hex'),
|
|
@@ -207,7 +201,7 @@ export async function assertAddWriterSuccessState(
|
|
|
207
201
|
}
|
|
208
202
|
|
|
209
203
|
const writerAddress = readerPeer.wallet.address;
|
|
210
|
-
|
|
204
|
+
const writerAddressBuffer = addressUtils.addressToBuffer(writerAddress, config.addressPrefix);
|
|
211
205
|
const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
212
206
|
const writingKeyHex = writingKey.toString('hex');
|
|
213
207
|
|
|
@@ -588,7 +582,7 @@ async function assertWriterDowngradedEntry(
|
|
|
588
582
|
'writer liquid balance matches expected amount after downgrade'
|
|
589
583
|
);
|
|
590
584
|
}
|
|
591
|
-
|
|
585
|
+
const addressBuffer = addressUtils.addressToBuffer(address, config.addressPrefix);
|
|
592
586
|
const writerRegistryEntry = await base.view.get(
|
|
593
587
|
EntryType.WRITER_ADDRESS + writingKey.toString('hex')
|
|
594
588
|
);
|
|
@@ -654,7 +648,7 @@ async function withPeerEntryOverrideOnApply({
|
|
|
654
648
|
const node = assertWritableNode(selectNode(context));
|
|
655
649
|
const base = node.base;
|
|
656
650
|
const targetAddress = targetPeer.wallet.address;
|
|
657
|
-
|
|
651
|
+
const targetBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
|
|
658
652
|
const originalApply = base._handlers.apply;
|
|
659
653
|
|
|
660
654
|
base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
|
|
@@ -12,6 +12,7 @@ import { initializeBalances, whitelistAddress } from '../common/commonScenarioHe
|
|
|
12
12
|
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
13
13
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
14
14
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
15
|
+
import { config } from '../../../../helpers/config.js';
|
|
15
16
|
|
|
16
17
|
export default function addWriterValidatorRewardScenario() {
|
|
17
18
|
test(
|
|
@@ -97,7 +98,7 @@ function assertPayloadValidator(t, payload, validatorAddress) {
|
|
|
97
98
|
t.ok(decoded, 'validator reward payload decodes');
|
|
98
99
|
const validatorBuffer = decoded?.rao?.va;
|
|
99
100
|
t.ok(validatorBuffer, 'payload carries validator address');
|
|
100
|
-
const expected = addressUtils.addressToBuffer(validatorAddress);
|
|
101
|
+
const expected = addressUtils.addressToBuffer(validatorAddress, config.addressPrefix);
|
|
101
102
|
t.ok(
|
|
102
103
|
b4a.equals(validatorBuffer, expected),
|
|
103
104
|
'payload validator address matches processing writer'
|
|
@@ -2,7 +2,6 @@ import b4a from 'b4a';
|
|
|
2
2
|
import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
|
|
3
3
|
import nodeEntryUtils, { setWritingKey } from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
4
4
|
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
5
|
-
import { blake3Hash } from '../../../../../src/utils/crypto.js';
|
|
6
5
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
7
6
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
8
7
|
import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
@@ -16,8 +15,8 @@ import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
|
|
|
16
15
|
import { buildAddIndexerPayload } from '../addIndexer/addIndexerScenarioHelpers.js';
|
|
17
16
|
import { toBalance, BALANCE_FEE } from '../../../../../src/core/state/utils/balance.js';
|
|
18
17
|
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
19
|
-
import * as bufferUtils from '../../../../../src/utils/buffer.js';
|
|
20
18
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
19
|
+
import { config } from '../../../../helpers/config.js';
|
|
21
20
|
|
|
22
21
|
export const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('50'));
|
|
23
22
|
export const TRANSFER_AMOUNT = bigIntTo16ByteBuffer(decimalStringToBigInt('1'));
|
|
@@ -91,21 +90,21 @@ export async function buildAdminRecoveryPayload(context) {
|
|
|
91
90
|
const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
|
|
92
91
|
const txValidity = await deriveIndexerSequenceState(validatorPeer1.base);
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
|
|
94
|
+
.assembleAdminRecoveryMessage(
|
|
95
|
+
b4a.toString(newAdminWriterKey, 'hex'),
|
|
96
|
+
b4a.toString(txValidity, 'hex')
|
|
97
|
+
);
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
|
|
100
|
+
.assembleAdminRecoveryMessage(
|
|
101
|
+
partial.address,
|
|
102
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
103
|
+
b4a.from(partial.rao.txv, 'hex'),
|
|
104
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
105
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
106
|
+
b4a.from(partial.rao.is, 'hex')
|
|
107
|
+
);
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTxValidity) {
|
|
@@ -114,21 +113,21 @@ export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTx
|
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
|
|
117
|
+
.assembleAdminRecoveryMessage(
|
|
118
|
+
b4a.toString(newAdminWriterKey, 'hex'),
|
|
119
|
+
b4a.toString(mutatedTxValidity, 'hex')
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
|
|
123
|
+
.assembleAdminRecoveryMessage(
|
|
124
|
+
partial.address,
|
|
125
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
126
|
+
mutatedTxValidity,
|
|
127
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
128
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
129
|
+
b4a.from(partial.rao.is, 'hex')
|
|
130
|
+
);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
export async function applyAdminRecovery(context, payload) {
|
|
@@ -517,15 +516,13 @@ export async function applyTransferSeries(context, count = TRANSFER_COUNT) {
|
|
|
517
516
|
|
|
518
517
|
async function buildSimpleTransferPayload({ requesterPeer, validatorPeer, recipientPeer, amount }) {
|
|
519
518
|
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
520
|
-
const partial = await PartialStateMessageOperations.assembleTransferOperationMessage(
|
|
521
|
-
requesterPeer.wallet,
|
|
519
|
+
const partial = await new PartialStateMessageOperations(requesterPeer.wallet, config).assembleTransferOperationMessage(
|
|
522
520
|
recipientPeer.wallet.address,
|
|
523
521
|
b4a.toString(amount, 'hex'),
|
|
524
522
|
b4a.toString(txValidity, 'hex')
|
|
525
523
|
);
|
|
526
524
|
|
|
527
|
-
return CompleteStateMessageOperations.assembleCompleteTransferOperationMessage(
|
|
528
|
-
validatorPeer.wallet,
|
|
525
|
+
return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleCompleteTransferOperationMessage(
|
|
529
526
|
partial.address,
|
|
530
527
|
b4a.from(partial.tro.tx, 'hex'),
|
|
531
528
|
b4a.from(partial.tro.txv, 'hex'),
|
|
@@ -548,7 +545,7 @@ export async function assertAdminRecoverySuccessState(t, context, { viewBase } =
|
|
|
548
545
|
const adminEntry = await base.view.get(EntryType.ADMIN);
|
|
549
546
|
t.ok(adminEntry, 'admin entry exists');
|
|
550
547
|
|
|
551
|
-
const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value);
|
|
548
|
+
const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value, config.addressPrefix);
|
|
552
549
|
t.ok(decodedAdminEntry, 'admin entry decodes');
|
|
553
550
|
t.ok(b4a.equals(decodedAdminEntry.wk, newAdminWriterKey), 'admin writer key updated');
|
|
554
551
|
|
|
@@ -597,7 +594,7 @@ export async function assertAdminRecoveryFailureState(t, context, { skipSync } =
|
|
|
597
594
|
const adminEntry = await adminPeer.base.view.get(EntryType.ADMIN);
|
|
598
595
|
t.ok(adminEntry, 'admin entry persists');
|
|
599
596
|
|
|
600
|
-
const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value);
|
|
597
|
+
const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value, config.addressPrefix);
|
|
601
598
|
t.ok(decodedAdminEntry, 'admin entry decodes');
|
|
602
599
|
t.ok(b4a.equals(decodedAdminEntry.wk, oldAdminWriterKey), 'admin writer key remains unchanged');
|
|
603
600
|
|
|
@@ -767,15 +764,22 @@ export async function applyWithIndexerSequenceFailure(context, payload) {
|
|
|
767
764
|
}
|
|
768
765
|
|
|
769
766
|
export async function applyWithIndexerSequenceCorruption(context, payload) {
|
|
770
|
-
const
|
|
771
|
-
const originalHash =
|
|
772
|
-
|
|
767
|
+
const { PeerWallet } = await import('trac-wallet');
|
|
768
|
+
const originalHash = PeerWallet.blake3;
|
|
769
|
+
const originalHashSafe = PeerWallet.blake3Safe;
|
|
770
|
+
|
|
771
|
+
PeerWallet.blake3 = async () => {
|
|
773
772
|
throw new Error('forced indexer sequence state failure');
|
|
774
773
|
};
|
|
774
|
+
PeerWallet.blake3Safe = async () => {
|
|
775
|
+
return b4a.alloc(0);
|
|
776
|
+
}
|
|
777
|
+
|
|
775
778
|
try {
|
|
776
779
|
await applyAdminRecoveryViaValidator(context, payload);
|
|
777
780
|
} finally {
|
|
778
|
-
|
|
781
|
+
PeerWallet.blake3 = originalHash;
|
|
782
|
+
PeerWallet.blake3Safe = originalHashSafe;
|
|
779
783
|
}
|
|
780
784
|
}
|
|
781
785
|
|
|
@@ -4,17 +4,13 @@ import {
|
|
|
4
4
|
setupAdminRecoveryScenario,
|
|
5
5
|
buildAdminRecoveryPayload,
|
|
6
6
|
assertAdminRecoveryFailureState,
|
|
7
|
-
assertAdminRecoverySuccessState,
|
|
8
7
|
applyAdminRecoveryViaValidator,
|
|
9
8
|
buildAdminRecoveryPayloadWithTxValidity,
|
|
10
9
|
applyWithMissingComponentBypass,
|
|
11
10
|
applyWithRoleAccessBypass,
|
|
12
11
|
applyWithRegisteredWriterKey,
|
|
13
12
|
applyWithIndexerSequenceFailure,
|
|
14
|
-
applyWithIndexerSequenceCorruption,
|
|
15
13
|
applyWithAdminEntryMutation,
|
|
16
|
-
applyWithAdminNodeEntryMutation,
|
|
17
|
-
cloneIndexers,
|
|
18
14
|
applyWithAdminEncodeFailure,
|
|
19
15
|
applyWithAdminBalanceDecodeFailure,
|
|
20
16
|
applyWithInvalidRequesterMessage,
|
|
@@ -51,7 +47,7 @@ import ValidatorConsistencyScenarioBase, {
|
|
|
51
47
|
} from '../common/validatorConsistency/base/validatorConsistencyScenarioBase.js';
|
|
52
48
|
import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
|
|
53
49
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
54
|
-
import
|
|
50
|
+
import { config } from '../../../../helpers/config.js';
|
|
55
51
|
|
|
56
52
|
adminRecoveryHappyPathScenario();
|
|
57
53
|
|
|
@@ -299,8 +295,8 @@ new OperationValidationScenarioBase({
|
|
|
299
295
|
mutatePayload: (_t, payload) => payload,
|
|
300
296
|
applyInvalidPayload: async (context, invalidPayload) => {
|
|
301
297
|
const otherAddress = context.adminRecovery.validatorPeer2.wallet.address;
|
|
302
|
-
const otherAddressBuffer = addressUtils.addressToBuffer(otherAddress);
|
|
303
|
-
const mutatedEntry = adminEntryUtils.encode(otherAddressBuffer, context.adminRecovery.oldAdminWriterKey);
|
|
298
|
+
const otherAddressBuffer = addressUtils.addressToBuffer(otherAddress, config.addressPrefix);
|
|
299
|
+
const mutatedEntry = adminEntryUtils.encode(otherAddressBuffer, context.adminRecovery.oldAdminWriterKey, config.addressPrefix);
|
|
304
300
|
return applyWithAdminEntryMutation(context, invalidPayload, () => ({ value: mutatedEntry }));
|
|
305
301
|
},
|
|
306
302
|
expectedLogs: ['Admin public key does not match the node public key.']
|