Skip to content

Commit

Permalink
Fix signing for "staking-provider" commands. Sign before setting gas-…
Browse files Browse the repository at this point in the history
…limit.
  • Loading branch information
andreibancioiu committed Feb 29, 2024
1 parent 7e477e9 commit f980b5c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
36 changes: 24 additions & 12 deletions multiversx_sdk_cli/delegation/staking_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ def prepare_transaction_for_new_delegation_contract(self, owner: IAccount, args:
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_adding_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -73,11 +74,12 @@ def prepare_transaction_for_adding_nodes(self, owner: IAccount, args: Any) -> IT
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_removing_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -94,11 +96,12 @@ def prepare_transaction_for_removing_nodes(self, owner: IAccount, args: Any) ->
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_staking_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -115,11 +118,12 @@ def prepare_transaction_for_staking_nodes(self, owner: IAccount, args: Any) -> I
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_unbonding_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -136,11 +140,12 @@ def prepare_transaction_for_unbonding_nodes(self, owner: IAccount, args: Any) ->
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_unstaking_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -157,11 +162,12 @@ def prepare_transaction_for_unstaking_nodes(self, owner: IAccount, args: Any) ->
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_unjailing_nodes(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -178,11 +184,12 @@ def prepare_transaction_for_unjailing_nodes(self, owner: IAccount, args: Any) ->
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_changing_service_fee(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -197,11 +204,12 @@ def prepare_transaction_for_changing_service_fee(self, owner: IAccount, args: An
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_modifying_delegation_cap(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -216,11 +224,12 @@ def prepare_transaction_for_modifying_delegation_cap(self, owner: IAccount, args
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_automatic_activation(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -243,11 +252,12 @@ def prepare_transaction_for_automatic_activation(self, owner: IAccount, args: An
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_redelegate_cap(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -270,11 +280,12 @@ def prepare_transaction_for_redelegate_cap(self, owner: IAccount, args: Any) ->
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def prepare_transaction_for_setting_metadata(self, owner: IAccount, args: Any) -> ITransaction:
Expand All @@ -291,11 +302,12 @@ def prepare_transaction_for_setting_metadata(self, owner: IAccount, args: Any) -
tx.version = int(args.version)
tx.options = int(args.options)
tx.guardian = args.guardian
tx.signature = bytes.fromhex(owner.sign_transaction(tx))

if args.gas_limit:
tx.gas_limit = int(args.gas_limit)

tx.signature = bytes.fromhex(owner.sign_transaction(tx))

return tx

def _load_validators_public_keys(self, args: Any) -> List[ValidatorPublicKey]:
Expand Down
50 changes: 50 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_staking_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ def test_create_new_delegation_contract(capsys: Any):
assert transaction["chainID"] == "T"
assert transaction["gasLimit"] == 60126500
assert transaction["value"] == "1250000000000000000000"
assert transaction["signature"] == "0a6d7249c671b1db00f1b8807770bb64eac51e2e2779e426f35439c6cb7b00dadd023392a061ba1b6ee35d235ac2c0ad87283413b1d5558d8526bc5712588702"


def test_create_new_delegation_contract_with_provided_gas_limit(capsys: Any):
main([
"staking-provider", "create-new-delegation-contract",
"--pem", str(alice),
"--nonce", "7", "--estimate-gas",
"--value", "1250000000000000000000",
"--total-delegation-cap", "10000000000000000000000",
"--service-fee", "100",
"--chain", "T",
"--gas-limit", "60126501"
])
tx = get_transaction(capsys)
data = tx["emittedTransactionData"]
transaction = tx["emittedTransaction"]

assert data == "createNewDelegationContract@021e19e0c9bab2400000@64"
assert transaction["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction["receiver"] == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"
assert transaction["chainID"] == "T"
assert transaction["gasLimit"] == 60126501
assert transaction["value"] == "1250000000000000000000"
assert transaction["signature"] == "8e28aa5a11454d975a4841086397000de053784b04e68402da9abcf26adc8726d3ce32f415119e3aa38746f2e5524063a6176a0c8cd88c9e8e89f9626d045202"


def test_add_nodes(capsys: Any):
Expand All @@ -52,6 +77,31 @@ def test_add_nodes(capsys: Any):
assert data == "addNodes@e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208@604882237a9845f508ad03877b5aab90569683eeb51fafcbbeb87440ba359992b3c0b837a8757c25be18132549404f88@78689fd4b1e2e434d567fe01e61598a42717d83124308266bd09ccc15d2339dd318c019914b86ac29adbae5dd8a02d0307425e9bd85a296e94943708c72f8c670f0b7c50a890a5719088dbd9f1d062cad9acffa06df834106eebe1a4257ef00d@ec54a009695af56c3585ef623387b67b6df1974b0b3c9138eb64bde6eb33978ae9851112b20c99bf63588e8e949e4388@7188b234a8bf834f2e6258012aa09a2ab93178ffab9c789480275f61fe02cd1b9a58ddc63b79a73abea9e2b7ac5cac0b0d4324eff50aca2f0ec946b9ae6797511fa3ce461b57e77129cba8ab3b51147695d4ce889cbe67905f6586b4e4f22491@c6c637de17db5f89a2fa1d1d935cb60c0e5e8958d3bfc47f903f774dd97398c8fe22093e113865ee98c3afdd1de62694"
assert transaction["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction["receiver"] == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh"
assert transaction["gasLimit"] == 20367000
assert transaction["signature"] == "b383909206bf9631d5bef583c6e28250815494b459977fe8f037c2a97d2692a77d1b5c5dda6095d64ad180d213b5fd5eb7038a54af3765a3cb3fd86b86a1f305"


def test_add_nodes_with_gas_limit(capsys: Any):
validators_file = parent / "testdata" / "validators.json"

main([
"staking-provider", "add-nodes",
"--validators-file", str(validators_file),
"--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh",
"--pem", str(alice),
"--chain", "T",
"--nonce", "7",
"--gas-limit", "20367001"
])
tx = get_transaction(capsys)
data = tx["emittedTransactionData"]
transaction = tx["emittedTransaction"]

assert data == "addNodes@e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208@604882237a9845f508ad03877b5aab90569683eeb51fafcbbeb87440ba359992b3c0b837a8757c25be18132549404f88@78689fd4b1e2e434d567fe01e61598a42717d83124308266bd09ccc15d2339dd318c019914b86ac29adbae5dd8a02d0307425e9bd85a296e94943708c72f8c670f0b7c50a890a5719088dbd9f1d062cad9acffa06df834106eebe1a4257ef00d@ec54a009695af56c3585ef623387b67b6df1974b0b3c9138eb64bde6eb33978ae9851112b20c99bf63588e8e949e4388@7188b234a8bf834f2e6258012aa09a2ab93178ffab9c789480275f61fe02cd1b9a58ddc63b79a73abea9e2b7ac5cac0b0d4324eff50aca2f0ec946b9ae6797511fa3ce461b57e77129cba8ab3b51147695d4ce889cbe67905f6586b4e4f22491@c6c637de17db5f89a2fa1d1d935cb60c0e5e8958d3bfc47f903f774dd97398c8fe22093e113865ee98c3afdd1de62694"
assert transaction["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
assert transaction["receiver"] == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh"
assert transaction["gasLimit"] == 20367001
assert transaction["signature"] == "a889b50844eb5b33d410cbc8c8d2d88eebd64839d22fc1d246b82315123bd3acc6ad4445f9d2430965ce516ff89256faea42a97ebba2e1b386147ff8328b2e01"


def test_remove_nodes_with_bls_keys(capsys: Any):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.5.1"
version = "9.5.2"
authors = [
{ name="MultiversX" },
]
Expand Down

0 comments on commit f980b5c

Please sign in to comment.