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,22 @@
|
|
|
1
|
+
import InvalidPayloadValidationScenario from '../common/payload-structure/invalidPayloadValidationScenario.js';
|
|
2
|
+
import {
|
|
3
|
+
buildTransferPayload,
|
|
4
|
+
mutateTransferPayloadForInvalidSchema,
|
|
5
|
+
assertTransferFailureState,
|
|
6
|
+
setupTransferScenario,
|
|
7
|
+
applyInvalidTransferPayloadWithNoMutations
|
|
8
|
+
} from './transferScenarioHelpers.js';
|
|
9
|
+
|
|
10
|
+
export default function transferContractSchemaValidationScenario() {
|
|
11
|
+
new InvalidPayloadValidationScenario({
|
|
12
|
+
title: 'State.apply transfer rejects payloads when contract schema validation fails',
|
|
13
|
+
setupScenario: setupTransferScenario,
|
|
14
|
+
buildValidPayload: context => buildTransferPayload(context),
|
|
15
|
+
mutatePayload: mutateTransferPayloadForInvalidSchema,
|
|
16
|
+
applyInvalidPayload: (context, invalidPayload, t) =>
|
|
17
|
+
applyInvalidTransferPayloadWithNoMutations(t, context, invalidPayload),
|
|
18
|
+
assertStateUnchanged: (t, context, _validPayload, invalidPayload) =>
|
|
19
|
+
assertTransferFailureState(t, context, { payload: invalidPayload }),
|
|
20
|
+
expectedLogs: ['Contract schema validation failed.']
|
|
21
|
+
}).performScenario();
|
|
22
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { test } from 'brittle';
|
|
3
|
+
import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
4
|
+
import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
|
|
5
|
+
import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
6
|
+
import {
|
|
7
|
+
setupTransferScenario,
|
|
8
|
+
DEFAULT_TRANSFER_AMOUNT,
|
|
9
|
+
DEFAULT_INITIAL_BALANCE
|
|
10
|
+
} from './transferScenarioHelpers.js';
|
|
11
|
+
import { initializeBalances, whitelistAddress } from '../common/commonScenarioHelper.js';
|
|
12
|
+
import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
|
|
13
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
14
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
15
|
+
import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
|
|
16
|
+
|
|
17
|
+
export default function transferDoubleSpendAcrossValidatorsScenario() {
|
|
18
|
+
test('State.apply transfer prevents double spend across validators (distinct tx hashes)', async t => {
|
|
19
|
+
/* Sender has only amount+fee; sends two distinct transfers (different nonces/hashes) to two recipients via two validators. First succeeds, second is skipped (insufficient balance). */
|
|
20
|
+
const amountBalance = toBalance(DEFAULT_TRANSFER_AMOUNT);
|
|
21
|
+
const feeBalance = toBalance(transactionUtils.FEE);
|
|
22
|
+
const initialSenderBalance = amountBalance && feeBalance ? amountBalance.add(feeBalance)?.value : DEFAULT_INITIAL_BALANCE;
|
|
23
|
+
t.ok(initialSenderBalance, 'initial sender balance computed');
|
|
24
|
+
|
|
25
|
+
const context = await setupTransferScenario(t, {
|
|
26
|
+
nodes: 6,
|
|
27
|
+
recipientHasEntry: false,
|
|
28
|
+
senderInitialBalance: initialSenderBalance
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const nonAdmin = context.peers.slice(1);
|
|
32
|
+
const primaryValidator = context.transferScenario.validatorPeer;
|
|
33
|
+
const senderPeer = context.transferScenario.senderPeer;
|
|
34
|
+
const recipientA = context.transferScenario.recipientPeer;
|
|
35
|
+
const secondaryValidator = nonAdmin[3];
|
|
36
|
+
const recipientB = nonAdmin[4];
|
|
37
|
+
t.ok(recipientB, 'second recipient available');
|
|
38
|
+
|
|
39
|
+
// Prepare secondary validator as writer with funds.
|
|
40
|
+
await initializeBalances(context, [[secondaryValidator.wallet.address, DEFAULT_INITIAL_BALANCE]]);
|
|
41
|
+
await whitelistAddress(context, secondaryValidator.wallet.address);
|
|
42
|
+
await promotePeerToWriter(t, context, {
|
|
43
|
+
readerPeer: secondaryValidator,
|
|
44
|
+
validatorPeer: context.adminBootstrap,
|
|
45
|
+
expectedWriterIndex: 2
|
|
46
|
+
});
|
|
47
|
+
await context.sync();
|
|
48
|
+
|
|
49
|
+
const txValidityA = await deriveIndexerSequenceState(primaryValidator.base);
|
|
50
|
+
const txValidityB = await deriveIndexerSequenceState(secondaryValidator.base);
|
|
51
|
+
|
|
52
|
+
const partialA = await PartialStateMessageOperations.assembleTransferOperationMessage(
|
|
53
|
+
senderPeer.wallet,
|
|
54
|
+
recipientA.wallet.address,
|
|
55
|
+
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
56
|
+
b4a.toString(txValidityA, 'hex')
|
|
57
|
+
);
|
|
58
|
+
const partialB = await PartialStateMessageOperations.assembleTransferOperationMessage(
|
|
59
|
+
senderPeer.wallet,
|
|
60
|
+
recipientB.wallet.address,
|
|
61
|
+
b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
|
|
62
|
+
b4a.toString(txValidityB, 'hex')
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const payloadA = await CompleteStateMessageOperations.assembleCompleteTransferOperationMessage(
|
|
66
|
+
primaryValidator.wallet,
|
|
67
|
+
partialA.address,
|
|
68
|
+
b4a.from(partialA.tro.tx, 'hex'),
|
|
69
|
+
b4a.from(partialA.tro.txv, 'hex'),
|
|
70
|
+
b4a.from(partialA.tro.in, 'hex'),
|
|
71
|
+
partialA.tro.to,
|
|
72
|
+
b4a.from(partialA.tro.am, 'hex'),
|
|
73
|
+
b4a.from(partialA.tro.is, 'hex')
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const payloadB = await CompleteStateMessageOperations.assembleCompleteTransferOperationMessage(
|
|
77
|
+
secondaryValidator.wallet,
|
|
78
|
+
partialB.address,
|
|
79
|
+
b4a.from(partialB.tro.tx, 'hex'),
|
|
80
|
+
b4a.from(partialB.tro.txv, 'hex'),
|
|
81
|
+
b4a.from(partialB.tro.in, 'hex'),
|
|
82
|
+
partialB.tro.to,
|
|
83
|
+
b4a.from(partialB.tro.am, 'hex'),
|
|
84
|
+
b4a.from(partialB.tro.is, 'hex')
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Apply first transfer successfully via primary validator.
|
|
88
|
+
await primaryValidator.base.append(payloadA);
|
|
89
|
+
await primaryValidator.base.update();
|
|
90
|
+
await eventFlush();
|
|
91
|
+
await context.sync();
|
|
92
|
+
|
|
93
|
+
const senderAfterFirst = await primaryValidator.base.view.get(senderPeer.wallet.address);
|
|
94
|
+
const recipientAfterFirst = await primaryValidator.base.view.get(recipientA.wallet.address);
|
|
95
|
+
const validatorAfterFirst = await primaryValidator.base.view.get(primaryValidator.wallet.address);
|
|
96
|
+
|
|
97
|
+
t.ok(senderAfterFirst?.value, 'sender entry exists after first transfer');
|
|
98
|
+
t.ok(recipientAfterFirst?.value, 'first recipient entry exists after first transfer');
|
|
99
|
+
t.ok(validatorAfterFirst?.value, 'primary validator entry exists after first transfer');
|
|
100
|
+
|
|
101
|
+
const txHashA = partialA.tro.tx.toString('hex');
|
|
102
|
+
const txEntryA = await primaryValidator.base.view.get(txHashA);
|
|
103
|
+
t.ok(txEntryA, 'first tx hash recorded');
|
|
104
|
+
|
|
105
|
+
// Attempt second transfer via secondary validator (should be ignored: insufficient balance).
|
|
106
|
+
await secondaryValidator.base.append(payloadB);
|
|
107
|
+
await secondaryValidator.base.update();
|
|
108
|
+
await eventFlush();
|
|
109
|
+
await context.sync();
|
|
110
|
+
|
|
111
|
+
const senderAfterSecond = await secondaryValidator.base.view.get(senderPeer.wallet.address);
|
|
112
|
+
const recipientBAfter = await secondaryValidator.base.view.get(recipientB.wallet.address);
|
|
113
|
+
const validatorBAfter = await secondaryValidator.base.view.get(secondaryValidator.wallet.address);
|
|
114
|
+
|
|
115
|
+
// Sender balance unchanged vs after first.
|
|
116
|
+
const senderBalanceFirst = nodeEntryUtils.decode(senderAfterFirst?.value ?? Buffer.alloc(0))?.balance;
|
|
117
|
+
const senderBalanceSecond = nodeEntryUtils.decode(senderAfterSecond?.value ?? Buffer.alloc(0))?.balance;
|
|
118
|
+
t.ok(senderBalanceFirst && senderBalanceSecond && b4a.equals(senderBalanceFirst, senderBalanceSecond), 'sender balance unchanged after second attempt');
|
|
119
|
+
|
|
120
|
+
// Recipient B did not receive funds.
|
|
121
|
+
t.ok(!recipientBAfter?.value, 'second recipient entry absent after ignored transfer');
|
|
122
|
+
|
|
123
|
+
// Secondary validator not rewarded.
|
|
124
|
+
const validatorBalanceB = nodeEntryUtils.decode(validatorBAfter?.value ?? Buffer.alloc(0))?.balance;
|
|
125
|
+
const validatorInitialB = await primaryValidator.base.view.get(secondaryValidator.wallet.address);
|
|
126
|
+
const validatorBalanceInitialB = nodeEntryUtils.decode(validatorInitialB?.value ?? Buffer.alloc(0))?.balance;
|
|
127
|
+
if (validatorBalanceB && validatorBalanceInitialB) {
|
|
128
|
+
t.ok(b4a.equals(validatorBalanceB, validatorBalanceInitialB), 'secondary validator balance unchanged');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const txHashB = partialB.tro.tx.toString('hex');
|
|
132
|
+
const txEntryB = await secondaryValidator.base.view.get(txHashB);
|
|
133
|
+
t.is(txEntryB, null, 'second tx hash not recorded after insufficient balance');
|
|
134
|
+
|
|
135
|
+
t.ok(nodeEntryUtils.decode(recipientAfterFirst?.value ?? Buffer.alloc(0)), 'recipient A decodes');
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
DEFAULT_TRANSFER_AMOUNT,
|
|
8
|
+
DEFAULT_INITIAL_BALANCE
|
|
9
|
+
} from './transferScenarioHelpers.js';
|
|
10
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
11
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
12
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
13
|
+
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
14
|
+
|
|
15
|
+
export default function transferDoubleSpendSameBatchScenario() {
|
|
16
|
+
test('State.apply transfer prevents double spend in single batch (distinct tx hashes)', async t => {
|
|
17
|
+
/* Same validator processes two different tx hashes spending the same balance in one batch: first applies, second ignored (insufficient funds). */
|
|
18
|
+
const amountBalance = toBalance(DEFAULT_TRANSFER_AMOUNT);
|
|
19
|
+
const feeBalance = toBalance(transactionUtils.FEE);
|
|
20
|
+
const initialSenderBalance = amountBalance && feeBalance ? amountBalance.add(feeBalance)?.value : DEFAULT_INITIAL_BALANCE;
|
|
21
|
+
t.ok(initialSenderBalance, 'initial sender balance computed');
|
|
22
|
+
|
|
23
|
+
const context = await setupTransferScenario(t, {
|
|
24
|
+
nodes: 5,
|
|
25
|
+
recipientHasEntry: false,
|
|
26
|
+
senderInitialBalance: initialSenderBalance
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const nonAdmin = context.peers.slice(1);
|
|
30
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
31
|
+
const recipientB = nonAdmin[3];
|
|
32
|
+
t.ok(recipientB, 'second recipient available');
|
|
33
|
+
|
|
34
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
35
|
+
const payloadA = await buildTransferPayload(context, { recipientPeer });
|
|
36
|
+
const payloadB = await buildTransferPayload(context, { recipientPeer: recipientB });
|
|
37
|
+
|
|
38
|
+
// Append both in a single batch.
|
|
39
|
+
await validatorPeer.base.append([payloadA, payloadB]);
|
|
40
|
+
await validatorPeer.base.update();
|
|
41
|
+
await eventFlush();
|
|
42
|
+
|
|
43
|
+
// State should match single successful application of payloadA.
|
|
44
|
+
await assertTransferSuccessState(t, context, {
|
|
45
|
+
payload: payloadA,
|
|
46
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
47
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
48
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Second recipient should remain untouched (no entry if it did not exist).
|
|
52
|
+
const recipientBAfter = await validatorPeer.base.view.get(recipientB.wallet.address);
|
|
53
|
+
t.is(recipientBAfter, null, 'second recipient not credited after insufficient funds');
|
|
54
|
+
|
|
55
|
+
// Second tx hash should not be recorded.
|
|
56
|
+
const decodedB = safeDecodeApplyOperation(payloadB);
|
|
57
|
+
const txHashB = decodedB?.tro?.tx?.toString('hex') ?? '';
|
|
58
|
+
if (txHashB) {
|
|
59
|
+
const txEntryB = await validatorPeer.base.view.get(txHashB);
|
|
60
|
+
t.is(txEntryB, null, 'second tx hash not recorded after insufficient funds');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
DEFAULT_TRANSFER_AMOUNT,
|
|
8
|
+
DEFAULT_INITIAL_BALANCE
|
|
9
|
+
} from './transferScenarioHelpers.js';
|
|
10
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
11
|
+
import { toBalance } from '../../../../../src/core/state/utils/balance.js';
|
|
12
|
+
import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
|
|
13
|
+
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
14
|
+
|
|
15
|
+
export default function transferDoubleSpendSingleValidatorScenario() {
|
|
16
|
+
test('State.apply transfer prevents double spend via same validator (separate appends, distinct tx hashes)', async t => {
|
|
17
|
+
/* Sender has only amount+fee; same validator processes two distinct transfers (different nonces/hashes) to two recipients. First applies, second skipped. */
|
|
18
|
+
const amountBalance = toBalance(DEFAULT_TRANSFER_AMOUNT);
|
|
19
|
+
const feeBalance = toBalance(transactionUtils.FEE);
|
|
20
|
+
const initialSenderBalance = amountBalance && feeBalance ? amountBalance.add(feeBalance)?.value : DEFAULT_INITIAL_BALANCE;
|
|
21
|
+
t.ok(initialSenderBalance, 'initial sender balance computed');
|
|
22
|
+
|
|
23
|
+
const context = await setupTransferScenario(t, {
|
|
24
|
+
nodes: 5,
|
|
25
|
+
recipientHasEntry: false,
|
|
26
|
+
senderInitialBalance: initialSenderBalance
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const nonAdmin = context.peers.slice(1);
|
|
30
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
31
|
+
const recipientB = nonAdmin[3];
|
|
32
|
+
t.ok(recipientB, 'second recipient available');
|
|
33
|
+
|
|
34
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
35
|
+
const payloadA = await buildTransferPayload(context, { recipientPeer });
|
|
36
|
+
const payloadB = await buildTransferPayload(context, { recipientPeer: recipientB });
|
|
37
|
+
|
|
38
|
+
// First transfer
|
|
39
|
+
await validatorPeer.base.append(payloadA);
|
|
40
|
+
await validatorPeer.base.update();
|
|
41
|
+
await eventFlush();
|
|
42
|
+
|
|
43
|
+
// Second transfer (should be ignored due to insufficient balance)
|
|
44
|
+
await validatorPeer.base.append(payloadB);
|
|
45
|
+
await validatorPeer.base.update();
|
|
46
|
+
await eventFlush();
|
|
47
|
+
|
|
48
|
+
await assertTransferSuccessState(t, context, {
|
|
49
|
+
payload: payloadA,
|
|
50
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
51
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
52
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Second recipient should remain untouched (no entry if it did not exist).
|
|
56
|
+
const recipientBAfter = await validatorPeer.base.view.get(recipientB.wallet.address);
|
|
57
|
+
t.is(recipientBAfter, null, 'second recipient not credited after insufficient funds');
|
|
58
|
+
|
|
59
|
+
// Second tx hash should not be recorded.
|
|
60
|
+
const decodedB = safeDecodeApplyOperation(payloadB);
|
|
61
|
+
const txHashB = decodedB?.tro?.tx?.toString('hex') ?? '';
|
|
62
|
+
if (txHashB) {
|
|
63
|
+
const txEntryB = await validatorPeer.base.view.get(txHashB);
|
|
64
|
+
t.is(txEntryB, null, 'second tx hash not recorded after insufficient funds');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
DEFAULT_TRANSFER_AMOUNT
|
|
8
|
+
} from './transferScenarioHelpers.js';
|
|
9
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
10
|
+
|
|
11
|
+
export default function transferExistingRecipientAmountScenario() {
|
|
12
|
+
test('State.apply transfer pays existing recipient and validator (amount > 0)', async t => {
|
|
13
|
+
/* Existing recipient gains amount, sender pays amount+fee, validator earns 75% fee. */
|
|
14
|
+
const context = await setupTransferScenario(t, { recipientHasEntry: true });
|
|
15
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
16
|
+
|
|
17
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
18
|
+
const payload = await buildTransferPayload(context, { amount: DEFAULT_TRANSFER_AMOUNT });
|
|
19
|
+
|
|
20
|
+
await validatorPeer.base.append(payload);
|
|
21
|
+
await validatorPeer.base.update();
|
|
22
|
+
await eventFlush();
|
|
23
|
+
|
|
24
|
+
await assertTransferSuccessState(t, context, {
|
|
25
|
+
payload,
|
|
26
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
27
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
28
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
ZERO_TRANSFER_AMOUNT
|
|
8
|
+
} from './transferScenarioHelpers.js';
|
|
9
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
10
|
+
|
|
11
|
+
export default function transferExistingRecipientZeroAmountScenario() {
|
|
12
|
+
test('State.apply transfer charges fee when recipient exists (amount = 0)', async t => {
|
|
13
|
+
/* Sender only pays fee, recipient balance stays the same, validator earns 75% fee. */
|
|
14
|
+
const context = await setupTransferScenario(t, { recipientHasEntry: true });
|
|
15
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
16
|
+
|
|
17
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
18
|
+
const payload = await buildTransferPayload(context, { amount: ZERO_TRANSFER_AMOUNT });
|
|
19
|
+
|
|
20
|
+
await validatorPeer.base.append(payload);
|
|
21
|
+
await validatorPeer.base.update();
|
|
22
|
+
await eventFlush();
|
|
23
|
+
|
|
24
|
+
await assertTransferSuccessState(t, context, {
|
|
25
|
+
payload,
|
|
26
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
27
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
28
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createTransferHandlerGuardBypassScenario } from './transferScenarioHelpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Covers handler-level guards that react to null entries returned from #transfer.
|
|
5
|
+
* These are purely handler guards, not transfer arithmetic failures.
|
|
6
|
+
*/
|
|
7
|
+
export default function transferHandlerGuardScenarios() {
|
|
8
|
+
createTransferHandlerGuardBypassScenario({
|
|
9
|
+
title: 'State.apply transfer rejects payloads when sender entry from transfer result is null',
|
|
10
|
+
logMessage: 'Invalid sender entry.'
|
|
11
|
+
}).performScenario();
|
|
12
|
+
|
|
13
|
+
createTransferHandlerGuardBypassScenario({
|
|
14
|
+
title: 'State.apply transfer rejects payloads when validator entry from transfer result is null',
|
|
15
|
+
logMessage: 'Invalid validator entry.'
|
|
16
|
+
}).performScenario();
|
|
17
|
+
|
|
18
|
+
createTransferHandlerGuardBypassScenario({
|
|
19
|
+
title: 'State.apply transfer rejects payloads when recipient entry from transfer result is null',
|
|
20
|
+
logMessage: 'Invalid recipient entry.'
|
|
21
|
+
}).performScenario();
|
|
22
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { test } from 'brittle';
|
|
3
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
4
|
+
import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
|
|
5
|
+
import {
|
|
6
|
+
setupTransferScenario,
|
|
7
|
+
buildTransferPayload,
|
|
8
|
+
snapshotTransferEntries,
|
|
9
|
+
assertTransferFailureState
|
|
10
|
+
} from './transferScenarioHelpers.js';
|
|
11
|
+
|
|
12
|
+
export default function transferInvalidIncomingDataScenario() {
|
|
13
|
+
test('State.apply transfer rejects when incoming data is missing', async t => {
|
|
14
|
+
const context = await setupTransferScenario(t);
|
|
15
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
16
|
+
|
|
17
|
+
const snapshots = await snapshotTransferEntries(context, {
|
|
18
|
+
senderPeer,
|
|
19
|
+
recipientPeer,
|
|
20
|
+
validatorPeer
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const payload = await buildTransferPayload(context);
|
|
24
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
25
|
+
t.ok(decoded?.address && decoded?.tro?.to, 'transfer payload decodes');
|
|
26
|
+
|
|
27
|
+
const requesterAddressBuffer = decoded.address;
|
|
28
|
+
const recipientAddressBuffer = decoded.tro.to;
|
|
29
|
+
|
|
30
|
+
const originalEquals = b4a.equals;
|
|
31
|
+
const originalConsoleError = console.error;
|
|
32
|
+
const capturedLogs = [];
|
|
33
|
+
|
|
34
|
+
console.error = (...args) => {
|
|
35
|
+
capturedLogs.push(args);
|
|
36
|
+
originalConsoleError(...args);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
b4a.equals = (a, b) => {
|
|
40
|
+
if (originalEquals(a, requesterAddressBuffer) && originalEquals(b, recipientAddressBuffer)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return originalEquals(a, b);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
await validatorPeer.base.append(payload);
|
|
48
|
+
await validatorPeer.base.update();
|
|
49
|
+
await eventFlush();
|
|
50
|
+
} finally {
|
|
51
|
+
b4a.equals = originalEquals;
|
|
52
|
+
console.error = originalConsoleError;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await assertTransferFailureState(t, context, {
|
|
56
|
+
payload,
|
|
57
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
58
|
+
recipientEntryBefore: snapshots.recipientEntry
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const expectedLog = capturedLogs.some(args =>
|
|
62
|
+
args.some(arg => typeof arg === 'string' && arg.includes('Invalid transfer incoming data.'))
|
|
63
|
+
);
|
|
64
|
+
t.ok(expectedLog, 'expected apply log was emitted');
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
DEFAULT_TRANSFER_AMOUNT
|
|
8
|
+
} from './transferScenarioHelpers.js';
|
|
9
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
10
|
+
|
|
11
|
+
export default function transferNewRecipientAmountScenario() {
|
|
12
|
+
test('State.apply transfer creates recipient entry when missing (amount > 0)', async t => {
|
|
13
|
+
/* Missing recipient gets new reader entry with amount, sender pays amount+fee, validator earns 75% fee. */
|
|
14
|
+
const context = await setupTransferScenario(t, { recipientHasEntry: false });
|
|
15
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
16
|
+
|
|
17
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
18
|
+
const payload = await buildTransferPayload(context, { amount: DEFAULT_TRANSFER_AMOUNT });
|
|
19
|
+
|
|
20
|
+
await validatorPeer.base.append(payload);
|
|
21
|
+
await validatorPeer.base.update();
|
|
22
|
+
await eventFlush();
|
|
23
|
+
|
|
24
|
+
await assertTransferSuccessState(t, context, {
|
|
25
|
+
payload,
|
|
26
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
27
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
28
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { test } from 'brittle';
|
|
2
|
+
import {
|
|
3
|
+
setupTransferScenario,
|
|
4
|
+
buildTransferPayload,
|
|
5
|
+
assertTransferSuccessState,
|
|
6
|
+
snapshotTransferEntries,
|
|
7
|
+
ZERO_TRANSFER_AMOUNT
|
|
8
|
+
} from './transferScenarioHelpers.js';
|
|
9
|
+
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
10
|
+
|
|
11
|
+
export default function transferNewRecipientZeroAmountScenario() {
|
|
12
|
+
test('State.apply transfer initializes missing recipient with zero balance (amount = 0)', async t => {
|
|
13
|
+
/* Missing recipient gets zeroed reader entry, sender pays fee, validator earns 75% fee. */
|
|
14
|
+
const context = await setupTransferScenario(t, { recipientHasEntry: false });
|
|
15
|
+
const { senderPeer, recipientPeer, validatorPeer } = context.transferScenario;
|
|
16
|
+
|
|
17
|
+
const snapshots = await snapshotTransferEntries(context, { senderPeer, recipientPeer, validatorPeer });
|
|
18
|
+
const payload = await buildTransferPayload(context, { amount: ZERO_TRANSFER_AMOUNT });
|
|
19
|
+
|
|
20
|
+
await validatorPeer.base.append(payload);
|
|
21
|
+
await validatorPeer.base.update();
|
|
22
|
+
await eventFlush();
|
|
23
|
+
|
|
24
|
+
await assertTransferSuccessState(t, context, {
|
|
25
|
+
payload,
|
|
26
|
+
senderEntryBefore: snapshots.senderEntry,
|
|
27
|
+
recipientEntryBefore: snapshots.recipientEntry,
|
|
28
|
+
validatorEntryBefore: snapshots.validatorEntry
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|