trac-msb 0.2.18 → 0.2.20
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 +25 -8
- 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 +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +130 -34
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- 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 +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- 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 +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- 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/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- 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/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- 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 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- 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 -59
- 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 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- 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/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- 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/deepEqualApplyPayload/deepEqualApplyPayload.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 -303
- 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 -21
- package/whitelist/.gitkeep +0 -0
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { test } from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import { randomBuffer, TEN_THOUSAND_VALUE, tokenUnits } from '../stateTestUtils.js';
|
|
4
|
-
import { ZERO_BALANCE, decode, encode } from '../../../../src/core/state/utils/nodeEntry.js';
|
|
5
|
-
import { WRITER_BYTE_LENGTH, ADMIN_INITIAL_BALANCE, BALANCE_BYTE_LENGTH } from '../../../../src/utils/constants.js';
|
|
6
|
-
import { $TNK, toBalance, toTerm, percent } from '../../../../src/core/state/utils/balance.js';
|
|
7
|
-
import { bufferToBigInt } from '../../../../src/utils/amountSerialization.js';
|
|
8
|
-
import { ZERO_LICENSE } from '../../../../src/core/state/utils/nodeEntry.js';
|
|
9
|
-
test('Balance#asHex explicit', t => {
|
|
10
|
-
const val = $TNK(1000n)
|
|
11
|
-
t.is(toBalance(val).asHex(), b4a.toString(val, 'hex'), 'hex matches')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('Balance#add', () => {
|
|
15
|
-
test('with zero', t => {
|
|
16
|
-
const node = {
|
|
17
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
18
|
-
isWhitelisted: true,
|
|
19
|
-
isWriter: true,
|
|
20
|
-
isIndexer: false,
|
|
21
|
-
balance: ZERO_BALANCE,
|
|
22
|
-
license: ZERO_LICENSE,
|
|
23
|
-
stakedBalance: ZERO_BALANCE
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const balance = toBalance(node.balance)
|
|
27
|
-
const addedBalance = balance.add(toBalance(TEN_THOUSAND_VALUE))
|
|
28
|
-
|
|
29
|
-
const encoded = encode(node)
|
|
30
|
-
addedBalance.update(encoded)
|
|
31
|
-
|
|
32
|
-
const updated = decode(encoded)
|
|
33
|
-
console.log("updated", updated)
|
|
34
|
-
t.ok(b4a.equals(updated.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('other stuff', t => {
|
|
38
|
-
const node = {
|
|
39
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
40
|
-
isWhitelisted: true,
|
|
41
|
-
isWriter: true,
|
|
42
|
-
isIndexer: false,
|
|
43
|
-
balance: TEN_THOUSAND_VALUE
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const balance = toBalance(node.balance)
|
|
47
|
-
const addedBalance = balance.add(toBalance(TEN_THOUSAND_VALUE))
|
|
48
|
-
t.is(addedBalance.asHex(), '00000000000000000000000000004e20', 'balance matches');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('overflow returns NULL_BUFFER', t => {
|
|
52
|
-
const max = b4a.alloc(BALANCE_BYTE_LENGTH, 0xFF);
|
|
53
|
-
const balance = toBalance(max);
|
|
54
|
-
|
|
55
|
-
const oneRaw = b4a.alloc(BALANCE_BYTE_LENGTH);
|
|
56
|
-
oneRaw[oneRaw.length - 1] = 1; // +1
|
|
57
|
-
|
|
58
|
-
const result = balance.add(toBalance(oneRaw));
|
|
59
|
-
|
|
60
|
-
// Should return null-like buffer on overflow
|
|
61
|
-
t.is(result, null, 'overflow returns null');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('edge case: max - 1 + 1 = max', t => {
|
|
65
|
-
const maxMinusOne = b4a.alloc(BALANCE_BYTE_LENGTH, 0xFF);
|
|
66
|
-
maxMinusOne[maxMinusOne.length - 1] = 0xFE;
|
|
67
|
-
const balance = toBalance(maxMinusOne);
|
|
68
|
-
|
|
69
|
-
const oneRaw = b4a.alloc(BALANCE_BYTE_LENGTH);
|
|
70
|
-
oneRaw[oneRaw.length - 1] = 1;
|
|
71
|
-
|
|
72
|
-
const result = balance.add(toBalance(oneRaw));
|
|
73
|
-
|
|
74
|
-
// Should equal max value
|
|
75
|
-
const expected = b4a.alloc(BALANCE_BYTE_LENGTH, 0xFF);
|
|
76
|
-
t.ok(b4a.equals(result.value, expected), 'max - 1 + 1 = max');
|
|
77
|
-
});
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('Balance#sub', () => {
|
|
81
|
-
test('with zero', t => {
|
|
82
|
-
const node = {
|
|
83
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
84
|
-
isWhitelisted: true,
|
|
85
|
-
isWriter: true,
|
|
86
|
-
isIndexer: false,
|
|
87
|
-
balance: TEN_THOUSAND_VALUE,
|
|
88
|
-
license: ZERO_LICENSE,
|
|
89
|
-
stakedBalance: ZERO_BALANCE
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const balance = toBalance(node.balance)
|
|
93
|
-
const subBalance = balance.sub(toBalance(ZERO_BALANCE))
|
|
94
|
-
|
|
95
|
-
const encoded = encode(node)
|
|
96
|
-
subBalance.update(encoded)
|
|
97
|
-
|
|
98
|
-
const updated = decode(encoded)
|
|
99
|
-
t.ok(b4a.equals(updated.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test('zero from value', t => {
|
|
103
|
-
const node = {
|
|
104
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
105
|
-
isWhitelisted: true,
|
|
106
|
-
isWriter: true,
|
|
107
|
-
isIndexer: false,
|
|
108
|
-
balance: TEN_THOUSAND_VALUE,
|
|
109
|
-
license: ZERO_LICENSE,
|
|
110
|
-
stakedBalance: ZERO_BALANCE
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const balance = toBalance(node.balance)
|
|
114
|
-
const subBalance = balance.sub(toBalance(ZERO_BALANCE))
|
|
115
|
-
|
|
116
|
-
const encoded = encode(node)
|
|
117
|
-
subBalance.update(encoded)
|
|
118
|
-
|
|
119
|
-
const updated = decode(encoded)
|
|
120
|
-
t.ok(b4a.equals(updated.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('underflow returns NULL_BUFFER', t => {
|
|
124
|
-
const a = $TNK(1000n);
|
|
125
|
-
const b = $TNK(2000n);
|
|
126
|
-
const result = toBalance(a).sub(toBalance(b));
|
|
127
|
-
|
|
128
|
-
// Should return null-like buffer on underflow
|
|
129
|
-
t.is(result, null, 'overflow returns null');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('edge case: equal amounts = zero', t => {
|
|
133
|
-
const a = $TNK(5000n);
|
|
134
|
-
const b = $TNK(5000n);
|
|
135
|
-
const result = toBalance(a).sub(toBalance(b));
|
|
136
|
-
|
|
137
|
-
const expected = b4a.alloc(BALANCE_BYTE_LENGTH); // all zeros
|
|
138
|
-
t.ok(b4a.equals(result.value, expected), 'equal amounts subtract to zero');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('edge case: one less than a', t => {
|
|
142
|
-
const a = $TNK(1000n);
|
|
143
|
-
const b = $TNK(999n);
|
|
144
|
-
const result = toBalance(a).sub(toBalance(b));
|
|
145
|
-
|
|
146
|
-
const expected = $TNK(1n);
|
|
147
|
-
t.ok(b4a.equals(result.value, expected), 'subtracting 999 from 1000 gives 1');
|
|
148
|
-
});
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test('Balance#mul', () => {
|
|
152
|
-
test('basic multiplication', t => {
|
|
153
|
-
const a = $TNK(1000n);
|
|
154
|
-
const result = toBalance(a).mul(toTerm(4n));
|
|
155
|
-
|
|
156
|
-
// Should return null-like buffer on underflow
|
|
157
|
-
t.ok(toBalance($TNK(4000n)).equals(result), 'equal 4000n');
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('zero multiplication', t => {
|
|
161
|
-
const a = $TNK(4000n);
|
|
162
|
-
const result = toBalance(a).mul(toTerm(0n));
|
|
163
|
-
|
|
164
|
-
// Should return null-like buffer on underflow
|
|
165
|
-
t.ok(result.equals(toBalance($TNK(0n))), 'returns zero');
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test('zero value multiplication', t => {
|
|
169
|
-
const a = toBalance($TNK(0n));
|
|
170
|
-
const result = a.mul(toTerm(1000n));
|
|
171
|
-
|
|
172
|
-
// Should return null-like buffer on underflow
|
|
173
|
-
t.ok(result.equals(toBalance($TNK(0n))), 'returns zero');
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
test('zero value multiplication', t => {
|
|
177
|
-
const a = toBalance($TNK(0n));
|
|
178
|
-
const result = a.mul(toTerm(1000n));
|
|
179
|
-
|
|
180
|
-
// Should return null-like buffer on underflow
|
|
181
|
-
t.ok(result.equals(toBalance($TNK(0n))), 'returns zero');
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
test('overflow returns NULL_BUFFER', t => {
|
|
185
|
-
const max = b4a.alloc(BALANCE_BYTE_LENGTH, 0xFF);
|
|
186
|
-
const balance = toBalance(max);
|
|
187
|
-
|
|
188
|
-
const balance2 = toBalance(max);
|
|
189
|
-
|
|
190
|
-
const result = balance.mul(balance2);
|
|
191
|
-
|
|
192
|
-
// Should return null-like buffer on overflow
|
|
193
|
-
t.is(result, null, 'overflow returns null');
|
|
194
|
-
});
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
test('Balance#div', () => {
|
|
198
|
-
test('basic division', t => {
|
|
199
|
-
const a = $TNK(4000n);
|
|
200
|
-
const result = toBalance(a).div(toTerm(4n));
|
|
201
|
-
|
|
202
|
-
// Should return null-like buffer on underflow
|
|
203
|
-
t.ok(toBalance($TNK(1000n)).equals(result), 'equal 1000n');
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
test('zero division', t => {
|
|
207
|
-
const a = $TNK(4000n);
|
|
208
|
-
const result = toBalance(a).div(toTerm(0n));
|
|
209
|
-
|
|
210
|
-
// Should return null-like buffer on underflow
|
|
211
|
-
t.is(result, null, 'returns null');
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test('zero value division', t => {
|
|
215
|
-
const a = toBalance($TNK(0n));
|
|
216
|
-
const result = a.div(toTerm(1000n));
|
|
217
|
-
|
|
218
|
-
// Should return null-like buffer on underflow
|
|
219
|
-
t.ok(result.equals(toBalance($TNK(0n))), 'returns 0');
|
|
220
|
-
})
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
test('Balance#percentage', () => {
|
|
224
|
-
test('basic percentage', t => {
|
|
225
|
-
const a = $TNK(1000n);
|
|
226
|
-
const result = toBalance(a).percentage(percent(4));
|
|
227
|
-
|
|
228
|
-
// Should return null-like buffer on underflow
|
|
229
|
-
t.ok(toBalance($TNK(40n)).equals(result), 'equal 40n');
|
|
230
|
-
})
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
test('toTerm', t => {
|
|
234
|
-
const converted = bufferToBigInt(toTerm(4n))
|
|
235
|
-
t.is(converted, 4n, 'overflow returns null');
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
test('Balance#asBigInt', t => {
|
|
239
|
-
const node = {
|
|
240
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
241
|
-
isWhitelisted: true,
|
|
242
|
-
isWriter: true,
|
|
243
|
-
isIndexer: false,
|
|
244
|
-
balance: TEN_THOUSAND_VALUE
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const balance = toBalance(node.balance)
|
|
248
|
-
const addedBalance = balance.add(toBalance(TEN_THOUSAND_VALUE))
|
|
249
|
-
t.is(addedBalance.asBigInt(), 20_000n, 'balance matches');
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test('Balance#greaterThan', t => {
|
|
253
|
-
const $TNK1000 = $TNK(1000n)
|
|
254
|
-
const $TNK1001 = $TNK(1001n)
|
|
255
|
-
|
|
256
|
-
t.not(toBalance($TNK1000).greaterThan(toBalance($TNK1001)), '1000 not greater than 1001');
|
|
257
|
-
t.ok(toBalance($TNK1001).greaterThan(toBalance($TNK1000)), '1001 greater than 1000');
|
|
258
|
-
t.not(toBalance($TNK1000).greaterThan(toBalance($TNK1000)), '1000 not greater than 1000');
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test('Balance#lowerThan', t => {
|
|
262
|
-
const $TNK1000 = $TNK(1000n)
|
|
263
|
-
const $TNK1001 = $TNK(1001n)
|
|
264
|
-
|
|
265
|
-
t.not(toBalance($TNK1001).lowerThan(toBalance($TNK1000)), '1001 not lower than 1000');
|
|
266
|
-
t.ok(toBalance($TNK1000).lowerThan(toBalance($TNK1001)), '1000 lower than 1001');
|
|
267
|
-
t.not(toBalance($TNK1000).lowerThan(toBalance($TNK1000)), '1000 not lower than 1000');
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
test('Balance#equals', t => {
|
|
271
|
-
const $TNK1000 = $TNK(1000n)
|
|
272
|
-
|
|
273
|
-
t.ok(toBalance($TNK1000).equals(toBalance($TNK1000)), '1000 equals 1000');
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test('Balance $TNK', t => {
|
|
277
|
-
const $TNK300 = $TNK(300n)
|
|
278
|
-
const converted = toBalance($TNK300).asBigInt()
|
|
279
|
-
t.is(converted, tokenUnits(300n), 'balance matches');
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test('Node entry integration', t => {
|
|
283
|
-
const entry = encode({
|
|
284
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
285
|
-
isWhitelisted: true,
|
|
286
|
-
isWriter: true,
|
|
287
|
-
isIndexer: true,
|
|
288
|
-
balance: ADMIN_INITIAL_BALANCE,
|
|
289
|
-
license: b4a.from([0, 0, 0, 1]),
|
|
290
|
-
stakedBalance: TEN_THOUSAND_VALUE
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const decoded = decode(entry)
|
|
294
|
-
|
|
295
|
-
const updated = toBalance(decoded.balance)
|
|
296
|
-
.add(toBalance($TNK(300n)))
|
|
297
|
-
.update(encode(decoded))
|
|
298
|
-
|
|
299
|
-
t.is(toBalance(decode(updated).balance).asBigInt(), tokenUnits(1300n), 'balance matches');
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
test('Balance#greaterThanOrEquals', t => {
|
|
303
|
-
const b1000 = toBalance($TNK(1000n))
|
|
304
|
-
const b1001 = toBalance($TNK(1001n))
|
|
305
|
-
const b1000Dup = toBalance($TNK(1000n))
|
|
306
|
-
|
|
307
|
-
t.ok(b1001.greaterThanOrEquals(b1000), '1001 >= 1000')
|
|
308
|
-
t.ok(b1000.greaterThanOrEquals(b1000Dup), '1000 >= 1000')
|
|
309
|
-
t.ok(!b1000.greaterThanOrEquals(b1001), '1000 !>= 1001')
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
test('Balance#lowerThanOrEquals', t => {
|
|
313
|
-
const b1000 = toBalance($TNK(1000n))
|
|
314
|
-
const b1001 = toBalance($TNK(1001n))
|
|
315
|
-
const b1000Dup = toBalance($TNK(1000n))
|
|
316
|
-
|
|
317
|
-
t.ok(b1000.lowerThanOrEquals(b1001), '1000 <= 1001')
|
|
318
|
-
t.ok(b1000.lowerThanOrEquals(b1000Dup), '1000 <= 1000')
|
|
319
|
-
t.ok(!b1001.lowerThanOrEquals(b1000), '1001 !<= 1000')
|
|
320
|
-
})
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import test from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import lengthEntry from '../../../../src/core/state/utils/lengthEntry.js';
|
|
4
|
-
|
|
5
|
-
// Test init()
|
|
6
|
-
test('Length Entry - init returns a 4-byte buffer initialized to 0', t => {
|
|
7
|
-
const buf = lengthEntry.init();
|
|
8
|
-
t.ok(b4a.isBuffer(buf), 'should return a buffer');
|
|
9
|
-
t.is(buf.length, 4, 'buffer should be 4 bytes');
|
|
10
|
-
t.alike(buf, b4a.alloc(4, 0x00), 'buffer should be all zeros');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// Test encode()
|
|
14
|
-
test('Length Entry - encode encodes integer to 4-byte buffer (Little Endian)', t => {
|
|
15
|
-
const value = 123456;
|
|
16
|
-
const buf = lengthEntry.encode(value);
|
|
17
|
-
t.ok(b4a.isBuffer(buf), 'should return a buffer');
|
|
18
|
-
t.is(buf.length, 4, 'buffer should be 4 bytes');
|
|
19
|
-
t.is(buf.readUInt32LE(), value, 'buffer should decode to original value');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('Length Entry - encode(0) returns buffer of all zeros', t => {
|
|
23
|
-
const buf = lengthEntry.encode(0);
|
|
24
|
-
t.alike(buf, b4a.alloc(4, 0x00));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Test decode()
|
|
28
|
-
test('Length Entry - decode decodes 4-byte buffer to integer (LE)', t => {
|
|
29
|
-
const value = 987654;
|
|
30
|
-
const buf = b4a.alloc(4);
|
|
31
|
-
buf.writeUInt32LE(value);
|
|
32
|
-
t.is(lengthEntry.decode(buf), value);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// TODO: This test was deactivated because, currently, all function in lengthEntry.js can throw.
|
|
36
|
-
// When this behaviour is corrected, we should reactivate this test
|
|
37
|
-
// TODO: Also, implement other tests like this one for other functions in lengthEntry.js
|
|
38
|
-
|
|
39
|
-
// test('Length Entry - decode doesn\'t throw if buffer is too short', t => {
|
|
40
|
-
// const shortBuf = b4a.alloc(2);
|
|
41
|
-
// t.is(lengthEntry.decode(shortBuf), 0);
|
|
42
|
-
// });
|
|
43
|
-
|
|
44
|
-
// Test increment()
|
|
45
|
-
test('Length Entry - increment returns buffer with value+1', t => {
|
|
46
|
-
const value = 42;
|
|
47
|
-
const buf = lengthEntry.increment(value);
|
|
48
|
-
t.is(buf.readUInt32LE(), value + 1);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('Length Entry - increment(0) returns buffer with value 1', t => {
|
|
52
|
-
const buf = lengthEntry.increment(0);
|
|
53
|
-
t.is(buf.readUInt32LE(), 1);
|
|
54
|
-
});
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { test } from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import { WRITER_BYTE_LENGTH, LICENSE_BYTE_LENGTH } from '../../../../src/utils/constants.js';
|
|
4
|
-
import { randomBuffer, TEN_THOUSAND_VALUE } from '../stateTestUtils.js';
|
|
5
|
-
import { NodeRole } from '../../../../src/core/state/utils/roles.js';
|
|
6
|
-
import {
|
|
7
|
-
ZERO_BALANCE,
|
|
8
|
-
ZERO_LICENSE,
|
|
9
|
-
NODE_ENTRY_SIZE,
|
|
10
|
-
init as initNodeEntry,
|
|
11
|
-
encode as encodeNodeEntry,
|
|
12
|
-
decode as decodeNodeEntry,
|
|
13
|
-
setRole as setNodeEntryRole,
|
|
14
|
-
setBalance as setNodeEntryBalance,
|
|
15
|
-
setLicense as setNodeEntryLicense,
|
|
16
|
-
setStakedBalance as setNodeEntryStakedBalance,
|
|
17
|
-
} from '../../../../src/core/state/utils/nodeEntry.js';
|
|
18
|
-
|
|
19
|
-
// Test init()
|
|
20
|
-
test('Node Entry - init - Happy Path', t => {
|
|
21
|
-
const wk = randomBuffer(WRITER_BYTE_LENGTH)
|
|
22
|
-
const initialized = initNodeEntry(wk, NodeRole.WHITELISTED)
|
|
23
|
-
|
|
24
|
-
t.is(initialized.length, NODE_ENTRY_SIZE, "initialized has valid length");
|
|
25
|
-
const decoded = decodeNodeEntry(initialized);
|
|
26
|
-
t.ok(decoded, 'decoded should not be null');
|
|
27
|
-
t.ok(b4a.equals(decoded.wk, wk), 'wk matches');
|
|
28
|
-
t.is(decoded.isWhitelisted, true, 'isWhitelisted matches');
|
|
29
|
-
t.is(decoded.isWriter, false, 'isWriter matches');
|
|
30
|
-
t.is(decoded.isIndexer, false, 'isIndexer matches');
|
|
31
|
-
t.ok(b4a.equals(decoded.balance, ZERO_BALANCE), 'balance matches');
|
|
32
|
-
t.ok(b4a.equals(decoded.license, ZERO_LICENSE), 'license matches');
|
|
33
|
-
t.ok(b4a.equals(decoded.stakedBalance, ZERO_BALANCE), 'stakedBalance matches');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('Node Entry - init - Happy Path with balance', t => {
|
|
37
|
-
const wk = randomBuffer(WRITER_BYTE_LENGTH)
|
|
38
|
-
const initialized = initNodeEntry(wk, NodeRole.WHITELISTED, TEN_THOUSAND_VALUE)
|
|
39
|
-
|
|
40
|
-
t.is(initialized.length, NODE_ENTRY_SIZE, "initialized has valid length");
|
|
41
|
-
const decoded = decodeNodeEntry(initialized);
|
|
42
|
-
t.ok(decoded, 'decoded should not be null');
|
|
43
|
-
t.ok(b4a.equals(decoded.wk, wk), 'wk matches');
|
|
44
|
-
t.is(decoded.isWhitelisted, true, 'isWhitelisted matches');
|
|
45
|
-
t.is(decoded.isWriter, false, 'isWriter matches');
|
|
46
|
-
t.is(decoded.isIndexer, false, 'isIndexer matches');
|
|
47
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('Node Entry - init - Happy Path with licesnse', t => {
|
|
51
|
-
const wk = randomBuffer(WRITER_BYTE_LENGTH)
|
|
52
|
-
const license = randomBuffer(LICENSE_BYTE_LENGTH)
|
|
53
|
-
const initialized = initNodeEntry(wk, NodeRole.WHITELISTED, TEN_THOUSAND_VALUE, license)
|
|
54
|
-
|
|
55
|
-
t.is(initialized.length, NODE_ENTRY_SIZE, "initialized has valid length");
|
|
56
|
-
const decoded = decodeNodeEntry(initialized);
|
|
57
|
-
t.ok(decoded, 'decoded should not be null');
|
|
58
|
-
t.ok(b4a.equals(decoded.wk, wk), 'wk matches');
|
|
59
|
-
t.is(decoded.isWhitelisted, true, 'isWhitelisted matches');
|
|
60
|
-
t.is(decoded.isWriter, false, 'isWriter matches');
|
|
61
|
-
t.is(decoded.isIndexer, false, 'isIndexer matches');
|
|
62
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
63
|
-
t.ok(b4a.equals(decoded.license, license), 'license matches');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('Node Entry - init - Happy Path with staked balance', t => {
|
|
67
|
-
const wk = randomBuffer(WRITER_BYTE_LENGTH)
|
|
68
|
-
const license = randomBuffer(LICENSE_BYTE_LENGTH)
|
|
69
|
-
const initialized = initNodeEntry(wk, NodeRole.WHITELISTED, TEN_THOUSAND_VALUE, license, TEN_THOUSAND_VALUE)
|
|
70
|
-
|
|
71
|
-
t.is(initialized.length, NODE_ENTRY_SIZE, "initialized has valid length");
|
|
72
|
-
const decoded = decodeNodeEntry(initialized);
|
|
73
|
-
t.ok(decoded, 'decoded should not be null');
|
|
74
|
-
t.ok(b4a.equals(decoded.wk, wk), 'wk matches');
|
|
75
|
-
t.is(decoded.isWhitelisted, true, 'isWhitelisted matches');
|
|
76
|
-
t.is(decoded.isWriter, false, 'isWriter matches');
|
|
77
|
-
t.is(decoded.isIndexer, false, 'isIndexer matches');
|
|
78
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance matches');
|
|
79
|
-
t.ok(b4a.equals(decoded.license, license), 'license matches');
|
|
80
|
-
t.ok(b4a.equals(decoded.stakedBalance, TEN_THOUSAND_VALUE), 'stakedBalance matches');
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Test encode()
|
|
85
|
-
test('Node Entry - encode and decode - Happy Path', t => {
|
|
86
|
-
const node = {
|
|
87
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
88
|
-
isWhitelisted: true,
|
|
89
|
-
isWriter: true,
|
|
90
|
-
isIndexer: false,
|
|
91
|
-
balance: ZERO_BALANCE,
|
|
92
|
-
license: ZERO_LICENSE,
|
|
93
|
-
stakedBalance: ZERO_BALANCE
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const encoded = encodeNodeEntry(node);
|
|
97
|
-
t.is(encoded.length, NODE_ENTRY_SIZE, "encoding has valid length");
|
|
98
|
-
|
|
99
|
-
const decoded = decodeNodeEntry(encoded);
|
|
100
|
-
t.ok(decoded, 'decoded should not be null');
|
|
101
|
-
t.ok(b4a.equals(decoded.wk, node.wk), 'wk matches');
|
|
102
|
-
t.is(decoded.isWhitelisted, true, 'isWhitelisted matches');
|
|
103
|
-
t.is(decoded.isWriter, true, 'isWriter matches');
|
|
104
|
-
t.is(decoded.isIndexer, false, 'isIndexer matches');
|
|
105
|
-
t.ok(b4a.equals(decoded.balance, ZERO_BALANCE), 'balance matches');
|
|
106
|
-
t.ok(b4a.equals(decoded.license, ZERO_LICENSE), 'license matches');
|
|
107
|
-
t.ok(b4a.equals(decoded.stakedBalance, ZERO_BALANCE), 'stakedBalance matches');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('Node Entry - encode returns empty buffer on invalid wk', t => {
|
|
111
|
-
const node = {
|
|
112
|
-
wk: randomBuffer(10), // invalid size
|
|
113
|
-
isWhitelisted: false,
|
|
114
|
-
isWriter: false,
|
|
115
|
-
isIndexer: false,
|
|
116
|
-
balance: ZERO_BALANCE,
|
|
117
|
-
license: ZERO_LICENSE,
|
|
118
|
-
stakedBalance: ZERO_BALANCE
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
const encoded = encodeNodeEntry(node);
|
|
122
|
-
t.is(encoded.length, 0);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('Node Entry - encode returns empty buffer on invalid node role', t => {
|
|
126
|
-
const node = {
|
|
127
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
128
|
-
isWhitelisted: false,
|
|
129
|
-
isWriter: true, // can't be a writer without being whitelisted
|
|
130
|
-
isIndexer: false,
|
|
131
|
-
balance: ZERO_BALANCE
|
|
132
|
-
};
|
|
133
|
-
const encoded = encodeNodeEntry(node);
|
|
134
|
-
t.is(encoded.length, 0);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('Node Entry - encode returns empty buffer on invalid balance', t => {
|
|
138
|
-
const node = {
|
|
139
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
140
|
-
isWhitelisted: true,
|
|
141
|
-
isWriter: true,
|
|
142
|
-
isIndexer: false,
|
|
143
|
-
balance: b4a.from([
|
|
144
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
145
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27,
|
|
146
|
-
0x10,
|
|
147
|
-
])
|
|
148
|
-
};
|
|
149
|
-
const encoded = encodeNodeEntry(node);
|
|
150
|
-
t.is(encoded.length, 0);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('Node Entry - encode returns empty buffer on invalid license', t => {
|
|
154
|
-
const node = {
|
|
155
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
156
|
-
isWhitelisted: true,
|
|
157
|
-
isWriter: true,
|
|
158
|
-
isIndexer: false,
|
|
159
|
-
balance: ZERO_BALANCE,
|
|
160
|
-
license: randomBuffer(10), // invalid size
|
|
161
|
-
stakedBalance: ZERO_BALANCE
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
const encoded = encodeNodeEntry(node);
|
|
165
|
-
t.is(encoded.length, 0);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test('Node Entry - encode returns empty buffer on invalid staked balance', t => {
|
|
169
|
-
const node = {
|
|
170
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
171
|
-
isWhitelisted: true,
|
|
172
|
-
isWriter: true,
|
|
173
|
-
isIndexer: false,
|
|
174
|
-
balance: ZERO_BALANCE,
|
|
175
|
-
license: ZERO_LICENSE,
|
|
176
|
-
stakedBalance: b4a.from([
|
|
177
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
178
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27,
|
|
179
|
-
0x10,
|
|
180
|
-
])
|
|
181
|
-
};
|
|
182
|
-
const encoded = encodeNodeEntry(node);
|
|
183
|
-
t.is(encoded.length, 0);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Test decode()
|
|
187
|
-
test('Node Entry - decode returns null on invalid input', t => {
|
|
188
|
-
const buf = randomBuffer(10); // invalid size
|
|
189
|
-
const decoded = decodeNodeEntry(buf);
|
|
190
|
-
t.is(decoded, null);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('Node Entry - setRole updates role flags', t => {
|
|
194
|
-
const TEN_THOUSAND_VALUE = b4a.from([
|
|
195
|
-
0x00, 0x00, 0x00, 0x00,
|
|
196
|
-
0x00, 0x00, 0x00, 0x00,
|
|
197
|
-
0x00, 0x00, 0x00, 0x00,
|
|
198
|
-
0x00, 0x00, 0x27, 0x10,
|
|
199
|
-
])
|
|
200
|
-
|
|
201
|
-
let entry = encodeNodeEntry({
|
|
202
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
203
|
-
isWhitelisted: false,
|
|
204
|
-
isWriter: false,
|
|
205
|
-
isIndexer: false,
|
|
206
|
-
balance: TEN_THOUSAND_VALUE,
|
|
207
|
-
license: ZERO_LICENSE,
|
|
208
|
-
stakedBalance: ZERO_BALANCE
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Set maximum tier role (0x7)
|
|
212
|
-
entry = setNodeEntryRole(entry, NodeRole.INDEXER);
|
|
213
|
-
const decoded = decodeNodeEntry(entry);
|
|
214
|
-
t.ok(decoded.isWhitelisted, 'isWhitelisted should be true');
|
|
215
|
-
t.ok(decoded.isWriter, 'isWriter should be true');
|
|
216
|
-
t.ok(decoded.isIndexer, 'isIndexer should be true');
|
|
217
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance should not change');
|
|
218
|
-
|
|
219
|
-
// Set to no roles (0x0)
|
|
220
|
-
entry = setNodeEntryRole(entry, NodeRole.READER);
|
|
221
|
-
const decoded2 = decodeNodeEntry(entry);
|
|
222
|
-
t.not(decoded2.isWhitelisted, 'isWhitelisted should be false');
|
|
223
|
-
t.not(decoded2.isWriter, 'isWriter should be false');
|
|
224
|
-
t.not(decoded2.isIndexer, 'isIndexer should be false');
|
|
225
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance should not change');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('Node Entry - setBalance updates the balance', t => {
|
|
229
|
-
let entry = encodeNodeEntry({
|
|
230
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
231
|
-
isWhitelisted: false,
|
|
232
|
-
isWriter: false,
|
|
233
|
-
isIndexer: false,
|
|
234
|
-
balance: ZERO_BALANCE,
|
|
235
|
-
license: ZERO_LICENSE,
|
|
236
|
-
stakedBalance: ZERO_BALANCE
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
entry = setNodeEntryBalance(entry, TEN_THOUSAND_VALUE);
|
|
240
|
-
const decoded = decodeNodeEntry(entry);
|
|
241
|
-
t.not(decoded.isWhitelisted, 'isWhitelisted should be true');
|
|
242
|
-
t.not(decoded.isWriter, 'isWriter should be true');
|
|
243
|
-
t.not(decoded.isIndexer, 'isIndexer should be true');
|
|
244
|
-
t.ok(b4a.equals(decoded.balance, TEN_THOUSAND_VALUE), 'balance should be 10k');
|
|
245
|
-
|
|
246
|
-
const INVALID_BALANCE = b4a.from([
|
|
247
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
248
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27,
|
|
249
|
-
0x10,
|
|
250
|
-
])
|
|
251
|
-
|
|
252
|
-
// Set to no roles (0x0)
|
|
253
|
-
entry = setNodeEntryBalance(entry, INVALID_BALANCE);
|
|
254
|
-
const decoded2 = decodeNodeEntry(entry);
|
|
255
|
-
t.is(decoded2, null);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('Node Entry - setLicense updates the license', t => {
|
|
259
|
-
let entry = encodeNodeEntry({
|
|
260
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
261
|
-
isWhitelisted: false,
|
|
262
|
-
isWriter: false,
|
|
263
|
-
isIndexer: false,
|
|
264
|
-
balance: ZERO_BALANCE,
|
|
265
|
-
license: ZERO_LICENSE,
|
|
266
|
-
stakedBalance: ZERO_BALANCE
|
|
267
|
-
});
|
|
268
|
-
const randomLicense = randomBuffer(LICENSE_BYTE_LENGTH);
|
|
269
|
-
entry = setNodeEntryLicense(entry, randomLicense);
|
|
270
|
-
const decoded = decodeNodeEntry(entry);
|
|
271
|
-
t.not(decoded.isWhitelisted, 'isWhitelisted should be true');
|
|
272
|
-
t.not(decoded.isWriter, 'isWriter should be true');
|
|
273
|
-
t.not(decoded.isIndexer, 'isIndexer should be true');
|
|
274
|
-
t.ok(b4a.equals(decoded.balance, ZERO_BALANCE), 'balance should be 0');
|
|
275
|
-
t.ok(b4a.equals(decoded.license, randomLicense), 'license should be set');
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// set staked balance
|
|
279
|
-
|
|
280
|
-
test('Node Entry - setStakedBalance updates the staked balance', t => {
|
|
281
|
-
let entry = encodeNodeEntry({
|
|
282
|
-
wk: randomBuffer(WRITER_BYTE_LENGTH),
|
|
283
|
-
isWhitelisted: false,
|
|
284
|
-
isWriter: false,
|
|
285
|
-
isIndexer: false,
|
|
286
|
-
balance: ZERO_BALANCE,
|
|
287
|
-
license: ZERO_LICENSE,
|
|
288
|
-
stakedBalance: ZERO_BALANCE
|
|
289
|
-
});
|
|
290
|
-
entry = setNodeEntryStakedBalance(entry, TEN_THOUSAND_VALUE);
|
|
291
|
-
const decoded = decodeNodeEntry(entry);
|
|
292
|
-
t.not(decoded.isWhitelisted, 'isWhitelisted should be true');
|
|
293
|
-
t.not(decoded.isWriter, 'isWriter should be true');
|
|
294
|
-
t.not(decoded.isIndexer, 'isIndexer should be true');
|
|
295
|
-
t.ok(b4a.equals(decoded.balance, ZERO_BALANCE), 'balance should be 0');
|
|
296
|
-
t.ok(b4a.equals(decoded.license, ZERO_LICENSE), 'license should be set');
|
|
297
|
-
t.ok(b4a.equals(decoded.stakedBalance, TEN_THOUSAND_VALUE), 'staked balance should be 10k');
|
|
298
|
-
});
|