trac-msb 0.1.69 → 0.1.71

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/msb.mjs CHANGED
@@ -3,10 +3,8 @@ import {MainSettlementBus} from './src/index.js';
3
3
  const opts = {
4
4
  stores_directory : 'stores/',
5
5
  store_name : typeof process !== "undefined" ? process.argv[2] : Pear.config.args[0],
6
- bootstrap: '0768953b234c79eccc6306fdcba2d7c1f0b05b9af6815a3502e96a83a8878ff7',
7
- channel: '00abtracnetworkmainsettlementbus',
8
- disable_rate_limit : true,
9
- enable_txlogs : true
6
+ bootstrap: '19a12e9bdaf1cd9ae8169fd87f3d6d63d441c046e37e2ac6c3c36bcb87c59019',
7
+ channel: '0000tracnetworkmainsettlementbus',
10
8
  };
11
9
 
12
10
  const msb = new MainSettlementBus(opts);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.1.69",
4
+ "version": "0.1.71",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -9,7 +9,8 @@
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "dev": "pear run -d .",
12
- "test": "brittle test/*.test.js"
12
+ "test:node": "brittle test/all.test.js",
13
+ "test:bare": "bare test/all.test.js"
13
14
  },
14
15
  "dependencies": {
15
16
  "autobase": "7.6.3",
@@ -18,6 +19,7 @@
18
19
  "b4a": "1.6.7",
19
20
  "bare-readline": "1.0.7",
20
21
  "bare-tty": "5.0.2",
22
+ "brittle": "^3.16.2",
21
23
  "compact-encoding": "^2.16.0",
22
24
  "fastest-validator": "1.19.0",
23
25
  "hyperbee": "2.24.2",
@@ -38,9 +38,9 @@ export const MIN_INDEXERS = 1;
38
38
  export const WHITELIST_SLEEP_INTERVAL = 1000;
39
39
  export const MAX_PEERS = 128;
40
40
  export const MAX_PARALLEL = 128;
41
- export const MAX_SERVER_CONNECTIONS = 64;
42
- export const MAX_CLIENT_CONNECTIONS = 64;
43
- export const UPDATER_INTERVAL = 1_000;
41
+ export const MAX_SERVER_CONNECTIONS = Infinity;
42
+ export const MAX_CLIENT_CONNECTIONS = Infinity;
43
+ export const UPDATER_INTERVAL = 10_000;
44
44
 
45
45
  const constants = {
46
46
  EntryType,
@@ -1,6 +1,9 @@
1
1
  import fs from 'fs';
2
2
  import {WHITELIST_FILEPATH} from '../utils/constants.js';
3
3
 
4
+ // TODO: The methods in fileUtils need to be refactoed and generalized to improve code reusability
5
+ // -- For example, the readPublicKeysFromFile method is specific to reading a whitelist file set in constants.
6
+ // -- In the future, we might want to generalize this method to read any file and return its content.
4
7
  async function readPublicKeysFromFile() {
5
8
  try {
6
9
  const data = await fs.promises.readFile(WHITELIST_FILEPATH, 'utf8');
@@ -2,6 +2,8 @@ import b4a from 'b4a';
2
2
  import sodium from 'sodium-native';
3
3
  import {peer} from "hyperdht/lib/messages.js";
4
4
 
5
+ // TODO: (?) Should we allow 0x prefix?
6
+ // TODO: (?) Should an mepty string be considered valid?
5
7
  export function isHexString(string) {
6
8
  return typeof string === 'string' && /^[0-9a-fA-F]+$/.test(string) && string.length % 2 === 0;
7
9
  }
@@ -0,0 +1,18 @@
1
+ // This runner is auto-generated by Brittle
2
+
3
+ import { default as test } from 'brittle';
4
+
5
+ async function runTests() {
6
+ test.pause();
7
+
8
+ await import('./check.test.js');
9
+ await import('./fileUtils.test.js');
10
+ await import('./functions.test.js');
11
+
12
+ //TODO add test MsgUtils
13
+ //TODO add test Apply function
14
+
15
+ test.resume();
16
+ }
17
+
18
+ runTests();
@@ -0,0 +1,21 @@
1
+ import test from 'brittle'
2
+ import Check from '../src/utils/check.js';
3
+
4
+ test('preTx', function (t) {
5
+ const check = new Check();
6
+ const validData = {
7
+ op: 'pre-tx',
8
+ tx: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
9
+ is: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
10
+ wp: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
11
+ i: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
12
+ ipk: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
13
+ ch: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
14
+ in: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
15
+ bs: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234',
16
+ mbs: 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234'
17
+ }
18
+ const result = check.sanitizePreTx(validData)
19
+ t.ok(result, 'Valid data should pass the sanitization')
20
+
21
+ })
@@ -0,0 +1,16 @@
1
+ import test from 'brittle';
2
+ import fileUtils from '../src/utils/fileUtils.js';
3
+
4
+ test('readPublicKeysFromFile', async (t) => {
5
+ // TODO: This is reading the real whitelist file (which is not a good practice)
6
+ // -- In the future, this function should be generalized so we can mock the file reading
7
+ // -- and test the function without relying on the actual file.
8
+ // -- For now, we will just check if the file reading works and returns an array of public keys.
9
+ const pubKeys = await fileUtils.readPublicKeysFromFile();
10
+ t.ok(Array.isArray(pubKeys), 'Should return an array');
11
+ t.ok(pubKeys.length > 0, 'Should return a non-empty array'); // Assuming the file has at least one public key. Without being able to mock the file, we can't guarantee this.
12
+ pubKeys.forEach((key) => {
13
+ t.is(typeof key, 'string', 'Each public key should be a string');
14
+ });
15
+ }
16
+ );
@@ -0,0 +1,22 @@
1
+ import test from 'brittle';
2
+ import * as functions from '../src/utils/functions.js';
3
+
4
+ test('isHexString', (t) => {
5
+ // t.ok(functions.isHexString('0x1234567890abcdef'), 'Valid hex string should return true'); // Deactivated. See TODO in functions.js
6
+ t.ok(functions.isHexString('1234567890abcdef'), 'Valid hex string should return true');
7
+ t.ok(functions.isHexString('1234567890xyz') === false, 'Invalid hex string should return false');
8
+ t.ok(functions.isHexString('123456789') === false, 'Invalid size hex string should return false');
9
+ // t.ok(functions.isHexString('') === false, 'Empty string should return false'); // Deactivated. See TODO in functions.js
10
+ });
11
+
12
+ test('createHash', async (t) => {
13
+ // TODO: Add tests for other supported hash types
14
+ t.test('sha256', async (k) => {
15
+ const hash = await functions.createHash('sha256', 'test');
16
+ k.is(typeof hash, 'string', 'Hash should be a string');
17
+ k.ok(hash.length === 64, 'Hash should be 64 characters long');
18
+ k.ok(hash.match(/^[a-f0-9]+$/), 'Hash should be a hex string');
19
+ k.ok(hash !== await functions.createHash('sha256', 'Test'), 'Hash should be different for different inputs');
20
+ k.ok(hash === await functions.createHash('sha256', 'test'), 'Hash should be the same for the same input');
21
+ });
22
+ });