trac-msb 0.2.1 → 0.2.3

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.
Files changed (78) hide show
  1. package/.env +0 -0
  2. package/.github/workflows/CI.yml +2 -4
  3. package/.github/workflows/acceptance-tests.yml +35 -0
  4. package/LICENSE +2 -2
  5. package/SECURITY.md +54 -0
  6. package/package.json +8 -6
  7. package/rpc/handlers.mjs +9 -2
  8. package/src/index.js +5 -1
  9. package/src/utils/helpers.js +2 -0
  10. package/{test → tests}/acceptance/v1/rpc.test.mjs +3 -2
  11. package/{test → tests/integration}/apply/addAdmin/addAdminBasic.test.js +6 -6
  12. package/{test → tests/integration}/apply/addAdmin/addAdminRecovery.test.js +8 -8
  13. package/{test → tests/integration}/apply/addIndexer.test.js +3 -4
  14. package/{test → tests/integration}/apply/addWhitelist.test.js +5 -5
  15. package/{test → tests/integration}/apply/addWriter.test.js +7 -7
  16. package/{test → tests/integration}/apply/banValidator.test.js +13 -14
  17. package/{test → tests/integration}/apply/postTx/invalidSubValues.test.js +6 -7
  18. package/{test → tests/integration}/apply/postTx/postTx.test.js +7 -8
  19. package/{test → tests/integration}/apply/removeIndexer.test.js +4 -4
  20. package/{test → tests/integration}/apply/removeWriter.test.js +5 -5
  21. package/{test → tests/integration}/apply/transfer.test.js +7 -7
  22. package/tests/integration/integration.test.js +9 -0
  23. package/{test → tests/unit}/messageOperations/assemblePostTransaction.test.js +1 -1
  24. package/{test → tests/unit}/network/ConnectionManager.test.js +5 -5
  25. package/{test → tests/unit}/state/stateTestUtils.js +1 -1
  26. package/{test → tests/unit}/state/utils/address.test.js +2 -2
  27. package/{test → tests/unit}/state/utils/adminEntry.test.js +3 -3
  28. package/{test → tests/unit}/state/utils/balance.test.js +5 -5
  29. package/{test → tests/unit}/state/utils/indexerEntry.test.js +2 -2
  30. package/{test → tests/unit}/state/utils/lengthEntry.test.js +1 -1
  31. package/{test → tests/unit}/state/utils/nodeEntry.test.js +3 -3
  32. package/{test → tests/unit}/state/utils/roles.test.js +1 -1
  33. package/tests/unit/unit.test.js +14 -0
  34. package/{test/functions → tests/unit/utils/amountSerialization}/amountSerialization.test.js +3 -3
  35. package/{test → tests/unit/utils}/buffer/buffer.test.js +1 -1
  36. package/{test → tests/unit/utils}/check/adminControlOperation.test.js +2 -2
  37. package/{test → tests/unit/utils}/check/balanceInitializationOperation.test.js +2 -2
  38. package/{test → tests/unit/utils}/check/bootstrapDeploymentOperation.test.js +2 -2
  39. package/{test → tests/unit/utils}/check/common.test.js +2 -2
  40. package/{test → tests/unit/utils}/check/coreAdminOperation.test.js +2 -2
  41. package/{test → tests/unit/utils}/check/roleAccessOperation.test.js +2 -2
  42. package/{test → tests/unit/utils}/check/transactionOperation.test.js +2 -2
  43. package/{test → tests/unit/utils}/check/transferOperation.test.js +2 -2
  44. package/{test/functions → tests/unit/utils/crypto}/createHash.test.js +1 -1
  45. package/{test → tests/unit/utils}/fileUtils/readAddressesFromWhitelistFile.test.js +2 -2
  46. package/{test → tests/unit/utils}/fileUtils/readBalanceMigrationFile.test.js +2 -3
  47. package/{test/functions/functions.test.js → tests/unit/utils/helpers/helpers.test.js} +0 -3
  48. package/{test/functions → tests/unit/utils/helpers}/isHexString.test.js +1 -1
  49. package/{test/functions → tests/unit/utils/helpers}/normalizeHex.test.js +1 -1
  50. package/{test → tests/unit/utils}/migrationUtils/validateAddressFromIncomingFile.test.js +3 -3
  51. package/{test/functions → tests/unit/utils/protobuf}/applyOperations.test.js +3 -3
  52. package/{test/protobuf/protobuf.test.js → tests/unit/utils/protobuf/operationHelpers.test.js} +3 -2
  53. package/tests/unit/utils/protobuf/protobuf.test.js +12 -0
  54. package/tests/unit/utils/utils.test.js +20 -0
  55. package/test/all.test.js +0 -23
  56. package/test/state/apply.addAdmin.basic.test.js +0 -111
  57. /package/{test → tests}/fixtures/apply.fixtures.js +0 -0
  58. /package/{test → tests}/fixtures/assembleMessage.fixtures.js +0 -0
  59. /package/{test → tests}/fixtures/check.fixtures.js +0 -0
  60. /package/{test → tests}/fixtures/protobuf.fixtures.js +0 -0
  61. /package/{test/utils → tests/helpers}/regexHelper.js +0 -0
  62. /package/{test/utils → tests/helpers}/setupApplyTests.js +0 -0
  63. /package/{test/utils → tests/helpers}/wrapper.js +0 -0
  64. /package/{test → tests/integration}/apply/apply.test.js +0 -0
  65. /package/{test → tests/unit}/messageOperations/assembleAddIndexerMessage.test.js +0 -0
  66. /package/{test → tests/unit}/messageOperations/assembleAddWriterMessage.test.js +0 -0
  67. /package/{test → tests/unit}/messageOperations/assembleAdminMessage.test.js +0 -0
  68. /package/{test → tests/unit}/messageOperations/assembleBanWriterMessage.test.js +0 -0
  69. /package/{test → tests/unit}/messageOperations/assembleRemoveIndexerMessage.test.js +0 -0
  70. /package/{test → tests/unit}/messageOperations/assembleRemoveWriterMessage.test.js +0 -0
  71. /package/{test → tests/unit}/messageOperations/assembleWhitelistMessages.test.js +0 -0
  72. /package/{test → tests/unit}/messageOperations/commonsStateMessageOperationsTest.js +0 -0
  73. /package/{test → tests/unit}/messageOperations/stateMessageOperations.test.js +0 -0
  74. /package/{test/network/connectionManagerTests.test.js → tests/unit/network/networkModule.test.js} +0 -0
  75. /package/{test → tests/unit}/state/State.test.js +0 -0
  76. /package/{test/state/stateTests.test.js → tests/unit/state/stateModule.test.js} +0 -0
  77. /package/{test → tests/unit}/state/utils/transaction.test.js +0 -0
  78. /package/{test → tests/unit/utils}/check/check.test.js +0 -0
@@ -1,11 +1,11 @@
1
1
  import { test } from 'brittle';
2
2
  import b4a from 'b4a';
3
3
  import { randomBuffer, TEN_THOUSAND_VALUE, tokenUnits } from '../stateTestUtils.js';
4
- import { ZERO_BALANCE, decode, encode } from '../../../src/core/state/utils/nodeEntry.js';
5
- import { WRITER_BYTE_LENGTH, ADMIN_INITIAL_BALANCE, BALANCE_BYTE_LENGTH } from '../../../src/utils/constants.js';
6
- import { $TNK, toBalance, toTerm, percent } from '../../../src/core/state/utils/balance.js';
7
- import { bufferToBigInt } from '../../../src/utils/amountSerialization.js';
8
- import { ZERO_LICENSE } from '../../../src/core/state/utils/nodeEntry.js';
4
+ import { ZERO_BALANCE, decode, encode } from '../../../../src/core/state/utils/nodeEntry.js';
5
+ import { WRITER_BYTE_LENGTH, ADMIN_INITIAL_BALANCE, BALANCE_BYTE_LENGTH } from '../../../../src/utils/constants.js';
6
+ import { $TNK, toBalance, toTerm, percent } from '../../../../src/core/state/utils/balance.js';
7
+ import { bufferToBigInt } from '../../../../src/utils/amountSerialization.js';
8
+ import { ZERO_LICENSE } from '../../../../src/core/state/utils/nodeEntry.js';
9
9
  test('Balance#asHex explicit', t => {
10
10
  const val = $TNK(1000n)
11
11
  t.is(toBalance(val).asHex(), b4a.toString(val, 'hex'), 'hex matches')
@@ -1,8 +1,8 @@
1
1
  import { test } from 'brittle';
2
2
  import b4a from 'b4a';
3
- import { TRAC_ADDRESS_SIZE } from '../../../src/utils/constants.js';
3
+ import { TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
4
4
  import { randomBuffer } from '../stateTestUtils.js';
5
- import indexerEntryUtils, { append } from '../../../src/core/state/utils/indexerEntry.js';
5
+ import indexerEntryUtils, { append } from '../../../../src/core/state/utils/indexerEntry.js';
6
6
 
7
7
  const appendIndexer = indexerEntryUtils.append;
8
8
  const removeIndexer = indexerEntryUtils.remove;
@@ -1,6 +1,6 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
- import lengthEntry from '../../../src/core/state/utils/lengthEntry.js';
3
+ import lengthEntry from '../../../../src/core/state/utils/lengthEntry.js';
4
4
 
5
5
  // Test init()
6
6
  test('Length Entry - init returns a 4-byte buffer initialized to 0', t => {
@@ -1,8 +1,8 @@
1
1
  import { test } from 'brittle';
2
2
  import b4a from 'b4a';
3
- import { WRITER_BYTE_LENGTH, LICENSE_BYTE_LENGTH } from '../../../src/utils/constants.js';
3
+ import { WRITER_BYTE_LENGTH, LICENSE_BYTE_LENGTH } from '../../../../src/utils/constants.js';
4
4
  import { randomBuffer, TEN_THOUSAND_VALUE } from '../stateTestUtils.js';
5
- import { NodeRole } from '../../../src/core/state/utils/roles.js';
5
+ import { NodeRole } from '../../../../src/core/state/utils/roles.js';
6
6
  import {
7
7
  ZERO_BALANCE,
8
8
  ZERO_LICENSE,
@@ -14,7 +14,7 @@ import {
14
14
  setBalance as setNodeEntryBalance,
15
15
  setLicense as setNodeEntryLicense,
16
16
  setStakedBalance as setNodeEntryStakedBalance,
17
- } from '../../../src/core/state/utils/nodeEntry.js';
17
+ } from '../../../../src/core/state/utils/nodeEntry.js';
18
18
 
19
19
  // Test init()
20
20
  test('Node Entry - init - Happy Path', t => {
@@ -1,5 +1,5 @@
1
1
  import test from 'brittle';
2
- import roles from '../../../src/core/state/utils/roles.js';
2
+ import roles from '../../../../src/core/state/utils/roles.js';
3
3
 
4
4
  const { NodeRole, WHITELISTED_MASK, WRITER_MASK, INDEXER_MASK, calculateNodeRole, isNodeRoleValid } = roles;
5
5
 
@@ -0,0 +1,14 @@
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
+ await import('./network/networkModule.test.js')
8
+ await import('./state/stateModule.test.js');
9
+ await import('./utils/utils.test.js');
10
+ // await import('./messageOperations/stateMessageOperations.test.js'); // Broken test - needs fixing
11
+ test.resume();
12
+ }
13
+
14
+ await runTests();
@@ -1,8 +1,8 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
- import { decimalStringToBigInt, bigIntTo16ByteBuffer, bufferToBigInt, bigIntToDecimalString, licenseBufferToBigInt } from '../../src/utils/amountSerialization.js';
4
- import { errorMessageIncludes } from "../utils/regexHelper.js";
5
- import lengthEntryUtils from '../../src/core/state/utils/lengthEntry.js';
3
+ import { decimalStringToBigInt, bigIntTo16ByteBuffer, bufferToBigInt, bigIntToDecimalString, licenseBufferToBigInt } from '../../../../src/utils/amountSerialization.js';
4
+ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
5
+ import lengthEntryUtils from '../../../../src/core/state/utils/lengthEntry.js';
6
6
 
7
7
  test('decimalStringToBigInt', async t => {
8
8
  // Zero cases - all valid
@@ -1,6 +1,6 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
- import {createMessage, isBufferValid, safeWriteUInt32BE, deepCopyBuffer} from '../../src/utils/buffer.js';
3
+ import {createMessage, isBufferValid, safeWriteUInt32BE, deepCopyBuffer} from '../../../../src/utils/buffer.js';
4
4
 
5
5
  const invalidDataTypes = [
6
6
  null,
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js'
4
- import {ACO, not_allowed_data_types} from '../fixtures/check.fixtures.js'
3
+ import Check from '../../../../src/utils/check.js'
4
+ import {ACO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js'
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest } from './common.test.js';
6
6
 
7
7
  const check = new Check()
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js'
4
- import { BIO, not_allowed_data_types } from '../fixtures/check.fixtures.js'
3
+ import Check from '../../../../src/utils/check.js'
4
+ import { BIO, not_allowed_data_types } from '../../../fixtures/check.fixtures.js'
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest } from './common.test.js';
6
6
 
7
7
  const check = new Check()
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js';
4
- import {BDO, not_allowed_data_types} from '../fixtures/check.fixtures.js';
3
+ import Check from '../../../../src/utils/check.js';
4
+ import {BDO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js';
5
5
 
6
6
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest, partialTypeCommonTests } from './common.test.js';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
 
3
- import { MIN_SAFE_VALIDATION_INTEGER, MAX_SAFE_VALIDATION_INTEGER, TRAC_ADDRESS_SIZE } from '../../src/utils/constants.js';
4
- import { partial_operation_value_type } from "../fixtures/check.fixtures.js";
3
+ import { MIN_SAFE_VALIDATION_INTEGER, MAX_SAFE_VALIDATION_INTEGER, TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
4
+ import { partial_operation_value_type } from "../../../fixtures/check.fixtures.js";
5
5
 
6
6
  export function topLevelValidationTests(
7
7
  t,
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js'
4
- import {CAO, not_allowed_data_types} from '../fixtures/check.fixtures.js'
3
+ import Check from '../../../../src/utils/check.js'
4
+ import {CAO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js'
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest } from './common.test.js';
6
6
 
7
7
  const check = new Check()
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js';
4
- import {RAO, not_allowed_data_types} from '../fixtures/check.fixtures.js';
3
+ import Check from '../../../../src/utils/check.js';
4
+ import {RAO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js';
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest, partialTypeCommonTests } from './common.test.js';
6
6
 
7
7
  const check = new Check();
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js';
4
- import {TXO, not_allowed_data_types} from '../fixtures/check.fixtures.js';
3
+ import Check from '../../../../src/utils/check.js';
4
+ import {TXO, not_allowed_data_types} from '../../../fixtures/check.fixtures.js';
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest, partialTypeCommonTests } from './common.test.js';
6
6
 
7
7
  const check = new Check();
@@ -1,7 +1,7 @@
1
1
  import test from 'brittle'
2
2
 
3
- import Check from '../../src/utils/check.js';
4
- import {TRO, not_allowed_data_types, TXO} from '../fixtures/check.fixtures.js';
3
+ import Check from '../../../../src/utils/check.js';
4
+ import {TRO, not_allowed_data_types, TXO} from '../../../fixtures/check.fixtures.js';
5
5
  import { topLevelValidationTests, valueLevelValidationTest, addressBufferLengthTest, fieldsBufferLengthTest, partialTypeCommonTests } from './common.test.js';
6
6
 
7
7
  const check = new Check();
@@ -1,6 +1,6 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
- import { blake3Hash} from '../../src/utils/crypto.js';
3
+ import { blake3Hash} from '../../../../src/utils/crypto.js';
4
4
 
5
5
  test('blake3', async (t) => {
6
6
  t.test('blake3Hash', async (k) => {
@@ -1,6 +1,6 @@
1
1
  import { test, hook } from 'brittle';
2
- import fileUtils from '../../src/utils/fileUtils.js';
3
- import { errorMessageIncludes } from "../utils/regexHelper.js";
2
+ import fileUtils from '../../../../src/utils/fileUtils.js';
3
+ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
4
4
  import fs from 'fs';
5
5
  import PeerWallet from 'trac-wallet';
6
6
 
@@ -1,7 +1,6 @@
1
-
2
1
  import { test, hook } from 'brittle';
3
- import fileUtils from '../../src/utils/fileUtils.js';
4
- import { errorMessageIncludes } from "../utils/regexHelper.js";
2
+ import fileUtils from '../../../../src/utils/fileUtils.js';
3
+ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
5
4
  import fs from 'fs';
6
5
  import PeerWallet from 'trac-wallet';
7
6
 
@@ -3,11 +3,8 @@ import { default as test } from 'brittle';
3
3
  async function runMsgUtilsTests() {
4
4
  test.pause();
5
5
 
6
- await import('./applyOperations.test.js');
7
- await import('./createHash.test.js');
8
6
  await import('./isHexString.test.js');
9
7
  await import('./normalizeHex.test.js');
10
- await import('./amountSerialization.test.js');
11
8
  test.resume();
12
9
  }
13
10
 
@@ -1,5 +1,5 @@
1
1
  import test from 'brittle';
2
- import { isHexString } from '../../src/utils/helpers.js';
2
+ import { isHexString } from '../../../../src/utils/helpers.js';
3
3
 
4
4
  test('isHexString', (t) => {
5
5
  t.ok(isHexString('1234567890abcdef'), 'Valid hex string should return true with all lowercase characters');
@@ -1,6 +1,6 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
- import { normalizeHex } from '../../src/utils/helpers.js';
3
+ import { normalizeHex } from '../../../../src/utils/helpers.js';
4
4
 
5
5
  test('normalizeHex should convert hex string to buffer', t => {
6
6
  const hexString = '1234abcd';
@@ -1,7 +1,7 @@
1
1
  import { test, hook } from 'brittle';
2
- import migrationUtils from '../../src/utils/migrationUtils.js';
3
- import { errorMessageIncludes } from "../utils/regexHelper.js";
4
- import { ZERO_LICENSE } from '../../src/core/state/utils/nodeEntry.js';
2
+ import migrationUtils from '../../../../src/utils/migrationUtils.js';
3
+ import { errorMessageIncludes } from "../../../helpers/regexHelper.js";
4
+ import { ZERO_LICENSE } from '../../../../src/core/state/utils/nodeEntry.js';
5
5
  import b4a from 'b4a';
6
6
  const VALID_ADDRESS = 'trac1dguwzsvcsehslh6dgj2mqlsxdn7s5t5vhem56yd0xlg47aq6exzqymhr6u';
7
7
  const ADMIN_ADDRESS = 'trac1yva2pduhz5yst8jgzmrc9ve0as5mx7tcw6le9srj6xcwqkx9hacqxxhsf9';
@@ -1,8 +1,8 @@
1
1
  import test from 'brittle';
2
- import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../src/utils/protobuf/operationHelpers.js';
2
+ import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../src/utils/protobuf/operationHelpers.js';
3
3
  import b4a from 'b4a';
4
- import fixtures from '../fixtures/protobuf.fixtures.js';
5
-
4
+ import fixtures from '../../fixtures/protobuf.fixtures.js';
5
+ //TODO add missing operations tests and fill fixtures with them
6
6
  test('Happy path encode/decode roundtrip for protobuf applyOperation payloads', t => {
7
7
  const payloadsHashMap = new Map([
8
8
  ["tx", fixtures.validTransactionOperation],
@@ -1,9 +1,10 @@
1
1
  import test from 'brittle';
2
2
  import b4a from 'b4a';
3
3
 
4
- import applyOperations from '../../src/utils/protobuf/applyOperations.cjs';
5
- import fixtures from '../fixtures/protobuf.fixtures.js';
4
+ import applyOperations from '../../../../src/utils/protobuf/applyOperations.cjs';
5
+ import fixtures from '../../../fixtures/protobuf.fixtures.js';
6
6
 
7
+ //TODO add missing operations tests and fill fixtures with them
7
8
  test('Happy path encode/decode roundtrip for protobuf applyOperation payloads', t => {
8
9
  const payloadsHashMap = new Map([
9
10
  ["txComplete", fixtures.validTransactionOperation],
@@ -0,0 +1,12 @@
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
+ await import('./applyOperations.test.js');
8
+ await import('./operationHelpers.test.js');
9
+ test.resume();
10
+ }
11
+
12
+ await runTests();
@@ -0,0 +1,20 @@
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/check.test.js');
9
+ await import('./protobuf/operationHelpers.test.js');
10
+ await import('./helpers/helpers.test.js');
11
+ await import('./fileUtils/readAddressesFromWhitelistFile.test.js');
12
+ await import('./fileUtils/readBalanceMigrationFile.test.js');
13
+ await import('./migrationUtils/validateAddressFromIncomingFile.test.js');
14
+ await import('./buffer/buffer.test.js')
15
+ await import('./amountSerialization/amountSerialization.test.js');
16
+ await import('./crypto/createHash.test.js');
17
+ test.resume();
18
+ }
19
+
20
+ await runTests();
package/test/all.test.js DELETED
@@ -1,23 +0,0 @@
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('./state/stateTests.test.js');
9
- // await import('./state/apply.addAdmin.basic.test.js');
10
- // await import('./check/check.test.js');
11
- // await import('./protobuf/protobuf.test.js');
12
- // await import('./functions/functions.test.js');
13
- // await import('./fileUtils/readAddressesFromWhitelistFile.test.js');
14
- // await import('./fileUtils/readBalanceMigrationFile.test.js');
15
- // await import('./migrationUtils/validateAddressFromIncomingFile.test.js');
16
- // await import('./messageOperations/stateMessageOperations.test.js');
17
- // await import('./buffer/buffer.test.js')
18
- // await import('./network/connectionManagerTests.test.js')
19
- // await import('./apply/apply.test.js'); // This test has been disabled because Github CI fails due to lack of resources. This test can still be run locally but sometimes it hangs when destroying resources.
20
- test.resume();
21
- }
22
-
23
- await runTests();
@@ -1,111 +0,0 @@
1
- import { test, hook } from '../utils/wrapper.js'
2
- import Corestore from 'corestore'
3
- import path from 'path'
4
- import os from 'os'
5
- import { promises as fsp } from 'fs'
6
- import b4a from 'b4a'
7
-
8
- import PeerWallet from 'trac-wallet'
9
- import State from '../../src/core/state/State.js'
10
- import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js'
11
- import { ADMIN_INITIAL_BALANCE } from '../../src/utils/constants.js'
12
-
13
- // Prosty, szybki test apply(add_admin) inspirowany stylem Autobase/test/basic.js
14
- // Minimalny setup: Corestore + State + Wallet, bez sieci i dodatkowych warstw
15
-
16
- let tmpDir
17
- let store
18
- let wallet
19
- let state
20
-
21
- const STATE_OPTIONS = {
22
- enable_tx_apply_logs: false,
23
- enable_error_apply_logs: false
24
- }
25
-
26
- async function createTempStore() {
27
- const base = path.join(os.tmpdir(), `msb-state-test-${Date.now()}-${Math.random().toString(16).slice(2)}`)
28
- await fsp.mkdir(base, { recursive: true })
29
- return { base, db: path.join(base, 'db') }
30
- }
31
-
32
- async function createWalletFromFixture({ mnemonic }) {
33
- const w = new PeerWallet({ mnemonic })
34
- await w.ready
35
- return w
36
- }
37
-
38
- hook('setup state for add_admin', async () => {
39
- const paths = await createTempStore()
40
- tmpDir = paths.base
41
-
42
- const { testKeyPair1 } = await import('../fixtures/apply.fixtures.js')
43
- wallet = await createWalletFromFixture(testKeyPair1)
44
-
45
- // wyciągnij writing key bootstrapu (== klucz lokalnego writera)
46
- const bootstrapKey = await deriveBootstrapWriterKey(paths.db, wallet)
47
-
48
- // właściwy store + stan testowy
49
- store = new Corestore(paths.db)
50
- await store.ready()
51
-
52
- state = new State(store, bootstrapKey, wallet, STATE_OPTIONS)
53
- await state.ready()
54
-
55
- // pierwszy pusty append zapewnia, że widok/indexery są zainicjalizowane
56
- await state.append(null)
57
- await fastForwardIfAvailable(state)
58
- await state.base.view.update()
59
- })
60
-
61
- test('State.apply(add_admin) – podstawowy scenariusz', async t => {
62
- // preconditions
63
- const beforeAdmin = await state.getAdminEntry()
64
- t.is(beforeAdmin, null, 'admin entry nie istnieje przed operacją')
65
-
66
- // assemble + append
67
- const validity = await state.getIndexerSequenceState()
68
- const msg = await CompleteStateMessageOperations.assembleAddAdminMessage(
69
- wallet,
70
- state.writingKey,
71
- validity
72
- )
73
-
74
- await state.append(msg)
75
- // wymuś natychmiastowe przetworzenie apply i aktualizację widoku
76
- await fastForwardIfAvailable(state)
77
- await state.base.view.update()
78
-
79
- // assertions
80
- const adminEntry = await state.getAdminEntry()
81
- t.ok(adminEntry, 'admin entry powinien zostać dodany')
82
- t.ok(b4a.equals(adminEntry.wk, state.writingKey), 'wk admina == writingKey')
83
-
84
- const node = await state.getNodeEntry(adminEntry.address)
85
- t.ok(node?.isWriter, 'admin powinien być writerem')
86
- t.ok(node?.isIndexer, 'admin powinien być indexerem')
87
- t.ok(b4a.equals(node.balance, ADMIN_INITIAL_BALANCE), 'admin powinien mieć saldo początkowe')
88
- })
89
-
90
- hook('teardown state for add_admin', async () => {
91
- try { if (state) await state.close() } catch {}
92
- try { if (store) await store.close() } catch {}
93
- try { if (tmpDir) await fsp.rm(tmpDir, { recursive: true, force: true }) } catch {}
94
- })
95
-
96
- async function deriveBootstrapWriterKey(dbPath, walletInstance) {
97
- const bootstrapStore = new Corestore(dbPath)
98
- await bootstrapStore.ready()
99
- const bootstrapState = new State(bootstrapStore, null, walletInstance, STATE_OPTIONS)
100
- await bootstrapState.ready()
101
- const wk = bootstrapState.writingKey
102
- await bootstrapState.close()
103
- await bootstrapStore.close()
104
- return wk
105
- }
106
-
107
- async function fastForwardIfAvailable(testState) {
108
- if (typeof testState.base.forceFastForward === 'function') {
109
- await testState.base.forceFastForward()
110
- }
111
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes