Skip to content

Commit ec78e14

Browse files
committed
Fix default loading of identity
1 parent 39977c0 commit ec78e14

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/soroban/invoke.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def invoke(
3434
)
3535

3636
soroban_server = stellar_sdk.SorobanServer(network.rpc_url)
37-
source_account = soroban_server.load_account(identity.public_key)
37+
source_account_ = soroban_server.load_account(identity.public_key)
3838

3939
tx = (
4040
stellar_sdk.TransactionBuilder(
41-
source_account, network.network_passphrase, base_fee=network.base_fee
41+
source_account_, network.network_passphrase, base_fee=network.base_fee
4242
)
4343
.add_time_bounds(0, 0)
4444
.append_invoke_contract_function_op(

src/soroban/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class Identity(BaseSettings):
3636
@model_validator(mode="after")
3737
def load_keys(self) -> "Identity":
3838
if self.keypair is None and self.secret_key is None:
39-
raise ValueError("Either provide a secret key or a Keypair object.")
39+
raise ValueError(
40+
"Either provide a secret key or a Keypair object. Also look"
41+
"in 'identity.toml'"
42+
)
4043
if self.keypair is not None:
4144
self.secret_key = self.keypair.secret
4245
else:
@@ -50,7 +53,9 @@ def from_source_account(
5053
) -> "Identity":
5154
if account is None:
5255
identity = Identity()
53-
if isinstance(account, str) and account.startswith("S") and len(account) == 56:
56+
elif (
57+
isinstance(account, str) and account.startswith("S") and len(account) == 56
58+
):
5459
identity = Identity(secret_key=account)
5560
elif isinstance(account, (str, pathlib.Path)):
5661
fname = _load_configuration(account, "identity")

tests/identity.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
secret_key = "SDTZV5HD6WBU2LZKVUGFCUUR3JTOJHDHEXO2TSYVITMSH6RCY433HEYB"

tests/test_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import pathlib
34

45
import pytest
@@ -17,6 +18,9 @@ def test_from_pk(self):
1718
soroban.Identity(keypair=keypair)
1819

1920
def test_from_source_account(self):
21+
# identity.toml exists
22+
os.chdir(pathlib.Path(__file__).parent)
23+
soroban.Identity.from_source_account()
2024
alice_fname = pathlib.Path(__file__).parent / "alice.toml"
2125
soroban.Identity.from_source_account(account=alice_fname)
2226

@@ -26,6 +30,7 @@ def test_from_source_account(self):
2630
soroban.Identity.from_source_account(account=keypair.secret)
2731

2832
def test_raises(self):
33+
os.chdir(pathlib.Path(__file__).parent.parent)
2934
with pytest.raises(ValueError, match="provide a secret key or a Keypair"):
3035
soroban.Identity()
3136

0 commit comments

Comments
 (0)