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,46 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
|
|
3
|
+
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
4
|
+
import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
|
|
5
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
6
|
+
import {
|
|
7
|
+
setupTxOperationScenario,
|
|
8
|
+
buildTxOperationPayload,
|
|
9
|
+
assertTxOperationFailureState
|
|
10
|
+
} from './txOperationScenarioHelpers.js';
|
|
11
|
+
|
|
12
|
+
export default function txOperationInvalidSubnetCreatorAddressScenario() {
|
|
13
|
+
new OperationValidationScenarioBase({
|
|
14
|
+
title: 'State.apply txOperation rejects payloads when subnet creator address is invalid',
|
|
15
|
+
setupScenario: setupTxOperationScenario,
|
|
16
|
+
buildValidPayload: buildTxOperationPayload,
|
|
17
|
+
mutatePayload: async (_t, validPayload) => validPayload,
|
|
18
|
+
applyInvalidPayload: async (context, invalidPayload, _t, validPayload) => {
|
|
19
|
+
const node = context.txOperation?.validatorPeer ?? context.peers?.[1];
|
|
20
|
+
const payload = validPayload ?? invalidPayload;
|
|
21
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
22
|
+
const fallbackTxHash = decoded?.txo?.tx ?? b4a.alloc(32, 0x11);
|
|
23
|
+
const originalDecode = deploymentEntryUtils.decode;
|
|
24
|
+
|
|
25
|
+
// Force decode to yield an invalid address buffer so bufferToAddress returns null.
|
|
26
|
+
deploymentEntryUtils.decode = () => ({
|
|
27
|
+
txHash: fallbackTxHash,
|
|
28
|
+
address: b4a.alloc(1, 0x01)
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await node.base.append(payload);
|
|
33
|
+
await node.base.update();
|
|
34
|
+
await eventFlush();
|
|
35
|
+
} finally {
|
|
36
|
+
deploymentEntryUtils.decode = originalDecode;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
assertStateUnchanged: (t, context, _valid, invalidPayload) =>
|
|
40
|
+
assertTxOperationFailureState(t, context, {
|
|
41
|
+
payload: invalidPayload,
|
|
42
|
+
validatorEntryBefore: null
|
|
43
|
+
}),
|
|
44
|
+
expectedLogs: ['Invalid subnet creator address.']
|
|
45
|
+
}).performScenario();
|
|
46
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTxOperationScenario,
|
|
4
|
+
buildTxOperationPayload,
|
|
5
|
+
assertTxOperationSuccessState
|
|
6
|
+
} from './txOperationScenarioHelpers.js';
|
|
7
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
8
|
+
|
|
9
|
+
export default function txOperationRequesterCreatorHappyPathScenario() {
|
|
10
|
+
test('State.apply txOperation with requester as subnetwork creator (no bonus, 50% to validator)', async t => {
|
|
11
|
+
const context = await setupTxOperationScenario(t, { creatorPeerKind: 'requester' });
|
|
12
|
+
const payload = await buildTxOperationPayload(context);
|
|
13
|
+
const validatorPeer = context.txOperation?.validatorPeer ?? context.adminBootstrap;
|
|
14
|
+
|
|
15
|
+
await validatorPeer.base.append(payload);
|
|
16
|
+
await validatorPeer.base.update();
|
|
17
|
+
await eventFlush();
|
|
18
|
+
|
|
19
|
+
await assertTxOperationSuccessState(t, context, { payload, distribution: 'requesterIsCreator' });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
3
|
+
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
4
|
+
import {
|
|
5
|
+
deriveIndexerSequenceState,
|
|
6
|
+
eventFlush
|
|
7
|
+
} from '../../../../helpers/autobaseTestHelpers.js';
|
|
8
|
+
import {
|
|
9
|
+
setupAdminNetwork,
|
|
10
|
+
initializeBalances,
|
|
11
|
+
whitelistAddress
|
|
12
|
+
} from '../common/commonScenarioHelper.js';
|
|
13
|
+
import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
|
|
14
|
+
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
15
|
+
import addressUtils from '../../../../../src/core/state/utils/address.js';
|
|
16
|
+
import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
|
|
17
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
18
|
+
import { toBalance, PERCENT_25, PERCENT_50, PERCENT_75 } from '../../../../../src/core/state/utils/balance.js';
|
|
19
|
+
import { EntryType } from '../../../../../src/utils/constants.js';
|
|
20
|
+
import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
|
|
21
|
+
import {
|
|
22
|
+
buildBootstrapDeploymentPayload
|
|
23
|
+
} from '../bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js';
|
|
24
|
+
import {
|
|
25
|
+
safeDecodeApplyOperation,
|
|
26
|
+
safeEncodeApplyOperation
|
|
27
|
+
} from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
28
|
+
|
|
29
|
+
const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
|
|
30
|
+
const DEFAULT_CONTENT_HASH = b4a.alloc(32, 0xab);
|
|
31
|
+
|
|
32
|
+
function selectValidatorPeer(context, offset = 0) {
|
|
33
|
+
const peers = context.peers.slice(1);
|
|
34
|
+
if (!peers.length) {
|
|
35
|
+
throw new Error('TxOperation scenarios require at least one non-admin peer.');
|
|
36
|
+
}
|
|
37
|
+
return peers[Math.min(offset, peers.length - 1)];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function selectDeployerPeer(context, offset = 1) {
|
|
41
|
+
const peers = context.peers.slice(1);
|
|
42
|
+
if (peers.length < 2) {
|
|
43
|
+
throw new Error('TxOperation scenarios require a deployer peer.');
|
|
44
|
+
}
|
|
45
|
+
return peers[Math.min(offset, peers.length - 1)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function selectBroadcasterPeer(context, offset = 2) {
|
|
49
|
+
const peers = context.peers.slice(1);
|
|
50
|
+
if (peers.length < 3) {
|
|
51
|
+
throw new Error('TxOperation scenarios require a broadcaster peer.');
|
|
52
|
+
}
|
|
53
|
+
return peers[Math.min(offset, peers.length - 1)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function setupTxOperationScenario(
|
|
57
|
+
t,
|
|
58
|
+
{
|
|
59
|
+
nodes = 4,
|
|
60
|
+
validatorInitialBalance = DEFAULT_FUNDING,
|
|
61
|
+
deployerInitialBalance = DEFAULT_FUNDING,
|
|
62
|
+
broadcasterInitialBalance = DEFAULT_FUNDING,
|
|
63
|
+
contentHash = DEFAULT_CONTENT_HASH,
|
|
64
|
+
creatorPeerKind = 'deployer' // 'deployer' | 'validator' | 'requester'
|
|
65
|
+
} = {}
|
|
66
|
+
) {
|
|
67
|
+
const context = await setupAdminNetwork(t, { nodes: Math.max(nodes, 4) });
|
|
68
|
+
const validatorPeer = selectValidatorPeer(context);
|
|
69
|
+
const deployerPeer = selectDeployerPeer(context);
|
|
70
|
+
const broadcasterPeer = selectBroadcasterPeer(context);
|
|
71
|
+
|
|
72
|
+
await initializeBalances(context, [
|
|
73
|
+
[validatorPeer.wallet.address, validatorInitialBalance],
|
|
74
|
+
[deployerPeer.wallet.address, deployerInitialBalance],
|
|
75
|
+
[broadcasterPeer.wallet.address, broadcasterInitialBalance]
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
context.addWriterScenario = { writerInitialBalance: validatorInitialBalance };
|
|
79
|
+
await whitelistAddress(context, validatorPeer.wallet.address);
|
|
80
|
+
await whitelistAddress(context, deployerPeer.wallet.address);
|
|
81
|
+
await whitelistAddress(context, broadcasterPeer.wallet.address);
|
|
82
|
+
|
|
83
|
+
await promotePeerToWriter(t, context, { readerPeer: validatorPeer });
|
|
84
|
+
await context.sync();
|
|
85
|
+
|
|
86
|
+
const creatorPeer =
|
|
87
|
+
creatorPeerKind === 'validator'
|
|
88
|
+
? validatorPeer
|
|
89
|
+
: creatorPeerKind === 'requester'
|
|
90
|
+
? broadcasterPeer
|
|
91
|
+
: deployerPeer;
|
|
92
|
+
const bootstrapValidatorPeer =
|
|
93
|
+
creatorPeerKind === 'validator' ? context.adminBootstrap : validatorPeer;
|
|
94
|
+
|
|
95
|
+
const externalBootstrap = b4a.from(creatorPeer.base.local.key);
|
|
96
|
+
const bootstrapPayload = await buildBootstrapDeploymentPayload(context, {
|
|
97
|
+
validatorPeer: bootstrapValidatorPeer,
|
|
98
|
+
deployerPeer: creatorPeer,
|
|
99
|
+
externalBootstrap
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
await bootstrapValidatorPeer.base.append(bootstrapPayload);
|
|
103
|
+
await bootstrapValidatorPeer.base.update();
|
|
104
|
+
await eventFlush();
|
|
105
|
+
await context.sync();
|
|
106
|
+
|
|
107
|
+
const validatorEntryBefore = await validatorPeer.base.view.get(validatorPeer.wallet.address);
|
|
108
|
+
const deployerEntryBefore = await validatorPeer.base.view.get(creatorPeer.wallet.address);
|
|
109
|
+
const requesterEntryBefore = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
|
|
110
|
+
const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
|
|
111
|
+
|
|
112
|
+
context.txOperation = {
|
|
113
|
+
validatorPeer,
|
|
114
|
+
deployerPeer: creatorPeer,
|
|
115
|
+
creatorPeer,
|
|
116
|
+
broadcasterPeer,
|
|
117
|
+
externalBootstrap,
|
|
118
|
+
msbBootstrap: b4a.from(context.bootstrap.base.local.key),
|
|
119
|
+
txValidity,
|
|
120
|
+
contentHash,
|
|
121
|
+
validatorEntryBefore: validatorEntryBefore ? { value: b4a.from(validatorEntryBefore.value) } : null,
|
|
122
|
+
deployerEntryBefore: deployerEntryBefore ? { value: b4a.from(deployerEntryBefore.value) } : null,
|
|
123
|
+
requesterEntryBefore: requesterEntryBefore ? { value: b4a.from(requesterEntryBefore.value) } : null
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return context;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function buildTxOperationPayload(
|
|
130
|
+
context,
|
|
131
|
+
{
|
|
132
|
+
validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
|
|
133
|
+
broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
|
|
134
|
+
externalBootstrap = context.txOperation?.externalBootstrap ?? b4a.from(broadcasterPeer.base.local.key),
|
|
135
|
+
msbBootstrap = context.txOperation?.msbBootstrap ?? b4a.from(context.bootstrap.base.local.key),
|
|
136
|
+
txValidity = context.txOperation?.txValidity ?? null,
|
|
137
|
+
contentHash = context.txOperation?.contentHash ?? DEFAULT_CONTENT_HASH,
|
|
138
|
+
writerKeyBuffer = broadcasterPeer.base.local.key
|
|
139
|
+
} = {}
|
|
140
|
+
) {
|
|
141
|
+
const resolvedTxValidity = txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
|
|
142
|
+
|
|
143
|
+
const partial = await PartialStateMessageOperations.assembleTransactionOperationMessage(
|
|
144
|
+
broadcasterPeer.wallet,
|
|
145
|
+
writerKeyBuffer.toString('hex'),
|
|
146
|
+
resolvedTxValidity.toString('hex'),
|
|
147
|
+
contentHash.toString('hex'),
|
|
148
|
+
externalBootstrap.toString('hex'),
|
|
149
|
+
msbBootstrap.toString('hex')
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return CompleteStateMessageOperations.assembleCompleteTransactionOperationMessage(
|
|
153
|
+
validatorPeer.wallet,
|
|
154
|
+
partial.address,
|
|
155
|
+
b4a.from(partial.txo.tx, 'hex'),
|
|
156
|
+
b4a.from(partial.txo.txv, 'hex'),
|
|
157
|
+
b4a.from(partial.txo.iw, 'hex'),
|
|
158
|
+
b4a.from(partial.txo.in, 'hex'),
|
|
159
|
+
b4a.from(partial.txo.ch, 'hex'),
|
|
160
|
+
b4a.from(partial.txo.is, 'hex'),
|
|
161
|
+
b4a.from(partial.txo.bs, 'hex'),
|
|
162
|
+
b4a.from(partial.txo.mbs, 'hex')
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function buildTxOperationPayloadWithTxValidity(context, txValidity, options = {}) {
|
|
167
|
+
if (!b4a.isBuffer(txValidity)) {
|
|
168
|
+
throw new Error('buildTxOperationPayloadWithTxValidity requires a tx validity buffer.');
|
|
169
|
+
}
|
|
170
|
+
return buildTxOperationPayload(context, { ...options, txValidity });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function assertTxOperationSuccessState(
|
|
174
|
+
t,
|
|
175
|
+
context,
|
|
176
|
+
{
|
|
177
|
+
payload,
|
|
178
|
+
validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
|
|
179
|
+
deployerPeer = context.txOperation?.deployerPeer ?? selectDeployerPeer(context),
|
|
180
|
+
broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
|
|
181
|
+
creatorPeer = context.txOperation?.creatorPeer ?? deployerPeer,
|
|
182
|
+
validatorEntryBefore = context.txOperation?.validatorEntryBefore?.value ?? null,
|
|
183
|
+
deployerEntryBefore = context.txOperation?.deployerEntryBefore?.value ?? null,
|
|
184
|
+
requesterEntryBefore = context.txOperation?.requesterEntryBefore?.value ?? null,
|
|
185
|
+
distribution = 'standard', // 'standard' | 'requesterIsCreator' | 'validatorIsCreator'
|
|
186
|
+
skipSync = false
|
|
187
|
+
} = {}
|
|
188
|
+
) {
|
|
189
|
+
if (!payload) throw new Error('assertTxOperationSuccessState requires the processed payload.');
|
|
190
|
+
|
|
191
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
192
|
+
t.ok(decoded, 'txOperation payload decodes');
|
|
193
|
+
if (!decoded?.txo) return;
|
|
194
|
+
|
|
195
|
+
const txHashBuffer = decoded.txo.tx;
|
|
196
|
+
const requesterAddressBuffer = decoded.address;
|
|
197
|
+
const validatorAddressBuffer = decoded.txo.va;
|
|
198
|
+
const externalBootstrap = decoded.txo.bs;
|
|
199
|
+
const msbBootstrap = decoded.txo.mbs;
|
|
200
|
+
|
|
201
|
+
t.ok(requesterAddressBuffer, 'payload carries requester address');
|
|
202
|
+
t.ok(validatorAddressBuffer, 'payload carries validator address');
|
|
203
|
+
t.ok(txHashBuffer, 'payload exposes tx hash');
|
|
204
|
+
if (externalBootstrap) {
|
|
205
|
+
t.ok(b4a.equals(externalBootstrap, context.txOperation?.externalBootstrap), 'payload external bootstrap matches deployment');
|
|
206
|
+
}
|
|
207
|
+
if (msbBootstrap) {
|
|
208
|
+
t.ok(b4a.equals(msbBootstrap, context.txOperation?.msbBootstrap), 'payload MSB bootstrap matches network');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
|
|
212
|
+
const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer);
|
|
213
|
+
|
|
214
|
+
t.is(requesterAddress, broadcasterPeer.wallet.address, 'requester matches broadcaster');
|
|
215
|
+
t.is(validatorAddress, validatorPeer.wallet.address, 'validator matches selected peer');
|
|
216
|
+
|
|
217
|
+
if (!validatorEntryBefore || !deployerEntryBefore || !requesterEntryBefore) {
|
|
218
|
+
throw new Error('assertTxOperationSuccessState requires entry snapshots.');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const feeAmount = toBalance(transactionUtils.FEE);
|
|
222
|
+
t.ok(feeAmount, 'fee decodes');
|
|
223
|
+
if (!feeAmount) return;
|
|
224
|
+
|
|
225
|
+
const requesterBeforeDecoded = nodeEntryUtils.decode(requesterEntryBefore);
|
|
226
|
+
const validatorBeforeDecoded = nodeEntryUtils.decode(validatorEntryBefore);
|
|
227
|
+
const deployerBeforeDecoded = nodeEntryUtils.decode(deployerEntryBefore);
|
|
228
|
+
|
|
229
|
+
t.ok(requesterBeforeDecoded, 'requester entry before decodes');
|
|
230
|
+
t.ok(validatorBeforeDecoded, 'validator entry before decodes');
|
|
231
|
+
t.ok(deployerBeforeDecoded, 'deployer entry before decodes');
|
|
232
|
+
if (!requesterBeforeDecoded || !validatorBeforeDecoded || !deployerBeforeDecoded) return;
|
|
233
|
+
|
|
234
|
+
const requesterBalanceBefore = toBalance(requesterBeforeDecoded.balance);
|
|
235
|
+
const validatorBalanceBefore = toBalance(validatorBeforeDecoded.balance);
|
|
236
|
+
const deployerBalanceBefore = toBalance(deployerBeforeDecoded.balance);
|
|
237
|
+
|
|
238
|
+
t.ok(requesterBalanceBefore, 'requester balance before decodes');
|
|
239
|
+
t.ok(validatorBalanceBefore, 'validator balance before decodes');
|
|
240
|
+
t.ok(deployerBalanceBefore, 'deployer balance before decodes');
|
|
241
|
+
if (!requesterBalanceBefore || !validatorBalanceBefore || !deployerBalanceBefore) return;
|
|
242
|
+
|
|
243
|
+
const expectedRequesterBalance = requesterBalanceBefore.sub(feeAmount);
|
|
244
|
+
let expectedValidatorBalance = validatorBalanceBefore.add(feeAmount.percentage(PERCENT_50));
|
|
245
|
+
let expectedDeployerBalance = deployerBalanceBefore.add(feeAmount.percentage(PERCENT_25));
|
|
246
|
+
|
|
247
|
+
if (distribution === 'validatorIsCreator') {
|
|
248
|
+
expectedValidatorBalance = validatorBalanceBefore.add(feeAmount.percentage(PERCENT_75));
|
|
249
|
+
expectedDeployerBalance = null; // same as validator
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (distribution === 'requesterIsCreator') {
|
|
253
|
+
expectedDeployerBalance = null; // requester is creator, no bonus
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
await context.sync();
|
|
257
|
+
const requesterAfter = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
|
|
258
|
+
const validatorAfter = await validatorPeer.base.view.get(validatorPeer.wallet.address);
|
|
259
|
+
const deployerAfter = await validatorPeer.base.view.get(deployerPeer.wallet.address);
|
|
260
|
+
|
|
261
|
+
t.ok(requesterAfter?.value, 'requester entry exists after tx');
|
|
262
|
+
t.ok(validatorAfter?.value, 'validator entry exists after tx');
|
|
263
|
+
t.ok(deployerAfter?.value, 'deployer entry exists after tx');
|
|
264
|
+
|
|
265
|
+
const requesterDecoded = requesterAfter?.value ? nodeEntryUtils.decode(requesterAfter.value) : null;
|
|
266
|
+
const validatorDecoded = validatorAfter?.value ? nodeEntryUtils.decode(validatorAfter.value) : null;
|
|
267
|
+
const deployerDecoded = deployerAfter?.value ? nodeEntryUtils.decode(deployerAfter.value) : null;
|
|
268
|
+
|
|
269
|
+
t.ok(requesterDecoded, 'requester entry decodes after tx');
|
|
270
|
+
t.ok(validatorDecoded, 'validator entry decodes after tx');
|
|
271
|
+
t.ok(deployerDecoded, 'deployer entry decodes after tx');
|
|
272
|
+
if (!requesterDecoded || !validatorDecoded || !deployerDecoded) return;
|
|
273
|
+
|
|
274
|
+
t.ok(
|
|
275
|
+
b4a.equals(requesterDecoded.balance, expectedRequesterBalance.value),
|
|
276
|
+
'requester balance reduced by full fee'
|
|
277
|
+
);
|
|
278
|
+
t.ok(
|
|
279
|
+
b4a.equals(validatorDecoded.balance, expectedValidatorBalance.value),
|
|
280
|
+
distribution === 'validatorIsCreator'
|
|
281
|
+
? 'validator rewarded with 75% fee when creator'
|
|
282
|
+
: 'validator rewarded with 50% fee'
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
if (distribution === 'standard') {
|
|
286
|
+
t.ok(
|
|
287
|
+
b4a.equals(deployerDecoded.balance, expectedDeployerBalance.value),
|
|
288
|
+
'deployer rewarded with 25% fee'
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (distribution === 'requesterIsCreator') {
|
|
293
|
+
t.ok(
|
|
294
|
+
b4a.equals(requesterDecoded.balance, expectedRequesterBalance.value),
|
|
295
|
+
'requester pays full fee and receives no creator reward'
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (distribution === 'validatorIsCreator') {
|
|
300
|
+
// deployer is validator; nothing to assert on separate deployer entry
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
t.is(requesterDecoded.isWhitelisted, true, 'requester stays whitelisted');
|
|
304
|
+
t.is(validatorDecoded.isWriter, true, 'validator remains a writer');
|
|
305
|
+
|
|
306
|
+
const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
|
|
307
|
+
t.ok(txEntry, 'tx hash recorded for replay protection');
|
|
308
|
+
|
|
309
|
+
const deploymentKey = `${EntryType.DEPLOYMENT}${externalBootstrap.toString('hex')}`;
|
|
310
|
+
const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
|
|
311
|
+
t.ok(deploymentEntry, 'deployment entry remains present after tx');
|
|
312
|
+
const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value);
|
|
313
|
+
t.ok(decodedDeployment, 'deployment entry decodes after tx');
|
|
314
|
+
if (decodedDeployment?.address) {
|
|
315
|
+
const creatorAddress = addressUtils.bufferToAddress(decodedDeployment.address);
|
|
316
|
+
t.is(
|
|
317
|
+
creatorAddress,
|
|
318
|
+
creatorPeer.wallet.address,
|
|
319
|
+
'deployment entry still bound to subnetwork creator'
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!skipSync) {
|
|
324
|
+
await context.sync();
|
|
325
|
+
const replicaTxEntry = await broadcasterPeer.base.view.get(txHashBuffer.toString('hex'));
|
|
326
|
+
t.ok(replicaTxEntry, 'tx entry replicated to broadcaster');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export async function assertTxOperationFailureState(
|
|
331
|
+
t,
|
|
332
|
+
context,
|
|
333
|
+
{
|
|
334
|
+
payload,
|
|
335
|
+
validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
|
|
336
|
+
deployerPeer = context.txOperation?.deployerPeer ?? selectDeployerPeer(context),
|
|
337
|
+
broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
|
|
338
|
+
validatorEntryBefore = context.txOperation?.validatorEntryBefore?.value ?? null,
|
|
339
|
+
deployerEntryBefore = context.txOperation?.deployerEntryBefore?.value ?? null,
|
|
340
|
+
requesterEntryBefore = context.txOperation?.requesterEntryBefore?.value ?? null
|
|
341
|
+
} = {}
|
|
342
|
+
) {
|
|
343
|
+
if (!payload) throw new Error('assertTxOperationFailureState requires payload.');
|
|
344
|
+
|
|
345
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
346
|
+
t.ok(decoded, 'invalid tx payload decodes');
|
|
347
|
+
|
|
348
|
+
if (validatorEntryBefore) {
|
|
349
|
+
const after = await validatorPeer.base.view.get(validatorPeer.wallet.address);
|
|
350
|
+
t.ok(after, 'validator entry still exists after rejection');
|
|
351
|
+
if (after?.value) {
|
|
352
|
+
t.ok(b4a.equals(after.value, validatorEntryBefore), 'validator entry unchanged after rejection');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (deployerEntryBefore) {
|
|
357
|
+
const after = await validatorPeer.base.view.get(deployerPeer.wallet.address);
|
|
358
|
+
t.ok(after, 'deployer entry still exists after rejection');
|
|
359
|
+
if (after?.value) {
|
|
360
|
+
t.ok(b4a.equals(after.value, deployerEntryBefore), 'deployer entry unchanged after rejection');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (requesterEntryBefore) {
|
|
365
|
+
const after = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
|
|
366
|
+
t.ok(after, 'requester entry still exists after rejection');
|
|
367
|
+
if (after?.value) {
|
|
368
|
+
t.ok(b4a.equals(after.value, requesterEntryBefore), 'requester entry unchanged after rejection');
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const txHashBuffer = decoded?.txo?.tx;
|
|
373
|
+
if (txHashBuffer) {
|
|
374
|
+
const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
|
|
375
|
+
t.is(txEntry, null, 'tx hash not recorded after rejection');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export async function appendInvalidTxPayload(context, invalidPayload) {
|
|
380
|
+
const node =
|
|
381
|
+
context.bootstrap ?? context.adminBootstrap ?? context.txOperation?.validatorPeer ?? context.peers?.[0];
|
|
382
|
+
await node.base.append(invalidPayload);
|
|
383
|
+
await node.base.update();
|
|
384
|
+
await eventFlush();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export function mutateBootstrapEqualMbs(t, validPayload) {
|
|
388
|
+
const decoded = safeDecodeApplyOperation(validPayload);
|
|
389
|
+
t.ok(decoded, 'fixtures decode');
|
|
390
|
+
if (!decoded?.txo) return validPayload;
|
|
391
|
+
decoded.txo.bs = decoded.txo.mbs;
|
|
392
|
+
return safeEncodeApplyOperation(decoded);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export function mutateMbsMismatch(t, validPayload) {
|
|
396
|
+
const decoded = safeDecodeApplyOperation(validPayload);
|
|
397
|
+
t.ok(decoded, 'fixtures decode');
|
|
398
|
+
if (!decoded?.txo) return validPayload;
|
|
399
|
+
decoded.txo.mbs = b4a.alloc(decoded.txo.mbs?.length ?? 32, 0x7e);
|
|
400
|
+
return safeEncodeApplyOperation(decoded);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function mutateValidatorSignature(t, validPayload) {
|
|
404
|
+
const decoded = safeDecodeApplyOperation(validPayload);
|
|
405
|
+
t.ok(decoded, 'fixtures decode');
|
|
406
|
+
const parent = decoded?.txo;
|
|
407
|
+
if (!parent?.vs) return validPayload;
|
|
408
|
+
const mutated = b4a.from(parent.vs);
|
|
409
|
+
mutated[mutated.length - 1] ^= 0xff;
|
|
410
|
+
parent.vs = mutated;
|
|
411
|
+
return safeEncodeApplyOperation(decoded);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function mutateBootstrapUnregistered(t, validPayload) {
|
|
415
|
+
const decoded = safeDecodeApplyOperation(validPayload);
|
|
416
|
+
t.ok(decoded, 'fixtures decode');
|
|
417
|
+
const parent = decoded?.txo;
|
|
418
|
+
if (!parent?.bs) return validPayload;
|
|
419
|
+
const mutated = b4a.alloc(parent.bs.length, 0x24);
|
|
420
|
+
parent.bs = mutated;
|
|
421
|
+
return safeEncodeApplyOperation(decoded);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export default {
|
|
425
|
+
setupTxOperationScenario,
|
|
426
|
+
buildTxOperationPayload,
|
|
427
|
+
assertTxOperationSuccessState,
|
|
428
|
+
assertTxOperationFailureState
|
|
429
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTxOperationScenario,
|
|
4
|
+
buildTxOperationPayload,
|
|
5
|
+
assertTxOperationSuccessState
|
|
6
|
+
} from './txOperationScenarioHelpers.js';
|
|
7
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
8
|
+
|
|
9
|
+
export default function txOperationStandardHappyPathScenario() {
|
|
10
|
+
test('State.apply txOperation processes subnetwork tx - happy path', async t => {
|
|
11
|
+
const context = await setupTxOperationScenario(t);
|
|
12
|
+
const payload = await buildTxOperationPayload(context);
|
|
13
|
+
const validatorPeer = context.txOperation?.validatorPeer ?? context.adminBootstrap;
|
|
14
|
+
|
|
15
|
+
await validatorPeer.base.append(payload);
|
|
16
|
+
await validatorPeer.base.update();
|
|
17
|
+
await eventFlush();
|
|
18
|
+
|
|
19
|
+
await assertTxOperationSuccessState(t, context, { payload });
|
|
20
|
+
});
|
|
21
|
+
}
|
package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
2
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
3
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
4
|
+
|
|
5
|
+
export default function txOperationTransferFeeAddCreatorBalanceFailureScenario() {
|
|
6
|
+
createTransferFeeGuardScenario({
|
|
7
|
+
title: 'State.transferFeeTxOperation rejects when adding fee to subnetwork creator balance fails',
|
|
8
|
+
applyPatch: async () => {
|
|
9
|
+
const feeAmount = toBalance(transactionUtils.FEE);
|
|
10
|
+
const balanceProto = Object.getPrototypeOf(feeAmount);
|
|
11
|
+
const originalAdd = balanceProto.add;
|
|
12
|
+
let calls = 0;
|
|
13
|
+
balanceProto.add = function (...args) {
|
|
14
|
+
calls += 1;
|
|
15
|
+
// validator add first, creator add second -> fail on second
|
|
16
|
+
if (calls === 2) return null;
|
|
17
|
+
return originalAdd.apply(this, args);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
balanceProto.add = originalAdd;
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
expectedLogs: ['Failed to add fee to subnetwork creator balance.']
|
|
25
|
+
}).performScenario();
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
2
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
3
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
4
|
+
|
|
5
|
+
export default function txOperationTransferFeeAddValidatorBalanceFailureScenario() {
|
|
6
|
+
createTransferFeeGuardScenario({
|
|
7
|
+
title: 'State.transferFeeTxOperation rejects when adding fee to validator balance fails',
|
|
8
|
+
applyPatch: async () => {
|
|
9
|
+
const feeAmount = toBalance(transactionUtils.FEE);
|
|
10
|
+
const balanceProto = Object.getPrototypeOf(feeAmount);
|
|
11
|
+
const originalAdd = balanceProto.add;
|
|
12
|
+
let calls = 0;
|
|
13
|
+
balanceProto.add = function (...args) {
|
|
14
|
+
calls += 1;
|
|
15
|
+
if (calls === 1) return null;
|
|
16
|
+
return originalAdd.apply(this, args);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
balanceProto.add = originalAdd;
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
expectedLogs: ['Failed to add fee to validator balance.']
|
|
24
|
+
}).performScenario();
|
|
25
|
+
}
|
package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
2
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
3
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
4
|
+
|
|
5
|
+
export default function txOperationTransferFeeAddValidatorBonusFailureScenario() {
|
|
6
|
+
createTransferFeeGuardScenario({
|
|
7
|
+
title: 'State.transferFeeTxOperation rejects when adding validator bonus fee fails',
|
|
8
|
+
setupOptions: { creatorPeerKind: 'validator' },
|
|
9
|
+
applyPatch: async () => {
|
|
10
|
+
const feeAmount = toBalance(transactionUtils.FEE);
|
|
11
|
+
const balanceProto = Object.getPrototypeOf(feeAmount);
|
|
12
|
+
const originalAdd = balanceProto.add;
|
|
13
|
+
let calls = 0;
|
|
14
|
+
balanceProto.add = function (...args) {
|
|
15
|
+
calls += 1;
|
|
16
|
+
// first add (50%) ok, second (bonus) fails
|
|
17
|
+
if (calls === 2) return null;
|
|
18
|
+
return originalAdd.apply(this, args);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return () => {
|
|
22
|
+
balanceProto.add = originalAdd;
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
expectedLogs: ['Failed to add bonus fee to validator balance.']
|
|
26
|
+
}).performScenario();
|
|
27
|
+
}
|
package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { createTransferFeeGuardScenario, patchBatchGet } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
3
|
+
|
|
4
|
+
export default function txOperationTransferFeeDecodeCreatorEntryScenario() {
|
|
5
|
+
createTransferFeeGuardScenario({
|
|
6
|
+
title: 'State.transferFeeTxOperation rejects undecodable subnetwork creator entry',
|
|
7
|
+
applyPatch: async ({ context, node }) => {
|
|
8
|
+
const creatorAddressString = context.txOperation?.deployerPeer?.wallet.address;
|
|
9
|
+
const matcher = key => {
|
|
10
|
+
if (!creatorAddressString) return false;
|
|
11
|
+
if (typeof key === 'string') return key === creatorAddressString;
|
|
12
|
+
return b4a.isBuffer(key) && b4a.toString(key, 'ascii') === creatorAddressString;
|
|
13
|
+
};
|
|
14
|
+
return patchBatchGet(node, matcher, () => ({ value: b4a.alloc(0) }));
|
|
15
|
+
},
|
|
16
|
+
expectedLogs: ['Invalid subnetwork creator node entry, can not to decode.']
|
|
17
|
+
}).performScenario();
|
|
18
|
+
}
|
package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { createTransferFeeGuardScenario, patchBatchGet } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
3
|
+
|
|
4
|
+
export default function txOperationTransferFeeDecodeRequesterEntryScenario() {
|
|
5
|
+
createTransferFeeGuardScenario({
|
|
6
|
+
title: 'State.transferFeeTxOperation rejects undecodable requester node entry',
|
|
7
|
+
applyPatch: async ({ node, decoded, requesterAddressString }) => {
|
|
8
|
+
const matcher = key => {
|
|
9
|
+
if (!requesterAddressString) return false;
|
|
10
|
+
if (typeof key === 'string') return key === requesterAddressString;
|
|
11
|
+
return b4a.isBuffer(key) && b4a.toString(key, 'ascii') === requesterAddressString;
|
|
12
|
+
};
|
|
13
|
+
return patchBatchGet(node, matcher, () => ({ value: b4a.alloc(0) }));
|
|
14
|
+
},
|
|
15
|
+
expectedLogs: ['Invalid requester node entry, can not to decode.']
|
|
16
|
+
}).performScenario();
|
|
17
|
+
}
|
package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
3
|
+
import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
|
|
4
|
+
|
|
5
|
+
export default function txOperationTransferFeeDecodeValidatorEntryScenario() {
|
|
6
|
+
createTransferFeeGuardScenario({
|
|
7
|
+
title: 'State.transferFeeTxOperation rejects undecodable validator node entry',
|
|
8
|
+
applyPatch: async ({ node, decoded }) => {
|
|
9
|
+
const validatorAddressString = decoded?.txo?.va
|
|
10
|
+
? decoded.txo.va.toString('ascii')
|
|
11
|
+
: node.wallet.address;
|
|
12
|
+
const validatorEntry = await node.base.view.get(validatorAddressString);
|
|
13
|
+
const validatorEntryBuffer = validatorEntry?.value ? b4a.from(validatorEntry.value) : null;
|
|
14
|
+
const originalDecode = nodeEntryUtils.decode;
|
|
15
|
+
let calls = 0;
|
|
16
|
+
|
|
17
|
+
nodeEntryUtils.decode = entry => {
|
|
18
|
+
if (validatorEntryBuffer && b4a.equals(entry, validatorEntryBuffer)) {
|
|
19
|
+
calls += 1;
|
|
20
|
+
if (calls === 2) return null; // first decode for validator checks ok, second fails
|
|
21
|
+
}
|
|
22
|
+
return originalDecode(entry);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
nodeEntryUtils.decode = originalDecode;
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
expectedLogs: ['Invalid validator node entry, can not to decode.']
|
|
30
|
+
}).performScenario();
|
|
31
|
+
}
|