diff --git a/multiversx_sdk/network_providers/accounts.py b/multiversx_sdk/network_providers/accounts.py index bd062b3c..b4915ea3 100644 --- a/multiversx_sdk/network_providers/accounts.py +++ b/multiversx_sdk/network_providers/accounts.py @@ -8,35 +8,47 @@ class AccountOnNetwork: def __init__(self): self.address: IAddress = EmptyAddress() + self.owner_address = EmptyAddress() self.nonce: int = 0 self.balance: int = 0 - self.code: bytes = b'' - self.username: str = '' - self.code_hash: str = '' + self.developer_reward = 0 + self.code: bytes = b"" + self.username: str = "" + self.code_hash: str = "" + self.root_hash: str = "" @staticmethod - def from_http_response(payload: Dict[str, Any]) -> 'AccountOnNetwork': + def from_http_response(payload: Dict[str, Any]) -> "AccountOnNetwork": result = AccountOnNetwork() - address = payload.get('address', '') + address = payload.get("address", "") + owner_address = payload.get("ownerAddress", "") + result.address = Address.new_from_bech32(address) if address else EmptyAddress() + result.owner_address = Address.new_from_bech32(owner_address) if owner_address else EmptyAddress() + + result.nonce = payload.get("nonce", 0) + result.balance = int(payload.get("balance", 0)) + result.developer_reward = int(payload.get("developerReward", 0)) - result.nonce = payload.get('nonce', 0) - result.balance = int(payload.get('balance', 0)) - result.code = bytes.fromhex(payload.get('code', '')) - result.username = payload.get('username', '') - result.code_hash = payload.get('codeHash', '') + result.code = bytes.fromhex(payload.get("code", "")) + result.username = payload.get("username", "") + result.code_hash = payload.get("codeHash", "") + result.root_hash = payload.get("rootHash", "") return result def to_dictionary(self) -> Dict[str, Any]: return { "address": self.address.to_bech32(), + "ownerAddress": self.owner_address.to_bech32(), "nonce": self.nonce, "balance": self.balance, + "developerReward": self.developer_reward, "code": self.code.hex(), "username": self.username, - "codeHash": self.code_hash + "codeHash": self.code_hash, + "rootHash": self.root_hash } @@ -47,10 +59,10 @@ def __init__(self): self.pending_guardian: Guardian = Guardian() @staticmethod - def from_http_response(response: Dict[str, Any]) -> 'GuardianData': + def from_http_response(response: Dict[str, Any]) -> "GuardianData": result = GuardianData() - result.guarded = response.get('guarded', False) + result.guarded = response.get("guarded", False) if response.get("activeGuardian", None): result.active_guardian = Guardian.from_http_response(response["activeGuardian"]) @@ -73,11 +85,11 @@ def __init__(self) -> None: self.service_uid: str = "" @staticmethod - def from_http_response(response: Dict[str, Any]) -> 'Guardian': + def from_http_response(response: Dict[str, Any]) -> "Guardian": result = Guardian() - result.activation_epoch = int(response.get('activationEpoch', 0)) - result.address = Address.new_from_bech32(response.get('address', '')) - result.service_uid = response.get('serviceUID', '') + result.activation_epoch = int(response.get("activationEpoch", 0)) + result.address = Address.new_from_bech32(response.get("address", "")) + result.service_uid = response.get("serviceUID", "") return result diff --git a/multiversx_sdk/network_providers/api_network_provider_test.py b/multiversx_sdk/network_providers/api_network_provider_test.py index 3f6e5ecf..3a959d2c 100644 --- a/multiversx_sdk/network_providers/api_network_provider_test.py +++ b/multiversx_sdk/network_providers/api_network_provider_test.py @@ -1,3 +1,5 @@ +import base64 + import pytest from multiversx_sdk.core.address import Address @@ -56,8 +58,18 @@ def test_get_account(self): address = Address.new_from_bech32('erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl') result = self.api.get_account(address) - assert result.address.to_bech32() == 'erd1487vz5m4zpxjyqw4flwa3xhnkzg4yrr3mkzf5sf0zgt94hjprc8qazcccl' + assert result.address.to_bech32() == address.to_bech32() + assert result.username == '' + assert len(result.code_hash) == 0 + assert len(base64.b64decode(result.root_hash)) == 32 + + address = Address.new_from_bech32('erd1qqqqqqqqqqqqqpgqws44xjx2t056nn79fn29q0rjwfrd3m43396ql35kxy') + result = self.api.get_account(address) + + assert result.address.to_bech32() == address.to_bech32() assert result.username == '' + assert len(base64.b64decode(result.code_hash)) == 32 + assert len(base64.b64decode(result.root_hash)) == 32 def test_get_generic_with_bad_address(self): with pytest.raises(GenericError, match='a bech32 address is expected'): diff --git a/pyproject.toml b/pyproject.toml index 7ba0a2d9..21d37741 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "multiversx-sdk" -version = "0.9.1" +version = "0.9.2" authors = [ { name="MultiversX" }, ]