Skip to content

Commit

Permalink
Merge pull request #1035 from HorizenOfficial/st/EON-1852
Browse files Browse the repository at this point in the history
Disabled pagedForgingStakes API after Forger Stakes V2 activation
  • Loading branch information
paolocappelletti authored May 24, 2024
2 parents 7711a14 + 8e2fa8d commit b796608
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
12 changes: 10 additions & 2 deletions qa/sc_evm_native_forger_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ def run_test(self):

generate_next_block(sc_node_1, "first node", force_switch_to_next_epoch=False)

# Check that after activate, calling makeForgerStake and spendForgingStake HTTP APIs is not possible anymore
# Check that after activate, calling makeForgerStake, spendForgingStake and pagedForgingStakes HTTP APIs is
# not possible anymore
make_forger_stake_json_res = ac_makeForgerStake(sc_node_1, evm_address_5, block_sign_pub_key_1,
vrf_pub_key_1, convertZenToZennies(4))

Expand All @@ -462,10 +463,17 @@ def run_test(self):
spend_forger_stake_json_res = sc_node_1.transaction_spendForgingStake(
json.dumps({"stakeId": stake_id}))
if "error" not in spend_forger_stake_json_res:
fail("spend forger stake failed: " + json.dumps(spend_forger_stake_json_res))
fail("spendForgingStake with native smart contract v1 should fail after activate")
assert_equal("Method is disabled after Fork 1.4. Use Forger Stakes Native Smart Contract V2",
spend_forger_stake_json_res['error']['description'])

paged_stakes_res = sc_node_1.transaction_pagedForgingStakes(json.dumps({"size": 10, "startPos": 0}))
if "error" not in paged_stakes_res:
fail("pagedForgingStakes native smart contract v1 should fail after activate")
assert_equal("Method is disabled after Fork 1.4. Use Forger Stakes Native Smart Contract V2",
spend_forger_stake_json_res['error']['description'])


# Check getPagedForgers
method = 'getPagedForgers(int32,int32)'
data = forger_v2_native_contract.raw_encode_call(method, *get_paged_forgers_args)
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/resources/account/api/accountApi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ paths:
tags:
- transaction
summary: creates transaction with forger stake
description: Creates transaction with forger stake. It will be disabled after Forger Stake V2 will be activated.
description: Creates transaction with forger stake. This endpoint is disabled after Forger Stake V2 activation..
operationId: makeForgerStake
security:
- basicAuth: []
Expand Down Expand Up @@ -707,7 +707,7 @@ paths:
tags:
- transaction
summary: creates and signs sidechain transaction for spending forging stake
description: Creates and signs sidechain transaction for spending forging stake. It will be disabled after Forger Stake V2 will be activated.
description: Creates and signs sidechain transaction for spending forging stake. This endpoint is disabled after Forger Stake V2 activation..
operationId: spendForgingStake
security:
- basicAuth: []
Expand Down Expand Up @@ -1500,7 +1500,7 @@ paths:
tags:
- transaction
summary: Returns the paginated list of forging stakes.
description: Returns the paginated list of forging stakes.
description: Returns the paginated list of forging stakes. This endpoint is disabled after Forger Stake V2 activation..
operationId: pagedForgingStakes
responses:
'200':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,19 +554,23 @@ case class AccountTransactionApiRoute(override val settings: RESTApiSettings,
withNodeView { sidechainNodeView =>
val accountState = sidechainNodeView.getNodeState
val epochNumber = accountState.getConsensusEpochNumber.getOrElse(0)
if (Version1_3_0Fork.get(epochNumber).active) {
Try {
accountState.getPagedListOfForgersStakes(body.startPos, body.size)
} match {
case Success((nextPos, listOfForgerStakes)) =>
ApiResponseUtil.toResponse(RespPagedForgerStakes(nextPos, listOfForgerStakes.toList))
case Failure(exception) =>
ApiResponseUtil.toResponse(GenericTransactionError(s"Invalid input parameters", JOptional.of(exception)))
if (!sidechainNodeView.getNodeState.isForgerStakeV1SmartContractDisabled(Version1_4_0Fork.get(epochNumber).active)) {
if (Version1_3_0Fork.get(epochNumber).active) {
Try {
accountState.getPagedListOfForgersStakes(body.startPos, body.size)
} match {
case Success((nextPos, listOfForgerStakes)) =>
ApiResponseUtil.toResponse(RespPagedForgerStakes(nextPos, listOfForgerStakes.toList))
case Failure(exception) =>
ApiResponseUtil.toResponse(GenericTransactionError(s"Invalid input parameters", JOptional.of(exception)))
}
} else {
ApiResponseUtil.toResponse(GenericTransactionError(s"Fork 1.3 is not active, can not invoke this command",
JOptional.empty()))
}
} else {
ApiResponseUtil.toResponse(GenericTransactionError(s"Fork 1.3 is not active, can not invoke this command",
JOptional.empty()))
}
else
ApiResponseUtil.toResponse(ErrorDisabledMethod())
}
}
}
Expand Down

0 comments on commit b796608

Please sign in to comment.