Skip to content

Commit

Permalink
Fix Parameter validator
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Mar 7, 2024
1 parent 944c3ab commit bc0d7db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/soroban/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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()

0 comments on commit bc0d7db

Please sign in to comment.