Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test wallet config option #3355

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarProfile(opened, context)

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions acapy_agent/askar/profile_anon.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,19 @@ async def provision(
) -> Profile:
"""Provision a new instance of a profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=True)
opened = await store_config.open_store(
provision=True, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

async def open(
self, context: InjectionContext, config: Mapping[str, Any] = None
) -> Profile:
"""Open an instance of an existing profile."""
store_config = AskarStoreConfig(config)
opened = await store_config.open_store(provision=False)
opened = await store_config.open_store(
provision=False, in_memory=config.get("test")
)
return AskarAnoncredsProfile(opened, context)

@classmethod
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/commands/tests/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_exec_start(self):
"0.0.0.0",
"80",
"--no-ledger",
"--wallet-test",
]
)
start_app.assert_called_once()
Expand Down
1 change: 1 addition & 0 deletions acapy_agent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ async def test_execute(self):
"--from-version",
"v0.7.0",
"--force-upgrade",
"--wallet-test",
]
)

Expand Down
26 changes: 20 additions & 6 deletions acapy_agent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,13 +1610,13 @@ def add_arguments(self, parser: ArgumentParser):
"--wallet-type",
type=str,
metavar="<wallet-type>",
default="basic",
default="askar",
env_var="ACAPY_WALLET_TYPE",
help=(
"Specifies the type of wallet provider to use. "
"Supported internal storage types are 'basic' (memory), 'askar' "
"Supported internal storage types are 'askar' "
"and 'askar-anoncreds'."
"The default (if not specified) is 'basic'."
"The default (if not specified) is 'askar'."
),
)
parser.add_argument(
Expand All @@ -1627,11 +1627,23 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_WALLET_STORAGE_TYPE",
help=(
"Specifies the type of wallet backend to use. "
"Supported internal storage types are 'basic' (memory), "
"'default' (sqlite), and 'postgres_storage'. The default, "
"Supported internal storage types are 'default' (sqlite), "
"and 'postgres_storage'. The default, "
"if not specified, is 'default'."
),
)
parser.add_argument(
"--wallet-test",
action="store_true",
default=False,
env_var="ACAPY_WALLET_TEST",
help=(
"Using this option will create a wallet with an in-memory askar wallet "
"storage with a random name. This is useful for testing purposes. "
"The data will not be persisted after the agent is stopped. The default "
"is False. "
),
)
parser.add_argument(
"--wallet-storage-config",
type=str,
Expand Down Expand Up @@ -1714,6 +1726,8 @@ def get_settings(self, args: Namespace) -> dict:
settings["wallet.storage_type"] = args.wallet_storage_type
if args.wallet_type:
settings["wallet.type"] = args.wallet_type
if args.wallet_test:
settings["wallet.test"] = True
if args.wallet_key_derivation_method:
settings["wallet.key_derivation_method"] = args.wallet_key_derivation_method
if args.wallet_rekey_derivation_method:
Expand All @@ -1731,7 +1745,7 @@ def get_settings(self, args: Namespace) -> dict:
# check required settings for persistent wallets
if settings["wallet.type"] in ["askar", "askar-anoncreds"]:
# requires name, key
if not args.wallet_name or not args.wallet_key:
if not args.wallet_test and (not args.wallet_name or not args.wallet_key):
raise ArgsParseError(
"Parameters --wallet-name and --wallet-key must be provided "
"for persistent wallets"
Expand Down
6 changes: 2 additions & 4 deletions acapy_agent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,7 @@ async def test_wallet_key_derivation_method_value_parsing(self):
group.add_arguments(parser)

result = parser.parse_args(
[
"--wallet-key-derivation-method",
key_derivation_method,
]
["--wallet-key-derivation-method", key_derivation_method, "--wallet-test"]
)

settings = group.get_settings(result)
Expand All @@ -545,6 +542,7 @@ async def test_wallet_key_value_parsing(self):
[
"--wallet-key",
key_value,
"--wallet-test",
]
)

Expand Down
1 change: 1 addition & 0 deletions acapy_agent/config/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"storage_config",
"storage_creds",
"storage_type",
"test",
}


Expand Down
Loading