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.
- package/.env +0 -0
- package/.github/workflows/CI.yml +2 -4
- package/.github/workflows/acceptance-tests.yml +35 -0
- package/LICENSE +2 -2
- package/SECURITY.md +54 -0
- package/package.json +8 -6
- package/rpc/handlers.mjs +9 -2
- package/src/index.js +5 -1
- package/src/utils/helpers.js +2 -0
- package/{test → tests}/acceptance/v1/rpc.test.mjs +3 -2
- package/{test → tests/integration}/apply/addAdmin/addAdminBasic.test.js +6 -6
- package/{test → tests/integration}/apply/addAdmin/addAdminRecovery.test.js +8 -8
- package/{test → tests/integration}/apply/addIndexer.test.js +3 -4
- package/{test → tests/integration}/apply/addWhitelist.test.js +5 -5
- package/{test → tests/integration}/apply/addWriter.test.js +7 -7
- package/{test → tests/integration}/apply/banValidator.test.js +13 -14
- package/{test → tests/integration}/apply/postTx/invalidSubValues.test.js +6 -7
- package/{test → tests/integration}/apply/postTx/postTx.test.js +7 -8
- package/{test → tests/integration}/apply/removeIndexer.test.js +4 -4
- package/{test → tests/integration}/apply/removeWriter.test.js +5 -5
- package/{test → tests/integration}/apply/transfer.test.js +7 -7
- package/tests/integration/integration.test.js +9 -0
- package/{test → tests/unit}/messageOperations/assemblePostTransaction.test.js +1 -1
- package/{test → tests/unit}/network/ConnectionManager.test.js +5 -5
- package/{test → tests/unit}/state/stateTestUtils.js +1 -1
- package/{test → tests/unit}/state/utils/address.test.js +2 -2
- package/{test → tests/unit}/state/utils/adminEntry.test.js +3 -3
- package/{test → tests/unit}/state/utils/balance.test.js +5 -5
- package/{test → tests/unit}/state/utils/indexerEntry.test.js +2 -2
- package/{test → tests/unit}/state/utils/lengthEntry.test.js +1 -1
- package/{test → tests/unit}/state/utils/nodeEntry.test.js +3 -3
- package/{test → tests/unit}/state/utils/roles.test.js +1 -1
- package/tests/unit/unit.test.js +14 -0
- package/{test/functions → tests/unit/utils/amountSerialization}/amountSerialization.test.js +3 -3
- package/{test → tests/unit/utils}/buffer/buffer.test.js +1 -1
- package/{test → tests/unit/utils}/check/adminControlOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/balanceInitializationOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/bootstrapDeploymentOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/common.test.js +2 -2
- package/{test → tests/unit/utils}/check/coreAdminOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/roleAccessOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/transactionOperation.test.js +2 -2
- package/{test → tests/unit/utils}/check/transferOperation.test.js +2 -2
- package/{test/functions → tests/unit/utils/crypto}/createHash.test.js +1 -1
- package/{test → tests/unit/utils}/fileUtils/readAddressesFromWhitelistFile.test.js +2 -2
- package/{test → tests/unit/utils}/fileUtils/readBalanceMigrationFile.test.js +2 -3
- package/{test/functions/functions.test.js → tests/unit/utils/helpers/helpers.test.js} +0 -3
- package/{test/functions → tests/unit/utils/helpers}/isHexString.test.js +1 -1
- package/{test/functions → tests/unit/utils/helpers}/normalizeHex.test.js +1 -1
- package/{test → tests/unit/utils}/migrationUtils/validateAddressFromIncomingFile.test.js +3 -3
- package/{test/functions → tests/unit/utils/protobuf}/applyOperations.test.js +3 -3
- package/{test/protobuf/protobuf.test.js → tests/unit/utils/protobuf/operationHelpers.test.js} +3 -2
- package/tests/unit/utils/protobuf/protobuf.test.js +12 -0
- package/tests/unit/utils/utils.test.js +20 -0
- package/test/all.test.js +0 -23
- package/test/state/apply.addAdmin.basic.test.js +0 -111
- /package/{test → tests}/fixtures/apply.fixtures.js +0 -0
- /package/{test → tests}/fixtures/assembleMessage.fixtures.js +0 -0
- /package/{test → tests}/fixtures/check.fixtures.js +0 -0
- /package/{test → tests}/fixtures/protobuf.fixtures.js +0 -0
- /package/{test/utils → tests/helpers}/regexHelper.js +0 -0
- /package/{test/utils → tests/helpers}/setupApplyTests.js +0 -0
- /package/{test/utils → tests/helpers}/wrapper.js +0 -0
- /package/{test → tests/integration}/apply/apply.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleAddIndexerMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleAddWriterMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleAdminMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleBanWriterMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleRemoveIndexerMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleRemoveWriterMessage.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/assembleWhitelistMessages.test.js +0 -0
- /package/{test → tests/unit}/messageOperations/commonsStateMessageOperationsTest.js +0 -0
- /package/{test → tests/unit}/messageOperations/stateMessageOperations.test.js +0 -0
- /package/{test/network/connectionManagerTests.test.js → tests/unit/network/networkModule.test.js} +0 -0
- /package/{test → tests/unit}/state/State.test.js +0 -0
- /package/{test/state/stateTests.test.js → tests/unit/state/stateModule.test.js} +0 -0
- /package/{test → tests/unit}/state/utils/transaction.test.js +0 -0
- /package/{test → tests/unit/utils}/check/check.test.js +0 -0
package/.env
ADDED
|
File without changes
|
package/.github/workflows/CI.yml
CHANGED
|
@@ -30,12 +30,10 @@ jobs:
|
|
|
30
30
|
cache: 'npm'
|
|
31
31
|
- name: Install dependencies
|
|
32
32
|
run: npm ci
|
|
33
|
-
- name: Run node tests
|
|
34
|
-
run: npm run test:node
|
|
35
33
|
- name: Install bare
|
|
36
34
|
run: npm i -g bare
|
|
37
|
-
- name: Run
|
|
38
|
-
run: npm run test:
|
|
35
|
+
- name: Run all tests
|
|
36
|
+
run: npm run test:unit:all
|
|
39
37
|
# For now acceptance tests should be disable due to instability of the running MSB instance in the github actions environment
|
|
40
38
|
# Github machines are not powerful enough to run MSB, and we won't ever finish our tests.
|
|
41
39
|
# - name: Run rpc acceptance tests
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: MSB-Acceptance-Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
concurrency:
|
|
7
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
8
|
+
cancel-in-progress: true
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
integration-tests:
|
|
12
|
+
name: Acceptance Tests
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
node-version: [lts/*]
|
|
17
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
+
uses: actions/setup-node@v3
|
|
24
|
+
with:
|
|
25
|
+
node-version: ${{ matrix.node-version }}
|
|
26
|
+
cache: 'npm'
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm ci
|
|
30
|
+
|
|
31
|
+
- name: Install bare
|
|
32
|
+
run: npm i -g bare
|
|
33
|
+
|
|
34
|
+
- name: Run Integration Tests
|
|
35
|
+
run: npm run test:acceptance
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
Copyright 2025 Trac Systems UG
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
|
@@ -198,4 +198,4 @@
|
|
|
198
198
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
199
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
200
|
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
201
|
+
limitations under the License.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
The following table shows which versions of this project are currently receiving security updates.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| -------- | ------------------ |
|
|
9
|
+
| 0.2.x | :white_check_mark: |
|
|
10
|
+
| < 0.2 | :x: |
|
|
11
|
+
|
|
12
|
+
Older versions (< 0.2.x) are no longer supported.
|
|
13
|
+
Please upgrade to the latest release to ensure you receive security fixes.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Reporting a Vulnerability
|
|
18
|
+
|
|
19
|
+
If you discover a security vulnerability affecting the TRAC Network,
|
|
20
|
+
please **do not disclose it publicly** (e.g., on social media, Discord, or GitHub Issues).
|
|
21
|
+
|
|
22
|
+
Instead, report it responsibly and confidentially through one of the following contacts:
|
|
23
|
+
|
|
24
|
+
- 📧 **info@trac.network** — protocol, API, infrastructure, or tooling vulnerabilities
|
|
25
|
+
|
|
26
|
+
Alternatively, you can use the **“Report a vulnerability”** option on GitHub if available.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### Responsible Disclosure Guidelines
|
|
31
|
+
|
|
32
|
+
- **Do not exploit or test vulnerabilities on mainnet.**
|
|
33
|
+
Use **testnet** environments or isolated local nodes for proof-of-concepts (PoCs).
|
|
34
|
+
- Include clear and reproducible details in your report:
|
|
35
|
+
- affected **component or module**,
|
|
36
|
+
- minimal **proof of concept (PoC)** showing the issue,
|
|
37
|
+
- expected vs. actual behavior,
|
|
38
|
+
- estimated **impact** (e.g., fund loss, network instability, or data integrity issue),
|
|
39
|
+
- any relevant **logs or transaction hashes** if applicable.
|
|
40
|
+
- Please avoid:
|
|
41
|
+
- phishing or social engineering,
|
|
42
|
+
- denial-of-service (DoS) or spam tests,
|
|
43
|
+
- public disclosure before coordinated remediation.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### Response Process
|
|
48
|
+
|
|
49
|
+
- You will receive an **acknowledgment within 72 hours** of submission.
|
|
50
|
+
- The TRAC Network security team will investigate and validate the issue.
|
|
51
|
+
- If confirmed, we’ll provide updates on the **remediation plan and timeline**.
|
|
52
|
+
- After a fix is deployed, we may publicly recognize your contribution (with your consent).
|
|
53
|
+
|
|
54
|
+
Thank you for helping us keep the TRAC Network ecosystem secure and resilient 💙
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-msb",
|
|
3
3
|
"main": "msb.mjs",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"pear": {
|
|
6
6
|
"name": "trac-msb",
|
|
7
7
|
"type": "terminal"
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
"dev-rpc": "pear run -d . ${npm_config_store} --rpc --port ${npm_config_port}",
|
|
14
14
|
"prod-rpc": "pear run . ${npm_config_store} --rpc --host ${npm_config_host} --port ${npm_config_port}",
|
|
15
15
|
"protobuf": "node scripts/generate-protobufs.js",
|
|
16
|
-
"test:acceptance": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=200000
|
|
17
|
-
"test:
|
|
18
|
-
"test:
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
16
|
+
"test:acceptance": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=200000 tests/acceptance/",
|
|
17
|
+
"test:integration": "brittle-node -t 1200000 tests/integration/integration.test.js",
|
|
18
|
+
"test:unit:node": "brittle-node -t 60000 tests/unit/unit.test.js",
|
|
19
|
+
"test:unit:bare": "brittle-bare -t 60000 tests/unit/unit.test.js",
|
|
20
|
+
"test:unit:all": "(npm run test:unit:node && npm run test:unit:bare) || exit 1",
|
|
21
|
+
"test:unit:node:cov": "brittle-node -c -t 60000 tests/unit/unit.test.js",
|
|
22
|
+
"test:unit:bare:cov": "brittle-bare -c -t 60000 tests/unit/unit.test.js"
|
|
21
23
|
},
|
|
22
24
|
"dependencies": {
|
|
23
25
|
"@tracsystems/blake3": "0.0.13",
|
package/rpc/handlers.mjs
CHANGED
|
@@ -68,10 +68,17 @@ export async function handleBroadcastTransaction({ msbInstance, respond, req })
|
|
|
68
68
|
const result = await msbInstance.handleCommand('/broadcast_transaction', null, sanitizedPayload);
|
|
69
69
|
respond(200, { result });
|
|
70
70
|
} catch (error) {
|
|
71
|
+
let code = error instanceof SyntaxError ? 400 : 500;
|
|
72
|
+
let errorMsg = code === 400 ? 'Invalid JSON payload.' : 'An error occurred processing the transaction.'
|
|
73
|
+
|
|
74
|
+
if(error.message.includes("Failed to broadcast transaction after multiple attempts.")){
|
|
75
|
+
code = 429;
|
|
76
|
+
errorMsg = "Failed to broadcast transaction after multiple attempts."
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
console.error('Error in handleBroadcastTransaction:', error);
|
|
72
80
|
// Use 400 for client errors (like bad JSON), 500 for server/command errors
|
|
73
|
-
|
|
74
|
-
respond(code, { error: code === 400 ? 'Invalid JSON payload.' : 'An error occurred processing the transaction.' });
|
|
81
|
+
respond(code, { error: errorMsg});
|
|
75
82
|
}
|
|
76
83
|
});
|
|
77
84
|
|
package/src/index.js
CHANGED
|
@@ -1199,7 +1199,11 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
1199
1199
|
this.network.validatorConnectionManager.rotate() // force change connection rotation for the next retry
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
|
-
|
|
1202
|
+
if (await this.#state.get(hash) === null) {
|
|
1203
|
+
throw new Error("Failed to broadcast transaction after multiple attempts.");
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
return { message: "Transaction broadcasted successfully.", signedLength, unsignedLength, tx: hash };
|
|
1203
1207
|
} else {
|
|
1204
1208
|
// Handle case where payload is missing if called internally without one.
|
|
1205
1209
|
throw new Error("Transaction payload is required for broadcast_transaction command.");
|
package/src/utils/helpers.js
CHANGED
|
@@ -2,6 +2,8 @@ import b4a from "b4a";
|
|
|
2
2
|
import {bufferToAddress} from "../core/state/utils/address.js";
|
|
3
3
|
import { EntryType, TRAC_ADDRESS_SIZE } from "./constants.js";
|
|
4
4
|
|
|
5
|
+
//TODO: change file name or split functions below into multiple files (Remember to update imports and tests accordingly)
|
|
6
|
+
|
|
5
7
|
export function isHexString(string) {
|
|
6
8
|
return typeof string === 'string' && string.length > 1 && /^[0-9a-fA-F]+$/.test(string) && string.length % 2 === 0;
|
|
7
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import request from "supertest"
|
|
2
2
|
import { createServer } from "../../../rpc/create_server.mjs"
|
|
3
|
-
import { initTemporaryDirectory } from '../../
|
|
3
|
+
import { initTemporaryDirectory } from '../../helpers/setupApplyTests.js'
|
|
4
4
|
import { testKeyPair1, testKeyPair2 } from '../../fixtures/apply.fixtures.js'
|
|
5
|
-
import { randomBytes, setupMsbAdmin, setupMsbWriter, fundPeer, removeTemporaryDirectory } from "../../
|
|
5
|
+
import { randomBytes, setupMsbAdmin, setupMsbWriter, fundPeer, removeTemporaryDirectory } from "../../helpers/setupApplyTests.js"
|
|
6
6
|
import { $TNK } from "../../../src/core/state/utils/balance.js"
|
|
7
7
|
import tracCrypto from 'trac-crypto-api';
|
|
8
8
|
import b4a from 'b4a'
|
|
@@ -124,6 +124,7 @@ describe("API acceptance tests", () => {
|
|
|
124
124
|
message: "Transaction broadcasted successfully.",
|
|
125
125
|
signedLength: expect.any(Number),
|
|
126
126
|
unsignedLength: expect.any(Number),
|
|
127
|
+
tx: expect.any(String)
|
|
127
128
|
}
|
|
128
129
|
})
|
|
129
130
|
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {test, hook} from '
|
|
1
|
+
import {test, hook} from '../../../helpers/wrapper.js';
|
|
2
2
|
import {
|
|
3
3
|
initMsbAdmin, initTemporaryDirectory, removeTemporaryDirectory, setupMsbPeer, setupMsbWriter, setupMsbIndexer,
|
|
4
4
|
tryToSyncWriters
|
|
5
|
-
} from '
|
|
6
|
-
import {randomBytes} from '
|
|
7
|
-
import CompleteStateMessageOperations from '
|
|
8
|
-
import {testKeyPair1} from '
|
|
5
|
+
} from '../../../helpers/setupApplyTests.js';
|
|
6
|
+
import {randomBytes} from '../../../helpers/setupApplyTests.js';
|
|
7
|
+
import CompleteStateMessageOperations from '../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
8
|
+
import {testKeyPair1} from '../../../fixtures/apply.fixtures.js';
|
|
9
9
|
import b4a from 'b4a';
|
|
10
|
-
import { ADMIN_INITIAL_BALANCE } from '
|
|
10
|
+
import { ADMIN_INITIAL_BALANCE } from '../../../../src/utils/constants.js';
|
|
11
11
|
|
|
12
12
|
//TODO: ADD TEST WHEN NON-ADMIN NODE FORGES ADD ADMIN OPERATION AND BROADCASTS IT TO THE STATE - SHOULD BE REJECTED
|
|
13
13
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {test, hook} from '
|
|
1
|
+
import {test, hook} from '../../../helpers/wrapper.js';
|
|
2
2
|
import {
|
|
3
3
|
initTemporaryDirectory, removeTemporaryDirectory, setupMsbPeer, setupMsbWriter, setupMsbIndexer,
|
|
4
4
|
tryToSyncWriters, waitForAdminEntry, setupMsbAdmin
|
|
5
|
-
} from '
|
|
5
|
+
} from '../../../helpers/setupApplyTests.js';
|
|
6
6
|
|
|
7
|
-
import {randomBytes} from '
|
|
8
|
-
import CompleteStateMessageOperations from '
|
|
9
|
-
import PartialStateMessageOperations from '
|
|
10
|
-
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4} from '
|
|
7
|
+
import {randomBytes} from '../../../helpers/setupApplyTests.js';
|
|
8
|
+
import CompleteStateMessageOperations from '../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
9
|
+
import PartialStateMessageOperations from '../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js'
|
|
10
|
+
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4} from '../../../fixtures/apply.fixtures.js';
|
|
11
11
|
import b4a from 'b4a';
|
|
12
|
-
import { decode as decodeAdmin } from '
|
|
13
|
-
import { EntryType } from '
|
|
12
|
+
import { decode as decodeAdmin } from '../../../../src/core/state/utils/adminEntry.js';
|
|
13
|
+
import { EntryType } from '../../../../src/utils/constants.js';
|
|
14
14
|
//TODO: ADD TEST WHEN NON-ADMIN NODE FORGES ADD ADMIN OPERATION AND BROADCASTS IT TO THE STATE - SHOULD BE REJECTED
|
|
15
15
|
|
|
16
16
|
let admin, newAdmin;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {test, hook, solo} from 'brittle';
|
|
2
|
-
import CompleteStateMessageOperations from '
|
|
3
|
-
import {formatIndexersEntry} from '../../src/utils/helpers.js';
|
|
2
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
4
3
|
import {
|
|
5
4
|
initTemporaryDirectory,
|
|
6
5
|
removeTemporaryDirectory,
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
randomBytes,
|
|
10
9
|
setupMsbPeer,
|
|
11
10
|
setupWhitelist, waitForNodeState, tryToSyncWriters, waitIndexer
|
|
12
|
-
} from '
|
|
11
|
+
} from '../../helpers/setupApplyTests.js';
|
|
13
12
|
import {
|
|
14
13
|
testKeyPair1,
|
|
15
14
|
testKeyPair2,
|
|
@@ -18,7 +17,7 @@ import {
|
|
|
18
17
|
testKeyPair5,
|
|
19
18
|
testKeyPair6,
|
|
20
19
|
testKeyPair7
|
|
21
|
-
} from '
|
|
20
|
+
} from '../../fixtures/apply.fixtures.js';
|
|
22
21
|
import b4a from 'b4a';
|
|
23
22
|
|
|
24
23
|
let tmpDirectory, admin, indexer1, indexer2, reader1, reader2, indexer3, writer;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { test, hook } from '
|
|
1
|
+
import { test, hook } from '../../helpers/wrapper.js';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
import { setupMsbAdmin, initTemporaryDirectory, removeTemporaryDirectory, randomBytes } from '
|
|
4
|
-
import { testKeyPair1, testKeyPair2 } from '
|
|
5
|
-
import fileUtils from '
|
|
6
|
-
import CompleteStateMessageOperations from '
|
|
3
|
+
import { setupMsbAdmin, initTemporaryDirectory, removeTemporaryDirectory, randomBytes } from '../../helpers/setupApplyTests.js';
|
|
4
|
+
import { testKeyPair1, testKeyPair2 } from '../../fixtures/apply.fixtures.js';
|
|
5
|
+
import fileUtils from '../../../src/utils/fileUtils.js';
|
|
6
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
7
7
|
import { address as addressApi } from 'trac-crypto-api';
|
|
8
8
|
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
9
9
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { test, hook } from '
|
|
2
|
+
import { test, hook } from '../../helpers/wrapper.js';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
setupMsbAdmin,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
tryToSyncWriters,
|
|
15
15
|
waitForNodeState,
|
|
16
16
|
waitWritable
|
|
17
|
-
} from '
|
|
17
|
+
} from '../../helpers/setupApplyTests.js';
|
|
18
18
|
import {
|
|
19
19
|
testKeyPair1,
|
|
20
20
|
testKeyPair2,
|
|
@@ -22,11 +22,11 @@ import {
|
|
|
22
22
|
testKeyPair4,
|
|
23
23
|
testKeyPair5,
|
|
24
24
|
testKeyPair6
|
|
25
|
-
} from '
|
|
26
|
-
import PartialStateMessageOperations from "
|
|
27
|
-
import CompleteStateMessageOperations from '
|
|
28
|
-
import {ZERO_WK} from '
|
|
29
|
-
import { $TNK } from '
|
|
25
|
+
} from '../../fixtures/apply.fixtures.js';
|
|
26
|
+
import PartialStateMessageOperations from "../../../src/messages/partialStateMessages/PartialStateMessageOperations.js";
|
|
27
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
28
|
+
import {ZERO_WK} from '../../../src/utils/buffer.js';
|
|
29
|
+
import { $TNK } from '../../../src/core/state/utils/balance.js';
|
|
30
30
|
|
|
31
31
|
const sendAddWriter = async (invoker, broadcaster) => {
|
|
32
32
|
const validity = await invoker.msb.state.getIndexerSequenceState()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {test, hook} from '
|
|
1
|
+
import { test, hook } from '../../helpers/wrapper.js';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
initTemporaryDirectory,
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
setupMsbIndexer,
|
|
8
8
|
setupMsbAdmin,
|
|
9
9
|
tryToSyncWriters
|
|
10
|
-
} from '
|
|
11
|
-
import {randomBytes} from '
|
|
12
|
-
import CompleteStateMessageOperations from '
|
|
13
|
-
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4} from '
|
|
14
|
-
import {sleep} from '
|
|
10
|
+
} from '../../helpers/setupApplyTests.js';
|
|
11
|
+
import { randomBytes } from '../../helpers/setupApplyTests.js';
|
|
12
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
13
|
+
import { testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4 } from '../../fixtures/apply.fixtures.js';
|
|
14
|
+
import { sleep } from '../../../src/utils/helpers.js';
|
|
15
15
|
import b4a from 'b4a'
|
|
16
16
|
|
|
17
17
|
let admin;
|
|
@@ -99,12 +99,11 @@ test('handleApplyBanValidatorOperation (apply) - Append banValidator payload int
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
hook('Clean up banValidator setup', async t => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (indexer
|
|
105
|
-
if (writer1
|
|
106
|
-
if (writer2
|
|
107
|
-
|
|
108
|
-
await Promise.all(toClose)
|
|
102
|
+
const toClose = [];
|
|
103
|
+
if (admin?.msb) toClose.push(admin.msb.close());
|
|
104
|
+
if (indexer?.msb) toClose.push(indexer.msb.close());
|
|
105
|
+
if (writer1?.msb) toClose.push(writer1.msb.close());
|
|
106
|
+
if (writer2?.msb) toClose.push(writer2.msb.close());
|
|
107
|
+
await Promise.all(toClose);
|
|
109
108
|
if (tmpDirectory) await removeTemporaryDirectory(tmpDirectory);
|
|
110
|
-
})
|
|
109
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {hook, test} from '
|
|
2
|
-
import b4a from "b4a";
|
|
1
|
+
import {hook, test} from '../../../helpers/wrapper.js';
|
|
3
2
|
import {
|
|
4
3
|
generatePostTx,
|
|
5
4
|
initTemporaryDirectory,
|
|
@@ -13,11 +12,11 @@ import {
|
|
|
13
12
|
tryToSyncWriters,
|
|
14
13
|
waitDemotion,
|
|
15
14
|
promoteToWriter
|
|
16
|
-
} from '
|
|
17
|
-
import {safeDecodeApplyOperation, safeEncodeApplyOperation} from '
|
|
18
|
-
import {testKeyPair1, testKeyPair2, testKeyPair4, testKeyPair5} from '
|
|
19
|
-
import { $TNK } from '
|
|
20
|
-
import { decode as decodeNodeEntry } from '
|
|
15
|
+
} from '../../../helpers/setupApplyTests.js';
|
|
16
|
+
import {safeDecodeApplyOperation, safeEncodeApplyOperation} from '../../../../src/utils/protobuf/operationHelpers.js'
|
|
17
|
+
import {testKeyPair1, testKeyPair2, testKeyPair4, testKeyPair5} from '../../../fixtures/apply.fixtures.js';
|
|
18
|
+
import { $TNK } from '../../../../src/core/state/utils/balance.js';
|
|
19
|
+
import { decode as decodeNodeEntry } from '../../../../src/core/state/utils/nodeEntry.js';
|
|
21
20
|
|
|
22
21
|
let tmpDirectory, admin, writer, externalNode, externalBootstrap, maliciousPeer;
|
|
23
22
|
// is and vs is already covered
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {hook, test} from '
|
|
1
|
+
import {hook, test} from '../../../helpers/wrapper.js';
|
|
2
2
|
import b4a from "b4a";
|
|
3
3
|
import {
|
|
4
4
|
generatePostTx,
|
|
@@ -15,13 +15,12 @@ import {
|
|
|
15
15
|
waitForHash,
|
|
16
16
|
waitDemotion,
|
|
17
17
|
promoteToWriter
|
|
18
|
-
} from '
|
|
19
|
-
import {safeDecodeApplyOperation, safeEncodeApplyOperation} from '
|
|
20
|
-
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5} from '
|
|
21
|
-
import {OperationType} from "
|
|
22
|
-
import {addressToBuffer} from "
|
|
23
|
-
import { $TNK } from '
|
|
24
|
-
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
18
|
+
} from '../../../helpers/setupApplyTests.js';
|
|
19
|
+
import {safeDecodeApplyOperation, safeEncodeApplyOperation} from '../../../../src/utils/protobuf/operationHelpers.js'
|
|
20
|
+
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5} from '../../../fixtures/apply.fixtures.js';
|
|
21
|
+
import {OperationType} from "../../../../src/utils/constants.js";
|
|
22
|
+
import {addressToBuffer} from "../../../../src/core/state/utils/address.js";
|
|
23
|
+
import { $TNK } from '../../../../src/core/state/utils/balance.js';
|
|
25
24
|
|
|
26
25
|
let tmpDirectory, admin, writer, externalNode, externalBootstrap, maliciousPeer;
|
|
27
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {test, hook} from '
|
|
1
|
+
import {test, hook} from '../../helpers/wrapper.js';
|
|
2
2
|
|
|
3
|
-
import CompleteStateMessageOperations from '
|
|
3
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
4
4
|
import {
|
|
5
5
|
initTemporaryDirectory,
|
|
6
6
|
removeTemporaryDirectory,
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
setupMsbWriter,
|
|
9
9
|
randomBytes,
|
|
10
10
|
setupMsbIndexer, waitForNodeState, tryToSyncWriters
|
|
11
|
-
} from '
|
|
12
|
-
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4} from '
|
|
11
|
+
} from '../../helpers/setupApplyTests.js';
|
|
12
|
+
import {testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4} from '../../fixtures/apply.fixtures.js';
|
|
13
13
|
import b4a from 'b4a'
|
|
14
14
|
|
|
15
15
|
let tmpDirectory, admin, indexer1, indexer2, writer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {test, hook} from '
|
|
1
|
+
import {test, hook} from '../../helpers/wrapper.js';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
3
|
import {
|
|
4
4
|
setupMsbAdmin,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
tryToSyncWriters,
|
|
11
11
|
waitForNotIndexer,
|
|
12
12
|
waitForNodeState,
|
|
13
|
-
} from '
|
|
13
|
+
} from '../../helpers/setupApplyTests.js';
|
|
14
14
|
import {
|
|
15
15
|
testKeyPair1,
|
|
16
16
|
testKeyPair2,
|
|
@@ -18,9 +18,9 @@ import {
|
|
|
18
18
|
testKeyPair4,
|
|
19
19
|
testKeyPair5,
|
|
20
20
|
testKeyPair6
|
|
21
|
-
} from '
|
|
22
|
-
import CompleteStateMessageOperations from '
|
|
23
|
-
import PartialStateMessageOperations from '
|
|
21
|
+
} from '../../fixtures/apply.fixtures.js';
|
|
22
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
23
|
+
import PartialStateMessageOperations from '../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
24
24
|
|
|
25
25
|
let admin, writer1, writer2, writer3, writer4, indexer, tmpDirectory;
|
|
26
26
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { test, hook } from '
|
|
2
|
+
import { test, hook } from '../../helpers/wrapper.js';
|
|
3
3
|
import {
|
|
4
4
|
setupMsbAdmin,
|
|
5
5
|
initTemporaryDirectory,
|
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
setupMsbWriter,
|
|
8
8
|
waitForHash,
|
|
9
9
|
removeTemporaryDirectory
|
|
10
|
-
} from '
|
|
10
|
+
} from '../../helpers/setupApplyTests.js';
|
|
11
11
|
import {
|
|
12
12
|
testKeyPair1,
|
|
13
13
|
testKeyPair2,
|
|
14
14
|
testKeyPair3,
|
|
15
15
|
testKeyPair4
|
|
16
|
-
} from '
|
|
17
|
-
import PartialStateMessageOperations from "
|
|
18
|
-
import CompleteStateMessageOperations from '
|
|
19
|
-
import { $TNK } from '
|
|
16
|
+
} from '../../fixtures/apply.fixtures.js';
|
|
17
|
+
import PartialStateMessageOperations from "../../../src/messages/partialStateMessages/PartialStateMessageOperations.js";
|
|
18
|
+
import CompleteStateMessageOperations from '../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
19
|
+
import { $TNK } from '../../../src/core/state/utils/balance.js';
|
|
20
20
|
|
|
21
21
|
const buildTransfer = async (admin, from, to, amount) => {
|
|
22
22
|
const txValidity = await from.msb.state.getIndexerSequenceState()
|
|
@@ -62,7 +62,7 @@ test('handleApplyTransferOperation (apply) - append two transfers', async t => {
|
|
|
62
62
|
await Promise.all(
|
|
63
63
|
[await waitForHash(writer2, first.hash), await waitForHash(writer2, second.hash)]
|
|
64
64
|
);
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
const firstResult = await writer2.msb.state.get(first.hash)
|
|
67
67
|
const secondResult = await writer2.msb.state.get(second.hash)
|
|
68
68
|
t.ok(firstResult, 'First result should not be null');
|
|
@@ -7,7 +7,7 @@ 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 {generatePostTx, randomBytes} from "
|
|
10
|
+
import {generatePostTx, randomBytes} from "../../helpers/setupApplyTests.js";
|
|
11
11
|
|
|
12
12
|
const msgTxoLength = 10;
|
|
13
13
|
const opType = OperationType.TX;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import sinon from "sinon";
|
|
2
2
|
import { hook, test } from 'brittle'
|
|
3
3
|
import { default as EventEmitter } from "bare-events"
|
|
4
|
-
import { testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5, testKeyPair6, testKeyPair7, testKeyPair8, testKeyPair9 } from "
|
|
5
|
-
import ConnectionManager from "
|
|
6
|
-
import { tick } from "
|
|
4
|
+
import { testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5, testKeyPair6, testKeyPair7, testKeyPair8, testKeyPair9 } from "../../fixtures/apply.fixtures.js";
|
|
5
|
+
import ConnectionManager from "../../../src/core/network/services/ConnectionManager.js";
|
|
6
|
+
import { tick } from "../../helpers/setupApplyTests.js";
|
|
7
7
|
import b4a from 'b4a'
|
|
8
8
|
|
|
9
9
|
const createConnection = (key) => {
|
|
@@ -13,7 +13,7 @@ const createConnection = (key) => {
|
|
|
13
13
|
}
|
|
14
14
|
emitter.connected = true
|
|
15
15
|
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
return { key: b4a.from(key, 'hex'), connection: emitter }
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -50,7 +50,7 @@ test('ConnectionManager', () => {
|
|
|
50
50
|
reset()
|
|
51
51
|
const connectionManager = makeManager()
|
|
52
52
|
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
const data = createConnection(testKeyPair5.publicKey)
|
|
55
55
|
connectionManager.addValidator(data.key, data.connection)
|
|
56
56
|
t.is(connectionManager.connectionCount(), connections.length + 1, 'should have the same length')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { bech32m } from 'bech32';
|
|
3
3
|
import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
|
|
4
|
-
import { TOKEN_DECIMALS } from '
|
|
4
|
+
import { TOKEN_DECIMALS } from '../../../src/utils/constants.js';
|
|
5
5
|
|
|
6
6
|
export function randomBuffer(size) {
|
|
7
7
|
return b4a.from(Array.from({ length: size }, () => Math.floor(Math.random() * 256)));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
import { TRAC_ADDRESS_SIZE } from '
|
|
3
|
+
import { TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
|
|
4
4
|
import { randomAddress } from '../stateTestUtils.js';
|
|
5
|
-
import addressUtils from '
|
|
5
|
+
import addressUtils from '../../../../src/core/state/utils/address.js';
|
|
6
6
|
|
|
7
7
|
test('Convert bech32m address to and from buffer - Happy Path', t => {
|
|
8
8
|
const hrp = 'test';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { test } from 'brittle';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
|
-
import { WRITER_BYTE_LENGTH, TRAC_ADDRESS_SIZE } from '
|
|
3
|
+
import { WRITER_BYTE_LENGTH, TRAC_ADDRESS_SIZE } from '../../../../src/utils/constants.js';
|
|
4
4
|
import { randomAddress, randomBuffer } from '../stateTestUtils.js';
|
|
5
|
-
import addressUtils from '
|
|
6
|
-
import adminEntryUtils from '
|
|
5
|
+
import addressUtils from '../../../../src/core/state/utils/address.js';
|
|
6
|
+
import adminEntryUtils from '../../../../src/core/state/utils/adminEntry.js';
|
|
7
7
|
|
|
8
8
|
const isAddressValid = addressUtils.isAddressValid;
|
|
9
9
|
const addressToBuffer = addressUtils.addressToBuffer;
|