Skip to content

Commit fa7486e

Browse files
committed
Add account loading with secret_key
1 parent bc0d7db commit fa7486e

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/soroban/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def from_source_account(
5050
) -> "Identity":
5151
if account is None:
5252
identity = Identity()
53+
if isinstance(account, str) and account.startswith("S") and len(account) == 56:
54+
identity = Identity(secret_key=account)
5355
elif isinstance(account, (str, pathlib.Path)):
5456
fname = _load_configuration(account, "identity")
5557
identity = Identity(_env_file=fname)

tests/test_models.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
class TestIdentity:
1010
def test_file(self):
1111
alice_fname = pathlib.Path(__file__).parent / "alice.toml"
12-
soroban.Identity(_env_file=alice_fname).model_dump()
12+
soroban.Identity(_env_file=alice_fname)
1313

1414
def test_from_pk(self):
1515
keypair = Keypair.random()
1616
soroban.Identity(secret_key=keypair.secret)
17-
soroban.Identity(keypair=keypair).model_dump()
17+
soroban.Identity(keypair=keypair)
1818

1919
def test_from_source_account(self):
2020
alice_fname = pathlib.Path(__file__).parent / "alice.toml"
@@ -23,19 +23,21 @@ def test_from_source_account(self):
2323
keypair = Keypair.random()
2424
soroban.Identity.from_source_account(account=keypair)
2525

26+
soroban.Identity.from_source_account(account=keypair.secret)
27+
2628
def test_raises(self):
2729
with pytest.raises(ValueError, match="provide a secret key or a Keypair"):
28-
soroban.Identity().model_dump()
30+
soroban.Identity()
2931

3032
keypair = Keypair.random()
3133
with pytest.raises(ValueError, match="provide a secret key or a Keypair"):
32-
soroban.Identity(public_key=keypair.public_key).model_dump()
34+
soroban.Identity(public_key=keypair.public_key)
3335

3436

3537
class TestNetworkConfig:
3638
def test_from_network(self):
3739
testnet = pathlib.Path(__file__).parent / "testnet.toml"
38-
soroban.NetworkConfig.from_network(network=testnet).model_dump()
40+
soroban.NetworkConfig.from_network(network=testnet)
3941

4042

4143
class TestParams:

0 commit comments

Comments
 (0)