From bc0d7db0beb6c684cf15f9e83e210fcdaf71b4a2 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Thu, 7 Mar 2024 23:47:41 +0100 Subject: [PATCH] Fix Parameter validator --- src/soroban/models.py | 3 ++- tests/test_models.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/soroban/models.py b/src/soroban/models.py index 414a125..b3853da 100644 --- a/src/soroban/models.py +++ b/src/soroban/models.py @@ -90,7 +90,8 @@ class Parameter(Argument): def value_to_scval(self) -> "Parameter": if isinstance(self.value, list): self.value = [self._value_to_scval(val) for val in self.value] - return self._value_to_scval(self) + self.value = self._value_to_scval(self) + return self @staticmethod def _value_to_scval(value: Argument | xdr.SCVal): diff --git a/tests/test_models.py b/tests/test_models.py index fec0e6c..9f993ea 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -9,12 +9,12 @@ class TestIdentity: def test_file(self): alice_fname = pathlib.Path(__file__).parent / "alice.toml" - soroban.Identity(_env_file=alice_fname) + soroban.Identity(_env_file=alice_fname).model_dump() def test_from_pk(self): keypair = Keypair.random() soroban.Identity(secret_key=keypair.secret) - soroban.Identity(keypair=keypair) + soroban.Identity(keypair=keypair).model_dump() def test_from_source_account(self): alice_fname = pathlib.Path(__file__).parent / "alice.toml" @@ -25,33 +25,33 @@ def test_from_source_account(self): def test_raises(self): with pytest.raises(ValueError, match="provide a secret key or a Keypair"): - soroban.Identity() + soroban.Identity().model_dump() keypair = Keypair.random() with pytest.raises(ValueError, match="provide a secret key or a Keypair"): - soroban.Identity(public_key=keypair.public_key) + soroban.Identity(public_key=keypair.public_key).model_dump() class TestNetworkConfig: def test_from_network(self): testnet = pathlib.Path(__file__).parent / "testnet.toml" - soroban.NetworkConfig.from_network(network=testnet) + soroban.NetworkConfig.from_network(network=testnet).model_dump() class TestParams: def test_parameter(self): args = {"name": "distributor", "type": "int128", "value": 10} - soroban.Parameter(**args) + soroban.Parameter(**args).model_dump() args = {"name": "distributor", "type": "int128", "value": scval.to_int128(10)} - soroban.Parameter(**args) + soroban.Parameter(**args).model_dump() args = { "name": "thresholds", "type": "vec", "value": [scval.to_int128(10), {"type": "uint32", "value": 4}], } - soroban.Parameter(**args) + soroban.Parameter(**args).model_dump() args = { "name": "thresholds", @@ -61,10 +61,10 @@ def test_parameter(self): {"type": "int128", "value": scval.to_int128(10)}, ], } - soroban.Parameter(**args) + soroban.Parameter(**args).model_dump() def test_parameters(self): fname = pathlib.Path(__file__).parent / "params_invoke.json" with open(fname, "rb") as fd: args = json.load(fd) - soroban.Parameters(args=args) + soroban.Parameters(args=args).model_dump()