Skip to content

Commit 9c282b7

Browse files
authored
refactor: add validator registration value (#172)
1 parent fb36912 commit 9c282b7

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

crypto/transactions/builder/validator_registration_builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ def validator_public_key(self, validator_public_key: str):
1313
self.transaction.refresh_payload_data()
1414
return self
1515

16+
def value(self, value: int):
17+
self.transaction.data['value'] = int(value)
18+
self.transaction.refresh_payload_data()
19+
return self
20+
1621
def get_transaction_instance(self, data: dict):
1722
return ValidatorRegistration(data)

crypto/transactions/deserializer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ def __guess_transaction_from_data(self, data: dict) -> AbstractTransaction:
8181
if function_name == AbiFunction.MULTIPAYMENT.value:
8282
return Multipayment(data)
8383

84-
if data['value'] != '0':
85-
return Transfer(data)
86-
8784
consensus_payload_data = self.decode_payload(data)
8885
if consensus_payload_data is not None:
8986
function_name = consensus_payload_data.get('functionName')
@@ -108,6 +105,9 @@ def __guess_transaction_from_data(self, data: dict) -> AbstractTransaction:
108105
if function_name == AbiFunction.USERNAME_RESIGNATION.value:
109106
return UsernameResignation(data)
110107

108+
if data['value'] != '0':
109+
return Transfer(data)
110+
111111
return EvmCall(data)
112112

113113
@staticmethod

tests/fixtures/transactions/validator-registration.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"gasPrice": 5000000000,
66
"gas": 200000,
77
"to": "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
8-
"value": "0",
8+
"value": "250000000000000000000",
99
"data": "602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000",
1010
"v": 28,
11-
"r": "57216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413",
12-
"s": "66ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11",
11+
"r": "94cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72",
12+
"s": "6fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd",
1313
"senderPublicKey": "0243333347c8cbf4e3cbc7a96964181d02a2b0c854faa2fef86b4b8d92afcf473d",
1414
"from": "0x1E6747BEAa5B4076a6A98D735DF8c35a70D18Bdd",
15-
"hash": "5064b50091b8e5d50ec1d1eb7c5b71cdcf9c7355bba18ee0efeaeacb0b1c95d5"
15+
"hash": "a3a35d0fe9429b43833b4f4b8ec90cc56f431d68e24d10602967d9eab68caf6b"
1616
},
17-
"serialized": "02f8ef822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e180b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a057216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413a066ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11"
17+
"serialized": "02f8f8822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e1890d8d726b7177a80000b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a094cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72a06fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd"
1818
}

tests/transactions/builder/test_validator_registration_builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def test_validator_registration_transaction(passphrase, validator_public_key, lo
1010
.nonce(fixture['data']['nonce'])
1111
.network(fixture['data']['network'])
1212
.gas(fixture['data']['gas'])
13+
.value(fixture['data']['value'])
1314
.validator_public_key(validator_public_key)
1415
.to(fixture['data']['to'])
1516
.sign(passphrase)
@@ -40,6 +41,7 @@ def test_validator_registration_transaction_with_default_to(passphrase, validato
4041
.nonce(fixture['data']['nonce'])
4142
.network(fixture['data']['network'])
4243
.gas(fixture['data']['gas'])
44+
.value(fixture['data']['value'])
4345
.validator_public_key(validator_public_key)
4446
.sign(passphrase)
4547
)

tests/transactions/test_deserializer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ def test_deserialize_unvote(load_transaction_fixture):
4040

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

4545
assert isinstance(transaction, ValidatorRegistration)
46+
assert transaction.data['value'] == '250000000000000000000'
4647

4748
def test_deserialize_validator_resignation(load_transaction_fixture):
4849
fixture = load_transaction_fixture('transactions/validator-resignation')

0 commit comments

Comments
 (0)