Skip to content

Commit dd17d01

Browse files
authoredDec 2, 2024··
Add test wallet config option (#3355)
* Add test wallet config option Signed-off-by: jamshale <[email protected]> * Change wallet test arg to store true / Fix tests Signed-off-by: jamshale <[email protected]> * Add unit test with test wallet config Signed-off-by: jamshale <[email protected]> --------- Signed-off-by: jamshale <[email protected]>
1 parent 27edc6e commit dd17d01

File tree

8 files changed

+53
-27
lines changed

8 files changed

+53
-27
lines changed
 

‎acapy_agent/askar/profile.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,19 @@ async def provision(
324324
) -> Profile:
325325
"""Provision a new instance of a profile."""
326326
store_config = AskarStoreConfig(config)
327-
opened = await store_config.open_store(provision=True)
327+
opened = await store_config.open_store(
328+
provision=True, in_memory=config.get("test")
329+
)
328330
return AskarProfile(opened, context)
329331

330332
async def open(
331333
self, context: InjectionContext, config: Mapping[str, Any] = None
332334
) -> Profile:
333335
"""Open an instance of an existing profile."""
334336
store_config = AskarStoreConfig(config)
335-
opened = await store_config.open_store(provision=False)
337+
opened = await store_config.open_store(
338+
provision=False, in_memory=config.get("test")
339+
)
336340
return AskarProfile(opened, context)
337341

338342
@classmethod

‎acapy_agent/askar/profile_anon.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,19 @@ async def provision(
277277
) -> Profile:
278278
"""Provision a new instance of a profile."""
279279
store_config = AskarStoreConfig(config)
280-
opened = await store_config.open_store(provision=True)
280+
opened = await store_config.open_store(
281+
provision=True, in_memory=config.get("test")
282+
)
281283
return AskarAnoncredsProfile(opened, context)
282284

283285
async def open(
284286
self, context: InjectionContext, config: Mapping[str, Any] = None
285287
) -> Profile:
286288
"""Open an instance of an existing profile."""
287289
store_config = AskarStoreConfig(config)
288-
opened = await store_config.open_store(provision=False)
290+
opened = await store_config.open_store(
291+
provision=False, in_memory=config.get("test")
292+
)
289293
return AskarAnoncredsProfile(opened, context)
290294

291295
@classmethod

‎acapy_agent/askar/tests/test_profile.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import pytest
55

6-
from ...askar.profile import AskarProfile
6+
from ...askar.profile import AskarProfile, AskarProfileManager
77
from ...config.injection_context import InjectionContext
88
from ...ledger.base import BaseLedger
99
from .. import profile as test_module
10+
from ..profile_anon import AskarAnonProfileManager
1011

1112

1213
@pytest.fixture
@@ -107,15 +108,17 @@ async def test_profile_manager_transaction():
107108

108109
@pytest.mark.asyncio
109110
async def test_profile_manager_store():
110-
profile = "profileId"
111-
112-
with mock.patch("acapy_agent.askar.profile.AskarProfile") as AskarProfile:
113-
askar_profile = AskarProfile(None, False, profile_id=profile)
114-
askar_profile.profile_id = profile
115-
askar_profile_session = mock.MagicMock()
116-
askar_profile.store.session.return_value = askar_profile_session
117-
118-
sessionProfile = test_module.AskarProfileSession(askar_profile, False)
119-
120-
assert sessionProfile._opener == askar_profile_session
121-
askar_profile.store.session.assert_called_once_with(profile)
111+
config = {
112+
"test": True,
113+
}
114+
context = InjectionContext(
115+
settings=config,
116+
)
117+
await AskarProfileManager().provision(
118+
context=context,
119+
config=config,
120+
)
121+
await AskarAnonProfileManager().provision(
122+
context=context,
123+
config=config,
124+
)

‎acapy_agent/commands/tests/test_start.py

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def test_exec_start(self):
5555
"0.0.0.0",
5656
"80",
5757
"--no-ledger",
58+
"--wallet-test",
5859
]
5960
)
6061
start_app.assert_called_once()

‎acapy_agent/commands/tests/test_upgrade.py

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ async def test_execute(self):
439439
"--from-version",
440440
"v0.7.0",
441441
"--force-upgrade",
442+
"--wallet-test",
442443
]
443444
)
444445

‎acapy_agent/config/argparse.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -1610,13 +1610,13 @@ def add_arguments(self, parser: ArgumentParser):
16101610
"--wallet-type",
16111611
type=str,
16121612
metavar="<wallet-type>",
1613-
default="basic",
1613+
default="askar",
16141614
env_var="ACAPY_WALLET_TYPE",
16151615
help=(
16161616
"Specifies the type of wallet provider to use. "
1617-
"Supported internal storage types are 'basic' (memory), 'askar' "
1617+
"Supported internal storage types are 'askar' "
16181618
"and 'askar-anoncreds'."
1619-
"The default (if not specified) is 'basic'."
1619+
"The default (if not specified) is 'askar'."
16201620
),
16211621
)
16221622
parser.add_argument(
@@ -1627,11 +1627,23 @@ def add_arguments(self, parser: ArgumentParser):
16271627
env_var="ACAPY_WALLET_STORAGE_TYPE",
16281628
help=(
16291629
"Specifies the type of wallet backend to use. "
1630-
"Supported internal storage types are 'basic' (memory), "
1631-
"'default' (sqlite), and 'postgres_storage'. The default, "
1630+
"Supported internal storage types are 'default' (sqlite), "
1631+
"and 'postgres_storage'. The default, "
16321632
"if not specified, is 'default'."
16331633
),
16341634
)
1635+
parser.add_argument(
1636+
"--wallet-test",
1637+
action="store_true",
1638+
default=False,
1639+
env_var="ACAPY_WALLET_TEST",
1640+
help=(
1641+
"Using this option will create a wallet with an in-memory askar wallet "
1642+
"storage with a random name. This is useful for testing purposes. "
1643+
"The data will not be persisted after the agent is stopped. The default "
1644+
"is False. "
1645+
),
1646+
)
16351647
parser.add_argument(
16361648
"--wallet-storage-config",
16371649
type=str,
@@ -1714,6 +1726,8 @@ def get_settings(self, args: Namespace) -> dict:
17141726
settings["wallet.storage_type"] = args.wallet_storage_type
17151727
if args.wallet_type:
17161728
settings["wallet.type"] = args.wallet_type
1729+
if args.wallet_test:
1730+
settings["wallet.test"] = True
17171731
if args.wallet_key_derivation_method:
17181732
settings["wallet.key_derivation_method"] = args.wallet_key_derivation_method
17191733
if args.wallet_rekey_derivation_method:
@@ -1731,7 +1745,7 @@ def get_settings(self, args: Namespace) -> dict:
17311745
# check required settings for persistent wallets
17321746
if settings["wallet.type"] in ["askar", "askar-anoncreds"]:
17331747
# requires name, key
1734-
if not args.wallet_name or not args.wallet_key:
1748+
if not args.wallet_test and (not args.wallet_name or not args.wallet_key):
17351749
raise ArgsParseError(
17361750
"Parameters --wallet-name and --wallet-key must be provided "
17371751
"for persistent wallets"

‎acapy_agent/config/tests/test_argparse.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,7 @@ async def test_wallet_key_derivation_method_value_parsing(self):
525525
group.add_arguments(parser)
526526

527527
result = parser.parse_args(
528-
[
529-
"--wallet-key-derivation-method",
530-
key_derivation_method,
531-
]
528+
["--wallet-key-derivation-method", key_derivation_method, "--wallet-test"]
532529
)
533530

534531
settings = group.get_settings(result)
@@ -545,6 +542,7 @@ async def test_wallet_key_value_parsing(self):
545542
[
546543
"--wallet-key",
547544
key_value,
545+
"--wallet-test",
548546
]
549547
)
550548

‎acapy_agent/config/wallet.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"storage_config",
2727
"storage_creds",
2828
"storage_type",
29+
"test",
2930
}
3031

3132

0 commit comments

Comments
 (0)
Please sign in to comment.