trac-msb 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +8 -16
- package/docs/networking-dualstack-plan.md +75 -0
- package/docs/networking-layer-redesign.md +155 -0
- package/msb.mjs +11 -23
- package/package.json +2 -3
- package/rpc/{create_server.mjs → create_server.js} +2 -2
- package/rpc/{handlers.mjs → handlers.js} +5 -5
- package/rpc/routes/{index.mjs → index.js} +1 -1
- package/rpc/routes/{v1.mjs → v1.js} +1 -1
- package/rpc/{rpc_server.mjs → rpc_server.js} +1 -1
- package/rpc/rpc_services.js +4 -4
- package/src/config/config.js +137 -0
- package/src/config/env.js +61 -0
- package/src/core/network/Network.js +119 -73
- package/src/core/network/identity/NetworkWalletFactory.js +3 -4
- package/src/core/network/messaging/NetworkMessages.js +12 -11
- package/src/core/network/messaging/handlers/GetRequestHandler.js +5 -4
- package/src/core/network/messaging/handlers/ResponseHandler.js +4 -5
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +17 -19
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +44 -38
- package/src/core/network/messaging/handlers/TransferOperationHandler.js +29 -25
- package/src/core/network/messaging/handlers/base/BaseOperationHandler.js +20 -21
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +24 -20
- package/src/core/network/messaging/validators/AdminResponse.js +2 -2
- package/src/core/network/messaging/validators/CustomNodeResponse.js +2 -2
- package/src/core/network/messaging/validators/PartialBootstrapDeployment.js +3 -3
- package/src/core/network/messaging/validators/PartialRoleAccess.js +15 -12
- package/src/core/network/messaging/validators/PartialTransaction.js +9 -10
- package/src/core/network/messaging/validators/PartialTransfer.js +10 -7
- package/src/core/network/messaging/validators/ValidatorResponse.js +2 -2
- package/src/core/network/messaging/validators/base/BaseResponse.js +13 -5
- package/src/core/network/messaging/validators/base/PartialOperation.js +37 -21
- package/src/core/network/services/ConnectionManager.js +9 -15
- package/src/core/network/services/MessageOrchestrator.js +10 -22
- package/src/core/network/services/TransactionPoolService.js +9 -8
- package/src/core/network/services/ValidatorObserverService.js +46 -21
- package/src/core/state/State.js +136 -139
- package/src/core/state/utils/address.js +18 -16
- package/src/core/state/utils/adminEntry.js +17 -16
- package/src/core/state/utils/deploymentEntry.js +15 -15
- package/src/core/state/utils/transaction.js +3 -95
- package/src/index.js +153 -201
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +36 -32
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +39 -42
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +20 -20
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +29 -22
- package/src/utils/check.js +21 -17
- package/src/utils/cliCommands.js +11 -11
- package/src/utils/constants.js +2 -10
- package/src/utils/fileUtils.js +1 -4
- package/src/utils/helpers.js +9 -20
- package/src/utils/migrationUtils.js +2 -2
- package/src/utils/normalizers.js +10 -9
- package/tests/acceptance/v1/account/account.test.mjs +2 -2
- package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
- package/tests/acceptance/v1/rpc.test.mjs +9 -9
- package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
- package/tests/fixtures/check.fixtures.js +42 -42
- package/tests/fixtures/protobuf.fixtures.js +27 -26
- package/tests/helpers/StateNetworkFactory.js +3 -5
- package/tests/helpers/autobaseTestHelpers.js +1 -2
- package/tests/helpers/config.js +3 -0
- package/tests/helpers/setupApplyTests.js +89 -82
- package/tests/helpers/transactionPayloads.mjs +26 -12
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +10 -9
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +20 -19
- package/tests/integration/apply/addIndexer.test.js +23 -21
- package/tests/integration/apply/addWhitelist.test.js +9 -9
- package/tests/integration/apply/addWriter.test.js +33 -32
- package/tests/integration/apply/banValidator.test.js +16 -9
- package/tests/integration/apply/postTx/invalidSubValues.test.js +4 -4
- package/tests/integration/apply/postTx/postTx.test.js +7 -33
- package/tests/integration/apply/removeIndexer.test.js +11 -7
- package/tests/integration/apply/removeWriter.test.js +20 -19
- package/tests/integration/apply/transfer.test.js +18 -16
- package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +2 -1
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +9 -10
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +3 -2
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +25 -43
- package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +2 -2
- package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +5 -4
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +4 -3
- package/tests/unit/network/ConnectionManager.test.js +4 -2
- package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +6 -6
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +8 -8
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +6 -5
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +24 -23
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +10 -16
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +45 -41
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +17 -16
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +3 -4
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +23 -25
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +19 -18
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/commonScenarioHelper.js +3 -4
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +2 -2
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +11 -10
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +6 -7
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +35 -34
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +44 -43
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +26 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
- package/tests/unit/state/stateModule.test.js +0 -1
- package/tests/unit/state/stateTestUtils.js +7 -3
- package/tests/unit/state/utils/address.test.js +3 -3
- package/tests/unit/state/utils/adminEntry.test.js +10 -9
- package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
- package/tests/unit/utils/check/common.test.js +7 -6
- package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
- package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
- package/tests/unit/utils/check/transactionOperation.test.js +3 -3
- package/tests/unit/utils/check/transferOperation.test.js +3 -3
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
- package/tests/unit/utils/utils.test.js +0 -1
- package/src/core/state/utils/indexerEntry.js +0 -105
- package/src/utils/crypto.js +0 -11
- package/tests/unit/state/utils/indexerEntry.test.js +0 -83
- package/tests/unit/state/utils/transaction.test.js +0 -97
- package/tests/unit/utils/crypto/createHash.test.js +0 -15
- /package/rpc/{constants.mjs → constants.js} +0 -0
- /package/rpc/{cors.mjs → cors.js} +0 -0
- /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
- /package/rpc/utils/{helpers.mjs → helpers.js} +0 -0
- /package/rpc/utils/{url.mjs → url.js} +0 -0
|
@@ -17,21 +17,23 @@ import {
|
|
|
17
17
|
import PartialStateMessageOperations from "../../../src/messages/partialStateMessages/PartialStateMessageOperations.js";
|
|
18
18
|
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
19
19
|
import { $TNK } from '../../../src/core/state/utils/balance.js';
|
|
20
|
+
import { config } from '../../helpers/config.js';
|
|
20
21
|
|
|
21
22
|
const buildTransfer = async (admin, from, to, amount) => {
|
|
22
23
|
const txValidity = await from.msb.state.getIndexerSequenceState()
|
|
23
|
-
const tx = await PartialStateMessageOperations
|
|
24
|
+
const tx = await new PartialStateMessageOperations(from.wallet, config)
|
|
25
|
+
.assembleTransferOperationMessage(to.wallet.address, b4a.toString(amount, 'hex'), b4a.toString(txValidity, 'hex'))
|
|
24
26
|
return {
|
|
25
|
-
raw: await CompleteStateMessageOperations.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
raw: await new CompleteStateMessageOperations(admin.wallet, config)
|
|
28
|
+
.assembleCompleteTransferOperationMessage(
|
|
29
|
+
tx.address,
|
|
30
|
+
b4a.from(tx.tro.tx, 'hex'),
|
|
31
|
+
b4a.from(tx.tro.txv, 'hex'),
|
|
32
|
+
b4a.from(tx.tro.in, 'hex'),
|
|
33
|
+
tx.tro.to,
|
|
34
|
+
b4a.from(tx.tro.am, 'hex'),
|
|
35
|
+
b4a.from(tx.tro.is, 'hex'),
|
|
36
|
+
),
|
|
35
37
|
hash: tx.tro.tx
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -41,11 +43,11 @@ let admin, writer1, writer2, writer3, tmpDirectory;
|
|
|
41
43
|
hook('Initialize nodes for addWriter tests', async t => {
|
|
42
44
|
const randomChannel = randomBytes(32).toString('hex');
|
|
43
45
|
const baseOptions = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
enableTxApplyLogs: false,
|
|
47
|
+
enableInteractiveMode: false,
|
|
48
|
+
enableRoleRequester: false,
|
|
47
49
|
channel: randomChannel,
|
|
48
|
-
|
|
50
|
+
enableValidatorObserver: false
|
|
49
51
|
}
|
|
50
52
|
tmpDirectory = await initTemporaryDirectory();
|
|
51
53
|
admin = await setupMsbAdmin(testKeyPair1, tmpDirectory, baseOptions);
|
|
@@ -78,4 +80,4 @@ hook('Clean up handleApplyTransferOperation setup', async t => {
|
|
|
78
80
|
|
|
79
81
|
await Promise.all(toClose)
|
|
80
82
|
if (tmpDirectory) await removeTemporaryDirectory(tmpDirectory);
|
|
81
|
-
});
|
|
83
|
+
});
|
|
@@ -4,12 +4,13 @@ import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
|
|
|
4
4
|
import { writingKeyNonAdmin, walletNonAdmin, initAll ,walletAdmin} from '../fixtures/assembleMessage.fixtures.js';
|
|
5
5
|
import { messageOperationsBkoTest } from './commonsStateMessageOperationsTest.js';
|
|
6
6
|
import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
|
|
7
|
+
import { config } from '../../helpers/config.js';
|
|
7
8
|
|
|
8
9
|
const testName = 'assembleAddIndexerMessage';
|
|
9
10
|
test(testName, async (t) => {
|
|
10
11
|
await initAll();
|
|
11
12
|
const assembler = async (wallet, address) => {
|
|
12
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleAddIndexerMessage(
|
|
13
|
+
return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleAddIndexerMessage(address));
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.ADD_INDEXER, 2, walletNonAdmin.address);
|
|
@@ -18,4 +19,3 @@ test(testName, async (t) => {
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
|
|
@@ -4,12 +4,13 @@ import {OperationType} from '../../src/utils/protobuf/applyOperations.cjs';
|
|
|
4
4
|
import {initAll, walletNonAdmin, writingKeyNonAdmin} from '../fixtures/assembleMessage.fixtures.js';
|
|
5
5
|
import {messageOperationsEkoTest} from './commonsStateMessageOperationsTest.js';
|
|
6
6
|
import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
|
|
7
|
+
import { config } from '../../helpers/config.js'
|
|
7
8
|
|
|
8
9
|
const testName = 'assembleAddWriterMessage';
|
|
9
10
|
test(testName, async (t) => {
|
|
10
11
|
await initAll();
|
|
11
12
|
const assembler = async (wallet, writingKey) => {
|
|
12
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations
|
|
13
|
+
return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleAddWriterMessage(writingKey));
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
await messageOperationsEkoTest(t, testName, assembler, walletNonAdmin, writingKeyNonAdmin, OperationType.ADD_WRITER, 3, walletNonAdmin.address);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import test from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
|
|
4
3
|
import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
5
4
|
import {default as fixtures} from '../fixtures/assembleMessage.fixtures.js';
|
|
6
5
|
import {OperationType} from "../../src/utils/constants.js";
|
|
@@ -8,6 +7,7 @@ import {bufferToAddress} from "../../src/core/state/utils/address.js";
|
|
|
8
7
|
import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
|
|
9
8
|
import {isAddressValid} from "../../src/core/state/utils/address.js";
|
|
10
9
|
import {errorMessageIncludes} from "../utils/regexHelper.js";
|
|
10
|
+
import { config } from '../../helpers/config.js';
|
|
11
11
|
|
|
12
12
|
test('assembleAdminMessage', async (t) => {
|
|
13
13
|
await fixtures.initAll();
|
|
@@ -18,16 +18,15 @@ test('assembleAdminMessage', async (t) => {
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
t.test('assembleAdminMessage - setup admin', async (k) => {
|
|
21
|
-
|
|
22
|
-
const msg = safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleAddAdminMessage(walletAdmin, writingKeyAdmin));
|
|
21
|
+
const msg = safeDecodeApplyOperation(await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(writingKeyAdmin));
|
|
23
22
|
|
|
24
23
|
k.ok(msg, 'Message should be created');
|
|
25
24
|
k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
|
|
26
25
|
k.is(Object.keys(msg.eko).length, 3, 'Message value have 3 keys');
|
|
27
26
|
k.is(msg.type, OperationType.ADD_ADMIN, 'Message type should be ADD_ADMIN');
|
|
28
|
-
k.is(bufferToAddress(msg.address), walletAdmin.address, 'Message address should be the public key of the wallet');
|
|
27
|
+
k.is(bufferToAddress(msg.address, config.addressPrefix), walletAdmin.address, 'Message address should be the public key of the wallet');
|
|
29
28
|
|
|
30
|
-
k.ok(isAddressValid(msg.address), 'Message address should be a valid address');
|
|
29
|
+
k.ok(isAddressValid(msg.address, config.addressPrefix), 'Message address should be a valid address');
|
|
31
30
|
|
|
32
31
|
k.ok(b4a.equals(msg.eko.wk, writingKeyAdmin), 'Message wk should be the writing key');
|
|
33
32
|
k.is(msg.eko.nonce.length, 32, 'Message nonce should be 32 bytes long');
|
|
@@ -37,15 +36,15 @@ test('assembleAdminMessage', async (t) => {
|
|
|
37
36
|
});
|
|
38
37
|
|
|
39
38
|
t.test('assembleAdminMessage - admin recovery message', async (k) => {
|
|
40
|
-
const msg = safeDecodeApplyOperation(await CompleteStateMessageOperations
|
|
39
|
+
const msg = safeDecodeApplyOperation(await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(writingKeyNonAdmin));
|
|
41
40
|
|
|
42
41
|
k.ok(msg, 'Message should be created');
|
|
43
42
|
k.is(Object.keys(msg).length, 3, 'Message should have 3 keys');
|
|
44
43
|
k.is(Object.keys(msg.eko).length, 3, 'Message value have 3 keys');
|
|
45
44
|
k.is(msg.type, OperationType.ADD_ADMIN, 'Message type should be ADD_ADMIN');
|
|
46
45
|
|
|
47
|
-
k.is(bufferToAddress(msg.address), walletAdmin.address, 'Message address should be address of the wallet');
|
|
48
|
-
k.ok(isAddressValid(msg.address), 'Message address should be a valid address');
|
|
46
|
+
k.is(bufferToAddress(msg.address, config.addressPrefix), walletAdmin.address, 'Message address should be address of the wallet');
|
|
47
|
+
k.ok(isAddressValid(msg.address, config.addressPrefix), 'Message address should be a valid address');
|
|
49
48
|
|
|
50
49
|
k.ok(b4a.equals(msg.eko.wk, writingKeyNonAdmin), 'Message wk should be the writing key');
|
|
51
50
|
k.is(msg.eko.sig.length, 64, 'Message signature should be 64 bytes long')
|
|
@@ -55,14 +54,14 @@ test('assembleAdminMessage', async (t) => {
|
|
|
55
54
|
|
|
56
55
|
t.test('assembleAdminMessage - writer key is null', async (k) => {
|
|
57
56
|
await k.exception(
|
|
58
|
-
async () => await CompleteStateMessageOperations
|
|
57
|
+
async () => await new CompleteStateMessageOperations(walletAdmin, config).assembleAddAdminMessage(null),
|
|
59
58
|
errorMessageIncludes('Writer key must be a 32 length buffer')
|
|
60
59
|
);
|
|
61
60
|
});
|
|
62
61
|
|
|
63
62
|
t.test("assembleAdminMessage - admin wallet is null", async (k) => {
|
|
64
63
|
await k.exception(
|
|
65
|
-
async () => await CompleteStateMessageOperations
|
|
64
|
+
async () => await new CompleteStateMessageOperations(null, config).assembleAddAdminMessage(writingKeyAdmin),
|
|
66
65
|
errorMessageIncludes('Wallet must be a valid wallet object')
|
|
67
66
|
);
|
|
68
67
|
});
|
|
@@ -4,13 +4,14 @@ import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
|
|
|
4
4
|
import { writingKeyNonAdmin, walletNonAdmin, initAll, walletAdmin } from '../fixtures/assembleMessage.fixtures.js';
|
|
5
5
|
import { messageOperationsBkoTest } from './commonsStateMessageOperationsTest.js';
|
|
6
6
|
import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
|
|
7
|
+
import { config } from '../../helpers/config.js';
|
|
7
8
|
|
|
8
9
|
const testName = 'assembleBanWriterMessage';
|
|
9
10
|
test(testName, async (t) => {
|
|
10
11
|
await initAll();
|
|
11
12
|
const assembler = async (wallet,address) => {
|
|
12
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleBanWriterMessage(
|
|
13
|
+
return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleBanWriterMessage(address));
|
|
13
14
|
}
|
|
14
15
|
await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.BAN_VALIDATOR, 2, walletNonAdmin.address);
|
|
15
16
|
|
|
16
|
-
});
|
|
17
|
+
});
|
|
@@ -7,7 +7,8 @@ import b4a from 'b4a';
|
|
|
7
7
|
import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
|
|
8
8
|
import {isAddressValid} from "../../src/core/state/utils/address.js";
|
|
9
9
|
import {errorMessageIncludes} from "../utils/regexHelper.js";
|
|
10
|
-
import {
|
|
10
|
+
import {randomBytes} from "../../helpers/setupApplyTests.js";
|
|
11
|
+
import { config } from '../../helpers/config.js';
|
|
11
12
|
|
|
12
13
|
const msgTxoLength = 10;
|
|
13
14
|
const opType = OperationType.TX;
|
|
@@ -26,8 +27,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
26
27
|
const externalBootstrap = randomBytes(32);
|
|
27
28
|
const msbBootstrap = randomBytes(32);
|
|
28
29
|
|
|
29
|
-
const decodedPostTx = safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
30
|
-
nonAdminWallet,
|
|
30
|
+
const decodedPostTx = safeDecodeApplyOperation(await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
31
31
|
validatorAddress,
|
|
32
32
|
txHash,
|
|
33
33
|
incomingAddress,
|
|
@@ -44,11 +44,11 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
44
44
|
|
|
45
45
|
k.is(decodedPostTx.type, opType, `Message type should be ${opType}`);
|
|
46
46
|
|
|
47
|
-
k.ok(isAddressValid(decodedPostTx.address), 'Message validator address should be a valid address');
|
|
48
|
-
k.ok(isAddressValid(decodedPostTx.txo.ia), 'Message incoming address should be a valid address');
|
|
47
|
+
k.ok(isAddressValid(decodedPostTx.address, config.addressPrefix), 'Message validator address should be a valid address');
|
|
48
|
+
k.ok(isAddressValid(decodedPostTx.txo.ia, config.addressPrefix), 'Message incoming address should be a valid address');
|
|
49
49
|
|
|
50
|
-
k.ok(bufferToAddress(decodedPostTx.txo.ia) === incomingAddress, 'Message incoming address should be the address of the peer wallet');
|
|
51
|
-
k.ok(bufferToAddress(decodedPostTx.address) === validatorAddress, 'Message validator address should be the address of the non-admin wallet');
|
|
50
|
+
k.ok(bufferToAddress(decodedPostTx.txo.ia, config.addressPrefix) === incomingAddress, 'Message incoming address should be the address of the peer wallet');
|
|
51
|
+
k.ok(bufferToAddress(decodedPostTx.address, config.addressPrefix) === validatorAddress, 'Message validator address should be the address of the non-admin wallet');
|
|
52
52
|
|
|
53
53
|
k.ok(b4a.isBuffer(decodedPostTx.txo.tx), 'tx should be a buffer');
|
|
54
54
|
k.is(decodedPostTx.txo.tx.length, 32, 'tx should be 32 bytes long');
|
|
@@ -76,8 +76,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
76
76
|
address: 'trac1y6kkq48fgu3ur'
|
|
77
77
|
}
|
|
78
78
|
await k.exception(
|
|
79
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
80
|
-
invalidWallet,
|
|
79
|
+
async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
|
|
81
80
|
validatorAddress,
|
|
82
81
|
txHash,
|
|
83
82
|
incomingAddress,
|
|
@@ -97,8 +96,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
97
96
|
address: 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk'
|
|
98
97
|
}
|
|
99
98
|
await k.exception(
|
|
100
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
101
|
-
invalidWallet,
|
|
99
|
+
async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
|
|
102
100
|
validatorAddress,
|
|
103
101
|
txHash,
|
|
104
102
|
incomingAddress,
|
|
@@ -118,8 +116,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
118
116
|
address: ''
|
|
119
117
|
}
|
|
120
118
|
await k.exception(
|
|
121
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
122
|
-
invalidWallet,
|
|
119
|
+
async () => await new CompleteStateMessageOperations(invalidWallet, config).assembleCompleteTransactionOperationMessage(
|
|
123
120
|
validatorAddress,
|
|
124
121
|
txHash,
|
|
125
122
|
incomingAddress,
|
|
@@ -136,8 +133,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
136
133
|
|
|
137
134
|
k.test(`assemblePostTxMessage - Invalid wallet instance - null Wallet `, async (k) => {
|
|
138
135
|
await k.exception(
|
|
139
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
140
|
-
null,
|
|
136
|
+
async () => await new CompleteStateMessageOperations(null, config).assembleCompleteTransactionOperationMessage(
|
|
141
137
|
validatorAddress,
|
|
142
138
|
txHash,
|
|
143
139
|
incomingAddress,
|
|
@@ -154,8 +150,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
154
150
|
|
|
155
151
|
k.test(`assemblePostTxMessage - Invalid wallet instance - undefined Wallet`, async (k) => {
|
|
156
152
|
await k.exception(
|
|
157
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
158
|
-
undefined,
|
|
153
|
+
async () => await new CompleteStateMessageOperations(undefined, config).assembleCompleteTransactionOperationMessage(
|
|
159
154
|
validatorAddress,
|
|
160
155
|
txHash,
|
|
161
156
|
incomingAddress,
|
|
@@ -175,8 +170,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
175
170
|
const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
|
|
176
171
|
|
|
177
172
|
await k.exception(
|
|
178
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
179
|
-
nonAdminWallet,
|
|
173
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
180
174
|
invalid,
|
|
181
175
|
txHash,
|
|
182
176
|
incomingAddress,
|
|
@@ -195,8 +189,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
195
189
|
const invalid = 'trac1y6kkq48fgu3ur';
|
|
196
190
|
|
|
197
191
|
await k.exception(
|
|
198
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
199
|
-
nonAdminWallet,
|
|
192
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
200
193
|
invalid,
|
|
201
194
|
txHash,
|
|
202
195
|
incomingAddress,
|
|
@@ -215,8 +208,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
215
208
|
const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
|
|
216
209
|
|
|
217
210
|
await k.exception(
|
|
218
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
219
|
-
nonAdminWallet,
|
|
211
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
220
212
|
invalid,
|
|
221
213
|
txHash,
|
|
222
214
|
incomingAddress,
|
|
@@ -235,8 +227,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
235
227
|
const invalid = '';
|
|
236
228
|
|
|
237
229
|
await k.exception(
|
|
238
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
239
|
-
nonAdminWallet,
|
|
230
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
240
231
|
invalid,
|
|
241
232
|
txHash,
|
|
242
233
|
incomingAddress,
|
|
@@ -253,8 +244,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
253
244
|
k.test(`assemblePostTxMessage - Address parameter (validator address) - Null`, async (k) => {
|
|
254
245
|
|
|
255
246
|
await k.exception(
|
|
256
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
257
|
-
nonAdminWallet,
|
|
247
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
258
248
|
null,
|
|
259
249
|
txHash,
|
|
260
250
|
incomingAddress,
|
|
@@ -270,8 +260,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
270
260
|
|
|
271
261
|
k.test(`assemblePostTxMessage - Address parameter (validator address) - undefined`, async (k) => {
|
|
272
262
|
await k.exception(
|
|
273
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
274
|
-
nonAdminWallet,
|
|
263
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
275
264
|
undefined,
|
|
276
265
|
txHash,
|
|
277
266
|
incomingAddress,
|
|
@@ -288,8 +277,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
288
277
|
k.test(`assemblePostTxMessage - Address parameter (incoming address) - 'ą' does not belongs to the TRAC bench alphabet`, async (k) => {
|
|
289
278
|
const invalid = 'trac1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljką';
|
|
290
279
|
await k.exception(
|
|
291
|
-
|
|
292
|
-
nonAdminWallet,
|
|
280
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
293
281
|
validatorAddress, // correct validator address
|
|
294
282
|
txHash,
|
|
295
283
|
invalid, // invalid incoming address
|
|
@@ -307,8 +295,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
307
295
|
k.test(`assemblePostTxMessage - Address parameter (incoming address) - trac address is to short`, async (k) => {
|
|
308
296
|
const invalid = 'trac1y6kkq48fgu3ur';
|
|
309
297
|
await k.exception(
|
|
310
|
-
|
|
311
|
-
nonAdminWallet,
|
|
298
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
312
299
|
validatorAddress,
|
|
313
300
|
txHash,
|
|
314
301
|
invalid,
|
|
@@ -326,8 +313,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
326
313
|
k.test(`assemblePostTxMessage- Address parameter (incoming address) - invalid prefix`, async (k) => {
|
|
327
314
|
const invalid = 'testnet1y6kkq48fgu3urrhg0gm7h8zdyxl3gnaazd2u7568lfl5zxqs285q6kuljk';
|
|
328
315
|
await k.exception(
|
|
329
|
-
|
|
330
|
-
nonAdminWallet,
|
|
316
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
331
317
|
validatorAddress,
|
|
332
318
|
txHash,
|
|
333
319
|
invalid,
|
|
@@ -344,8 +330,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
344
330
|
k.test(`assemblePostTxMessage - Address parameter (incoming address) - empty string`, async (k) => {
|
|
345
331
|
const invalid = '';
|
|
346
332
|
await k.exception(
|
|
347
|
-
|
|
348
|
-
nonAdminWallet,
|
|
333
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
349
334
|
validatorAddress,
|
|
350
335
|
txHash,
|
|
351
336
|
invalid,
|
|
@@ -361,8 +346,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
361
346
|
|
|
362
347
|
k.test(`assemblePostTxMessage - Address parameter (incoming address) - Null`, async (k) => {
|
|
363
348
|
await k.exception(
|
|
364
|
-
|
|
365
|
-
nonAdminWallet,
|
|
349
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
366
350
|
validatorAddress,
|
|
367
351
|
txHash,
|
|
368
352
|
null,
|
|
@@ -378,8 +362,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
378
362
|
|
|
379
363
|
k.test(`assemblePostTxMessage - Address parameter (incoming address) - undefined`, async (k) => {
|
|
380
364
|
await k.exception(
|
|
381
|
-
|
|
382
|
-
nonAdminWallet,
|
|
365
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
383
366
|
validatorAddress,
|
|
384
367
|
txHash,
|
|
385
368
|
undefined,
|
|
@@ -421,8 +404,7 @@ test('assemblePostTxMessage - ....', async (k) => {
|
|
|
421
404
|
};
|
|
422
405
|
args[param.key] = invalid.value;
|
|
423
406
|
await k.exception(
|
|
424
|
-
async () => await CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
425
|
-
nonAdminWallet,
|
|
407
|
+
async () => await new CompleteStateMessageOperations(nonAdminWallet, config).assembleCompleteTransactionOperationMessage(
|
|
426
408
|
validatorAddress,
|
|
427
409
|
args.txHash,
|
|
428
410
|
incomingAddress,
|
|
@@ -4,16 +4,16 @@ import { OperationType } from '../../src/utils/protobuf/applyOperations.cjs';
|
|
|
4
4
|
import { writingKeyNonAdmin, walletNonAdmin, initAll ,walletAdmin} from '../fixtures/assembleMessage.fixtures.js';
|
|
5
5
|
import { messageOperationsBkoTest } from './commonsStateMessageOperationsTest.js';
|
|
6
6
|
import { safeDecodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
|
|
7
|
+
import { config } from '../../helpers/config.js';
|
|
7
8
|
|
|
8
9
|
const testName = 'assembleRemoveIndexerMessage';
|
|
9
10
|
test(testName, async (t) => {
|
|
10
11
|
await initAll();
|
|
11
12
|
const assembler = async (wallet,address) => {
|
|
12
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations.assembleRemoveIndexerMessage(
|
|
13
|
+
return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleRemoveIndexerMessage(address));
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
await messageOperationsBkoTest(t, testName, assembler, walletAdmin, writingKeyNonAdmin, OperationType.REMOVE_INDEXER, 2, walletNonAdmin.address);
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
|
|
@@ -4,13 +4,13 @@ import {OperationType} from '../../src/utils/protobuf/applyOperations.cjs';
|
|
|
4
4
|
import {initAll, walletNonAdmin, writingKeyNonAdmin} from '../fixtures/assembleMessage.fixtures.js';
|
|
5
5
|
import {messageOperationsEkoTest} from './commonsStateMessageOperationsTest.js';
|
|
6
6
|
import {safeDecodeApplyOperation} from '../../src/utils/protobuf/operationHelpers.js';
|
|
7
|
-
|
|
7
|
+
import { config } from '../../helpers/config.js';
|
|
8
8
|
|
|
9
9
|
const testName = 'assembleRemoveWriterMessage';
|
|
10
10
|
test(testName, async (t) => {
|
|
11
11
|
await initAll();
|
|
12
12
|
const assembler = async (wallet, writingKey) => {
|
|
13
|
-
return safeDecodeApplyOperation(await CompleteStateMessageOperations
|
|
13
|
+
return safeDecodeApplyOperation(await new CompleteStateMessageOperations(wallet, config).assembleRemoveWriterMessage(writingKey));
|
|
14
14
|
}
|
|
15
15
|
await messageOperationsEkoTest(t, testName, assembler, walletNonAdmin, writingKeyNonAdmin, OperationType.REMOVE_WRITER, 3, walletNonAdmin.address);
|
|
16
16
|
});
|
|
@@ -7,6 +7,7 @@ import fileUtils from "../../src/utils/fileUtils.js";
|
|
|
7
7
|
import CompleteStateMessageOperations from "../../src/messages/completeStateMessages/CompleteStateMessageOperations.js";
|
|
8
8
|
import {bufferToAddress} from "../../src/core/state/utils/address.js";
|
|
9
9
|
import {errorMessageIncludes} from "../utils/regexHelper.js";
|
|
10
|
+
import { config } from '../../helpers/config.js'
|
|
10
11
|
|
|
11
12
|
// MOCK SETUP
|
|
12
13
|
const whitelistAddresses = [
|
|
@@ -22,7 +23,7 @@ test('assembleWhitelistMessages', async (t) => {
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
t.test('assembleWhitelistMessages - Happy Path', async (k) => {
|
|
25
|
-
const mapMsg = await CompleteStateMessageOperations.assembleAppendWhitelistMessages(
|
|
26
|
+
const mapMsg = await new CompleteStateMessageOperations(walletAdmin, config).assembleAppendWhitelistMessages();
|
|
26
27
|
const msg = mapMsg.get(whitelistAddresses[0])
|
|
27
28
|
k.ok(msg, 'Message should be created');
|
|
28
29
|
k.ok(msg.length > 0, 'Message should be an array with at least one element');
|
|
@@ -31,7 +32,7 @@ test('assembleWhitelistMessages', async (t) => {
|
|
|
31
32
|
k.is(Object.keys(decodedMsg.bko).length, 2, 'Message value should have 2 keys');
|
|
32
33
|
k.is(decodedMsg.type, OperationType.APPEND_WHITELIST, 'Message type should be APPEND_WHITELIST');
|
|
33
34
|
|
|
34
|
-
k.is(bufferToAddress(decodedMsg.address) , whitelistAddresses[0], 'Message address should be the address in the file');
|
|
35
|
+
k.is(bufferToAddress(decodedMsg.address, config.addressPrefix) , whitelistAddresses[0], 'Message address should be the address in the file');
|
|
35
36
|
k.is(decodedMsg.bko.nonce.length, 32, 'Message nonce should be 32 bytes long');
|
|
36
37
|
k.ok(b4a.isBuffer(decodedMsg.bko.nonce), 'Message nonce should be a buffer');
|
|
37
38
|
k.is(decodedMsg.bko.sig.length, 64, 'Message signature should be 64 bytes long');
|
|
@@ -40,7 +41,7 @@ test('assembleWhitelistMessages', async (t) => {
|
|
|
40
41
|
|
|
41
42
|
t.test('assembleWhitelistMessages - Should return null when wallet is invalid', async (k) => {
|
|
42
43
|
await k.exception(
|
|
43
|
-
async () => await CompleteStateMessageOperations.assembleAppendWhitelistMessages(
|
|
44
|
+
async () => await new CompleteStateMessageOperations(null, config).assembleAppendWhitelistMessages(),
|
|
44
45
|
errorMessageIncludes('Wallet must be a valid wallet object')
|
|
45
46
|
);
|
|
46
47
|
});
|
|
@@ -48,7 +49,7 @@ test('assembleWhitelistMessages', async (t) => {
|
|
|
48
49
|
|
|
49
50
|
t.test('assembleWhitelistMessages - Empty object', async (k) => {
|
|
50
51
|
await k.exception(
|
|
51
|
-
async () => await CompleteStateMessageOperations
|
|
52
|
+
async () => await new CompleteStateMessageOperations({}, config).assembleAppendWhitelistMessages(),
|
|
52
53
|
errorMessageIncludes('Wallet should have a valid TRAC address.')
|
|
53
54
|
);
|
|
54
55
|
|
|
@@ -2,6 +2,7 @@ import b4a from 'b4a';
|
|
|
2
2
|
import {OperationType} from "../../src/utils/constants.js";
|
|
3
3
|
import {bufferToAddress, isAddressValid} from "../../src/core/state/utils/address.js";
|
|
4
4
|
import {errorMessageIncludes} from "../utils/regexHelper.js"
|
|
5
|
+
import { config } from '../../helpers/config.js'
|
|
5
6
|
|
|
6
7
|
export async function messageOperationsEkoTest(t, fnName, assembler, wallet, writingKey, opType, msgValueLength, expectedMessageAddress) {
|
|
7
8
|
console.log('address:', expectedMessageAddress)
|
|
@@ -17,8 +18,8 @@ export async function messageOperationsEkoTest(t, fnName, assembler, wallet, wri
|
|
|
17
18
|
k.ok(b4a.equals(msg.eko.wk, writingKey), 'Message wk should be the writing key');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
k.ok(bufferToAddress(msg.address) === expectedMessageAddress, 'Message key should be the the expected one');
|
|
21
|
-
k.ok(isAddressValid(msg.address), 'Message address should be a valid address');
|
|
21
|
+
k.ok(bufferToAddress(msg.address, config.addressPrefix) === expectedMessageAddress, 'Message key should be the the expected one');
|
|
22
|
+
k.ok(isAddressValid(msg.address, config.addressPrefix), 'Message address should be a valid address');
|
|
22
23
|
|
|
23
24
|
k.is(msg.eko.nonce.length, 32, 'Message nonce should be 32 bytes long');
|
|
24
25
|
k.ok(b4a.isBuffer(msg.eko.nonce), 'Message nonce should be a buffer');
|
|
@@ -152,7 +153,7 @@ export async function messageOperationsBkoTest(t, fnName, assembler, wallet, wri
|
|
|
152
153
|
|
|
153
154
|
k.is(msg.type, opType, `Message type should be ${opType}`);
|
|
154
155
|
|
|
155
|
-
k.ok(bufferToAddress(msg.address) === expectedMessageAddress, 'Message address should be the the expected one');
|
|
156
|
+
k.ok(bufferToAddress(msg.address, config.addressPrefix) === expectedMessageAddress, 'Message address should be the the expected one');
|
|
156
157
|
k.is(msg.bko.nonce.length, 32, 'Message nonce should be 32 bytes long');
|
|
157
158
|
k.ok(b4a.isBuffer(msg.bko.nonce), 'Message nonce should be a buffer');
|
|
158
159
|
k.is(msg.bko.sig.length, 64, 'Message signature should be 64 bytes long');
|
|
@@ -5,6 +5,7 @@ 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()
|
|
@@ -18,7 +19,8 @@ const createConnection = (key) => {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const makeManager = (maxValidators = 6, conns = connections) => {
|
|
21
|
-
const
|
|
22
|
+
const merged = createConfig(ENV.DEVELOPMENT, { maxValidators })
|
|
23
|
+
const connectionManager = new ConnectionManager(merged)
|
|
22
24
|
|
|
23
25
|
conns.forEach(({ key, connection }) => {
|
|
24
26
|
connectionManager.addValidator(key, connection)
|
|
@@ -78,7 +80,7 @@ test('ConnectionManager', () => {
|
|
|
78
80
|
createConnection(testKeyPair2.publicKey),
|
|
79
81
|
]
|
|
80
82
|
|
|
81
|
-
const connectionManager =
|
|
83
|
+
const connectionManager = makeManager(maxConnections)
|
|
82
84
|
localConnections.forEach(({ key, connection }) => {
|
|
83
85
|
connectionManager.addValidator(key, connection)
|
|
84
86
|
})
|
|
@@ -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
|
});
|