trac-msb 0.2.4 → 0.2.6
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/.dockerignore +16 -0
- package/.github/workflows/acceptance-tests.yml +7 -0
- package/.github/workflows/publish.yml +40 -0
- package/.github/workflows/{CI.yml → unit-tests.yml} +1 -1
- package/README.md +175 -50
- package/docker-compose.yml +16 -0
- package/dockerfile +41 -0
- package/docs/fee_distribution.md +89 -0
- package/msb.mjs +12 -14
- package/package.json +8 -4
- package/rpc/constants.mjs +4 -1
- package/rpc/handlers.mjs +109 -66
- package/rpc/routes/v1.mjs +3 -1
- package/rpc/rpc_services.js +126 -0
- package/rpc/utils/confirmedParameter.mjs +17 -0
- package/rpc/utils/url.mjs +38 -0
- package/src/core/network/Network.js +27 -10
- package/src/core/network/identity/NetworkWalletFactory.js +78 -0
- package/src/core/network/services/ConnectionManager.js +2 -2
- package/src/core/network/services/ValidatorObserverService.js +7 -4
- package/src/core/state/State.js +28 -22
- package/src/index.js +197 -385
- package/src/utils/cliCommands.js +280 -0
- package/src/utils/constants.js +3 -1
- package/tests/acceptance/v1/account/account.test.mjs +123 -0
- package/tests/acceptance/v1/balance/balance.test.mjs +55 -0
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +111 -0
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +19 -0
- package/tests/acceptance/v1/fee/fee.test.mjs +11 -0
- package/tests/acceptance/v1/rpc.test.mjs +62 -291
- package/tests/acceptance/v1/tx/tx.test.mjs +98 -0
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +195 -0
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +72 -0
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +27 -0
- package/tests/acceptance/v1/txv/txv.test.mjs +11 -0
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +11 -0
- package/tests/helpers/StateNetworkFactory.js +157 -0
- package/tests/helpers/autobaseTestHelpers.js +369 -0
- package/tests/helpers/createTestSignature.js +12 -0
- package/tests/helpers/transactionPayloads.mjs +78 -0
- package/tests/unit/network/NetworkWalletFactory.test.js +156 -0
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +38 -0
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +273 -0
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +30 -0
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +78 -0
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +30 -0
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +68 -0
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +155 -0
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +39 -0
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +167 -0
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +21 -0
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +21 -0
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +186 -0
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +445 -0
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +32 -0
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +297 -0
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +41 -0
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +32 -0
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +149 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +757 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +50 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +21 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +37 -0
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +42 -0
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +105 -0
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +54 -0
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +54 -0
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +29 -0
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +309 -0
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +30 -0
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +866 -0
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +439 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +78 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +98 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +66 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +55 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +103 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +60 -0
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +191 -0
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +220 -0
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +82 -0
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +106 -0
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +45 -0
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +81 -0
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +189 -0
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +155 -0
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +36 -0
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +534 -0
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +74 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +32 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +38 -0
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +91 -0
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +19 -0
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +266 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +142 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +26 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +94 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +37 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +86 -0
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +344 -0
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +57 -0
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +429 -0
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +119 -0
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +130 -0
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +93 -0
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +108 -0
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +126 -0
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +120 -0
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +50 -0
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +56 -0
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +52 -0
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +197 -0
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +52 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +15 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +15 -0
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +11 -0
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +40 -0
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +114 -0
- package/tests/unit/state/apply/common/commonScenarioHelper.js +103 -0
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +36 -0
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +36 -0
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +29 -0
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +66 -0
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +84 -0
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +47 -0
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +85 -0
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +52 -0
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +49 -0
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +73 -0
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +71 -0
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +31 -0
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +142 -0
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +87 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +70 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +72 -0
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +36 -0
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +44 -0
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +25 -0
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +98 -0
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +201 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +17 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +44 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +19 -0
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +18 -0
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +314 -0
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +18 -0
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +43 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +53 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +24 -0
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +197 -0
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +161 -0
- package/tests/unit/state/apply/missing-tests.md +18 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +58 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +98 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +167 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +428 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +22 -0
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +20 -0
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +291 -0
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +87 -0
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +38 -0
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +32 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +19 -0
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +344 -0
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +113 -0
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +33 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +21 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +26 -0
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +22 -0
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +307 -0
- package/tests/unit/state/apply/state.apply.test.js +24 -0
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +819 -0
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +22 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +137 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +63 -0
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +67 -0
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +22 -0
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +8 -0
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +66 -0
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +31 -0
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +1167 -0
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +38 -0
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +38 -0
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +318 -0
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +70 -0
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +23 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +48 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +39 -0
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +46 -0
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +21 -0
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +429 -0
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +21 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +27 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +18 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +17 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +31 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +49 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +92 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +28 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +29 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +28 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +17 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +33 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +18 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +25 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +26 -0
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +27 -0
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +21 -0
- package/tests/unit/state/stateModule.test.js +1 -0
- package/tests/unit/state/stateTestUtils.js +5 -1
- package/.env +0 -3
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import removeIndexerHappyPathScenario from './removeIndexerHappyPathScenario.js';
|
|
2
|
+
import removeIndexerReAddAndRemoveAgainScenario from './removeIndexerReAddAndRemoveAgainScenario.js';
|
|
3
|
+
import removeIndexerRemoveMultipleIndexersScenario from './removeIndexerRemoveMultipleIndexersScenario.js';
|
|
4
|
+
import removeIndexerTargetNotIndexerScenario from './removeIndexerTargetNotIndexerScenario.js';
|
|
5
|
+
import removeIndexerWriterKeyMissingScenario from './removeIndexerWriterKeyMissingScenario.js';
|
|
6
|
+
import AdminControlOperationValidationScenario from '../common/adminControlOperationValidationScenario.js';
|
|
7
|
+
import RequesterAddressValidationScenario from '../common/requesterAddressValidationScenario.js';
|
|
8
|
+
import createRequesterPublicKeyValidationScenario from '../common/requesterPublicKeyValidationScenario.js';
|
|
9
|
+
import InvalidAddressValidationScenario from '../common/payload-structure/invalidAddressValidationScenario.js';
|
|
10
|
+
import createAddressWithInvalidPublicKeyScenario from '../common/payload-structure/addressWithInvalidPublicKeyScenario.js';
|
|
11
|
+
import AdminEntryMissingScenario from '../common/access-control/adminEntryMissingScenario.js';
|
|
12
|
+
import AdminEntryDecodeFailureScenario from '../common/access-control/adminEntryDecodeFailureScenario.js';
|
|
13
|
+
import AdminOnlyGuardScenario from '../common/access-control/adminOnlyGuardScenario.js';
|
|
14
|
+
import AdminPublicKeyDecodeFailureScenario from '../common/access-control/adminPublicKeyDecodeFailureScenario.js';
|
|
15
|
+
import AdminConsistencyMismatchScenario from '../common/access-control/adminConsistencyMismatchScenario.js';
|
|
16
|
+
import InvalidHashValidationScenario from '../common/payload-structure/invalidHashValidationScenario.js';
|
|
17
|
+
import InvalidSignatureValidationScenario, { SignatureMutationStrategy } from '../common/payload-structure/invalidSignatureValidationScenario.js';
|
|
18
|
+
import TransactionValidityMismatchScenario from '../common/transactionValidityMismatchScenario.js';
|
|
19
|
+
import OperationAlreadyAppliedScenario from '../common/operationAlreadyAppliedScenario.js';
|
|
20
|
+
import RequesterNodeEntryMissingScenario from '../common/requester/requesterNodeEntryMissingScenario.js';
|
|
21
|
+
import RequesterBalanceScenarioBase from '../common/balances/base/requesterBalanceScenarioBase.js';
|
|
22
|
+
import RequesterBalanceInsufficientScenario from '../common/balances/requesterBalanceInsufficientScenario.js';
|
|
23
|
+
import RequesterBalanceFeeApplicationFailureScenario from '../common/balances/requesterBalanceFeeApplicationFailureScenario.js';
|
|
24
|
+
import {
|
|
25
|
+
selectIndexerCandidatePeer,
|
|
26
|
+
ensureIndexerRegistration
|
|
27
|
+
} from '../addIndexer/addIndexerScenarioHelpers.js';
|
|
28
|
+
import IndexerNodeEntryMissingScenario from '../common/indexer/indexerNodeEntryMissingScenario.js';
|
|
29
|
+
import IndexerNodeEntryDecodeFailureScenario from '../common/indexer/indexerNodeEntryDecodeFailureScenario.js';
|
|
30
|
+
import IndexerRoleUpdateFailureScenario from '../common/indexer/indexerRoleUpdateFailureScenario.js';
|
|
31
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
32
|
+
import { applyWithRequesterEntryCorruption } from '../addWriter/addWriterScenarioHelpers.js';
|
|
33
|
+
import {
|
|
34
|
+
setupRemoveIndexerScenario,
|
|
35
|
+
buildRemoveIndexerPayload,
|
|
36
|
+
buildRemoveIndexerPayloadWithTxValidity,
|
|
37
|
+
applyWithRemoveIndexerRoleUpdateFailure,
|
|
38
|
+
assertRemoveIndexerSuccessState,
|
|
39
|
+
assertRemoveIndexerFailureState,
|
|
40
|
+
assertRemoveIndexerGuardFailureState
|
|
41
|
+
} from './removeIndexerScenarioHelpers.js';
|
|
42
|
+
import IndexerSequenceStateInvalidScenario from '../common/indexer/indexerSequenceStateInvalidScenario.js';
|
|
43
|
+
|
|
44
|
+
removeIndexerHappyPathScenario();
|
|
45
|
+
removeIndexerReAddAndRemoveAgainScenario();
|
|
46
|
+
removeIndexerRemoveMultipleIndexersScenario();
|
|
47
|
+
|
|
48
|
+
// Handler validation order (removeIndexer)
|
|
49
|
+
new AdminControlOperationValidationScenario({
|
|
50
|
+
title: 'State.apply removeIndexer rejects payloads when contract schema validation fails',
|
|
51
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
52
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
53
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
54
|
+
expectedLogs: ['Contract schema validation failed.']
|
|
55
|
+
}).performScenario();
|
|
56
|
+
|
|
57
|
+
new RequesterAddressValidationScenario({
|
|
58
|
+
title: 'State.apply removeIndexer rejects payloads when requester address is invalid',
|
|
59
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
60
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
61
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
62
|
+
expectedLogs: ['Requester address is invalid.']
|
|
63
|
+
}).performScenario();
|
|
64
|
+
|
|
65
|
+
createRequesterPublicKeyValidationScenario({
|
|
66
|
+
title: 'State.apply removeIndexer rejects payloads when requester public key is invalid',
|
|
67
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
68
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
69
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
70
|
+
expectedLogs: ['Error while decoding requester public key.']
|
|
71
|
+
}).performScenario();
|
|
72
|
+
|
|
73
|
+
new InvalidAddressValidationScenario({
|
|
74
|
+
title: 'State.apply removeIndexer rejects payloads when target indexer address is invalid',
|
|
75
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
76
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
77
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
78
|
+
addressPath: ['aco', 'ia'],
|
|
79
|
+
expectedLogs: ['Target indexer address is invalid.']
|
|
80
|
+
}).performScenario();
|
|
81
|
+
|
|
82
|
+
createAddressWithInvalidPublicKeyScenario({
|
|
83
|
+
title: 'State.apply removeIndexer rejects payloads when target indexer public key is invalid',
|
|
84
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
85
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
86
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
87
|
+
addressPath: ['aco', 'ia'],
|
|
88
|
+
expectedLogs: ['Failed to decode target indexer public key.']
|
|
89
|
+
}).performScenario();
|
|
90
|
+
|
|
91
|
+
new AdminEntryMissingScenario({
|
|
92
|
+
title: 'State.apply removeIndexer rejects payloads when admin entry is missing',
|
|
93
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
94
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
95
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
96
|
+
expectedLogs: ['Invalid admin entry.']
|
|
97
|
+
}).performScenario();
|
|
98
|
+
|
|
99
|
+
new AdminEntryDecodeFailureScenario({
|
|
100
|
+
title: 'State.apply removeIndexer rejects payloads when admin entry cannot be decoded',
|
|
101
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
102
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
103
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
104
|
+
expectedLogs: ['Failed to decode admin entry.']
|
|
105
|
+
}).performScenario();
|
|
106
|
+
|
|
107
|
+
new AdminOnlyGuardScenario({
|
|
108
|
+
title: 'State.apply removeIndexer rejects non-admin nodes',
|
|
109
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
110
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
111
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
112
|
+
expectedLogs: ['Node is not allowed to perform this operation. (ADMIN ONLY)']
|
|
113
|
+
}).performScenario();
|
|
114
|
+
|
|
115
|
+
new AdminPublicKeyDecodeFailureScenario({
|
|
116
|
+
title: 'State.apply removeIndexer rejects payloads when admin public key cannot be decoded',
|
|
117
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
118
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
119
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
120
|
+
expectedLogs: ['Failed to decode admin public key.']
|
|
121
|
+
}).performScenario();
|
|
122
|
+
|
|
123
|
+
new AdminConsistencyMismatchScenario({
|
|
124
|
+
title: 'State.apply removeIndexer rejects payloads when admin public key mismatches requester',
|
|
125
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
126
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
127
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
128
|
+
expectedLogs: ['System admin and node public keys do not match.']
|
|
129
|
+
}).performScenario();
|
|
130
|
+
|
|
131
|
+
new InvalidHashValidationScenario({
|
|
132
|
+
title: 'State.apply removeIndexer rejects payloads when message hash mismatches tx hash',
|
|
133
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
134
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
135
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
136
|
+
expectedLogs: ['Message hash does not match the tx_hash.']
|
|
137
|
+
}).performScenario();
|
|
138
|
+
|
|
139
|
+
new InvalidSignatureValidationScenario({
|
|
140
|
+
title: 'State.apply removeIndexer rejects payloads when admin signature is invalid (foreign signature)',
|
|
141
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
142
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
143
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
144
|
+
expectedLogs: ['Failed to verify message signature.']
|
|
145
|
+
}).performScenario();
|
|
146
|
+
|
|
147
|
+
new InvalidSignatureValidationScenario({
|
|
148
|
+
title: 'State.apply removeIndexer rejects payloads when admin signature is invalid (zero fill)',
|
|
149
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
150
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
151
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
152
|
+
strategy: SignatureMutationStrategy.ZERO_FILL,
|
|
153
|
+
expectedLogs: ['Failed to verify message signature.']
|
|
154
|
+
}).performScenario();
|
|
155
|
+
|
|
156
|
+
new InvalidSignatureValidationScenario({
|
|
157
|
+
title: 'State.apply removeIndexer rejects payloads when admin signature is invalid (type mismatch)',
|
|
158
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
159
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
160
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
161
|
+
strategy: SignatureMutationStrategy.TYPE_MISMATCH,
|
|
162
|
+
expectedLogs: ['Failed to verify message signature.']
|
|
163
|
+
}).performScenario();
|
|
164
|
+
|
|
165
|
+
new IndexerSequenceStateInvalidScenario({
|
|
166
|
+
title: 'State.apply removeIndexer rejects payloads when indexer sequence state is invalid',
|
|
167
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
168
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
169
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
170
|
+
expectedLogs: ['Indexer sequence state is invalid.']
|
|
171
|
+
}).performScenario();
|
|
172
|
+
|
|
173
|
+
new TransactionValidityMismatchScenario({
|
|
174
|
+
title: 'State.apply removeIndexer rejects payloads when transaction validity mismatches indexer state',
|
|
175
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
176
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
177
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
178
|
+
txValidityPath: ['aco', 'txv'],
|
|
179
|
+
rebuildPayloadWithTxValidity: ({ context, mutatedTxValidity }) =>
|
|
180
|
+
buildRemoveIndexerPayloadWithTxValidity(context, mutatedTxValidity),
|
|
181
|
+
expectedLogs: ['Transaction was not executed.']
|
|
182
|
+
}).performScenario();
|
|
183
|
+
|
|
184
|
+
new OperationAlreadyAppliedScenario({
|
|
185
|
+
title: 'State.apply removeIndexer rejects payloads when operation was already applied',
|
|
186
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
187
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
188
|
+
assertStateUnchanged: (t, context, validPayload) =>
|
|
189
|
+
assertRemoveIndexerSuccessState(t, context, {
|
|
190
|
+
indexerPeer: context.removeIndexerScenario?.indexerPeer ?? selectIndexerCandidatePeer(context),
|
|
191
|
+
adminPeer: context.adminBootstrap,
|
|
192
|
+
indexerEntryBefore: context.removeIndexerScenario?.indexerEntryBeforeRemoval,
|
|
193
|
+
adminEntryBefore: context.removeIndexerScenario?.adminEntryBeforeRemoval,
|
|
194
|
+
payload: validPayload,
|
|
195
|
+
writersLengthBefore: context.removeIndexerScenario?.writersLengthBeforeRemoval,
|
|
196
|
+
skipSync: true
|
|
197
|
+
}),
|
|
198
|
+
beforeInvalidApply: ({ context, node }) => {
|
|
199
|
+
const writerKey = context.removeIndexerScenario?.indexerPeer?.base?.local?.key;
|
|
200
|
+
if (!writerKey) return null;
|
|
201
|
+
return ensureIndexerRegistration(node.base, writerKey);
|
|
202
|
+
},
|
|
203
|
+
expectedLogs: ['Operation has already been applied.']
|
|
204
|
+
}).performScenario();
|
|
205
|
+
|
|
206
|
+
new IndexerNodeEntryMissingScenario({
|
|
207
|
+
title: 'State.apply removeIndexer rejects payloads when target indexer entry is missing',
|
|
208
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
209
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
210
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
211
|
+
selectPeer: context => context.removeIndexerScenario?.indexerPeer ?? selectIndexerCandidatePeer(context),
|
|
212
|
+
expectedLogs: ['Failed to verify target indexer entry.']
|
|
213
|
+
}).performScenario();
|
|
214
|
+
|
|
215
|
+
new IndexerNodeEntryDecodeFailureScenario({
|
|
216
|
+
title: 'State.apply removeIndexer rejects payloads when target indexer entry cannot be decoded',
|
|
217
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
218
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
219
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
220
|
+
selectPeer: context => context.removeIndexerScenario?.indexerPeer ?? selectIndexerCandidatePeer(context),
|
|
221
|
+
expectedLogs: ['Failed to decode target indexer node entry.']
|
|
222
|
+
}).performScenario();
|
|
223
|
+
|
|
224
|
+
removeIndexerTargetNotIndexerScenario();
|
|
225
|
+
|
|
226
|
+
new IndexerRoleUpdateFailureScenario({
|
|
227
|
+
title: 'State.apply removeIndexer rejects payloads when node role update fails',
|
|
228
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
229
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
230
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerGuardFailureState(t, context, { skipSync: true }),
|
|
231
|
+
applyRoleMutationFailure: applyWithRemoveIndexerRoleUpdateFailure,
|
|
232
|
+
expectedLogs: ['Failed to update node role.']
|
|
233
|
+
}).performScenario();
|
|
234
|
+
|
|
235
|
+
removeIndexerWriterKeyMissingScenario();
|
|
236
|
+
|
|
237
|
+
new RequesterNodeEntryMissingScenario({
|
|
238
|
+
title: 'State.apply removeIndexer rejects payloads when requester node entry is missing',
|
|
239
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
240
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
241
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
242
|
+
selectPeer: context => context.adminBootstrap,
|
|
243
|
+
expectedLogs: ['Invalid requester node entry.']
|
|
244
|
+
}).performScenario();
|
|
245
|
+
|
|
246
|
+
new OperationValidationScenarioBase({
|
|
247
|
+
title: 'State.apply removeIndexer rejects payloads when requester node entry cannot be decoded',
|
|
248
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
249
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
250
|
+
mutatePayload: (_t, payload) => payload,
|
|
251
|
+
applyInvalidPayload: (context, invalidPayload) =>
|
|
252
|
+
applyWithRequesterEntryCorruption(context, invalidPayload, { peer: context.adminBootstrap }),
|
|
253
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
254
|
+
expectedLogs: ['Failed to decode requester node entry.']
|
|
255
|
+
}).performScenario();
|
|
256
|
+
|
|
257
|
+
new RequesterBalanceScenarioBase({
|
|
258
|
+
title: 'State.apply removeIndexer rejects payloads when admin balance cannot be decoded',
|
|
259
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
260
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
261
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
262
|
+
mutateDecodedEntry: decoded => ({ ...decoded, balance: decoded.balance ? decoded.balance.subarray(0, 1) : null }),
|
|
263
|
+
selectPeer: context => context.adminBootstrap,
|
|
264
|
+
expectedLogs: ['Invalid admin balance.']
|
|
265
|
+
}).performScenario();
|
|
266
|
+
|
|
267
|
+
new RequesterBalanceInsufficientScenario({
|
|
268
|
+
title: 'State.apply removeIndexer rejects payloads when requester balance is insufficient',
|
|
269
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
270
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
271
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
272
|
+
selectPeer: context => context.adminBootstrap
|
|
273
|
+
}).performScenario();
|
|
274
|
+
|
|
275
|
+
new RequesterBalanceFeeApplicationFailureScenario({
|
|
276
|
+
title: 'State.apply removeIndexer rejects payloads when requester fee cannot be applied',
|
|
277
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
278
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
279
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
280
|
+
selectPeer: context => context.adminBootstrap
|
|
281
|
+
}).performScenario();
|
|
282
|
+
|
|
283
|
+
new RequesterBalanceScenarioBase({
|
|
284
|
+
title: 'State.apply removeIndexer rejects payloads when requester balance update fails',
|
|
285
|
+
setupScenario: setupRemoveIndexerScenario,
|
|
286
|
+
buildValidPayload: context => buildRemoveIndexerPayload(context),
|
|
287
|
+
assertStateUnchanged: (t, context) => assertRemoveIndexerFailureState(t, context, { skipSync: true }),
|
|
288
|
+
selectPeer: context => context.adminBootstrap,
|
|
289
|
+
failNextBalanceUpdate: true,
|
|
290
|
+
expectedLogs: ['Failed to update requester node.']
|
|
291
|
+
}).performScenario();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import b4a from 'b4a';
|
|
3
|
+
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
4
|
+
import {
|
|
5
|
+
setupRemoveWriterScenario,
|
|
6
|
+
selectWriterPeer,
|
|
7
|
+
buildRemoveWriterPayload,
|
|
8
|
+
assertRemoveWriterSuccessState
|
|
9
|
+
} from './removeWriterScenarioHelpers.js';
|
|
10
|
+
import {
|
|
11
|
+
buildAddWriterPayload,
|
|
12
|
+
assertAddWriterSuccessState
|
|
13
|
+
} from '../addWriter/addWriterScenarioHelpers.js';
|
|
14
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
15
|
+
import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
|
|
16
|
+
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
17
|
+
|
|
18
|
+
export default function removeWriterAndAddWriterAgainScenario() {
|
|
19
|
+
test('State.apply removeWriter followed by addWriter re-promotes the same node', async t => {
|
|
20
|
+
const context = await setupRemoveWriterScenario(t);
|
|
21
|
+
const validatorPeer = context.adminBootstrap;
|
|
22
|
+
const writerPeer = selectWriterPeer(context);
|
|
23
|
+
const writerAddress = writerPeer.wallet.address;
|
|
24
|
+
|
|
25
|
+
const writerEntryBeforeRemoval = await validatorPeer.base.view.get(writerAddress);
|
|
26
|
+
t.ok(writerEntryBeforeRemoval, 'writer entry exists before removeWriter');
|
|
27
|
+
const validatorEntryBeforeRemoval = await validatorPeer.base.view.get(
|
|
28
|
+
validatorPeer.wallet.address
|
|
29
|
+
);
|
|
30
|
+
t.ok(validatorEntryBeforeRemoval, 'validator entry exists before removeWriter');
|
|
31
|
+
|
|
32
|
+
const removeWriterPayload = await buildRemoveWriterPayload(context, {
|
|
33
|
+
readerPeer: writerPeer,
|
|
34
|
+
validatorPeer
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await validatorPeer.base.append(removeWriterPayload);
|
|
38
|
+
await validatorPeer.base.update();
|
|
39
|
+
await eventFlush();
|
|
40
|
+
|
|
41
|
+
await assertRemoveWriterSuccessState(t, context, {
|
|
42
|
+
writerPeer,
|
|
43
|
+
validatorPeer,
|
|
44
|
+
writerEntryBefore: writerEntryBeforeRemoval,
|
|
45
|
+
validatorEntryBefore: validatorEntryBeforeRemoval,
|
|
46
|
+
payload: removeWriterPayload
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const validatorEntryBeforeReAdd = await validatorPeer.base.view.get(
|
|
50
|
+
validatorPeer.wallet.address
|
|
51
|
+
);
|
|
52
|
+
t.ok(validatorEntryBeforeReAdd, 'validator entry exists before addWriter re-promotion');
|
|
53
|
+
const decodedValidatorBeforeReAdd = nodeEntryUtils.decode(validatorEntryBeforeReAdd.value);
|
|
54
|
+
t.ok(decodedValidatorBeforeReAdd, 'validator entry decodes before addWriter re-promotion');
|
|
55
|
+
|
|
56
|
+
const writerEntryAfterRemoval = await validatorPeer.base.view.get(writerAddress);
|
|
57
|
+
t.ok(writerEntryAfterRemoval, 'writer entry exists after removeWriter');
|
|
58
|
+
const decodedWriterAfterRemoval = nodeEntryUtils.decode(writerEntryAfterRemoval.value);
|
|
59
|
+
t.ok(decodedWriterAfterRemoval, 'writer entry decodes after removeWriter');
|
|
60
|
+
|
|
61
|
+
const writerBalanceBeforeReAdd = b4a.from(decodedWriterAfterRemoval.balance);
|
|
62
|
+
const validatorBalanceBeforeReAdd = b4a.from(decodedValidatorBeforeReAdd.balance);
|
|
63
|
+
const writersLengthEntry = await validatorPeer.base.view.get(EntryType.WRITERS_LENGTH);
|
|
64
|
+
const nextWriterIndex = writersLengthEntry
|
|
65
|
+
? lengthEntryUtils.decodeBE(writersLengthEntry.value)
|
|
66
|
+
: 0;
|
|
67
|
+
|
|
68
|
+
const reAddPayload = await buildAddWriterPayload(context, {
|
|
69
|
+
readerPeer: writerPeer,
|
|
70
|
+
validatorPeer
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await validatorPeer.base.append(reAddPayload);
|
|
74
|
+
await validatorPeer.base.update();
|
|
75
|
+
await eventFlush();
|
|
76
|
+
|
|
77
|
+
await assertAddWriterSuccessState(t, context, {
|
|
78
|
+
readerPeer: writerPeer,
|
|
79
|
+
validatorPeer,
|
|
80
|
+
writerInitialBalance: writerBalanceBeforeReAdd,
|
|
81
|
+
validatorBalanceBefore: validatorBalanceBeforeReAdd,
|
|
82
|
+
payload: reAddPayload,
|
|
83
|
+
writerKeyBuffer: writerPeer.base.local.key,
|
|
84
|
+
expectedWriterIndex: nextWriterIndex
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
3
|
+
import {
|
|
4
|
+
setupRemoveWriterScenario,
|
|
5
|
+
selectWriterPeer,
|
|
6
|
+
buildRemoveWriterPayload,
|
|
7
|
+
assertRemoveWriterSuccessState
|
|
8
|
+
} from './removeWriterScenarioHelpers.js';
|
|
9
|
+
|
|
10
|
+
export default function removeWriterHappyPathScenario() {
|
|
11
|
+
test('State.apply removeWriter demotes writers and refunds stake - happy path', async t => {
|
|
12
|
+
const context = await setupRemoveWriterScenario(t);
|
|
13
|
+
const validatorPeer = context.adminBootstrap;
|
|
14
|
+
const writerPeer = selectWriterPeer(context);
|
|
15
|
+
|
|
16
|
+
const writerEntryBefore = await validatorPeer.base.view.get(writerPeer.wallet.address);
|
|
17
|
+
t.ok(writerEntryBefore, 'writer entry exists before removeWriter');
|
|
18
|
+
const validatorEntryBefore = await validatorPeer.base.view.get(validatorPeer.wallet.address);
|
|
19
|
+
t.ok(validatorEntryBefore, 'validator entry exists before removeWriter');
|
|
20
|
+
|
|
21
|
+
const payload = await buildRemoveWriterPayload(context, {
|
|
22
|
+
readerPeer: writerPeer,
|
|
23
|
+
validatorPeer
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await validatorPeer.base.append(payload);
|
|
27
|
+
await validatorPeer.base.update();
|
|
28
|
+
await eventFlush();
|
|
29
|
+
|
|
30
|
+
await assertRemoveWriterSuccessState(t, context, {
|
|
31
|
+
writerPeer,
|
|
32
|
+
validatorPeer,
|
|
33
|
+
writerEntryBefore,
|
|
34
|
+
validatorEntryBefore,
|
|
35
|
+
payload
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
3
|
+
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
4
|
+
import {
|
|
5
|
+
setupRemoveWriterScenario,
|
|
6
|
+
buildRemoveWriterPayload,
|
|
7
|
+
assertRemoveWriterFailureState
|
|
8
|
+
} from './removeWriterScenarioHelpers.js';
|
|
9
|
+
import { applyWithRoleAccessBypass } from '../addWriter/addWriterScenarioHelpers.js';
|
|
10
|
+
|
|
11
|
+
function mutateValidatorSignature(t, validPayload) {
|
|
12
|
+
const decoded = safeDecodeApplyOperation(validPayload);
|
|
13
|
+
t.ok(decoded, 'fixtures decode');
|
|
14
|
+
const parent = decoded?.rao;
|
|
15
|
+
if (!parent?.vs) return validPayload;
|
|
16
|
+
const mutated = b4a.from(parent.vs);
|
|
17
|
+
mutated[mutated.length - 1] ^= 0xff;
|
|
18
|
+
parent.vs = mutated;
|
|
19
|
+
return safeEncodeApplyOperation(decoded);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function removeWriterInvalidValidatorSignatureScenario() {
|
|
23
|
+
new OperationValidationScenarioBase({
|
|
24
|
+
title: 'State.apply removeWriter rejects payloads when validator signature is invalid',
|
|
25
|
+
setupScenario: setupRemoveWriterScenario,
|
|
26
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
27
|
+
mutatePayload: mutateValidatorSignature,
|
|
28
|
+
applyInvalidPayload: applyWithRoleAccessBypass,
|
|
29
|
+
assertStateUnchanged: assertRemoveWriterFailureState,
|
|
30
|
+
expectedLogs: ['Failed to verify validator message signature.']
|
|
31
|
+
}).performScenario();
|
|
32
|
+
}
|
package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import RequesterBalanceScenarioBase from '../common/balances/base/requesterBalanceScenarioBase.js';
|
|
3
|
+
import {
|
|
4
|
+
setupRemoveWriterScenario,
|
|
5
|
+
buildRemoveWriterPayload,
|
|
6
|
+
assertRemoveWriterFailureState,
|
|
7
|
+
selectWriterPeer
|
|
8
|
+
} from './removeWriterScenarioHelpers.js';
|
|
9
|
+
|
|
10
|
+
export default function removeWriterRequesterBalanceInsufficientScenario() {
|
|
11
|
+
new RequesterBalanceScenarioBase({
|
|
12
|
+
title: 'State.apply removeWriter rejects payloads when requester balance is insufficient',
|
|
13
|
+
setupScenario: setupRemoveWriterScenario,
|
|
14
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
15
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
16
|
+
selectPeer: selectWriterPeer,
|
|
17
|
+
mutateDecodedEntry: decoded =>
|
|
18
|
+
decoded ? { ...decoded, balance: b4a.alloc(decoded.balance.length) } : decoded,
|
|
19
|
+
expectedLogs: ['Insufficient requester balance.', 'Remove writer operation ignored.']
|
|
20
|
+
}).performScenario();
|
|
21
|
+
}
|
package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
2
|
+
import {
|
|
3
|
+
setupRemoveWriterScenario,
|
|
4
|
+
buildRemoveWriterPayload,
|
|
5
|
+
assertRemoveWriterFailureState
|
|
6
|
+
} from './removeWriterScenarioHelpers.js';
|
|
7
|
+
import { applyWithRequesterEntryCorruption } from '../addWriter/addWriterScenarioHelpers.js';
|
|
8
|
+
|
|
9
|
+
export default function removeWriterRequesterEntryDecodeFailureScenario() {
|
|
10
|
+
new OperationValidationScenarioBase({
|
|
11
|
+
title: 'State.apply removeWriter rejects payloads when requester entry cannot be decoded',
|
|
12
|
+
setupScenario: setupRemoveWriterScenario,
|
|
13
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
14
|
+
mutatePayload: (_t, payload) => payload,
|
|
15
|
+
applyInvalidPayload: applyWithRequesterEntryCorruption,
|
|
16
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
17
|
+
expectedLogs: ['Failed to decode requester node entry.']
|
|
18
|
+
}).performScenario();
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
2
|
+
import {
|
|
3
|
+
setupRemoveWriterScenario,
|
|
4
|
+
buildRemoveWriterPayload,
|
|
5
|
+
assertRemoveWriterFailureState
|
|
6
|
+
} from './removeWriterScenarioHelpers.js';
|
|
7
|
+
import { applyWithRequesterEntryRemoval } from '../addWriter/addWriterScenarioHelpers.js';
|
|
8
|
+
|
|
9
|
+
export default function removeWriterRequesterEntryMissingScenario() {
|
|
10
|
+
new OperationValidationScenarioBase({
|
|
11
|
+
title: 'State.apply removeWriter rejects payloads when requester entry is missing',
|
|
12
|
+
setupScenario: setupRemoveWriterScenario,
|
|
13
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
14
|
+
mutatePayload: (_t, payload) => payload,
|
|
15
|
+
applyInvalidPayload: applyWithRequesterEntryRemoval,
|
|
16
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
17
|
+
expectedLogs: ['Failed to verify requester node entry.']
|
|
18
|
+
}).performScenario();
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
2
|
+
import {
|
|
3
|
+
setupRemoveWriterScenario,
|
|
4
|
+
buildRemoveWriterPayload,
|
|
5
|
+
assertRemoveWriterFailureState
|
|
6
|
+
} from './removeWriterScenarioHelpers.js';
|
|
7
|
+
import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
|
|
8
|
+
import { applyWithRequesterRoleOverride } from '../addWriter/addWriterScenarioHelpers.js';
|
|
9
|
+
|
|
10
|
+
export default function removeWriterRequesterIndexerScenario() {
|
|
11
|
+
new OperationValidationScenarioBase({
|
|
12
|
+
title: 'State.apply removeWriter rejects payloads when requester is an indexer',
|
|
13
|
+
setupScenario: setupRemoveWriterScenario,
|
|
14
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
15
|
+
mutatePayload: (_t, payload) => payload,
|
|
16
|
+
applyInvalidPayload: (context, invalidPayload) =>
|
|
17
|
+
applyWithRequesterRoleOverride(context, invalidPayload, nodeRoleUtils.NodeRole.INDEXER),
|
|
18
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
19
|
+
expectedLogs: ['Node has to be a writer, and cannot be an indexer.']
|
|
20
|
+
}).performScenario();
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
2
|
+
import {
|
|
3
|
+
setupRemoveWriterScenario,
|
|
4
|
+
buildRemoveWriterPayload,
|
|
5
|
+
assertRemoveWriterFailureState
|
|
6
|
+
} from './removeWriterScenarioHelpers.js';
|
|
7
|
+
import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
|
|
8
|
+
import { applyWithRequesterRoleOverride } from '../addWriter/addWriterScenarioHelpers.js';
|
|
9
|
+
|
|
10
|
+
export default function removeWriterRequesterNotWriterScenario() {
|
|
11
|
+
new OperationValidationScenarioBase({
|
|
12
|
+
title: 'State.apply removeWriter rejects payloads when requester is not a writer',
|
|
13
|
+
setupScenario: setupRemoveWriterScenario,
|
|
14
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
15
|
+
mutatePayload: (_t, payload) => payload,
|
|
16
|
+
applyInvalidPayload: (context, invalidPayload) =>
|
|
17
|
+
applyWithRequesterRoleOverride(context, invalidPayload, nodeRoleUtils.NodeRole.READER),
|
|
18
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
19
|
+
expectedLogs: ['Node has to be a writer, and cannot be an indexer.', 'Failed to remove writer.']
|
|
20
|
+
}).performScenario();
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
2
|
+
import {
|
|
3
|
+
setupRemoveWriterScenario,
|
|
4
|
+
buildRemoveWriterPayload,
|
|
5
|
+
assertRemoveWriterFailureState,
|
|
6
|
+
applyWithRequesterRoleMutationFailure
|
|
7
|
+
} from './removeWriterScenarioHelpers.js';
|
|
8
|
+
|
|
9
|
+
export default function removeWriterRequesterRoleUpdateFailureScenario() {
|
|
10
|
+
new OperationValidationScenarioBase({
|
|
11
|
+
title: 'State.apply removeWriter rejects payloads when requester role cannot be updated',
|
|
12
|
+
setupScenario: setupRemoveWriterScenario,
|
|
13
|
+
buildValidPayload: context => buildRemoveWriterPayload(context),
|
|
14
|
+
mutatePayload: (_t, payload) => payload,
|
|
15
|
+
applyInvalidPayload: applyWithRequesterRoleMutationFailure,
|
|
16
|
+
assertStateUnchanged: (t, context) => assertRemoveWriterFailureState(t, context, { skipSync: true }),
|
|
17
|
+
expectedLogs: ['Failed to update node entry role.']
|
|
18
|
+
}).performScenario();
|
|
19
|
+
}
|