Skip to content

refactor: add validator registration value #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ def validator_public_key(self, validator_public_key: str):
self.transaction.refresh_payload_data()
return self

def value(self, value: int):
self.transaction.data['value'] = int(value)
self.transaction.refresh_payload_data()
return self

def get_transaction_instance(self, data: dict):
return ValidatorRegistration(data)
6 changes: 3 additions & 3 deletions crypto/transactions/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ def __guess_transaction_from_data(self, data: dict) -> AbstractTransaction:
if function_name == AbiFunction.MULTIPAYMENT.value:
return Multipayment(data)

if data['value'] != '0':
return Transfer(data)

consensus_payload_data = self.decode_payload(data)
if consensus_payload_data is not None:
function_name = consensus_payload_data.get('functionName')
Expand All @@ -108,6 +105,9 @@ def __guess_transaction_from_data(self, data: dict) -> AbstractTransaction:
if function_name == AbiFunction.USERNAME_RESIGNATION.value:
return UsernameResignation(data)

if data['value'] != '0':
return Transfer(data)

return EvmCall(data)

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/transactions/validator-registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"gasPrice": 5000000000,
"gas": 200000,
"to": "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
"value": "0",
"value": "250000000000000000000",
"data": "602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000",
"v": 28,
"r": "57216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413",
"s": "66ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11",
"r": "94cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72",
"s": "6fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd",
"senderPublicKey": "0243333347c8cbf4e3cbc7a96964181d02a2b0c854faa2fef86b4b8d92afcf473d",
"from": "0x1E6747BEAa5B4076a6A98D735DF8c35a70D18Bdd",
"hash": "5064b50091b8e5d50ec1d1eb7c5b71cdcf9c7355bba18ee0efeaeacb0b1c95d5"
"hash": "a3a35d0fe9429b43833b4f4b8ec90cc56f431d68e24d10602967d9eab68caf6b"
},
"serialized": "02f8ef822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e180b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a057216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413a066ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11"
"serialized": "02f8f8822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e1890d8d726b7177a80000b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a094cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72a06fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_validator_registration_transaction(passphrase, validator_public_key, lo
.nonce(fixture['data']['nonce'])
.network(fixture['data']['network'])
.gas(fixture['data']['gas'])
.value(fixture['data']['value'])
.validator_public_key(validator_public_key)
.to(fixture['data']['to'])
.sign(passphrase)
Expand Down Expand Up @@ -40,6 +41,7 @@ def test_validator_registration_transaction_with_default_to(passphrase, validato
.nonce(fixture['data']['nonce'])
.network(fixture['data']['network'])
.gas(fixture['data']['gas'])
.value(fixture['data']['value'])
.validator_public_key(validator_public_key)
.sign(passphrase)
)
Expand Down
3 changes: 2 additions & 1 deletion tests/transactions/test_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ def test_deserialize_unvote(load_transaction_fixture):

def test_deserialize_validator_registration(load_transaction_fixture):
fixture = load_transaction_fixture('transactions/validator-registration')
transaction = assert_deserialized(fixture, ['hash', 'nonce', 'gasPrice', 'gas', 'v', 'r', 's'])
transaction = assert_deserialized(fixture, ['hash', 'nonce', 'gasPrice', 'gas', 'value', 'v', 'r', 's'])

assert isinstance(transaction, ValidatorRegistration)
assert transaction.data['value'] == '250000000000000000000'

def test_deserialize_validator_resignation(load_transaction_fixture):
fixture = load_transaction_fixture('transactions/validator-resignation')
Expand Down