trac-msb 0.2.17 → 0.2.19
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/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +33 -11
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +163 -14
- package/src/config/env.js +57 -25
- package/src/core/network/Network.js +121 -56
- package/src/core/network/protocols/LegacyProtocol.js +21 -11
- package/src/core/network/protocols/NetworkMessages.js +38 -17
- package/src/core/network/protocols/ProtocolInterface.js +15 -3
- package/src/core/network/protocols/ProtocolSession.js +144 -17
- package/src/core/network/protocols/V1Protocol.js +37 -18
- package/src/core/network/protocols/connectionPolicies.js +174 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
- package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
- package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
- package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
- package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +212 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
- package/src/core/network/services/ConnectionManager.js +149 -96
- package/src/core/network/services/MessageOrchestrator.js +197 -37
- package/src/core/network/services/PendingRequestService.js +175 -0
- package/src/core/network/services/TransactionCommitService.js +149 -0
- package/src/core/network/services/TransactionPoolService.js +129 -18
- package/src/core/network/services/TransactionRateLimiterService.js +57 -35
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +400 -121
- package/src/core/state/State.js +259 -156
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +320 -278
- package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/Scheduler.js +0 -8
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +78 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- package/src/utils/migrationUtils.js +3 -3
- package/src/utils/normalizers.js +38 -0
- package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
- package/src/utils/protobuf/operationHelpers.js +24 -3
- package/.dockerignore +0 -16
- package/.github/workflows/acceptance-tests.yml +0 -38
- package/.github/workflows/lint-pr-title.yml +0 -26
- package/.github/workflows/publish.yml +0 -33
- package/.github/workflows/unit-tests.yml +0 -34
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network.proto +0 -74
- package/rpc/rpc_services.js +0 -163
- package/scripts/generate-protobufs.js +0 -42
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/acceptance/v1/account/account.test.mjs +0 -123
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -111
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -85
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -276
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/ConnectionManager.test.js +0 -191
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/networkModule.test.js +0 -10
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -305
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -20
- package/whitelist/.gitkeep +0 -0
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { test } from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import PeerWallet from 'trac-wallet';
|
|
4
|
-
|
|
5
|
-
import ApplyStateMessageBuilder from '../../../../src/messages/state/ApplyStateMessageBuilder.js';
|
|
6
|
-
import { OperationType } from '../../../../src/utils/constants.js';
|
|
7
|
-
import { isHexString } from '../../../../src/utils/helpers.js';
|
|
8
|
-
import { config } from '../../../helpers/config.js';
|
|
9
|
-
import { testKeyPair1, testKeyPair2 } from '../../../fixtures/apply.fixtures.js';
|
|
10
|
-
import { isAddressValid } from '../../../../src/core/state/utils/address.js';
|
|
11
|
-
|
|
12
|
-
const hex = (value, bytes) => value.repeat(bytes);
|
|
13
|
-
|
|
14
|
-
async function createWallet(mnemonic) {
|
|
15
|
-
const wallet = new PeerWallet({
|
|
16
|
-
mnemonic,
|
|
17
|
-
networkPrefix: config.addressPrefix,
|
|
18
|
-
derivationPath: config.derivationPath
|
|
19
|
-
});
|
|
20
|
-
await wallet.ready;
|
|
21
|
-
return wallet;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function expectHexField(t, value, bytes, label) {
|
|
25
|
-
t.is(typeof value, 'string', `${label} type`);
|
|
26
|
-
t.is(value.length, bytes * 2, `${label} length`);
|
|
27
|
-
t.ok(isHexString(value), `${label} hex`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function expectAddressField(t, value, label) {
|
|
31
|
-
t.is(typeof value, 'string', `${label} type`);
|
|
32
|
-
t.is(value.length, config.addressLength, `${label} length`);
|
|
33
|
-
t.ok(isAddressValid(value, config.addressPrefix), `${label} valid`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function expectKeys(t, value, keys, label) {
|
|
37
|
-
t.alike(Object.keys(value).sort(), keys.slice().sort(), `${label} keys`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function expectPayloadKeys(t, payload, bodyKey) {
|
|
41
|
-
expectKeys(t, payload, ['type', 'address', bodyKey], 'payload');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
test('ApplyStateMessageBuilder partial add writer (rao)', async t => {
|
|
45
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
46
|
-
const txValidity = hex('11', 32);
|
|
47
|
-
const writingKey = hex('22', 32);
|
|
48
|
-
|
|
49
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
50
|
-
await builder
|
|
51
|
-
.setPhase('partial')
|
|
52
|
-
.setOutput('json')
|
|
53
|
-
.setOperationType(OperationType.ADD_WRITER)
|
|
54
|
-
.setAddress(wallet.address)
|
|
55
|
-
.setTxValidity(txValidity)
|
|
56
|
-
.setWriterKey(writingKey)
|
|
57
|
-
.build();
|
|
58
|
-
|
|
59
|
-
const payload = builder.getPayload();
|
|
60
|
-
t.is(payload.type, OperationType.ADD_WRITER);
|
|
61
|
-
t.is(payload.address, wallet.address);
|
|
62
|
-
expectAddressField(t, payload.address, 'address');
|
|
63
|
-
expectPayloadKeys(t, payload, 'rao');
|
|
64
|
-
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
65
|
-
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
66
|
-
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
67
|
-
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
68
|
-
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
69
|
-
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
70
|
-
t.is(payload.rao.txv, txValidity);
|
|
71
|
-
t.is(payload.rao.iw, writingKey);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('ApplyStateMessageBuilder partial remove writer (rao)', async t => {
|
|
75
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
76
|
-
const txValidity = hex('33', 32);
|
|
77
|
-
const writingKey = hex('44', 32);
|
|
78
|
-
|
|
79
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
80
|
-
await builder
|
|
81
|
-
.setPhase('partial')
|
|
82
|
-
.setOutput('json')
|
|
83
|
-
.setOperationType(OperationType.REMOVE_WRITER)
|
|
84
|
-
.setAddress(wallet.address)
|
|
85
|
-
.setTxValidity(txValidity)
|
|
86
|
-
.setWriterKey(writingKey)
|
|
87
|
-
.build();
|
|
88
|
-
|
|
89
|
-
const payload = builder.getPayload();
|
|
90
|
-
t.is(payload.type, OperationType.REMOVE_WRITER);
|
|
91
|
-
t.is(payload.address, wallet.address);
|
|
92
|
-
expectPayloadKeys(t, payload, 'rao');
|
|
93
|
-
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
94
|
-
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
95
|
-
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
96
|
-
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
97
|
-
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
98
|
-
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
99
|
-
t.is(payload.rao.txv, txValidity);
|
|
100
|
-
t.is(payload.rao.iw, writingKey);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('ApplyStateMessageBuilder partial admin recovery (rao)', async t => {
|
|
104
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
105
|
-
const txValidity = hex('55', 32);
|
|
106
|
-
const writingKey = hex('66', 32);
|
|
107
|
-
|
|
108
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
109
|
-
await builder
|
|
110
|
-
.setPhase('partial')
|
|
111
|
-
.setOutput('json')
|
|
112
|
-
.setOperationType(OperationType.ADMIN_RECOVERY)
|
|
113
|
-
.setAddress(wallet.address)
|
|
114
|
-
.setTxValidity(txValidity)
|
|
115
|
-
.setWriterKey(writingKey)
|
|
116
|
-
.build();
|
|
117
|
-
|
|
118
|
-
const payload = builder.getPayload();
|
|
119
|
-
t.is(payload.type, OperationType.ADMIN_RECOVERY);
|
|
120
|
-
t.is(payload.address, wallet.address);
|
|
121
|
-
expectPayloadKeys(t, payload, 'rao');
|
|
122
|
-
expectKeys(t, payload.rao, ['tx', 'txv', 'iw', 'in', 'is'], 'rao');
|
|
123
|
-
expectHexField(t, payload.rao.tx, 32, 'rao.tx');
|
|
124
|
-
expectHexField(t, payload.rao.txv, 32, 'rao.txv');
|
|
125
|
-
expectHexField(t, payload.rao.iw, 32, 'rao.iw');
|
|
126
|
-
expectHexField(t, payload.rao.in, 32, 'rao.in');
|
|
127
|
-
expectHexField(t, payload.rao.is, 64, 'rao.is');
|
|
128
|
-
t.is(payload.rao.txv, txValidity);
|
|
129
|
-
t.is(payload.rao.iw, writingKey);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('ApplyStateMessageBuilder partial bootstrap deployment (bdo)', async t => {
|
|
133
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
134
|
-
const txValidity = hex('77', 32);
|
|
135
|
-
const externalBootstrap = hex('88', 32);
|
|
136
|
-
const channel = hex('99', 32);
|
|
137
|
-
|
|
138
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
139
|
-
await builder
|
|
140
|
-
.setPhase('partial')
|
|
141
|
-
.setOutput('json')
|
|
142
|
-
.setOperationType(OperationType.BOOTSTRAP_DEPLOYMENT)
|
|
143
|
-
.setAddress(wallet.address)
|
|
144
|
-
.setTxValidity(txValidity)
|
|
145
|
-
.setExternalBootstrap(externalBootstrap)
|
|
146
|
-
.setChannel(channel)
|
|
147
|
-
.build();
|
|
148
|
-
|
|
149
|
-
const payload = builder.getPayload();
|
|
150
|
-
t.is(payload.type, OperationType.BOOTSTRAP_DEPLOYMENT);
|
|
151
|
-
t.is(payload.address, wallet.address);
|
|
152
|
-
expectPayloadKeys(t, payload, 'bdo');
|
|
153
|
-
expectKeys(t, payload.bdo, ['tx', 'txv', 'bs', 'ic', 'in', 'is'], 'bdo');
|
|
154
|
-
expectHexField(t, payload.bdo.tx, 32, 'bdo.tx');
|
|
155
|
-
expectHexField(t, payload.bdo.txv, 32, 'bdo.txv');
|
|
156
|
-
expectHexField(t, payload.bdo.bs, 32, 'bdo.bs');
|
|
157
|
-
expectHexField(t, payload.bdo.ic, 32, 'bdo.ic');
|
|
158
|
-
expectHexField(t, payload.bdo.in, 32, 'bdo.in');
|
|
159
|
-
expectHexField(t, payload.bdo.is, 64, 'bdo.is');
|
|
160
|
-
t.is(payload.bdo.txv, txValidity);
|
|
161
|
-
t.is(payload.bdo.bs, externalBootstrap);
|
|
162
|
-
t.is(payload.bdo.ic, channel);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('ApplyStateMessageBuilder partial transaction operation (txo)', async t => {
|
|
166
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
167
|
-
const txValidity = hex('aa', 32);
|
|
168
|
-
const writingKey = hex('bb', 32);
|
|
169
|
-
const contentHash = hex('cc', 32);
|
|
170
|
-
const externalBootstrap = hex('dd', 32);
|
|
171
|
-
const msbBootstrap = hex('ee', 32);
|
|
172
|
-
|
|
173
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
174
|
-
await builder
|
|
175
|
-
.setPhase('partial')
|
|
176
|
-
.setOutput('json')
|
|
177
|
-
.setOperationType(OperationType.TX)
|
|
178
|
-
.setAddress(wallet.address)
|
|
179
|
-
.setTxValidity(txValidity)
|
|
180
|
-
.setWriterKey(writingKey)
|
|
181
|
-
.setContentHash(contentHash)
|
|
182
|
-
.setExternalBootstrap(externalBootstrap)
|
|
183
|
-
.setMsbBootstrap(msbBootstrap)
|
|
184
|
-
.build();
|
|
185
|
-
|
|
186
|
-
const payload = builder.getPayload();
|
|
187
|
-
t.is(payload.type, OperationType.TX);
|
|
188
|
-
t.is(payload.address, wallet.address);
|
|
189
|
-
expectPayloadKeys(t, payload, 'txo');
|
|
190
|
-
expectKeys(t, payload.txo, ['tx', 'txv', 'iw', 'ch', 'bs', 'mbs', 'in', 'is'], 'txo');
|
|
191
|
-
expectHexField(t, payload.txo.tx, 32, 'txo.tx');
|
|
192
|
-
expectHexField(t, payload.txo.txv, 32, 'txo.txv');
|
|
193
|
-
expectHexField(t, payload.txo.iw, 32, 'txo.iw');
|
|
194
|
-
expectHexField(t, payload.txo.ch, 32, 'txo.ch');
|
|
195
|
-
expectHexField(t, payload.txo.bs, 32, 'txo.bs');
|
|
196
|
-
expectHexField(t, payload.txo.mbs, 32, 'txo.mbs');
|
|
197
|
-
expectHexField(t, payload.txo.in, 32, 'txo.in');
|
|
198
|
-
expectHexField(t, payload.txo.is, 64, 'txo.is');
|
|
199
|
-
t.is(payload.txo.txv, txValidity);
|
|
200
|
-
t.is(payload.txo.iw, writingKey);
|
|
201
|
-
t.is(payload.txo.ch, contentHash);
|
|
202
|
-
t.is(payload.txo.bs, externalBootstrap);
|
|
203
|
-
t.is(payload.txo.mbs, msbBootstrap);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('ApplyStateMessageBuilder partial transfer operation (tro)', async t => {
|
|
207
|
-
const wallet = await createWallet(testKeyPair1.mnemonic);
|
|
208
|
-
const otherWallet = await createWallet(testKeyPair2.mnemonic);
|
|
209
|
-
const txValidity = hex('ab', 32);
|
|
210
|
-
const amount = hex('cd', 16);
|
|
211
|
-
|
|
212
|
-
const builder = new ApplyStateMessageBuilder(wallet, config);
|
|
213
|
-
await builder
|
|
214
|
-
.setPhase('partial')
|
|
215
|
-
.setOutput('json')
|
|
216
|
-
.setOperationType(OperationType.TRANSFER)
|
|
217
|
-
.setAddress(wallet.address)
|
|
218
|
-
.setTxValidity(txValidity)
|
|
219
|
-
.setIncomingAddress(otherWallet.address)
|
|
220
|
-
.setAmount(amount)
|
|
221
|
-
.build();
|
|
222
|
-
|
|
223
|
-
const payload = builder.getPayload();
|
|
224
|
-
t.is(payload.type, OperationType.TRANSFER);
|
|
225
|
-
t.is(payload.address, wallet.address);
|
|
226
|
-
expectPayloadKeys(t, payload, 'tro');
|
|
227
|
-
expectKeys(t, payload.tro, ['tx', 'txv', 'to', 'am', 'in', 'is'], 'tro');
|
|
228
|
-
expectHexField(t, payload.tro.tx, 32, 'tro.tx');
|
|
229
|
-
expectHexField(t, payload.tro.txv, 32, 'tro.txv');
|
|
230
|
-
expectAddressField(t, payload.tro.to, 'tro.to');
|
|
231
|
-
expectHexField(t, payload.tro.am, 16, 'tro.am');
|
|
232
|
-
expectHexField(t, payload.tro.in, 32, 'tro.in');
|
|
233
|
-
expectHexField(t, payload.tro.is, 64, 'tro.is');
|
|
234
|
-
t.is(payload.tro.txv, txValidity);
|
|
235
|
-
t.is(payload.tro.to, otherWallet.address);
|
|
236
|
-
t.is(payload.tro.am, amount);
|
|
237
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import sinon from "sinon";
|
|
2
|
-
import { hook, test } from 'brittle'
|
|
3
|
-
import { default as EventEmitter } from "bare-events"
|
|
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
|
-
import b4a from 'b4a'
|
|
8
|
-
import { createConfig, ENV } from "../../../src/config/env.js";
|
|
9
|
-
|
|
10
|
-
const createConnection = (key) => {
|
|
11
|
-
const emitter = new EventEmitter()
|
|
12
|
-
emitter.protocolSession = {
|
|
13
|
-
has: (name) => name === 'legacy',
|
|
14
|
-
send: sinon.stub().resolves(),
|
|
15
|
-
};
|
|
16
|
-
emitter.connected = true
|
|
17
|
-
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
18
|
-
|
|
19
|
-
return { key: b4a.from(key, 'hex'), connection: emitter }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const makeManager = (maxValidators = 6, conns = connections) => {
|
|
23
|
-
const merged = createConfig(ENV.DEVELOPMENT, { maxValidators })
|
|
24
|
-
const connectionManager = new ConnectionManager(merged)
|
|
25
|
-
|
|
26
|
-
conns.forEach(({ key, connection }) => {
|
|
27
|
-
connectionManager.addValidator(key, connection)
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return connectionManager
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const reset = () => {
|
|
34
|
-
sinon.restore()
|
|
35
|
-
connections.forEach(connection => {
|
|
36
|
-
connection.connection.protocolSession.send.resetHistory()
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let connections
|
|
41
|
-
hook('Initialize state', async () => {
|
|
42
|
-
connections = [
|
|
43
|
-
createConnection(testKeyPair1.publicKey),
|
|
44
|
-
createConnection(testKeyPair2.publicKey),
|
|
45
|
-
createConnection(testKeyPair3.publicKey),
|
|
46
|
-
createConnection(testKeyPair4.publicKey),
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('ConnectionManager', () => {
|
|
51
|
-
test('addValidator', async t => {
|
|
52
|
-
test('adds a validator', async t => {
|
|
53
|
-
reset()
|
|
54
|
-
const connectionManager = makeManager()
|
|
55
|
-
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
56
|
-
const data = createConnection(testKeyPair5.publicKey)
|
|
57
|
-
connectionManager.addValidator(data.key, data.connection)
|
|
58
|
-
t.is(connectionManager.connectionCount(), connections.length + 1, 'should have the same length')
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('dont surpass maxConnections', async t => {
|
|
62
|
-
reset()
|
|
63
|
-
const maxConnections = 5
|
|
64
|
-
const connectionManager = makeManager(maxConnections)
|
|
65
|
-
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
66
|
-
|
|
67
|
-
const toAdd = createConnection(testKeyPair5.publicKey)
|
|
68
|
-
connectionManager.addValidator(toAdd.key, toAdd.connection)
|
|
69
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should match the max connections')
|
|
70
|
-
|
|
71
|
-
const toNotAdd = createConnection(testKeyPair6.publicKey)
|
|
72
|
-
connectionManager.addValidator(toNotAdd.key, toNotAdd.connection)
|
|
73
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should not increase length')
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('does not add new validator when pool is full', async t => {
|
|
77
|
-
reset()
|
|
78
|
-
const maxConnections = 2
|
|
79
|
-
const localConnections = [
|
|
80
|
-
createConnection(testKeyPair1.publicKey),
|
|
81
|
-
createConnection(testKeyPair2.publicKey),
|
|
82
|
-
]
|
|
83
|
-
|
|
84
|
-
const connectionManager = makeManager(maxConnections)
|
|
85
|
-
localConnections.forEach(({ key, connection }) => {
|
|
86
|
-
connectionManager.addValidator(key, connection)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'pool should be full')
|
|
90
|
-
|
|
91
|
-
const newConn = createConnection(testKeyPair3.publicKey)
|
|
92
|
-
connectionManager.addValidator(newConn.key, newConn.connection)
|
|
93
|
-
|
|
94
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should stay at max size')
|
|
95
|
-
t.not(connectionManager.connected(newConn.key), 'new validator should not be in the pool')
|
|
96
|
-
|
|
97
|
-
const remainingOld = localConnections.filter(c => connectionManager.connected(c.key)).length
|
|
98
|
-
t.is(remainingOld, 2, 'all of the old validators should remain')
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('connected', async t => {
|
|
103
|
-
test('true', async t => {
|
|
104
|
-
reset()
|
|
105
|
-
const connectionManager = makeManager()
|
|
106
|
-
connections.forEach(con => {
|
|
107
|
-
t.ok(connectionManager.connected(con.key), 'should respond true')
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('false', async t => {
|
|
112
|
-
reset()
|
|
113
|
-
const connectionManager = makeManager()
|
|
114
|
-
t.ok(!connectionManager.connected(testKeyPair6.publicKey), 'should respond false')
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
test('send', async t => {
|
|
119
|
-
test('triggers send on messenger', async t => {
|
|
120
|
-
reset()
|
|
121
|
-
const connectionManager = makeManager()
|
|
122
|
-
|
|
123
|
-
const target = connectionManager.send([1,2,3,4])
|
|
124
|
-
|
|
125
|
-
const totalCalls = connections.reduce((sum, con) => sum + con.connection.protocolSession.send.callCount, 0)
|
|
126
|
-
t.is(totalCalls, 1, 'should send to exactly one validator')
|
|
127
|
-
t.ok(target, 'should return a target public key')
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
test('does not throw on individual send errors', async t => {
|
|
131
|
-
reset()
|
|
132
|
-
const errorConnections = [
|
|
133
|
-
createConnection(testKeyPair7.publicKey),
|
|
134
|
-
createConnection(testKeyPair8.publicKey),
|
|
135
|
-
]
|
|
136
|
-
|
|
137
|
-
errorConnections.forEach(con => {
|
|
138
|
-
con.connection.protocolSession.send = sinon.stub().throws(new Error())
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const connectionManager = makeManager(5, errorConnections)
|
|
142
|
-
|
|
143
|
-
t.is(errorConnections.length, 2, 'should have two connections')
|
|
144
|
-
connectionManager.send([1,2,3,4])
|
|
145
|
-
t.ok(true, 'send should not throw even if individual sends fail')
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
test('on close', async t => {
|
|
150
|
-
test('removes from list', async t => {
|
|
151
|
-
reset()
|
|
152
|
-
const connectionManager = makeManager()
|
|
153
|
-
|
|
154
|
-
const connectionCount = connectionManager.connectionCount()
|
|
155
|
-
|
|
156
|
-
connections[1].connection.connected = false
|
|
157
|
-
connections[1].connection.emit('close')
|
|
158
|
-
await tick()
|
|
159
|
-
t.is(connectionCount, connectionManager.connectionCount() + 1, 'first on the list should have been called')
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test('remove', async t => {
|
|
164
|
-
test('removes a validator by public key', async t => {
|
|
165
|
-
reset()
|
|
166
|
-
const connectionManager = makeManager()
|
|
167
|
-
const previousCount = connectionManager.connectionCount()
|
|
168
|
-
const lastValidator = connections.shift()
|
|
169
|
-
|
|
170
|
-
t.ok(connectionManager.connected(lastValidator.key), 'should be connected')
|
|
171
|
-
connectionManager.remove(lastValidator.key)
|
|
172
|
-
|
|
173
|
-
t.is(connectionManager.connectionCount(), previousCount - 1, 'should reduce the connection count')
|
|
174
|
-
t.ok(!connectionManager.connected(lastValidator.key), 'should be connected')
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
test('on close', async t => {
|
|
179
|
-
test('removes from list', async t => {
|
|
180
|
-
reset()
|
|
181
|
-
const connectionManager = makeManager()
|
|
182
|
-
|
|
183
|
-
const connectionCount = connectionManager.connectionCount()
|
|
184
|
-
|
|
185
|
-
connections[1].connection.connected = false
|
|
186
|
-
connections[1].connection.emit('close')
|
|
187
|
-
await tick()
|
|
188
|
-
t.is(connectionCount, connectionManager.connectionCount() + 1, 'first on the list should have been called')
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
})
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { test } from 'brittle';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import b4a from 'b4a';
|
|
4
|
-
|
|
5
|
-
import PeerWallet from 'trac-wallet';
|
|
6
|
-
import NetworkWalletFactory, { EphemeralWallet } from '../../../src/core/network/identity/NetworkWalletFactory.js';
|
|
7
|
-
import { errorMessageIncludes } from '../../helpers/regexHelper.js';
|
|
8
|
-
import { testKeyPair1, testKeyPair2 } from '../../fixtures/apply.fixtures.js';
|
|
9
|
-
import { config } from '../../helpers/config.js';
|
|
10
|
-
|
|
11
|
-
test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
|
|
12
|
-
const publicKey = b4a.from(testKeyPair2.publicKey, 'hex');
|
|
13
|
-
const address = PeerWallet.encodeBech32m(config.addressPrefix, publicKey);
|
|
14
|
-
const signResult = b4a.from('abcd', 'hex');
|
|
15
|
-
const wallet = {
|
|
16
|
-
publicKey,
|
|
17
|
-
address,
|
|
18
|
-
sign: sinon.stub().returns(signResult),
|
|
19
|
-
verify: sinon.stub().returns(true)
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const provider = NetworkWalletFactory.provide({ wallet, enableWallet: true, networkPrefix: config.addressPrefix });
|
|
23
|
-
const message = b4a.from('00112233', 'hex');
|
|
24
|
-
const signature = provider.sign(message);
|
|
25
|
-
|
|
26
|
-
t.alike(provider.publicKey, publicKey);
|
|
27
|
-
t.is(provider.address, address);
|
|
28
|
-
t.alike(signature, signResult);
|
|
29
|
-
t.ok(wallet.sign.calledOnceWithExactly(message));
|
|
30
|
-
|
|
31
|
-
const verifyResult = provider.verify(signature, message);
|
|
32
|
-
t.ok(verifyResult);
|
|
33
|
-
t.ok(wallet.verify.calledOnceWithExactly(signature, message));
|
|
34
|
-
|
|
35
|
-
sinon.restore();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('NetworkWalletFactory.provide requires both public and secret keys when wallet disabled', async t => {
|
|
39
|
-
const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
|
|
40
|
-
await t.exception(
|
|
41
|
-
() => NetworkWalletFactory.provide({ enableWallet: false, keyPair: { publicKey }, networkPrefix: config.addressPrefix }),
|
|
42
|
-
errorMessageIncludes('keyPair with publicKey and secretKey is required')
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('NetworkWalletFactory.provide rejects non-buffer inputs', async t => {
|
|
47
|
-
const secretKey = b4a.from(testKeyPair1.secretKey, 'hex');
|
|
48
|
-
await t.exception(
|
|
49
|
-
() =>
|
|
50
|
-
NetworkWalletFactory.provide({
|
|
51
|
-
enableWallet: false,
|
|
52
|
-
keyPair: { publicKey: 'not-a-buffer', secretKey },
|
|
53
|
-
networkPrefix: config.addressPrefix
|
|
54
|
-
}),
|
|
55
|
-
errorMessageIncludes('must be a Buffer')
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('NetworkWalletFactory.provide propagates invalid public key length errors', async t => {
|
|
60
|
-
const secretKey = b4a.from(testKeyPair1.secretKey, 'hex');
|
|
61
|
-
const invalidPublicKey = b4a.alloc(10);
|
|
62
|
-
|
|
63
|
-
await t.exception(
|
|
64
|
-
() =>
|
|
65
|
-
NetworkWalletFactory.provide({
|
|
66
|
-
enableWallet: false,
|
|
67
|
-
keyPair: { publicKey: invalidPublicKey, secretKey },
|
|
68
|
-
networkPrefix: config.addressPrefix
|
|
69
|
-
}),
|
|
70
|
-
errorMessageIncludes('Invalid public key')
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('NetworkWalletFactory.provide derives address and signs payloads from keyPair', async t => {
|
|
75
|
-
const keyPair = {
|
|
76
|
-
publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
|
|
77
|
-
secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
|
|
78
|
-
};
|
|
79
|
-
const provider = NetworkWalletFactory.provide({
|
|
80
|
-
enableWallet: false,
|
|
81
|
-
keyPair,
|
|
82
|
-
networkPrefix: config.addressPrefix
|
|
83
|
-
});
|
|
84
|
-
const message = b4a.from('123455555', 'hex');
|
|
85
|
-
const signature = provider.sign(message);
|
|
86
|
-
|
|
87
|
-
t.is(
|
|
88
|
-
provider.address,
|
|
89
|
-
PeerWallet.encodeBech32m(config.addressPrefix, provider.publicKey)
|
|
90
|
-
);
|
|
91
|
-
t.ok(PeerWallet.verify(signature, message, provider.publicKey));
|
|
92
|
-
t.ok(provider.verify(signature, message));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('NetworkWalletFactory handles falsy address derivation results', async t => {
|
|
96
|
-
const keyPair = {
|
|
97
|
-
publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
|
|
98
|
-
secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const stub = sinon.stub(PeerWallet, 'encodeBech32m').returns(null);
|
|
102
|
-
await t.exception(
|
|
103
|
-
() =>
|
|
104
|
-
NetworkWalletFactory.provide({
|
|
105
|
-
enableWallet: false,
|
|
106
|
-
keyPair,
|
|
107
|
-
networkPrefix: config.addressPrefix
|
|
108
|
-
}),
|
|
109
|
-
errorMessageIncludes('failed to derive address')
|
|
110
|
-
);
|
|
111
|
-
stub.restore();
|
|
112
|
-
sinon.restore();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('NetworkWalletFactory propagates encoder exceptions', async t => {
|
|
116
|
-
const keyPair = {
|
|
117
|
-
publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
|
|
118
|
-
secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const stub = sinon.stub(PeerWallet, 'encodeBech32m').throws(new Error('test exception'));
|
|
122
|
-
await t.exception(
|
|
123
|
-
() =>
|
|
124
|
-
NetworkWalletFactory.provide({
|
|
125
|
-
enableWallet: false,
|
|
126
|
-
keyPair,
|
|
127
|
-
networkPrefix: config.addressPrefix
|
|
128
|
-
}),
|
|
129
|
-
errorMessageIncludes('test exception')
|
|
130
|
-
);
|
|
131
|
-
stub.restore();
|
|
132
|
-
sinon.restore();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('EphemeralWallet exposes wallet like interface', async t => {
|
|
136
|
-
const keyPair = {
|
|
137
|
-
publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
|
|
138
|
-
secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
|
|
139
|
-
};
|
|
140
|
-
const wallet = new EphemeralWallet(keyPair, config.addressPrefix);
|
|
141
|
-
const message = b4a.from('feedface', 'hex');
|
|
142
|
-
const signature = wallet.sign(message);
|
|
143
|
-
|
|
144
|
-
t.alike(wallet.publicKey, keyPair.publicKey);
|
|
145
|
-
t.is(wallet.address, PeerWallet.encodeBech32m(config.addressPrefix, keyPair.publicKey));
|
|
146
|
-
t.ok(PeerWallet.verify(signature, message, wallet.publicKey));
|
|
147
|
-
t.ok(wallet.verify(signature, message));
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('EphemeralWallet requires both public and secret keys', async t => {
|
|
151
|
-
const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
|
|
152
|
-
await t.exception(
|
|
153
|
-
() => new EphemeralWallet({ publicKey }, config.addressPrefix),
|
|
154
|
-
errorMessageIncludes('keyPair with publicKey and secretKey is required')
|
|
155
|
-
);
|
|
156
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { test, hook } from 'brittle';
|
|
2
|
-
import { encode, decode, ZERO_BALANCE } from '../../src/core/state/utils/nodeEntry.js';
|
|
3
|
-
import esmock from "esmock";
|
|
4
|
-
import sinon from "sinon";
|
|
5
|
-
import { randomBuffer, tokenUnits } from './stateTestUtils.js';
|
|
6
|
-
import { WRITER_BYTE_LENGTH, ADMIN_INITIAL_BALANCE } from '../../src/utils/constants.js';
|
|
7
|
-
import { $TNK, toBalance } from '../../src/core/state/utils/balance.js';
|
|
8
|
-
import b4a from 'b4a'
|
|
9
|
-
|
|
10
|
-
let state
|
|
11
|
-
hook('Initialize state', async () => {
|
|
12
|
-
const checkout = sinon.stub().returns({ get: () => {
|
|
13
|
-
return { value: encode({
|
|
14
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
15
|
-
isWhitelisted: true,
|
|
16
|
-
isWriter: true,
|
|
17
|
-
isIndexer: true,
|
|
18
|
-
balance: ADMIN_INITIAL_BALANCE })
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const AutoBaseMock = sinon.stub().returns({ view: { checkout, core: { signedLength: 1 }} });
|
|
24
|
-
const State = await esmock('../../src/core/state/State.js', {
|
|
25
|
-
"autobase": AutoBaseMock
|
|
26
|
-
});
|
|
27
|
-
state = new State(null, null, null)
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('State#incrementBalance', () => {
|
|
31
|
-
test('adds two balances and produce a node entry', async t => {
|
|
32
|
-
const entry = await state.incrementBalance('adminAddress', $TNK(150n))
|
|
33
|
-
t.is(toBalance(decode(entry).balance).asBigInt(), tokenUnits(1150n), 'balance matches');
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('do not add zero', async t => {
|
|
37
|
-
const entry = await state.incrementBalance('adminAddress', $TNK(0n))
|
|
38
|
-
t.is(entry, null, 'entry is null');
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('null entry', async t => {
|
|
42
|
-
const AutoBaseMock = sinon.stub().returns({ view: { checkout: sinon.stub().returns({ get: () => ({ value: null }) }), core: { signedLength: 1 }} });
|
|
43
|
-
const State = await esmock('../../src/core/state/State.js', {
|
|
44
|
-
"autobase": AutoBaseMock
|
|
45
|
-
});
|
|
46
|
-
const entry = await new State(null, null, null).incrementBalance('adminAddress', $TNK(150n))
|
|
47
|
-
t.is(entry, null, 'entry is null');
|
|
48
|
-
})
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('State#derementBalance', async t => {
|
|
52
|
-
test('subtract two balances and produce a node entry', async t => {
|
|
53
|
-
const entry = await state.decrementBalance('adminAddress', $TNK(150n))
|
|
54
|
-
t.is(toBalance(decode(entry).balance).asBigInt(), tokenUnits(850n), 'balance matches');
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('do not subtract zero', async t => {
|
|
58
|
-
const entry = await state.decrementBalance('adminAddress', $TNK(0n))
|
|
59
|
-
t.is(entry, null, 'entry is null');
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('do not produce negative balance', async t => {
|
|
63
|
-
const entry = await state.decrementBalance('adminAddress', $TNK(1001n))
|
|
64
|
-
t.is(entry, null, 'entry is null');
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('can zero balance', async t => {
|
|
68
|
-
const entry = await state.decrementBalance('adminAddress', $TNK(1000n))
|
|
69
|
-
t.ok(b4a.equals(decode(entry).balance, ZERO_BALANCE), 'balance matches');
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('null entry', async t => {
|
|
73
|
-
const AutoBaseMock = sinon.stub().returns({ view: { checkout: sinon.stub().returns({ get: () => ({ value: null }) }), core: { signedLength: 1 }} });
|
|
74
|
-
const State = await esmock('../../src/core/state/State.js', {
|
|
75
|
-
"autobase": AutoBaseMock
|
|
76
|
-
});
|
|
77
|
-
const entry = await new State(null, null, null).decrementBalance('adminAddress', $TNK(150n))
|
|
78
|
-
t.is(entry, null, 'entry is null');
|
|
79
|
-
})
|
|
80
|
-
});
|