trac-msb 0.2.9 → 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 +4 -21
- package/package.json +8 -9
- package/rpc/handlers.js +163 -90
- package/rpc/routes/v1.js +3 -1
- package/rpc/rpc_server.js +3 -3
- package/rpc/rpc_services.js +25 -29
- package/rpc/utils/helpers.js +82 -51
- package/src/config/args.js +46 -0
- package/src/config/config.js +78 -5
- package/src/config/env.js +69 -4
- package/src/core/network/Network.js +6 -10
- package/src/core/network/protocols/NetworkMessages.js +1 -1
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +1 -1
- package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +2 -2
- package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/shared/handlers/TransferOperationHandler.js +1 -1
- package/src/core/network/protocols/shared/handlers/base/BaseOperationHandler.js +5 -6
- package/src/core/network/services/ConnectionManager.js +1 -1
- package/src/core/network/services/MessageOrchestrator.js +1 -1
- package/src/core/network/services/TransactionPoolService.js +4 -4
- package/src/core/network/services/TransactionRateLimiterService.js +8 -11
- package/src/core/network/services/ValidatorObserverService.js +5 -6
- package/src/core/state/State.js +2 -3
- package/src/index.js +3 -1
- package/src/messages/network/v1/NetworkMessageBuilder.js +2 -2
- package/src/messages/state/ApplyStateMessageBuilder.js +1 -1
- package/src/utils/check.js +1 -1
- package/src/utils/constants.js +0 -17
- package/src/utils/fileUtils.js +13 -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 +3 -2
- 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 +3 -2
- package/tests/fixtures/protobuf.fixtures.js +33 -32
- 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 +6 -10
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +3 -3
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +3 -5
- 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/type/type.test.js +25 -0
- package/tests/unit/utils/utils.test.js +1 -0
|
@@ -82,11 +82,10 @@ export async function fundPeer(admin, toFund, amount) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export async function initMsbPeer(peerName, peerKeyPair, temporaryDirectory, options = {}) {
|
|
85
|
-
const
|
|
86
|
-
peer
|
|
87
|
-
peer.options
|
|
88
|
-
peer.
|
|
89
|
-
peer.config = createConfig(ENV.DEVELOPMENT, peer.options)
|
|
85
|
+
const config = createConfig(ENV.DEVELOPMENT, { ...options, storesDirectory: `${temporaryDirectory}/${peerName}` })
|
|
86
|
+
const peer = await initDirectoryStructure(peerName, peerKeyPair, config.storesFullPath);
|
|
87
|
+
peer.options = { ...options, storesDirectory: config.storesDirectory }
|
|
88
|
+
peer.config = config
|
|
90
89
|
const msb = new MainSettlementBus(peer.config);
|
|
91
90
|
|
|
92
91
|
peer.msb = msb;
|
|
@@ -290,9 +289,7 @@ export async function removeTemporaryDirectory(temporaryDirectory) {
|
|
|
290
289
|
export async function initDirectoryStructure(peerName, keyPair, temporaryDirectory) {
|
|
291
290
|
try {
|
|
292
291
|
await ensureEnvReady();
|
|
293
|
-
const
|
|
294
|
-
const storeName = peerName + '/';
|
|
295
|
-
const corestoreDbDirectory = path.join(storesDirectory, storeName, 'db');
|
|
292
|
+
const corestoreDbDirectory = path.join(temporaryDirectory, 'db');
|
|
296
293
|
await fsp.mkdir(corestoreDbDirectory, {recursive: true});
|
|
297
294
|
|
|
298
295
|
const keypath = path.join(corestoreDbDirectory, 'keypair.json');
|
|
@@ -303,8 +300,7 @@ export async function initDirectoryStructure(peerName, keyPair, temporaryDirecto
|
|
|
303
300
|
await wallet.ready
|
|
304
301
|
await wallet.exportToFile(keypath)
|
|
305
302
|
return {
|
|
306
|
-
storesDirectory,
|
|
307
|
-
storeName,
|
|
303
|
+
storesDirectory: temporaryDirectory,
|
|
308
304
|
corestoreDbDirectory,
|
|
309
305
|
keypath,
|
|
310
306
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
3
|
import PeerWallet from 'trac-wallet';
|
|
4
|
-
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
5
4
|
import { v7 as uuidv7 } from 'uuid';
|
|
6
5
|
import NetworkWalletFactory from '../../../../src/core/network/identity/NetworkWalletFactory.js';
|
|
7
6
|
import NetworkMessageBuilder from '../../../../src/messages/network/v1/NetworkMessageBuilder.js';
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
} from '../../../../src/utils/buffer.js';
|
|
21
20
|
import { addressToBuffer } from '../../../../src/core/state/utils/address.js';
|
|
22
21
|
import { config } from '../../../helpers/config.js';
|
|
22
|
+
import { asAddress } from '../../../helpers/address.js';
|
|
23
23
|
import { testKeyPair1 } from '../../../fixtures/apply.fixtures.js';
|
|
24
24
|
|
|
25
25
|
function createWallet() {
|
|
@@ -30,7 +30,7 @@ function createWallet() {
|
|
|
30
30
|
return NetworkWalletFactory.provide({
|
|
31
31
|
enableWallet: false,
|
|
32
32
|
keyPair,
|
|
33
|
-
networkPrefix:
|
|
33
|
+
networkPrefix: config.addressPrefix
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -79,7 +79,7 @@ test('NetworkMessageBuilder iterates validator connection response ResultCode va
|
|
|
79
79
|
const wallet = createWallet();
|
|
80
80
|
const builder = new NetworkMessageBuilder(wallet, config);
|
|
81
81
|
const id = uuidv7();
|
|
82
|
-
const otherAddress = '
|
|
82
|
+
const otherAddress = asAddress('36fdaf941de4afe602cbb1e2f56dc582466ef23fad1da55c09fd6dd841cbd117');
|
|
83
83
|
const caps = ['cap:b', 'cap:a'];
|
|
84
84
|
|
|
85
85
|
for (const code of uniqueResultCodes()) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
3
|
import PeerWallet from 'trac-wallet';
|
|
4
|
-
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
5
|
-
|
|
6
4
|
import NetworkWalletFactory from '../../../../src/core/network/identity/NetworkWalletFactory.js';
|
|
7
5
|
import NetworkMessageDirector from '../../../../src/messages/network/v1/NetworkMessageDirector.js';
|
|
8
6
|
import NetworkMessageBuilder from '../../../../src/messages/network/v1/NetworkMessageBuilder.js';
|
|
@@ -17,6 +15,7 @@ import {
|
|
|
17
15
|
} from '../../../../src/utils/buffer.js';
|
|
18
16
|
import { addressToBuffer } from '../../../../src/core/state/utils/address.js';
|
|
19
17
|
import { config } from '../../../helpers/config.js';
|
|
18
|
+
import { asAddress } from '../../../helpers/address.js';
|
|
20
19
|
import { testKeyPair1 } from '../../../fixtures/apply.fixtures.js';
|
|
21
20
|
|
|
22
21
|
function createWallet() {
|
|
@@ -27,7 +26,7 @@ function createWallet() {
|
|
|
27
26
|
return NetworkWalletFactory.provide({
|
|
28
27
|
enableWallet: false,
|
|
29
28
|
keyPair,
|
|
30
|
-
networkPrefix:
|
|
29
|
+
networkPrefix: config.addressPrefix
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -175,8 +174,7 @@ test('NetworkMessageDirector iterates validator connection response ResultCode v
|
|
|
175
174
|
|
|
176
175
|
const id = '1';
|
|
177
176
|
const caps = ['cap:b', 'cap:a'];
|
|
178
|
-
const otherAddress =
|
|
179
|
-
'trac1xm76l9qaujh7vqktk8302mw9sfrxau3l45w62hqfl4kasswt6yts0autkh';
|
|
177
|
+
const otherAddress = asAddress('36fdaf941de4afe602cbb1e2f56dc582466ef23fad1da55c09fd6dd841cbd117');
|
|
180
178
|
|
|
181
179
|
for (const code of uniqueResultCodes()) {
|
|
182
180
|
const payload = await director.buildValidatorConnectionResponse(
|
|
@@ -4,6 +4,7 @@ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import PeerWallet from 'trac-wallet';
|
|
6
6
|
import { config } from '../../../helpers/config.js';
|
|
7
|
+
import { asAddress } from '../../../helpers/address.js';
|
|
7
8
|
|
|
8
9
|
const DUMMY_PATH_OK = './dummy_whitelist_ok.csv';
|
|
9
10
|
const DUMMY_PATH_DUP = './dummy_whitelist_dup.csv';
|
|
@@ -12,8 +13,8 @@ const DUMMY_PATH_BLANK = './dummy_whitelist_blank.csv';
|
|
|
12
13
|
const DUMMY_PATH_BOM = './dummy_whitelist_bom.csv';
|
|
13
14
|
const DUMMY_PATH_LARGE = './dummy_whitelist_large.csv';
|
|
14
15
|
|
|
15
|
-
const ADDR1 = '
|
|
16
|
-
const ADDR2 = '
|
|
16
|
+
const ADDR1 = asAddress('6a38e14198866f0fdf4d4495b07e066cfd0a2e8cbe774d11af37d15f741ac984');
|
|
17
|
+
const ADDR2 = asAddress('544514242356432739de9af71deb8d526fb03d6c5c15e0a934d9a20b6710e2fe');
|
|
17
18
|
|
|
18
19
|
hook('Initialize dummy whitelist files', async t => {
|
|
19
20
|
// Happy path
|
|
@@ -91,4 +92,4 @@ hook('Cleanup dummy whitelist files', async t => {
|
|
|
91
92
|
[DUMMY_PATH_OK, DUMMY_PATH_DUP, DUMMY_PATH_EMPTY, DUMMY_PATH_BLANK, DUMMY_PATH_BOM, DUMMY_PATH_LARGE].forEach(path => {
|
|
92
93
|
if (fs.existsSync(path)) fs.unlinkSync(path);
|
|
93
94
|
});
|
|
94
|
-
});
|
|
95
|
+
});
|
|
@@ -4,6 +4,7 @@ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import PeerWallet from 'trac-wallet';
|
|
6
6
|
import { config } from '../../../helpers/config.js';
|
|
7
|
+
import { asAddress } from '../../../helpers/address.js';
|
|
7
8
|
|
|
8
9
|
const DUMMY_PATH_OK = './dummy_balance_ok.csv';
|
|
9
10
|
const DUMMY_PATH_DUP = './dummy_balance_dup.csv';
|
|
@@ -19,8 +20,8 @@ const DUMMY_PATH_ZERO = './dummy_balance_zero.csv';
|
|
|
19
20
|
const DUMMY_PATH_BOM = './dummy_balance_bom.csv';
|
|
20
21
|
const DUMMY_PATH_LARGE = './dummy_balance_large.csv';
|
|
21
22
|
|
|
22
|
-
const ADDR1 = '
|
|
23
|
-
const ADDR2 = '
|
|
23
|
+
const ADDR1 = asAddress('6a38e14198866f0fdf4d4495b07e066cfd0a2e8cbe774d11af37d15f741ac984');
|
|
24
|
+
const ADDR2 = asAddress('544514242356432739de9af71deb8d526fb03d6c5c15e0a934d9a20b6710e2fe');
|
|
24
25
|
|
|
25
26
|
hook('Initialize dummy balance files', async t => {
|
|
26
27
|
// Happy path
|
|
@@ -4,9 +4,10 @@ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
|
|
|
4
4
|
import { ZERO_LICENSE } from '../../../../src/core/state/utils/nodeEntry.js';
|
|
5
5
|
import b4a from 'b4a';
|
|
6
6
|
import { config } from '../../../helpers/config.js';
|
|
7
|
+
import { asAddress } from '../../../helpers/address.js';
|
|
7
8
|
|
|
8
|
-
const VALID_ADDRESS = '
|
|
9
|
-
const ADMIN_ADDRESS = '
|
|
9
|
+
const VALID_ADDRESS = asAddress('6a38e14198866f0fdf4d4495b07e066cfd0a2e8cbe774d11af37d15f741ac984');
|
|
10
|
+
const ADMIN_ADDRESS = asAddress('233aa0b7971509059e4816c782b32fec29b3797876bf92c072d1b0e058c5bf70');
|
|
10
11
|
const INVALID_ADDRESS = 'notanaddress';
|
|
11
12
|
const LICENSE_NUMBER_ONE = b4a.alloc(4, 1);
|
|
12
13
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import test from 'brittle';
|
|
2
|
+
import { isDefined } from '../../../../src/utils/type.js';
|
|
3
|
+
|
|
4
|
+
const assertIsDefined = (t, value, expected, message) => {
|
|
5
|
+
try {
|
|
6
|
+
t.is(isDefined(value), expected, message);
|
|
7
|
+
} catch (err) {
|
|
8
|
+
t.fail(`${message}. Threw: ${err.message}`);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
test('isDefined returns false for nullish and NaN', t => {
|
|
13
|
+
assertIsDefined(t, null, false, 'null should be treated as not defined');
|
|
14
|
+
assertIsDefined(t, void 0, false, 'undefined should be treated as not defined');
|
|
15
|
+
assertIsDefined(t, NaN, false, 'NaN should be treated as not defined');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('isDefined returns true for defined non-NaN values', t => {
|
|
19
|
+
assertIsDefined(t, 0, true, '0 should be treated as defined');
|
|
20
|
+
assertIsDefined(t, Infinity, true, 'Infinity should be treated as defined');
|
|
21
|
+
assertIsDefined(t, '', true, 'empty string should be treated as defined');
|
|
22
|
+
assertIsDefined(t, false, true, 'boolean false should be treated as defined');
|
|
23
|
+
assertIsDefined(t, {}, true, 'object should be treated as defined');
|
|
24
|
+
assertIsDefined(t, [], true, 'array should be treated as defined');
|
|
25
|
+
});
|
|
@@ -12,6 +12,7 @@ async function runTests() {
|
|
|
12
12
|
await import('./fileUtils/readBalanceMigrationFile.test.js');
|
|
13
13
|
await import('./migrationUtils/validateAddressFromIncomingFile.test.js');
|
|
14
14
|
await import('./buffer/buffer.test.js')
|
|
15
|
+
await import('./type/type.test.js');
|
|
15
16
|
await import('./amountSerialization/amountSerialization.test.js');
|
|
16
17
|
test.resume();
|
|
17
18
|
}
|