trac-msb 0.2.8 → 0.2.10
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/acceptance-tests.yml +7 -11
- package/.github/workflows/lint-pr-title.yml +26 -0
- package/.github/workflows/unit-tests.yml +2 -8
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +33 -18
- package/docker-compose.yml +1 -0
- package/docs/trac_network_http_api.openapi.yaml +889 -0
- package/msb.mjs +5 -22
- package/package.json +14 -10
- package/proto/network.proto +74 -0
- package/rpc/create_server.js +2 -2
- package/rpc/handlers.js +165 -92
- package/rpc/routes/v1.js +3 -1
- package/rpc/rpc_server.js +4 -4
- package/rpc/rpc_services.js +62 -25
- package/rpc/utils/helpers.js +83 -52
- package/src/config/args.js +46 -0
- package/src/config/config.js +78 -5
- package/src/config/env.js +70 -3
- package/src/core/network/Network.js +34 -70
- package/src/core/network/identity/NetworkWalletFactory.js +2 -2
- 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/base/BaseResponse.js +2 -3
- 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/{messaging → protocols/shared}/handlers/TransferOperationHandler.js +17 -16
- package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +10 -15
- package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +2 -2
- package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +5 -5
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +4 -4
- package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +14 -12
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
- package/src/core/network/services/ConnectionManager.js +5 -5
- package/src/core/network/services/MessageOrchestrator.js +2 -2
- package/src/core/network/services/TransactionPoolService.js +5 -6
- package/src/core/network/services/TransactionRateLimiterService.js +12 -13
- package/src/core/network/services/ValidatorObserverService.js +5 -6
- package/src/core/state/State.js +3 -5
- package/src/index.js +156 -181
- 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 +1 -1
- package/src/utils/cli.js +0 -8
- package/src/utils/constants.js +33 -30
- package/src/utils/fileUtils.js +13 -0
- package/src/utils/normalizers.js +84 -2
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +10 -0
- package/src/utils/type.js +26 -0
- package/tests/acceptance/v1/balance/balance.test.mjs +1 -2
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +26 -30
- package/tests/acceptance/v1/health/health.test.mjs +33 -0
- package/tests/acceptance/v1/rpc.test.mjs +4 -3
- package/tests/acceptance/v1/tx/tx.test.mjs +27 -16
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +26 -12
- package/tests/fixtures/check.fixtures.js +33 -32
- package/tests/fixtures/networkV1.fixtures.js +85 -0
- package/tests/fixtures/protobuf.fixtures.js +109 -25
- package/tests/helpers/StateNetworkFactory.js +2 -2
- package/tests/helpers/address.js +6 -0
- package/tests/helpers/autobaseTestHelpers.js +2 -1
- package/tests/helpers/config.js +2 -1
- package/tests/helpers/setupApplyTests.js +59 -56
- 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 +201 -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 +6 -5
- 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 +9 -6
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +10 -7
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +53 -38
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +46 -35
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +13 -16
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +11 -12
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/common/commonScenarioHelper.js +15 -14
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +9 -4
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +17 -11
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +19 -14
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +37 -29
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +9 -7
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +11 -9
- package/tests/unit/unit.test.js +1 -1
- package/tests/unit/utils/buffer/buffer.test.js +62 -1
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +4 -3
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +3 -2
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +3 -2
- package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
- package/tests/unit/utils/type/type.test.js +25 -0
- package/tests/unit/utils/utils.test.js +1 -0
- package/docs/networking-dualstack-plan.md +0 -75
- package/docs/networking-layer-redesign.md +0 -155
- package/src/core/network/messaging/NetworkMessages.js +0 -64
- package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -113
- package/src/core/network/messaging/handlers/ResponseHandler.js +0 -107
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -114
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -149
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -98
- package/src/core/network/messaging/validators/AdminResponse.js +0 -58
- package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
- package/src/messages/base/StateBuilder.js +0 -25
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -425
- package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -296
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
- package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -138
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -69
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -126
- package/tests/integration/apply/addIndexer.test.js +0 -239
- package/tests/integration/apply/addWhitelist.test.js +0 -53
- package/tests/integration/apply/addWriter.test.js +0 -245
- package/tests/integration/apply/apply.test.js +0 -19
- package/tests/integration/apply/banValidator.test.js +0 -116
- package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
- package/tests/integration/apply/postTx/postTx.test.js +0 -196
- package/tests/integration/apply/removeIndexer.test.js +0 -132
- package/tests/integration/apply/removeWriter.test.js +0 -168
- package/tests/integration/apply/transfer.test.js +0 -83
- 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 -17
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -68
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -424
- 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 -59
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -278
- package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
- /package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +0 -0
- /package/src/utils/{operations.js → applyOperations.js} +0 -0
|
@@ -4,8 +4,8 @@ import nodeEntryUtils, { setWritingKey } from '../../../../../src/core/state/uti
|
|
|
4
4
|
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
5
5
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
6
6
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
8
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
9
9
|
import {
|
|
10
10
|
setupAdminNetwork,
|
|
11
11
|
initializeBalances,
|
|
@@ -90,21 +90,24 @@ export async function buildAdminRecoveryPayload(context) {
|
|
|
90
90
|
const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
|
|
91
91
|
const txValidity = await deriveIndexerSequenceState(validatorPeer1.base);
|
|
92
92
|
|
|
93
|
-
const partial = await
|
|
94
|
-
.
|
|
93
|
+
const partial = await applyStateMessageFactory(adminPeer.wallet, config)
|
|
94
|
+
.buildPartialAdminRecoveryMessage(
|
|
95
|
+
adminPeer.wallet.address,
|
|
95
96
|
b4a.toString(newAdminWriterKey, 'hex'),
|
|
96
|
-
b4a.toString(txValidity, 'hex')
|
|
97
|
+
b4a.toString(txValidity, 'hex'),
|
|
98
|
+
'json'
|
|
97
99
|
);
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
const payload = await applyStateMessageFactory(validatorPeer1.wallet, config)
|
|
102
|
+
.buildCompleteAdminRecoveryMessage(
|
|
103
|
+
partial.address,
|
|
104
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
105
|
+
b4a.from(partial.rao.txv, 'hex'),
|
|
106
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
107
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
108
|
+
b4a.from(partial.rao.is, 'hex')
|
|
109
|
+
);
|
|
110
|
+
return safeEncodeApplyOperation(payload);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTxValidity) {
|
|
@@ -113,21 +116,24 @@ export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTx
|
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
|
|
116
|
-
const partial = await
|
|
117
|
-
.
|
|
119
|
+
const partial = await applyStateMessageFactory(adminPeer.wallet, config)
|
|
120
|
+
.buildPartialAdminRecoveryMessage(
|
|
121
|
+
adminPeer.wallet.address,
|
|
118
122
|
b4a.toString(newAdminWriterKey, 'hex'),
|
|
119
|
-
b4a.toString(mutatedTxValidity, 'hex')
|
|
123
|
+
b4a.toString(mutatedTxValidity, 'hex'),
|
|
124
|
+
'json'
|
|
120
125
|
);
|
|
121
126
|
|
|
122
|
-
|
|
123
|
-
.
|
|
124
|
-
|
|
127
|
+
const payload = await applyStateMessageFactory(validatorPeer1.wallet, config)
|
|
128
|
+
.buildCompleteAdminRecoveryMessage(
|
|
129
|
+
partial.address,
|
|
125
130
|
b4a.from(partial.rao.tx, 'hex'),
|
|
126
131
|
mutatedTxValidity,
|
|
127
132
|
b4a.from(partial.rao.iw, 'hex'),
|
|
128
133
|
b4a.from(partial.rao.in, 'hex'),
|
|
129
134
|
b4a.from(partial.rao.is, 'hex')
|
|
130
135
|
);
|
|
136
|
+
return safeEncodeApplyOperation(payload);
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
export async function applyAdminRecovery(context, payload) {
|
|
@@ -516,21 +522,26 @@ export async function applyTransferSeries(context, count = TRANSFER_COUNT) {
|
|
|
516
522
|
|
|
517
523
|
async function buildSimpleTransferPayload({ requesterPeer, validatorPeer, recipientPeer, amount }) {
|
|
518
524
|
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
519
|
-
const partial = await
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
525
|
+
const partial = await applyStateMessageFactory(requesterPeer.wallet, config)
|
|
526
|
+
.buildPartialTransferOperationMessage(
|
|
527
|
+
requesterPeer.wallet.address,
|
|
528
|
+
recipientPeer.wallet.address,
|
|
529
|
+
b4a.toString(amount, 'hex'),
|
|
530
|
+
b4a.toString(txValidity, 'hex'),
|
|
531
|
+
'json'
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
535
|
+
.buildCompleteTransferOperationMessage(
|
|
536
|
+
partial.address,
|
|
537
|
+
b4a.from(partial.tro.tx, 'hex'),
|
|
538
|
+
b4a.from(partial.tro.txv, 'hex'),
|
|
539
|
+
b4a.from(partial.tro.in, 'hex'),
|
|
540
|
+
partial.tro.to,
|
|
541
|
+
b4a.from(partial.tro.am, 'hex'),
|
|
542
|
+
b4a.from(partial.tro.is, 'hex')
|
|
543
|
+
);
|
|
544
|
+
return safeEncodeApplyOperation(payload);
|
|
534
545
|
}
|
|
535
546
|
|
|
536
547
|
export async function assertAdminRecoverySuccessState(t, context, { viewBase } = {}) {
|
|
@@ -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 { AUTOBASE_VALUE_ENCODING, EntryType } from '../../../../../src/utils/constants.js';
|
|
11
11
|
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
12
12
|
import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
@@ -45,11 +45,10 @@ export async function buildAppendWhitelistPayload(context, readerAddress = null)
|
|
|
45
45
|
const adminNode = context.adminBootstrap;
|
|
46
46
|
const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
|
|
47
47
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
48
|
+
return safeEncodeApplyOperation(
|
|
49
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
50
|
+
.buildCompleteAppendWhitelistMessage(adminNode.wallet.address, targetAddress, txValidity)
|
|
51
|
+
);
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
export async function buildAppendWhitelistPayloadWithTxValidity(
|
|
@@ -59,21 +58,19 @@ export async function buildAppendWhitelistPayloadWithTxValidity(
|
|
|
59
58
|
) {
|
|
60
59
|
const adminNode = context.adminBootstrap;
|
|
61
60
|
const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
61
|
+
return safeEncodeApplyOperation(
|
|
62
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
63
|
+
.buildCompleteAppendWhitelistMessage(adminNode.wallet.address, targetAddress, txValidity)
|
|
64
|
+
);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
export async function buildBanWriterPayload(context, readerAddress) {
|
|
70
68
|
const adminNode = context.adminBootstrap;
|
|
71
69
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
);
|
|
70
|
+
return safeEncodeApplyOperation(
|
|
71
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
72
|
+
.buildCompleteBanWriterMessage(adminNode.wallet.address, readerAddress, txValidity)
|
|
73
|
+
);
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
export function mutateAppendWhitelistPayloadForInvalidSchema(t, validPayload) {
|
package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js
CHANGED
|
@@ -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 { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
|
|
11
11
|
import { toTerm } from '../../../../../src/core/state/utils/balance.js';
|
|
12
12
|
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
@@ -42,11 +42,14 @@ async function bootstrapAdmin(context) {
|
|
|
42
42
|
export async function buildBalanceInitializationPayload(context, recipientAddress, balanceBuffer) {
|
|
43
43
|
const adminNode = context.adminBootstrap;
|
|
44
44
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const payload = await applyStateMessageFactory(adminNode.wallet, config)
|
|
46
|
+
.buildCompleteBalanceInitializationMessage(
|
|
47
|
+
adminNode.wallet.address,
|
|
48
|
+
recipientAddress,
|
|
49
|
+
balanceBuffer,
|
|
50
|
+
txValidity
|
|
51
|
+
);
|
|
52
|
+
return safeEncodeApplyOperation(payload);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export async function buildBalanceInitializationPayloadWithTxValidity({
|
|
@@ -60,11 +63,14 @@ export async function buildBalanceInitializationPayloadWithTxValidity({
|
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
const adminNode = context.adminBootstrap;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const payload = await applyStateMessageFactory(adminNode.wallet, config)
|
|
67
|
+
.buildCompleteBalanceInitializationMessage(
|
|
68
|
+
adminNode.wallet.address,
|
|
69
|
+
decoded.bio.ia,
|
|
70
|
+
decoded.bio.am,
|
|
71
|
+
mutatedTxValidity
|
|
72
|
+
);
|
|
73
|
+
return safeEncodeApplyOperation(payload);
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
export async function buildDefaultBalanceInitializationPayload(context) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import PeerWallet from 'trac-wallet';
|
|
3
3
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
4
|
-
import
|
|
4
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
5
5
|
import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
6
6
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
7
7
|
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
@@ -62,9 +62,9 @@ export async function buildBanValidatorPayload(
|
|
|
62
62
|
/* cover tests */
|
|
63
63
|
) {
|
|
64
64
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
return safeEncodeApplyOperation(
|
|
66
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
67
|
+
.buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -73,9 +73,9 @@ export async function buildBanValidatorPayloadWithTxValidity(
|
|
|
73
73
|
mutatedTxValidity,
|
|
74
74
|
{ adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
|
|
75
75
|
) {
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
return safeEncodeApplyOperation(
|
|
77
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
78
|
+
.buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, mutatedTxValidity)
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -339,11 +339,10 @@ export async function promoteValidatorToIndexer(
|
|
|
339
339
|
{ adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
|
|
340
340
|
) {
|
|
341
341
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
342
|
-
const payload =
|
|
343
|
-
.
|
|
344
|
-
validatorPeer.wallet.address,
|
|
345
|
-
|
|
346
|
-
);
|
|
342
|
+
const payload = safeEncodeApplyOperation(
|
|
343
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
344
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
|
|
345
|
+
);
|
|
347
346
|
|
|
348
347
|
await adminPeer.base.append(payload);
|
|
349
348
|
await adminPeer.base.update();
|
|
@@ -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,
|
|
@@ -109,15 +108,17 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
|
|
|
109
108
|
context.bootstrapDeployment?.txValidity ??
|
|
110
109
|
(await deriveIndexerSequenceState(validatorPeer.base));
|
|
111
110
|
|
|
112
|
-
const partial = await
|
|
113
|
-
.
|
|
111
|
+
const partial = await applyStateMessageFactory(deployerPeer.wallet, config)
|
|
112
|
+
.buildPartialBootstrapDeploymentMessage(
|
|
113
|
+
deployerPeer.wallet.address,
|
|
114
114
|
externalBootstrap.toString('hex'),
|
|
115
115
|
channel.toString('hex'),
|
|
116
|
-
txValidity.toString('hex')
|
|
116
|
+
txValidity.toString('hex'),
|
|
117
|
+
'json'
|
|
117
118
|
);
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
.
|
|
120
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
121
|
+
.buildCompleteBootstrapDeploymentMessage(
|
|
121
122
|
partial.address,
|
|
122
123
|
b4a.from(partial.bdo.tx, 'hex'),
|
|
123
124
|
b4a.from(partial.bdo.txv, 'hex'),
|
|
@@ -126,6 +127,7 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
|
|
|
126
127
|
b4a.from(partial.bdo.in, 'hex'),
|
|
127
128
|
b4a.from(partial.bdo.is, 'hex')
|
|
128
129
|
);
|
|
130
|
+
return safeEncodeApplyOperation(payload);
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
export async function buildBootstrapDeploymentPayloadWithTxValidity(context, txValidity, options = {}) {
|
|
@@ -5,7 +5,8 @@ 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';
|
|
11
12
|
import { config } from '../../../../helpers/config.js';
|
|
@@ -59,13 +60,16 @@ export async function initializeBalances(context, recipients) {
|
|
|
59
60
|
if (!adminNode || !Array.isArray(recipients) || recipients.length === 0) return;
|
|
60
61
|
|
|
61
62
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
62
|
-
const
|
|
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,12 +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
|
-
txValidity
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
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));
|
|
85
86
|
await adminNode.base.update();
|
|
86
87
|
await eventFlush();
|
|
87
88
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
import { config } from '../../../../../helpers/config.js';
|
|
5
6
|
|
|
6
7
|
export default class InitializationDisabledScenario extends OperationValidationScenarioBase {
|
|
@@ -34,9 +35,13 @@ async function disableInitializationAndApply(context, invalidPayload) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
37
|
-
const disablePayload =
|
|
38
|
-
adminNode.
|
|
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);
|
package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js
CHANGED
|
@@ -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 { 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';
|
|
@@ -55,20 +55,26 @@ export async function buildDisableInitializationPayload(context) {
|
|
|
55
55
|
const adminNode = context.adminBootstrap;
|
|
56
56
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
return safeEncodeApplyOperation(
|
|
59
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
60
|
+
.buildCompleteDisableInitializationMessage(
|
|
61
|
+
adminNode.wallet.address,
|
|
62
|
+
adminNode.base.local.key,
|
|
63
|
+
txValidity
|
|
64
|
+
)
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
export async function buildDisableInitializationPayloadWithTxValidity(context, txValidity) {
|
|
66
69
|
const adminNode = context.adminBootstrap;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
return safeEncodeApplyOperation(
|
|
71
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
72
|
+
.buildCompleteDisableInitializationMessage(
|
|
73
|
+
adminNode.wallet.address,
|
|
74
|
+
adminNode.base.local.key,
|
|
75
|
+
txValidity
|
|
76
|
+
)
|
|
77
|
+
);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
export async function assertInitializationDisabledState(t, base, payload) {
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
assertValidatorReward,
|
|
8
8
|
promotePeerToWriter
|
|
9
9
|
} from '../addWriter/addWriterScenarioHelpers.js';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
11
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
12
12
|
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
13
13
|
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
14
14
|
import { toBalance, BALANCE_FEE, BALANCE_TO_STAKE } from '../../../../../src/core/state/utils/balance.js';
|
|
@@ -180,18 +180,23 @@ export async function buildRemoveWriterPayloadWithTxValidity(context, mutatedTxV
|
|
|
180
180
|
}
|
|
181
181
|
const { readerPeer = selectWriterPeer(context), validatorPeer = context.adminBootstrap, writerKeyBuffer = null } = options;
|
|
182
182
|
const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
183
|
-
const partial = await
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
183
|
+
const partial = await applyStateMessageFactory(readerPeer.wallet, config)
|
|
184
|
+
.buildPartialRemoveWriterMessage(
|
|
185
|
+
readerPeer.wallet.address,
|
|
186
|
+
writerKey.toString('hex'),
|
|
187
|
+
mutatedTxValidity.toString('hex'),
|
|
188
|
+
'json'
|
|
189
|
+
);
|
|
190
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
191
|
+
.buildCompleteRemoveWriterMessage(
|
|
192
|
+
partial.address,
|
|
193
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
194
|
+
mutatedTxValidity,
|
|
195
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
196
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
197
|
+
b4a.from(partial.rao.is, 'hex')
|
|
198
|
+
);
|
|
199
|
+
return safeEncodeApplyOperation(payload);
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
export async function snapshotDowngradedWriterEntry(context) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { test } from 'brittle';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
4
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
5
5
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
6
6
|
import {
|
|
7
7
|
setupTransferScenario,
|
|
@@ -50,40 +50,48 @@ export default function transferDoubleSpendAcrossValidatorsScenario() {
|
|
|
50
50
|
const txValidityA = await deriveIndexerSequenceState(primaryValidator.base);
|
|
51
51
|
const txValidityB = await deriveIndexerSequenceState(secondaryValidator.base);
|
|
52
52
|
|
|
53
|
-
const partialA = await
|
|
54
|
-
.
|
|
53
|
+
const partialA = await applyStateMessageFactory(senderPeer.wallet, config)
|
|
54
|
+
.buildPartialTransferOperationMessage(
|
|
55
|
+
senderPeer.wallet.address,
|
|
55
56
|
recipientA.wallet.address,
|
|
56
57
|
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
57
|
-
b4a.toString(txValidityA, 'hex')
|
|
58
|
+
b4a.toString(txValidityA, 'hex'),
|
|
59
|
+
'json'
|
|
58
60
|
);
|
|
59
|
-
const partialB = await
|
|
60
|
-
.
|
|
61
|
+
const partialB = await applyStateMessageFactory(senderPeer.wallet, config)
|
|
62
|
+
.buildPartialTransferOperationMessage(
|
|
63
|
+
senderPeer.wallet.address,
|
|
61
64
|
recipientB.wallet.address,
|
|
62
65
|
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
63
|
-
b4a.toString(txValidityB, 'hex')
|
|
66
|
+
b4a.toString(txValidityB, 'hex'),
|
|
67
|
+
'json'
|
|
64
68
|
);
|
|
65
69
|
|
|
66
|
-
const payloadA =
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
70
|
+
const payloadA = safeEncodeApplyOperation(
|
|
71
|
+
await applyStateMessageFactory(primaryValidator.wallet, config)
|
|
72
|
+
.buildCompleteTransferOperationMessage(
|
|
73
|
+
partialA.address,
|
|
74
|
+
b4a.from(partialA.tro.tx, 'hex'),
|
|
75
|
+
b4a.from(partialA.tro.txv, 'hex'),
|
|
76
|
+
b4a.from(partialA.tro.in, 'hex'),
|
|
77
|
+
partialA.tro.to,
|
|
78
|
+
b4a.from(partialA.tro.am, 'hex'),
|
|
79
|
+
b4a.from(partialA.tro.is, 'hex')
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const payloadB = safeEncodeApplyOperation(
|
|
84
|
+
await applyStateMessageFactory(secondaryValidator.wallet, config)
|
|
85
|
+
.buildCompleteTransferOperationMessage(
|
|
86
|
+
partialB.address,
|
|
87
|
+
b4a.from(partialB.tro.tx, 'hex'),
|
|
88
|
+
b4a.from(partialB.tro.txv, 'hex'),
|
|
89
|
+
b4a.from(partialB.tro.in, 'hex'),
|
|
90
|
+
partialB.tro.to,
|
|
91
|
+
b4a.from(partialB.tro.am, 'hex'),
|
|
92
|
+
b4a.from(partialB.tro.is, 'hex')
|
|
93
|
+
)
|
|
94
|
+
);
|
|
87
95
|
|
|
88
96
|
// Apply first transfer successfully via primary validator.
|
|
89
97
|
await primaryValidator.base.append(payloadA);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import PeerWallet from 'trac-wallet';
|
|
3
|
-
import
|
|
4
|
-
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
3
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
5
4
|
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
6
5
|
import {
|
|
7
6
|
setupAdminNetwork,
|
|
@@ -123,15 +122,17 @@ export async function buildTransferPayload(
|
|
|
123
122
|
const resolvedTxValidity =
|
|
124
123
|
txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
|
|
125
124
|
|
|
126
|
-
const partial = await
|
|
127
|
-
.
|
|
125
|
+
const partial = await applyStateMessageFactory(senderPeer.wallet, config)
|
|
126
|
+
.buildPartialTransferOperationMessage(
|
|
127
|
+
senderPeer.wallet.address,
|
|
128
128
|
recipientAddress,
|
|
129
129
|
b4a.toString(amount, 'hex'),
|
|
130
|
-
b4a.toString(resolvedTxValidity, 'hex')
|
|
130
|
+
b4a.toString(resolvedTxValidity, 'hex'),
|
|
131
|
+
'json'
|
|
131
132
|
);
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
.
|
|
134
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
135
|
+
.buildCompleteTransferOperationMessage(
|
|
135
136
|
partial.address,
|
|
136
137
|
b4a.from(partial.tro.tx, 'hex'),
|
|
137
138
|
b4a.from(partial.tro.txv, 'hex'),
|
|
@@ -140,6 +141,7 @@ export async function buildTransferPayload(
|
|
|
140
141
|
b4a.from(partial.tro.am, 'hex'),
|
|
141
142
|
b4a.from(partial.tro.is, 'hex')
|
|
142
143
|
);
|
|
144
|
+
return safeEncodeApplyOperation(payload);
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
export async function buildTransferPayloadWithTxValidity(
|