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,280 @@
|
|
|
1
|
+
import { ZERO_WK } from "./buffer.js";
|
|
2
|
+
import { bigIntToDecimalString, bufferToBigInt } from "./amountSerialization.js";
|
|
3
|
+
import { normalizeDecodedPayloadForJson } from "./normalizers.js";
|
|
4
|
+
import { get_confirmed_tx_info, get_unconfirmed_tx_info } from "./cli.js";
|
|
5
|
+
import { EntryType } from "./constants.js";
|
|
6
|
+
import { bufferToAddress } from "../core/state/utils/address.js";
|
|
7
|
+
import deploymentEntryUtils from "../core/state/utils/deploymentEntry.js";
|
|
8
|
+
import { safeDecodeApplyOperation } from "./protobuf/operationHelpers.js";
|
|
9
|
+
|
|
10
|
+
export async function getBalanceCommand(state, address, confirmedFlag) {
|
|
11
|
+
const unconfirmedBalance = confirmedFlag === "false";
|
|
12
|
+
const nodeEntry = unconfirmedBalance
|
|
13
|
+
? await state.getNodeEntryUnsigned(address)
|
|
14
|
+
: await state.getNodeEntry(address);
|
|
15
|
+
|
|
16
|
+
if (nodeEntry) {
|
|
17
|
+
console.log({
|
|
18
|
+
Address: address,
|
|
19
|
+
Balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
address,
|
|
23
|
+
balance: bufferToBigInt(nodeEntry.balance).toString()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log("Node Entry:", {
|
|
28
|
+
WritingKey: ZERO_WK.toString("hex"),
|
|
29
|
+
IsWhitelisted: false,
|
|
30
|
+
IsWriter: false,
|
|
31
|
+
IsIndexer: false,
|
|
32
|
+
balance: bigIntToDecimalString(0n)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function nodeStatusCommand(state, address) {
|
|
37
|
+
const nodeEntry = await state.getNodeEntry(address);
|
|
38
|
+
if (nodeEntry) {
|
|
39
|
+
const licenseValue = nodeEntry.license.readUInt32BE(0);
|
|
40
|
+
const licenseDisplay = licenseValue === 0 ? "N/A" : licenseValue.toString();
|
|
41
|
+
console.log("Node Status:", {
|
|
42
|
+
Address: address,
|
|
43
|
+
WritingKey: nodeEntry.wk.toString("hex"),
|
|
44
|
+
IsWhitelisted: nodeEntry.isWhitelisted,
|
|
45
|
+
IsWriter: nodeEntry.isWriter,
|
|
46
|
+
IsIndexer: nodeEntry.isIndexer,
|
|
47
|
+
License: licenseDisplay,
|
|
48
|
+
StakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance)),
|
|
49
|
+
Balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
address,
|
|
53
|
+
writingKey: nodeEntry.wk.toString("hex"),
|
|
54
|
+
isWhitelisted: nodeEntry.isWhitelisted,
|
|
55
|
+
isWriter: nodeEntry.isWriter,
|
|
56
|
+
isIndexer: nodeEntry.isIndexer,
|
|
57
|
+
license: licenseDisplay,
|
|
58
|
+
stakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log("Node Status:", {
|
|
63
|
+
WritingKey: ZERO_WK.toString("hex"),
|
|
64
|
+
IsWhitelisted: false,
|
|
65
|
+
IsWriter: false,
|
|
66
|
+
IsIndexer: false,
|
|
67
|
+
license: "N/A",
|
|
68
|
+
stakedBalance: "0"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function coreInfoCommand(state) {
|
|
73
|
+
const admin = await state.getAdminEntry();
|
|
74
|
+
console.log("Admin:", admin ? {
|
|
75
|
+
address: admin.address,
|
|
76
|
+
writingKey: admin.wk.toString("hex")
|
|
77
|
+
} : null);
|
|
78
|
+
const formattedIndexers = await state.getIndexersEntry().then(entry => entry ? entry : null);
|
|
79
|
+
if (!formattedIndexers || (Array.isArray(formattedIndexers) && formattedIndexers.length === 0)) {
|
|
80
|
+
console.log("Indexers: no indexers");
|
|
81
|
+
} else {
|
|
82
|
+
console.log("Indexers:", formattedIndexers);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function getValidatorAddressCommand(state, wkHexString) {
|
|
87
|
+
const payload = await state.getSigned(EntryType.WRITER_ADDRESS + wkHexString);
|
|
88
|
+
if (payload === null) {
|
|
89
|
+
console.log(`No address assigned to the writer key: ${wkHexString}`);
|
|
90
|
+
} else {
|
|
91
|
+
console.log(`Address assigned to the writer key: ${wkHexString} - ${bufferToAddress(payload)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function getDeploymentCommand(state, bootstrapHex) {
|
|
96
|
+
const deploymentEntry = await state.getRegisteredBootstrapEntry(bootstrapHex);
|
|
97
|
+
console.log(`Searching deployment for bootstrap: ${bootstrapHex}`);
|
|
98
|
+
if (deploymentEntry) {
|
|
99
|
+
const decodedDeploymentEntry = deploymentEntryUtils.decode(deploymentEntry);
|
|
100
|
+
const txhash = decodedDeploymentEntry.txHash.toString("hex");
|
|
101
|
+
console.log(`Bootstrap deployed under transaction hash: ${txhash}`);
|
|
102
|
+
const payload = await state.getSigned(txhash);
|
|
103
|
+
if (payload) {
|
|
104
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
105
|
+
console.log("Decoded Bootstrap Deployment Payload:", decoded);
|
|
106
|
+
} else {
|
|
107
|
+
console.log(`No payload found for transaction hash: ${txhash}`);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
console.log(`No deployment found for bootstrap: ${bootstrapHex}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function getTxInfoCommand(state, txHash) {
|
|
115
|
+
const txInfo = await get_confirmed_tx_info(state, txHash);
|
|
116
|
+
if (txInfo) {
|
|
117
|
+
console.log(`Payload for transaction hash ${txHash}:`);
|
|
118
|
+
console.log(txInfo.decoded);
|
|
119
|
+
} else {
|
|
120
|
+
console.log(`No information found for transaction hash: ${txHash}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function getLicenseNumberCommand(state, address) {
|
|
125
|
+
const nodeEntry = await state.getNodeEntry(address);
|
|
126
|
+
if (nodeEntry) {
|
|
127
|
+
console.log({
|
|
128
|
+
Address: address,
|
|
129
|
+
License: bufferToBigInt(nodeEntry.license).toString()
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function getLicenseAddressCommand(state, licenseId) {
|
|
135
|
+
if (isNaN(licenseId) || licenseId < 0) {
|
|
136
|
+
console.log("Invalid license ID. Please provide a valid non-negative number.");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const address = await state.getAddressByLicenseId(licenseId);
|
|
141
|
+
if (address) {
|
|
142
|
+
console.log({
|
|
143
|
+
LicenseId: licenseId,
|
|
144
|
+
Address: address
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
console.log(`No address found for license ID: ${licenseId}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function getLicenseCountCommand(state, isAdminFn) {
|
|
152
|
+
const adminEntry = await state.getAdminEntry();
|
|
153
|
+
|
|
154
|
+
if (!adminEntry) {
|
|
155
|
+
throw new Error("Cannot read license count. Admin does not exist");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!isAdminFn(adminEntry)) {
|
|
159
|
+
throw new Error("Cannot perform this operation - you are not the admin!.");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const licenseCount = await state.getLicenseCount();
|
|
163
|
+
console.log({
|
|
164
|
+
LicensesCount: licenseCount
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function getTxvCommand(state) {
|
|
169
|
+
const txv = await state.getIndexerSequenceState();
|
|
170
|
+
console.log("Current TXV:", txv.toString("hex"));
|
|
171
|
+
return txv;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function getFeeCommand(state) {
|
|
175
|
+
const fee = state.getFee();
|
|
176
|
+
console.log("Current FEE:", bigIntToDecimalString(bufferToBigInt(fee)));
|
|
177
|
+
return bufferToBigInt(fee).toString();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function getConfirmedLengthCommand(state) {
|
|
181
|
+
const confirmedLength = state.getSignedLength();
|
|
182
|
+
console.log("Confirmed_length:", confirmedLength);
|
|
183
|
+
return confirmedLength;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function getUnconfirmedLengthCommand(state) {
|
|
187
|
+
const unconfirmedLength = state.getUnsignedLength();
|
|
188
|
+
console.log("Unconfirmed_length:", unconfirmedLength);
|
|
189
|
+
return unconfirmedLength;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function getTxPayloadsBulkCommand(state, hashes) {
|
|
193
|
+
if (!Array.isArray(hashes) || hashes.length === 0) {
|
|
194
|
+
throw new Error("Missing hash list.");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (hashes.length > 1500) {
|
|
198
|
+
throw new Error("Length of input tx hashes exceeded.");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const res = { results: [], missing: [] };
|
|
202
|
+
|
|
203
|
+
const promises = hashes.map(hash => get_confirmed_tx_info(state, hash));
|
|
204
|
+
const results = await Promise.all(promises);
|
|
205
|
+
|
|
206
|
+
results.forEach((result, index) => {
|
|
207
|
+
const hash = hashes[index];
|
|
208
|
+
if (result === null || result === undefined) {
|
|
209
|
+
res.missing.push(hash);
|
|
210
|
+
} else {
|
|
211
|
+
const decodedResult = normalizeDecodedPayloadForJson(result.decoded);
|
|
212
|
+
res.results.push({ hash, payload: decodedResult });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return res;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export async function getTxHashesCommand(state, start, end) {
|
|
220
|
+
try {
|
|
221
|
+
const hashes = await state.confirmedTransactionsBetween(start, end);
|
|
222
|
+
return { hashes };
|
|
223
|
+
} catch (error) {
|
|
224
|
+
throw new Error("Invalid params to perform the request.", error.message);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export async function getTxDetailsCommand(state, hash) {
|
|
229
|
+
try {
|
|
230
|
+
const rawPayload = await get_confirmed_tx_info(state, hash);
|
|
231
|
+
if (!rawPayload) {
|
|
232
|
+
console.log(`No payload found for tx hash: ${hash}`);
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return normalizeDecodedPayloadForJson(rawPayload.decoded);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
throw new Error("Invalid params to perform the request.", error.message);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export async function getExtendedTxDetailsCommand(state, hash, confirmed) {
|
|
242
|
+
if (confirmed) {
|
|
243
|
+
const rawPayload = await get_confirmed_tx_info(state, hash);
|
|
244
|
+
if (!rawPayload) {
|
|
245
|
+
throw new Error(`No payload found for tx hash: ${hash}`);
|
|
246
|
+
}
|
|
247
|
+
const confirmedLength = await state.getTransactionConfirmedLength(hash);
|
|
248
|
+
if (confirmedLength === null) {
|
|
249
|
+
throw new Error(`No confirmed length found for tx hash: ${hash} in confirmed mode`);
|
|
250
|
+
}
|
|
251
|
+
const normalizedPayload = normalizeDecodedPayloadForJson(rawPayload.decoded, true);
|
|
252
|
+
const fee = state.getFee();
|
|
253
|
+
return {
|
|
254
|
+
txDetails: normalizedPayload,
|
|
255
|
+
confirmed_length: confirmedLength,
|
|
256
|
+
fee: bufferToBigInt(fee).toString()
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const rawPayload = await get_unconfirmed_tx_info(state, hash);
|
|
261
|
+
if (!rawPayload) {
|
|
262
|
+
throw new Error(`No payload found for tx hash: ${hash}`);
|
|
263
|
+
}
|
|
264
|
+
const normalizedPayload = normalizeDecodedPayloadForJson(rawPayload.decoded, true);
|
|
265
|
+
const length = await state.getTransactionConfirmedLength(hash);
|
|
266
|
+
if (length === null) {
|
|
267
|
+
return {
|
|
268
|
+
txDetails: normalizedPayload,
|
|
269
|
+
confirmed_length: 0,
|
|
270
|
+
fee: "0"
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const fee = state.getFee();
|
|
275
|
+
return {
|
|
276
|
+
txDetails: normalizedPayload,
|
|
277
|
+
confirmed_length: length,
|
|
278
|
+
fee: bufferToBigInt(fee).toString()
|
|
279
|
+
};
|
|
280
|
+
}
|
package/src/utils/constants.js
CHANGED
|
@@ -124,4 +124,6 @@ export const TRAC_ADDRESS_SIZE = 63; // TODO: Change this to config().addressLe
|
|
|
124
124
|
export const NETWORK_ID = 918; // TODO: Change this to config().network_id || 918
|
|
125
125
|
|
|
126
126
|
export const MAX_VALIDATORS = 50
|
|
127
|
-
export const MAX_RETRIES = 3
|
|
127
|
+
export const MAX_RETRIES = 3
|
|
128
|
+
|
|
129
|
+
export const MAX_REQUEST_COUNT = 5;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import request from "supertest"
|
|
2
|
+
import { bufferToBigInt, licenseBufferToBigInt } from "../../../../src/utils/amountSerialization.js"
|
|
3
|
+
import { ZERO_WK } from "../../../../rpc/constants.mjs"
|
|
4
|
+
import { ADMIN_INITIAL_STAKED_BALANCE } from "../../../../src/utils/constants.js"
|
|
5
|
+
import { BALANCE_TO_STAKE } from "../../../../src/core/state/utils/balance.js"
|
|
6
|
+
import { randomAddress } from "../../../unit/state/stateTestUtils.js"
|
|
7
|
+
|
|
8
|
+
export const registerAccountTests = (context) => {
|
|
9
|
+
const formatNodeEntryResponse = (address, entry) => {
|
|
10
|
+
const licenseValue = licenseBufferToBigInt(entry.license)
|
|
11
|
+
return {
|
|
12
|
+
address,
|
|
13
|
+
writingKey: entry.wk.toString('hex'),
|
|
14
|
+
isWhitelisted: entry.isWhitelisted,
|
|
15
|
+
isValidator: entry.isWriter,
|
|
16
|
+
isIndexer: entry.isIndexer,
|
|
17
|
+
license: licenseValue === 0n ? null : licenseValue.toString(),
|
|
18
|
+
balance: bufferToBigInt(entry.balance).toString(),
|
|
19
|
+
stakedBalance: bufferToBigInt(entry.stakedBalance).toString(),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("GET /v1/account", () => {
|
|
24
|
+
it("returns admin account details", async () => {
|
|
25
|
+
const adminEntry = await context.rpcMsb.state.getNodeEntry(context.adminWallet.address)
|
|
26
|
+
expect(adminEntry).toBeTruthy()
|
|
27
|
+
|
|
28
|
+
const res = await request(context.server).get(`/v1/account/${context.adminWallet.address}`)
|
|
29
|
+
expect(res.statusCode).toBe(200)
|
|
30
|
+
expect(res.body).toEqual(formatNodeEntryResponse(context.adminWallet.address, adminEntry))
|
|
31
|
+
expect(res.body).toMatchObject({
|
|
32
|
+
isWhitelisted: true,
|
|
33
|
+
isValidator: true,
|
|
34
|
+
isIndexer: true,
|
|
35
|
+
stakedBalance: bufferToBigInt(ADMIN_INITIAL_STAKED_BALANCE).toString(),
|
|
36
|
+
license: '1',
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it("returns validator account details", async () => {
|
|
41
|
+
const writerEntry = await context.rpcMsb.state.getNodeEntry(context.wallet.address)
|
|
42
|
+
expect(writerEntry).toBeTruthy()
|
|
43
|
+
|
|
44
|
+
const res = await request(context.server).get(`/v1/account/${context.wallet.address}`)
|
|
45
|
+
expect(res.statusCode).toBe(200)
|
|
46
|
+
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, writerEntry))
|
|
47
|
+
expect(res.body).toMatchObject({
|
|
48
|
+
isWhitelisted: true,
|
|
49
|
+
isValidator: true,
|
|
50
|
+
stakedBalance: bufferToBigInt(BALANCE_TO_STAKE.value).toString(),
|
|
51
|
+
})
|
|
52
|
+
expect(res.body.license).not.toBeNull()
|
|
53
|
+
expect(res.body.license).not.toBe('1')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it("returns validator account details when confirmed=true", async () => {
|
|
57
|
+
const confirmedEntry = await context.rpcMsb.state.getNodeEntry(context.wallet.address)
|
|
58
|
+
expect(confirmedEntry).toBeTruthy()
|
|
59
|
+
|
|
60
|
+
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=true`)
|
|
61
|
+
expect(res.statusCode).toBe(200)
|
|
62
|
+
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, confirmedEntry))
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it("returns validator account details (unconfirmed view)", async () => {
|
|
66
|
+
const unsignedEntry = await context.rpcMsb.state.getNodeEntryUnsigned(context.wallet.address)
|
|
67
|
+
expect(unsignedEntry).toBeTruthy()
|
|
68
|
+
|
|
69
|
+
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=false`)
|
|
70
|
+
expect(res.statusCode).toBe(200)
|
|
71
|
+
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, unsignedEntry))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("returns default state for non-existent node", async () => {
|
|
75
|
+
const address = randomAddress()
|
|
76
|
+
|
|
77
|
+
const res = await request(context.server).get(`/v1/account/${address}`)
|
|
78
|
+
expect(res.statusCode).toBe(200)
|
|
79
|
+
expect(res.body).toEqual({
|
|
80
|
+
address: address,
|
|
81
|
+
writingKey: ZERO_WK.toString('hex'),
|
|
82
|
+
isWhitelisted: false,
|
|
83
|
+
isValidator: false,
|
|
84
|
+
isIndexer: false,
|
|
85
|
+
license: null,
|
|
86
|
+
balance: '0',
|
|
87
|
+
stakedBalance: '0',
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("returns 400 when address is missing", async () => {
|
|
92
|
+
const res = await request(context.server).get("/v1/account")
|
|
93
|
+
expect(res.statusCode).toBe(400)
|
|
94
|
+
expect(res.body).toEqual({ error: "Account address is required" })
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("returns 400 for invalid address format", async () => {
|
|
98
|
+
const res = await request(context.server).get("/v1/account/not-a-valid-address")
|
|
99
|
+
expect(res.statusCode).toBe(400)
|
|
100
|
+
expect(res.body).toEqual({ error: "Invalid account address format" })
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("returns 400 for invalid confirmed parameter", async () => {
|
|
104
|
+
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=test`)
|
|
105
|
+
expect(res.statusCode).toBe(400)
|
|
106
|
+
expect(res.body).toEqual({ error: 'Parameter "confirmed" must be exactly "true" or "false"' })
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it("returns 500 on internal error", async () => {
|
|
110
|
+
const originalGetNodeEntry = context.rpcMsb.state.getNodeEntry
|
|
111
|
+
|
|
112
|
+
context.rpcMsb.state.getNodeEntry = async () => { throw new Error("test") }
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const res = await request(context.server).get(`/v1/account/${context.wallet.address}`)
|
|
116
|
+
expect(res.statusCode).toBe(500)
|
|
117
|
+
expect(res.body).toEqual({ error: 'An error occurred processing the request.' })
|
|
118
|
+
} finally {
|
|
119
|
+
context.rpcMsb.state.getNodeEntry = originalGetNodeEntry
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import request from "supertest"
|
|
2
|
+
import { randomAddress } from "../../../unit/state/stateTestUtils.js"
|
|
3
|
+
|
|
4
|
+
export const registerBalanceTests = (context) => {
|
|
5
|
+
let expectedBalance
|
|
6
|
+
describe("GET /v1/balance", () => {
|
|
7
|
+
it("returns balance for confirmed view by default", async () => {
|
|
8
|
+
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}`)
|
|
9
|
+
expect(res.statusCode).toBe(200)
|
|
10
|
+
expect(res.body.address).toBe(context.wallet.address)
|
|
11
|
+
expect(typeof res.body.balance).toBe("string")
|
|
12
|
+
expectedBalance = res.body.balance
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it("returns balance for unconfirmed view", async () => {
|
|
16
|
+
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=false`)
|
|
17
|
+
expect(res.statusCode).toBe(200)
|
|
18
|
+
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it("returns balance when confirmed flag is explicitly true", async () => {
|
|
22
|
+
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=true`)
|
|
23
|
+
expect(res.statusCode).toBe(200)
|
|
24
|
+
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("falls back to unconfirmed view on invalid confirmed flag", async () => {
|
|
28
|
+
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=test`)
|
|
29
|
+
expect(res.statusCode).toBe(200)
|
|
30
|
+
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("returns 400 when address is missing", async () => {
|
|
34
|
+
const res = await request(context.server).get("/v1/balance")
|
|
35
|
+
expect(res.statusCode).toBe(400)
|
|
36
|
+
expect(res.body).toEqual({ error: "Wallet address is required" })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("returns zero balance for an unknown address", async () => {
|
|
40
|
+
const address = randomAddress()
|
|
41
|
+
const res = await request(context.server).get(`/v1/balance/${address}`)
|
|
42
|
+
expect(res.statusCode).toBe(200)
|
|
43
|
+
expect(res.body.address).toBe(address)
|
|
44
|
+
expect(BigInt(res.body.balance)).toBe(0n)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
//TODO: This test should return 400, but for backward compatibility reasons it currently returns 200 with zero balance. Please fix this.
|
|
48
|
+
it.skip("returns zero balance for an invalid address format", async () => {
|
|
49
|
+
const invalidAddress = "not-a-valid-address"
|
|
50
|
+
const res = await request(context.server).get(`/v1/balance/${invalidAddress}`)
|
|
51
|
+
expect(res.statusCode).toBe(400)
|
|
52
|
+
expect(res.body).toEqual({ error: "Invalid account address format" })
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import request from "supertest"
|
|
2
|
+
import b4a from "b4a"
|
|
3
|
+
import { $TNK } from "../../../../src/core/state/utils/balance.js"
|
|
4
|
+
import { buildRpcSelfTransferPayload } from "../../../helpers/transactionPayloads.mjs"
|
|
5
|
+
|
|
6
|
+
const toBase64 = (value) => b4a.toString(b4a.from(JSON.stringify(value)), "base64")
|
|
7
|
+
|
|
8
|
+
export const registerBroadcastTransactionTests = (context) => {
|
|
9
|
+
describe("POST /v1/broadcast-transaction", () => {
|
|
10
|
+
it("broadcasts transaction and returns lengths", async () => {
|
|
11
|
+
const { payload } = await buildRpcSelfTransferPayload(
|
|
12
|
+
context.wallet,
|
|
13
|
+
context.rpcMsb.state,
|
|
14
|
+
1n
|
|
15
|
+
);
|
|
16
|
+
const res = await request(context.server)
|
|
17
|
+
.post("/v1/broadcast-transaction")
|
|
18
|
+
.set("Accept", "application/json")
|
|
19
|
+
.send(JSON.stringify({ payload }))
|
|
20
|
+
|
|
21
|
+
expect(res.statusCode).toBe(200)
|
|
22
|
+
expect(res.body).toMatchObject({
|
|
23
|
+
result: {
|
|
24
|
+
message: "Transaction broadcasted successfully.",
|
|
25
|
+
signedLength: expect.any(Number),
|
|
26
|
+
unsignedLength: expect.any(Number),
|
|
27
|
+
tx: expect.any(String)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it("returns 400 when payload is missing", async () => {
|
|
33
|
+
const res = await request(context.server)
|
|
34
|
+
.post("/v1/broadcast-transaction")
|
|
35
|
+
.set("Accept", "application/json")
|
|
36
|
+
.send(JSON.stringify({}))
|
|
37
|
+
|
|
38
|
+
expect(res.statusCode).toBe(400)
|
|
39
|
+
expect(res.body).toEqual({ error: "Payload is missing." })
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it("returns 400 when payload is not base64", async () => {
|
|
43
|
+
const res = await request(context.server)
|
|
44
|
+
.post("/v1/broadcast-transaction")
|
|
45
|
+
.set("Accept", "application/json")
|
|
46
|
+
.send(JSON.stringify({ payload: "not-base64" }))
|
|
47
|
+
|
|
48
|
+
expect(res.statusCode).toBe(400)
|
|
49
|
+
expect(res.body).toEqual({ error: "Payload must be a valid base64 string." })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// TODO: enable once handler returns 400 for client-side decode errors
|
|
53
|
+
it.skip("returns 400 when decoded payload is not valid JSON", async () => {
|
|
54
|
+
const invalidJsonBase64 = b4a.toString(b4a.from("{{invalid"), "base64")
|
|
55
|
+
const res = await request(context.server)
|
|
56
|
+
.post("/v1/broadcast-transaction")
|
|
57
|
+
.set("Accept", "application/json")
|
|
58
|
+
.send(JSON.stringify({ payload: invalidJsonBase64 }))
|
|
59
|
+
|
|
60
|
+
expect(res.statusCode).toBe(400)
|
|
61
|
+
expect(res.body).toEqual({ error: "Decoded payload is not valid JSON." })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// TODO: enable once handler returns 400 for client-side validation errors
|
|
65
|
+
it.skip("returns 400 for invalid transaction structure", async () => {
|
|
66
|
+
const invalidStructure = {
|
|
67
|
+
type: 1,
|
|
68
|
+
address: context.wallet.address,
|
|
69
|
+
}
|
|
70
|
+
const res = await request(context.server)
|
|
71
|
+
.post("/v1/broadcast-transaction")
|
|
72
|
+
.set("Accept", "application/json")
|
|
73
|
+
.send(JSON.stringify({ payload: toBase64(invalidStructure) }))
|
|
74
|
+
|
|
75
|
+
expect(res.statusCode).toBe(400)
|
|
76
|
+
expect(res.body).toEqual({ error: "Invalid payload structure." })
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// TODO: AFTER REFACTORIZATION IMPROVE THESE IMPLEMENTATIONS ENDPOINT TO COVER THESE TESTS.
|
|
80
|
+
it.skip("returns 413 when payload exceeds size limit", async () => {
|
|
81
|
+
const largeString = "a".repeat(3_000_000)
|
|
82
|
+
const payload = toBase64({ type: 1, address: context.wallet.address, txo: { large: largeString } })
|
|
83
|
+
|
|
84
|
+
const res = await request(context.server)
|
|
85
|
+
.post("/v1/broadcast-transaction")
|
|
86
|
+
.set("Accept", "application/json")
|
|
87
|
+
.send(JSON.stringify({ payload }))
|
|
88
|
+
|
|
89
|
+
expect(res.statusCode).toBe(413)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it.skip("returns 429 on repeated broadcast failures", async () => {
|
|
93
|
+
// TODO: Would require forcing msb to throw 'Failed to broadcast transaction after multiple attempts.'
|
|
94
|
+
const txData = await tracCrypto.transaction.preBuild(
|
|
95
|
+
context.wallet.address,
|
|
96
|
+
context.wallet.address,
|
|
97
|
+
b4a.toString($TNK(1n), 'hex'),
|
|
98
|
+
b4a.toString(await context.rpcMsb.state.getIndexerSequenceState(), 'hex')
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const payload = tracCrypto.transaction.build(txData, b4a.from(context.wallet.secretKey, 'hex'))
|
|
102
|
+
const res = await request(context.server)
|
|
103
|
+
.post("/v1/broadcast-transaction")
|
|
104
|
+
.set("Accept", "application/json")
|
|
105
|
+
.send(JSON.stringify({ payload }))
|
|
106
|
+
|
|
107
|
+
expect(res.statusCode).toBe(429)
|
|
108
|
+
expect(res.body).toEqual({ error: "Failed to broadcast transaction after multiple attempts." })
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import request from "supertest"
|
|
2
|
+
|
|
3
|
+
export const registerConfirmedLengthTests = (context) => {
|
|
4
|
+
describe("GET /v1/confirmed-length", () => {
|
|
5
|
+
it("returns confirmed length", async () => {
|
|
6
|
+
const res = await request(context.server).get("/v1/confirmed-length")
|
|
7
|
+
expect(res.statusCode).toBe(200)
|
|
8
|
+
expect(res.body).toEqual({ confirmed_length: expect.any(Number) })
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it("matches signed length from state", async () => {
|
|
12
|
+
const res = await request(context.server).get("/v1/confirmed-length")
|
|
13
|
+
expect(res.statusCode).toBe(200)
|
|
14
|
+
|
|
15
|
+
const signedLength = context.rpcMsb.state.getSignedLength()
|
|
16
|
+
expect(res.body).toEqual({ confirmed_length: signedLength })
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import request from "supertest"
|
|
2
|
+
|
|
3
|
+
export const registerFeeTests = (context) => {
|
|
4
|
+
describe("GET /v1/fee", () => {
|
|
5
|
+
it("returns fee", async () => {
|
|
6
|
+
const res = await request(context.server).get("/v1/fee")
|
|
7
|
+
expect(res.statusCode).toBe(200)
|
|
8
|
+
expect(res.body).toEqual({ fee: expect.stringMatching(/^-?\d+(\.\d+)?$/) })
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
}
|