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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import b4a from 'b4a';
|
|
3
|
+
import PeerWallet from 'trac-wallet';
|
|
4
|
+
|
|
5
|
+
import ApplyStateMessageBuilder from '../../../../src/messages/state/ApplyStateMessageBuilder.js';
|
|
6
|
+
import { OperationType } from '../../../../src/utils/constants.js';
|
|
7
|
+
import { isHexString } from '../../../../src/utils/helpers.js';
|
|
8
|
+
import { config } from '../../../helpers/config.js';
|
|
9
|
+
import { testKeyPair1, testKeyPair2 } from '../../../fixtures/apply.fixtures.js';
|
|
10
|
+
import { isAddressValid } from '../../../../src/core/state/utils/address.js';
|
|
11
|
+
|
|
12
|
+
const hex = (value, bytes) => value.repeat(bytes);
|
|
13
|
+
|
|
14
|
+
async function createWallet(mnemonic) {
|
|
15
|
+
const wallet = new PeerWallet({ mnemonic, networkPrefix: config.addressPrefix });
|
|
16
|
+
await wallet.ready;
|
|
17
|
+
return wallet;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function expectHexField(t, value, bytes, label) {
|
|
21
|
+
t.is(typeof value, 'string', `${label} type`);
|
|
22
|
+
t.is(value.length, bytes * 2, `${label} length`);
|
|
23
|
+
t.ok(isHexString(value), `${label} hex`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function expectAddressField(t, value, label) {
|
|
27
|
+
t.is(typeof value, 'string', `${label} type`);
|
|
28
|
+
t.is(value.length, config.addressLength, `${label} length`);
|
|
29
|
+
t.ok(isAddressValid(value, config.addressPrefix), `${label} valid`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function expectKeys(t, value, keys, label) {
|
|
33
|
+
t.alike(Object.keys(value).sort(), keys.slice().sort(), `${label} keys`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function expectPayloadKeys(t, payload, bodyKey) {
|
|
37
|
+
expectKeys(t, payload, ['type', 'address', bodyKey], 'payload');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
test('ApplyStateMessageBuilder partial add writer (rao)', async t => {
|
|
41
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
42
|
+
const txValidity = hex('11', 32);
|
|
43
|
+
const writingKey = hex('22', 32);
|
|
44
|
+
|
|
45
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
46
|
+
await builder
|
|
47
|
+
.setPhase('partial')
|
|
48
|
+
.setOutput('json')
|
|
49
|
+
.setOperationType(OperationType.ADD_WRITER)
|
|
50
|
+
.setAddress(wallet.address)
|
|
51
|
+
.setTxValidity(txValidity)
|
|
52
|
+
.setWriterKey(writingKey)
|
|
53
|
+
.build();
|
|
54
|
+
|
|
55
|
+
const payload = builder.getPayload();
|
|
56
|
+
t.is(payload.type, OperationType.ADD_WRITER);
|
|
57
|
+
t.is(payload.address, wallet.address);
|
|
58
|
+
expectAddressField(t, payload.address, 'address');
|
|
59
|
+
expectPayloadKeys(t, payload, 'rao');
|
|
60
|
+
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
61
|
+
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
62
|
+
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
63
|
+
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
64
|
+
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
65
|
+
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
66
|
+
t.is(payload.rao.txv, txValidity);
|
|
67
|
+
t.is(payload.rao.iw, writingKey);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('ApplyStateMessageBuilder partial remove writer (rao)', async t => {
|
|
71
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
72
|
+
const txValidity = hex('33', 32);
|
|
73
|
+
const writingKey = hex('44', 32);
|
|
74
|
+
|
|
75
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
76
|
+
await builder
|
|
77
|
+
.setPhase('partial')
|
|
78
|
+
.setOutput('json')
|
|
79
|
+
.setOperationType(OperationType.REMOVE_WRITER)
|
|
80
|
+
.setAddress(wallet.address)
|
|
81
|
+
.setTxValidity(txValidity)
|
|
82
|
+
.setWriterKey(writingKey)
|
|
83
|
+
.build();
|
|
84
|
+
|
|
85
|
+
const payload = builder.getPayload();
|
|
86
|
+
t.is(payload.type, OperationType.REMOVE_WRITER);
|
|
87
|
+
t.is(payload.address, wallet.address);
|
|
88
|
+
expectPayloadKeys(t, payload, 'rao');
|
|
89
|
+
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
90
|
+
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
91
|
+
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
92
|
+
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
93
|
+
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
94
|
+
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
95
|
+
t.is(payload.rao.txv, txValidity);
|
|
96
|
+
t.is(payload.rao.iw, writingKey);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('ApplyStateMessageBuilder partial admin recovery (rao)', async t => {
|
|
100
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
101
|
+
const txValidity = hex('55', 32);
|
|
102
|
+
const writingKey = hex('66', 32);
|
|
103
|
+
|
|
104
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
105
|
+
await builder
|
|
106
|
+
.setPhase('partial')
|
|
107
|
+
.setOutput('json')
|
|
108
|
+
.setOperationType(OperationType.ADMIN_RECOVERY)
|
|
109
|
+
.setAddress(wallet.address)
|
|
110
|
+
.setTxValidity(txValidity)
|
|
111
|
+
.setWriterKey(writingKey)
|
|
112
|
+
.build();
|
|
113
|
+
|
|
114
|
+
const payload = builder.getPayload();
|
|
115
|
+
t.is(payload.type, OperationType.ADMIN_RECOVERY);
|
|
116
|
+
t.is(payload.address, wallet.address);
|
|
117
|
+
expectPayloadKeys(t, payload, 'rao');
|
|
118
|
+
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
119
|
+
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
120
|
+
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
121
|
+
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
122
|
+
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
123
|
+
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
124
|
+
t.is(payload.rao.txv, txValidity);
|
|
125
|
+
t.is(payload.rao.iw, writingKey);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('ApplyStateMessageBuilder partial bootstrap deployment (bdo)', async t => {
|
|
129
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
130
|
+
const txValidity = hex('77', 32);
|
|
131
|
+
const externalBootstrap = hex('88', 32);
|
|
132
|
+
const channel = hex('99', 32);
|
|
133
|
+
|
|
134
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
135
|
+
await builder
|
|
136
|
+
.setPhase('partial')
|
|
137
|
+
.setOutput('json')
|
|
138
|
+
.setOperationType(OperationType.BOOTSTRAP_DEPLOYMENT)
|
|
139
|
+
.setAddress(wallet.address)
|
|
140
|
+
.setTxValidity(txValidity)
|
|
141
|
+
.setExternalBootstrap(externalBootstrap)
|
|
142
|
+
.setChannel(channel)
|
|
143
|
+
.build();
|
|
144
|
+
|
|
145
|
+
const payload = builder.getPayload();
|
|
146
|
+
t.is(payload.type, OperationType.BOOTSTRAP_DEPLOYMENT);
|
|
147
|
+
t.is(payload.address, wallet.address);
|
|
148
|
+
expectPayloadKeys(t, payload, 'bdo');
|
|
149
|
+
expectKeys(t, payload.bdo, ['tx', 'txv', 'bs', 'ic', 'in', 'is'], 'bdo');
|
|
150
|
+
expectHexField(t, payload.bdo.tx, 32, 'bdo.tx');
|
|
151
|
+
expectHexField(t, payload.bdo.txv, 32, 'bdo.txv');
|
|
152
|
+
expectHexField(t, payload.bdo.bs, 32, 'bdo.bs');
|
|
153
|
+
expectHexField(t, payload.bdo.ic, 32, 'bdo.ic');
|
|
154
|
+
expectHexField(t, payload.bdo.in, 32, 'bdo.in');
|
|
155
|
+
expectHexField(t, payload.bdo.is, 64, 'bdo.is');
|
|
156
|
+
t.is(payload.bdo.txv, txValidity);
|
|
157
|
+
t.is(payload.bdo.bs, externalBootstrap);
|
|
158
|
+
t.is(payload.bdo.ic, channel);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('ApplyStateMessageBuilder partial transaction operation (txo)', async t => {
|
|
162
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
163
|
+
const txValidity = hex('aa', 32);
|
|
164
|
+
const writingKey = hex('bb', 32);
|
|
165
|
+
const contentHash = hex('cc', 32);
|
|
166
|
+
const externalBootstrap = hex('dd', 32);
|
|
167
|
+
const msbBootstrap = hex('ee', 32);
|
|
168
|
+
|
|
169
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
170
|
+
await builder
|
|
171
|
+
.setPhase('partial')
|
|
172
|
+
.setOutput('json')
|
|
173
|
+
.setOperationType(OperationType.TX)
|
|
174
|
+
.setAddress(wallet.address)
|
|
175
|
+
.setTxValidity(txValidity)
|
|
176
|
+
.setWriterKey(writingKey)
|
|
177
|
+
.setContentHash(contentHash)
|
|
178
|
+
.setExternalBootstrap(externalBootstrap)
|
|
179
|
+
.setMsbBootstrap(msbBootstrap)
|
|
180
|
+
.build();
|
|
181
|
+
|
|
182
|
+
const payload = builder.getPayload();
|
|
183
|
+
t.is(payload.type, OperationType.TX);
|
|
184
|
+
t.is(payload.address, wallet.address);
|
|
185
|
+
expectPayloadKeys(t, payload, 'txo');
|
|
186
|
+
expectKeys(t, payload.txo, ['tx', 'txv', 'iw', 'ch', 'bs', 'mbs', 'in', 'is'], 'txo');
|
|
187
|
+
expectHexField(t, payload.txo.tx, 32, 'txo.tx');
|
|
188
|
+
expectHexField(t, payload.txo.txv, 32, 'txo.txv');
|
|
189
|
+
expectHexField(t, payload.txo.iw, 32, 'txo.iw');
|
|
190
|
+
expectHexField(t, payload.txo.ch, 32, 'txo.ch');
|
|
191
|
+
expectHexField(t, payload.txo.bs, 32, 'txo.bs');
|
|
192
|
+
expectHexField(t, payload.txo.mbs, 32, 'txo.mbs');
|
|
193
|
+
expectHexField(t, payload.txo.in, 32, 'txo.in');
|
|
194
|
+
expectHexField(t, payload.txo.is, 64, 'txo.is');
|
|
195
|
+
t.is(payload.txo.txv, txValidity);
|
|
196
|
+
t.is(payload.txo.iw, writingKey);
|
|
197
|
+
t.is(payload.txo.ch, contentHash);
|
|
198
|
+
t.is(payload.txo.bs, externalBootstrap);
|
|
199
|
+
t.is(payload.txo.mbs, msbBootstrap);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('ApplyStateMessageBuilder partial transfer operation (tro)', async t => {
|
|
203
|
+
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
204
|
+
const otherWallet = await createWallet(testKeyPair2.mnemonic);
|
|
205
|
+
const txValidity = hex('ab', 32);
|
|
206
|
+
const amount = hex('cd', 16);
|
|
207
|
+
|
|
208
|
+
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
209
|
+
await builder
|
|
210
|
+
.setPhase('partial')
|
|
211
|
+
.setOutput('json')
|
|
212
|
+
.setOperationType(OperationType.TRANSFER)
|
|
213
|
+
.setAddress(wallet.address)
|
|
214
|
+
.setTxValidity(txValidity)
|
|
215
|
+
.setIncomingAddress(otherWallet.address)
|
|
216
|
+
.setAmount(amount)
|
|
217
|
+
.build();
|
|
218
|
+
|
|
219
|
+
const payload = builder.getPayload();
|
|
220
|
+
t.is(payload.type, OperationType.TRANSFER);
|
|
221
|
+
t.is(payload.address, wallet.address);
|
|
222
|
+
expectPayloadKeys(t, payload, 'tro');
|
|
223
|
+
expectKeys(t, payload.tro, ['tx', 'txv', 'to', 'am', 'in', 'is'], 'tro');
|
|
224
|
+
expectHexField(t, payload.tro.tx, 32, 'tro.tx');
|
|
225
|
+
expectHexField(t, payload.tro.txv, 32, 'tro.txv');
|
|
226
|
+
expectAddressField(t, payload.tro.to, 'tro.to');
|
|
227
|
+
expectHexField(t, payload.tro.am, 16, 'tro.am');
|
|
228
|
+
expectHexField(t, payload.tro.in, 32, 'tro.in');
|
|
229
|
+
expectHexField(t, payload.tro.is, 64, 'tro.is');
|
|
230
|
+
t.is(payload.tro.txv, txValidity);
|
|
231
|
+
t.is(payload.tro.to, otherWallet.address);
|
|
232
|
+
t.is(payload.tro.am, amount);
|
|
233
|
+
});
|
|
@@ -5,12 +5,14 @@ import { testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5, t
|
|
|
5
5
|
import ConnectionManager from "../../../src/core/network/services/ConnectionManager.js";
|
|
6
6
|
import { tick } from "../../helpers/setupApplyTests.js";
|
|
7
7
|
import b4a from 'b4a'
|
|
8
|
+
import { createConfig, ENV } from "../../../src/config/env.js";
|
|
8
9
|
|
|
9
10
|
const createConnection = (key) => {
|
|
10
11
|
const emitter = new EventEmitter()
|
|
11
|
-
emitter.
|
|
12
|
+
emitter.protocolSession = {
|
|
13
|
+
has: (name) => name === 'legacy',
|
|
12
14
|
send: sinon.stub().resolves(),
|
|
13
|
-
}
|
|
15
|
+
};
|
|
14
16
|
emitter.connected = true
|
|
15
17
|
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
16
18
|
|
|
@@ -18,7 +20,8 @@ const createConnection = (key) => {
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
const makeManager = (maxValidators = 6, conns = connections) => {
|
|
21
|
-
const
|
|
23
|
+
const merged = createConfig(ENV.DEVELOPMENT, { maxValidators })
|
|
24
|
+
const connectionManager = new ConnectionManager(merged)
|
|
22
25
|
|
|
23
26
|
conns.forEach(({ key, connection }) => {
|
|
24
27
|
connectionManager.addValidator(key, connection)
|
|
@@ -30,7 +33,7 @@ const makeManager = (maxValidators = 6, conns = connections) => {
|
|
|
30
33
|
const reset = () => {
|
|
31
34
|
sinon.restore()
|
|
32
35
|
connections.forEach(connection => {
|
|
33
|
-
connection.connection.
|
|
36
|
+
connection.connection.protocolSession.send.resetHistory()
|
|
34
37
|
})
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -78,7 +81,7 @@ test('ConnectionManager', () => {
|
|
|
78
81
|
createConnection(testKeyPair2.publicKey),
|
|
79
82
|
]
|
|
80
83
|
|
|
81
|
-
const connectionManager =
|
|
84
|
+
const connectionManager = makeManager(maxConnections)
|
|
82
85
|
localConnections.forEach(({ key, connection }) => {
|
|
83
86
|
connectionManager.addValidator(key, connection)
|
|
84
87
|
})
|
|
@@ -119,7 +122,7 @@ test('ConnectionManager', () => {
|
|
|
119
122
|
|
|
120
123
|
const target = connectionManager.send([1,2,3,4])
|
|
121
124
|
|
|
122
|
-
const totalCalls = connections.reduce((sum, con) => sum + con.connection.
|
|
125
|
+
const totalCalls = connections.reduce((sum, con) => sum + con.connection.protocolSession.send.callCount, 0)
|
|
123
126
|
t.is(totalCalls, 1, 'should send to exactly one validator')
|
|
124
127
|
t.ok(target, 'should return a target public key')
|
|
125
128
|
})
|
|
@@ -132,7 +135,7 @@ test('ConnectionManager', () => {
|
|
|
132
135
|
]
|
|
133
136
|
|
|
134
137
|
errorConnections.forEach(con => {
|
|
135
|
-
con.connection.
|
|
138
|
+
con.connection.protocolSession.send = sinon.stub().throws(new Error())
|
|
136
139
|
})
|
|
137
140
|
|
|
138
141
|
const connectionManager = makeManager(5, errorConnections)
|
|
@@ -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
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { default as test } from 'brittle';
|
|
2
2
|
|
|
3
|
-
async function
|
|
3
|
+
async function runNetworkModuleTests() {
|
|
4
4
|
test.pause();
|
|
5
5
|
await import('./ConnectionManager.test.js');
|
|
6
|
+
await import('./NetworkWalletFactory.test.js');
|
|
6
7
|
test.resume();
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
await runNetworkModuleTests();
|
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
} from '../../../../helpers/autobaseTestHelpers.js';
|
|
6
6
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
7
7
|
import { toTerm } from '../../../../../src/core/state/utils/balance.js';
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
9
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
10
10
|
import { setupAddAdminScenario, assertAdminState } from './addAdminScenarioHelpers.js';
|
|
11
|
+
import { config } from '../../../../helpers/config.js';
|
|
11
12
|
|
|
12
13
|
export default function addAdminHappyPathScenario() {
|
|
13
14
|
test('State.apply addAdmin bootstraps admin node - happy path', async t => {
|
|
@@ -17,10 +18,13 @@ export default function addAdminHappyPathScenario() {
|
|
|
17
18
|
const reader = readerNodes[0];
|
|
18
19
|
|
|
19
20
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
20
|
-
const addAdminPayload =
|
|
21
|
-
adminNode.wallet,
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const addAdminPayload = safeEncodeApplyOperation(
|
|
22
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
23
|
+
.buildCompleteAddAdminMessage(
|
|
24
|
+
adminNode.wallet.address,
|
|
25
|
+
adminNode.base.local.key,
|
|
26
|
+
txValidity
|
|
27
|
+
)
|
|
24
28
|
);
|
|
25
29
|
|
|
26
30
|
await adminNode.base.append(addAdminPayload);
|
|
@@ -6,7 +6,7 @@ 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 {
|
|
11
11
|
safeDecodeApplyOperation,
|
|
12
12
|
safeEncodeApplyOperation
|
|
@@ -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,10 +42,13 @@ 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
|
-
return
|
|
46
|
-
adminNode.wallet,
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
return safeEncodeApplyOperation(
|
|
46
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
47
|
+
.buildCompleteAddAdminMessage(
|
|
48
|
+
adminNode.wallet.address,
|
|
49
|
+
adminNode.base.local.key,
|
|
50
|
+
txValidity
|
|
51
|
+
)
|
|
49
52
|
);
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -103,7 +106,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
|
|
|
103
106
|
const adminEntryRecord = await base.view.get(EntryType.ADMIN);
|
|
104
107
|
t.ok(adminEntryRecord, 'admin entry should exist');
|
|
105
108
|
|
|
106
|
-
const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value);
|
|
109
|
+
const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value, config.addressPrefix);
|
|
107
110
|
t.ok(decodedAdminEntry, 'admin entry decodes');
|
|
108
111
|
t.is(decodedAdminEntry.address, wallet.address, 'admin entry stores wallet address');
|
|
109
112
|
t.ok(b4a.equals(decodedAdminEntry.wk, writingKey), 'admin entry stores writing key');
|
|
@@ -126,7 +129,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
|
|
|
126
129
|
'admin license id assigned'
|
|
127
130
|
);
|
|
128
131
|
|
|
129
|
-
const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address);
|
|
132
|
+
const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address, config.addressPrefix);
|
|
130
133
|
t.ok(adminAddressBuffer.length > 0, 'admin address encoded as buffer');
|
|
131
134
|
const writerRegistry = await base.view.get(EntryType.WRITER_ADDRESS + writingKey.toString('hex'));
|
|
132
135
|
t.ok(writerRegistry, 'writer registry entry exists');
|
|
@@ -18,11 +18,13 @@ import WriterKeyExistsValidationScenario from '../common/writerKeyExistsValidati
|
|
|
18
18
|
import OperationAlreadyAppliedScenario from '../common/operationAlreadyAppliedScenario.js';
|
|
19
19
|
import TransactionValidityMismatchScenario from '../common/transactionValidityMismatchScenario.js';
|
|
20
20
|
import IndexerSequenceStateInvalidScenario from '../common/indexer/indexerSequenceStateInvalidScenario.js';
|
|
21
|
-
import
|
|
21
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
22
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
22
23
|
import addAdminEntryExistsScenario from './adminEntryExistsScenario.js';
|
|
23
24
|
import addAdminNonBootstrapNodeScenario from './nonBootstrapNodeScenario.js';
|
|
24
25
|
import addAdminNodeEntryInitializationFailureScenario from './nodeEntryInitializationFailureScenario.js';
|
|
25
26
|
import addAdminEntryEncodingFailureScenario from './adminEntryEncodingFailureScenario.js';
|
|
27
|
+
import { config } from '../../../../helpers/config.js';
|
|
26
28
|
|
|
27
29
|
// happy path
|
|
28
30
|
addAdminHappyPathScenario();
|
|
@@ -126,13 +128,15 @@ new TransactionValidityMismatchScenario({
|
|
|
126
128
|
setupScenario: setupAddAdminScenario,
|
|
127
129
|
buildValidPayload: buildAddAdminRequesterPayload,
|
|
128
130
|
assertStateUnchanged: assertAddAdminRequesterFailureState,
|
|
129
|
-
rebuildPayloadWithTxValidity: ({ context, mutatedTxValidity }) => {
|
|
131
|
+
rebuildPayloadWithTxValidity: async ({ context, mutatedTxValidity }) => {
|
|
130
132
|
const adminNode = context.adminBootstrap;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
const payload = await applyStateMessageFactory(adminNode.wallet, config)
|
|
134
|
+
.buildCompleteAddAdminMessage(
|
|
135
|
+
adminNode.wallet.address,
|
|
136
|
+
adminNode.base.local.key,
|
|
137
|
+
mutatedTxValidity
|
|
138
|
+
);
|
|
139
|
+
return safeEncodeApplyOperation(payload);
|
|
136
140
|
},
|
|
137
141
|
expectedLogs: ['Transaction was not executed.']
|
|
138
142
|
}).performScenario();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
2
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
3
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
3
4
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
4
5
|
import {
|
|
5
6
|
setupAddWriterScenario,
|
|
@@ -12,6 +13,7 @@ import transactionUtils from '../../../../../src/core/state/utils/transaction.js
|
|
|
12
13
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
13
14
|
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
14
15
|
import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
|
|
16
|
+
import { config } from '../../../../helpers/config.js';
|
|
15
17
|
|
|
16
18
|
export function selectIndexerCandidatePeer(context, offset = 0) {
|
|
17
19
|
return selectWriterPeer(context, offset);
|
|
@@ -50,10 +52,9 @@ export async function buildAddIndexerPayload(
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
53
|
-
return
|
|
54
|
-
adminPeer.wallet,
|
|
55
|
-
|
|
56
|
-
txValidity
|
|
55
|
+
return safeEncodeApplyOperation(
|
|
56
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
57
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, writerPeer.wallet.address, txValidity)
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -98,10 +99,9 @@ export async function buildAddIndexerPayloadWithTxValidity(
|
|
|
98
99
|
throw new Error('buildAddIndexerPayloadWithTxValidity requires an admin peer.');
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
return
|
|
102
|
-
adminPeer.wallet,
|
|
103
|
-
|
|
104
|
-
mutatedTxValidity
|
|
102
|
+
return safeEncodeApplyOperation(
|
|
103
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
104
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, writerPeer.wallet.address, mutatedTxValidity)
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -146,10 +146,9 @@ export async function buildRemoveIndexerPayload(
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
149
|
-
return
|
|
150
|
-
adminPeer.wallet,
|
|
151
|
-
|
|
152
|
-
txValidity
|
|
149
|
+
return safeEncodeApplyOperation(
|
|
150
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
151
|
+
.buildCompleteRemoveIndexerMessage(adminPeer.wallet.address, indexerPeer.wallet.address, txValidity)
|
|
153
152
|
);
|
|
154
153
|
}
|
|
155
154
|
|
|
@@ -168,10 +167,9 @@ export async function buildRemoveIndexerPayloadWithTxValidity(
|
|
|
168
167
|
throw new Error('buildRemoveIndexerPayloadWithTxValidity requires an admin peer.');
|
|
169
168
|
}
|
|
170
169
|
|
|
171
|
-
return
|
|
172
|
-
adminPeer.wallet,
|
|
173
|
-
|
|
174
|
-
mutatedTxValidity
|
|
170
|
+
return safeEncodeApplyOperation(
|
|
171
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
172
|
+
.buildCompleteRemoveIndexerMessage(adminPeer.wallet.address, indexerPeer.wallet.address, mutatedTxValidity)
|
|
175
173
|
);
|
|
176
174
|
}
|
|
177
175
|
|
|
@@ -299,7 +297,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
|
|
|
299
297
|
|
|
300
298
|
const requesterAddressBuffer = decodedOperation.address;
|
|
301
299
|
t.ok(requesterAddressBuffer, 'addIndexer payload contains requester address');
|
|
302
|
-
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
300
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
|
|
303
301
|
t.ok(requesterAddress, 'addIndexer requester address decodes');
|
|
304
302
|
if (requesterAddress) {
|
|
305
303
|
t.is(requesterAddress, expectedAdminAddress, 'addIndexer payload signed by admin');
|
|
@@ -307,7 +305,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
|
|
|
307
305
|
|
|
308
306
|
const candidateAddressBuffer = decodedOperation?.aco?.ia;
|
|
309
307
|
t.ok(candidateAddressBuffer, 'addIndexer payload contains candidate address');
|
|
310
|
-
const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer);
|
|
308
|
+
const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer, config.addressPrefix);
|
|
311
309
|
t.ok(candidateAddress, 'addIndexer candidate address decodes');
|
|
312
310
|
if (candidateAddress) {
|
|
313
311
|
t.is(candidateAddress, expectedCandidate, 'addIndexer payload nominates expected writer');
|
|
@@ -403,7 +401,7 @@ export async function applyWithPretenderRoleMutation(context, invalidPayload, ro
|
|
|
403
401
|
if (typeof key === 'string' ? key !== address : true) {
|
|
404
402
|
// string path comparison; buffer path is unlikely for address entries here
|
|
405
403
|
if (b4a.isBuffer(key)) {
|
|
406
|
-
const addrBuf = addressUtils.addressToBuffer(address);
|
|
404
|
+
const addrBuf = addressUtils.addressToBuffer(address, config.addressPrefix);
|
|
407
405
|
if (!addrBuf || !b4a.equals(addrBuf, key)) {
|
|
408
406
|
return originalGet(key);
|
|
409
407
|
}
|