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
|
@@ -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
|
+
});
|
|
@@ -9,9 +9,10 @@ import { createConfig, ENV } from "../../../src/config/env.js";
|
|
|
9
9
|
|
|
10
10
|
const createConnection = (key) => {
|
|
11
11
|
const emitter = new EventEmitter()
|
|
12
|
-
emitter.
|
|
12
|
+
emitter.protocolSession = {
|
|
13
|
+
has: (name) => name === 'legacy',
|
|
13
14
|
send: sinon.stub().resolves(),
|
|
14
|
-
}
|
|
15
|
+
};
|
|
15
16
|
emitter.connected = true
|
|
16
17
|
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
17
18
|
|
|
@@ -32,7 +33,7 @@ const makeManager = (maxValidators = 6, conns = connections) => {
|
|
|
32
33
|
const reset = () => {
|
|
33
34
|
sinon.restore()
|
|
34
35
|
connections.forEach(connection => {
|
|
35
|
-
connection.connection.
|
|
36
|
+
connection.connection.protocolSession.send.resetHistory()
|
|
36
37
|
})
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -121,7 +122,7 @@ test('ConnectionManager', () => {
|
|
|
121
122
|
|
|
122
123
|
const target = connectionManager.send([1,2,3,4])
|
|
123
124
|
|
|
124
|
-
const totalCalls = connections.reduce((sum, con) => sum + con.connection.
|
|
125
|
+
const totalCalls = connections.reduce((sum, con) => sum + con.connection.protocolSession.send.callCount, 0)
|
|
125
126
|
t.is(totalCalls, 1, 'should send to exactly one validator')
|
|
126
127
|
t.ok(target, 'should return a target public key')
|
|
127
128
|
})
|
|
@@ -134,7 +135,7 @@ test('ConnectionManager', () => {
|
|
|
134
135
|
]
|
|
135
136
|
|
|
136
137
|
errorConnections.forEach(con => {
|
|
137
|
-
con.connection.
|
|
138
|
+
con.connection.protocolSession.send = sinon.stub().throws(new Error())
|
|
138
139
|
})
|
|
139
140
|
|
|
140
141
|
const connectionManager = makeManager(5, errorConnections)
|
|
@@ -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,7 +5,8 @@ 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
|
|
8
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
9
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
9
10
|
import { setupAddAdminScenario, assertAdminState } from './addAdminScenarioHelpers.js';
|
|
10
11
|
import { config } from '../../../../helpers/config.js';
|
|
11
12
|
|
|
@@ -17,11 +18,14 @@ export default function addAdminHappyPathScenario() {
|
|
|
17
18
|
const reader = readerNodes[0];
|
|
18
19
|
|
|
19
20
|
const txValidity = await deriveIndexerSequenceState(adminNode.base);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const addAdminPayload = safeEncodeApplyOperation(
|
|
22
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
23
|
+
.buildCompleteAddAdminMessage(
|
|
24
|
+
adminNode.wallet.address,
|
|
25
|
+
adminNode.base.local.key,
|
|
26
|
+
txValidity
|
|
27
|
+
)
|
|
28
|
+
);
|
|
25
29
|
|
|
26
30
|
await adminNode.base.append(addAdminPayload);
|
|
27
31
|
await adminNode.base.update();
|
|
@@ -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
|
|
@@ -42,11 +42,14 @@ 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 safeEncodeApplyOperation(
|
|
46
|
+
await applyStateMessageFactory(adminNode.wallet, config)
|
|
47
|
+
.buildCompleteAddAdminMessage(
|
|
48
|
+
adminNode.wallet.address,
|
|
49
|
+
adminNode.base.local.key,
|
|
50
|
+
txValidity
|
|
51
|
+
)
|
|
52
|
+
);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export async function assertAddAdminRequesterFailureState(t, context) {
|
|
@@ -18,7 +18,8 @@ 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';
|
|
@@ -127,13 +128,15 @@ new TransactionValidityMismatchScenario({
|
|
|
127
128
|
setupScenario: setupAddAdminScenario,
|
|
128
129
|
buildValidPayload: buildAddAdminRequesterPayload,
|
|
129
130
|
assertStateUnchanged: assertAddAdminRequesterFailureState,
|
|
130
|
-
rebuildPayloadWithTxValidity: ({ context, mutatedTxValidity }) => {
|
|
131
|
+
rebuildPayloadWithTxValidity: async ({ context, mutatedTxValidity }) => {
|
|
131
132
|
const adminNode = context.adminBootstrap;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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);
|
|
137
140
|
},
|
|
138
141
|
expectedLogs: ['Transaction was not executed.']
|
|
139
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,
|
|
@@ -51,11 +52,10 @@ export async function buildAddIndexerPayload(
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
55
|
+
return safeEncodeApplyOperation(
|
|
56
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
57
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, writerPeer.wallet.address, txValidity)
|
|
58
|
+
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export async function applyWithIndexerRoleUpdateFailure(context, invalidPayload) {
|
|
@@ -99,11 +99,10 @@ export async function buildAddIndexerPayloadWithTxValidity(
|
|
|
99
99
|
throw new Error('buildAddIndexerPayloadWithTxValidity requires an admin peer.');
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
102
|
+
return safeEncodeApplyOperation(
|
|
103
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
104
|
+
.buildCompleteAddIndexerMessage(adminPeer.wallet.address, writerPeer.wallet.address, mutatedTxValidity)
|
|
105
|
+
);
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
export function ensureIndexerRegistration(base, writingKey) {
|
|
@@ -147,11 +146,10 @@ export async function buildRemoveIndexerPayload(
|
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
const txValidity = await deriveIndexerSequenceState(adminPeer.base);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
149
|
+
return safeEncodeApplyOperation(
|
|
150
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
151
|
+
.buildCompleteRemoveIndexerMessage(adminPeer.wallet.address, indexerPeer.wallet.address, txValidity)
|
|
152
|
+
);
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
export async function buildRemoveIndexerPayloadWithTxValidity(
|
|
@@ -169,11 +167,10 @@ export async function buildRemoveIndexerPayloadWithTxValidity(
|
|
|
169
167
|
throw new Error('buildRemoveIndexerPayloadWithTxValidity requires an admin peer.');
|
|
170
168
|
}
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
);
|
|
170
|
+
return safeEncodeApplyOperation(
|
|
171
|
+
await applyStateMessageFactory(adminPeer.wallet, config)
|
|
172
|
+
.buildCompleteRemoveIndexerMessage(adminPeer.wallet.address, indexerPeer.wallet.address, mutatedTxValidity)
|
|
173
|
+
);
|
|
177
174
|
}
|
|
178
175
|
|
|
179
176
|
export async function assertAddIndexerSuccessState(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
|
|
3
|
+
import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
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';
|
|
@@ -105,19 +105,24 @@ 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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
const partial = await applyStateMessageFactory(readerPeer.wallet, config)
|
|
109
|
+
.buildPartialAddWriterMessage(
|
|
110
|
+
readerPeer.wallet.address,
|
|
111
|
+
writingKey.toString('hex'),
|
|
112
|
+
txValidity.toString('hex'),
|
|
113
|
+
'json'
|
|
114
|
+
);
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
117
|
+
.buildCompleteAddWriterMessage(
|
|
118
|
+
partial.address,
|
|
119
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
120
|
+
b4a.from(partial.rao.txv, 'hex'),
|
|
121
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
122
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
123
|
+
b4a.from(partial.rao.is, 'hex')
|
|
124
|
+
);
|
|
125
|
+
return safeEncodeApplyOperation(payload);
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
export async function buildAddWriterPayloadWithTxValidity(
|
|
@@ -134,19 +139,24 @@ export async function buildAddWriterPayloadWithTxValidity(
|
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
137
|
-
const partial = await
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
const partial = await applyStateMessageFactory(readerPeer.wallet, config)
|
|
143
|
+
.buildPartialAddWriterMessage(
|
|
144
|
+
readerPeer.wallet.address,
|
|
145
|
+
writingKey.toString('hex'),
|
|
146
|
+
mutatedTxValidity.toString('hex'),
|
|
147
|
+
'json'
|
|
148
|
+
);
|
|
141
149
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
151
|
+
.buildCompleteAddWriterMessage(
|
|
152
|
+
partial.address,
|
|
153
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
154
|
+
mutatedTxValidity,
|
|
155
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
156
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
157
|
+
b4a.from(partial.rao.is, 'hex')
|
|
158
|
+
);
|
|
159
|
+
return safeEncodeApplyOperation(payload);
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
export async function buildRemoveWriterPayload(
|
|
@@ -159,19 +169,24 @@ export async function buildRemoveWriterPayload(
|
|
|
159
169
|
) {
|
|
160
170
|
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
161
171
|
const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
|
|
162
|
-
const partial = await
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
const partial = await applyStateMessageFactory(readerPeer.wallet, config)
|
|
173
|
+
.buildPartialRemoveWriterMessage(
|
|
174
|
+
readerPeer.wallet.address,
|
|
175
|
+
writerKey.toString('hex'),
|
|
176
|
+
txValidity.toString('hex'),
|
|
177
|
+
'json'
|
|
178
|
+
);
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
180
|
+
const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
|
|
181
|
+
.buildCompleteRemoveWriterMessage(
|
|
182
|
+
partial.address,
|
|
183
|
+
b4a.from(partial.rao.tx, 'hex'),
|
|
184
|
+
b4a.from(partial.rao.txv, 'hex'),
|
|
185
|
+
b4a.from(partial.rao.iw, 'hex'),
|
|
186
|
+
b4a.from(partial.rao.in, 'hex'),
|
|
187
|
+
b4a.from(partial.rao.is, 'hex')
|
|
188
|
+
);
|
|
189
|
+
return safeEncodeApplyOperation(payload);
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
export async function assertAddWriterSuccessState(
|