From 4af6e02ed0ca4a3b1933ce55b535a6339dfaf5e2 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Wed, 28 Jan 2026 16:14:14 +0300 Subject: [PATCH 1/2] BG-701: Implements alt methods for shop/wallet accounts --- .../party_management/src/pm_party_handler.erl | 19 ++++++++ .../test/pm_party_tests_SUITE.erl | 48 +++++++++++++++++++ apps/pm_client/src/pm_client_party.erl | 19 ++++++++ rebar.config | 2 +- rebar.lock | 2 +- 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/apps/party_management/src/pm_party_handler.erl b/apps/party_management/src/pm_party_handler.erl index 642b1f6..39e57e2 100644 --- a/apps/party_management/src/pm_party_handler.erl +++ b/apps/party_management/src/pm_party_handler.erl @@ -2,6 +2,7 @@ -include_lib("damsel/include/dmsl_payproc_thrift.hrl"). -include_lib("damsel/include/dmsl_domain_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl"). %% Woody handler called by pm_woody_wrapper @@ -19,6 +20,15 @@ handle_function(Func, Args, Opts) -> -spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return(). %% Accounts +handle_function_('GetShopAccountForVersion', {PartyRef, ShopRef, VersionReference}, Opts) -> + DomainRevision = version_reference_to_revision_number(VersionReference), + handle_function('GetShopAccount', {PartyRef, ShopRef, DomainRevision}, Opts); +handle_function_('GetWalletAccountForVersion', {PartyRef, WalletRef, VersionReference}, Opts) -> + DomainRevision = version_reference_to_revision_number(VersionReference), + handle_function_('GetWalletAccount', {PartyRef, WalletRef, DomainRevision}, Opts); +handle_function_('GetAccountStateForVersion', {PartyRef, AccountID, VersionReference}, Opts) -> + DomainRevision = version_reference_to_revision_number(VersionReference), + handle_function_('GetAccountState', {PartyRef, AccountID, DomainRevision}, Opts); handle_function_('GetShopAccount', {PartyRef, ShopRef, DomainRevision}, _Opts) -> _ = set_party_mgmt_meta(PartyRef), pm_party:get_shop_account(ShopRef, PartyRef, DomainRevision); @@ -94,6 +104,15 @@ handle_function_('ComputeTerms', Args, _Opts) -> %% +version_reference_to_revision_number({head, #domain_conf_v2_Head{}}) -> + %% NOTE `dmt_client` is gonna normalize 'head' reference into integer-typed + %% version anyway. + dmt_client:get_latest_version(); +version_reference_to_revision_number({version, Version}) -> + Version; +version_reference_to_revision_number(Arg) -> + erlang:error({badarg, Arg}). + assert_provider_reduced(#domain_Provider{terms = Terms}) -> assert_provider_terms_reduced(Terms). diff --git a/apps/party_management/test/pm_party_tests_SUITE.erl b/apps/party_management/test/pm_party_tests_SUITE.erl index ae4fd6f..5d5a77b 100644 --- a/apps/party_management/test/pm_party_tests_SUITE.erl +++ b/apps/party_management/test/pm_party_tests_SUITE.erl @@ -8,6 +8,7 @@ -include_lib("damsel/include/dmsl_domain_thrift.hrl"). -include_lib("damsel/include/dmsl_base_thrift.hrl"). -include_lib("damsel/include/dmsl_limiter_config_thrift.hrl"). +-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl"). -export([all/0]). -export([groups/0]). @@ -18,6 +19,9 @@ -export([init_per_testcase/2]). -export([end_per_testcase/2]). +-export([get_shop_account_for_version/1]). +-export([get_wallet_account_for_version/1]). +-export([get_account_state_for_version/1]). -export([get_shop_account/1]). -export([get_shop_account_non_existant_version/1]). -export([get_wallet_account/1]). @@ -76,6 +80,9 @@ all() -> groups() -> [ {accounts, [parallel], [ + get_shop_account_for_version, + get_wallet_account_for_version, + get_account_state_for_version, get_shop_account, get_shop_account_non_existant_version, get_wallet_account, @@ -150,6 +157,9 @@ end_per_testcase(_Name, _C) -> -define(WRONG_DMT_OBJ_ID, 99999). +-spec get_shop_account_for_version(config()) -> _ | no_return(). +-spec get_wallet_account_for_version(config()) -> _ | no_return(). +-spec get_account_state_for_version(config()) -> _ | no_return(). -spec get_shop_account(config()) -> _ | no_return(). -spec get_shop_account_non_existant_version(config()) -> _ | no_return(). -spec get_wallet_account(config()) -> _ | no_return(). @@ -185,6 +195,44 @@ end_per_testcase(_Name, _C) -> -define(NON_EXISTANT_DOMAIN_REVISION, 42_000_000). -define(NON_EXISTANT_ACCOUNT_ID, 42_000). +get_shop_account_for_version(C) -> + Client = cfg(client, C), + DomainRevision = pm_domain:head(), + ?assertMatch( + #domain_ShopAccount{}, + pm_client_party:get_shop_account_for_version(?shop(?SHOP_ID), {version, DomainRevision}, Client) + ), + ?assertMatch( + #domain_ShopAccount{}, + pm_client_party:get_shop_account_for_version(?shop(?SHOP_ID), {head, #domain_conf_v2_Head{}}, Client) + ). + +get_wallet_account_for_version(C) -> + Client = cfg(client, C), + DomainRevision = pm_domain:head(), + ?assertMatch( + #domain_WalletAccount{}, + pm_client_party:get_wallet_account_for_version(?wallet(?WALLET_ID), {version, DomainRevision}, Client) + ), + ?assertMatch( + #domain_WalletAccount{}, + pm_client_party:get_wallet_account_for_version(?wallet(?WALLET_ID), {head, #domain_conf_v2_Head{}}, Client) + ). + +get_account_state_for_version(C) -> + Client = cfg(client, C), + DomainRevision = pm_domain:head(), + #domain_ShopAccount{settlement = AccountID} = + pm_client_party:get_shop_account(?shop(?SHOP_ID), DomainRevision, Client), + ?assertMatch( + #payproc_AccountState{account_id = AccountID}, + pm_client_party:get_account_state_for_version(AccountID, {version, DomainRevision}, Client) + ), + ?assertMatch( + #payproc_AccountState{account_id = AccountID}, + pm_client_party:get_account_state_for_version(AccountID, {head, #domain_conf_v2_Head{}}, Client) + ). + get_shop_account(C) -> Client = cfg(client, C), DomainRevision = pm_domain:head(), diff --git a/apps/pm_client/src/pm_client_party.erl b/apps/pm_client/src/pm_client_party.erl index 6b5b3e1..48a307d 100644 --- a/apps/pm_client/src/pm_client_party.erl +++ b/apps/pm_client/src/pm_client_party.erl @@ -6,6 +6,9 @@ -export([compute_terms/4]). -export([compute_payment_institution/4]). +-export([get_shop_account_for_version/3]). +-export([get_wallet_account_for_version/3]). +-export([get_account_state_for_version/3]). -export([get_shop_account/3]). -export([get_wallet_account/3]). -export([get_account_state/3]). @@ -28,6 +31,7 @@ -type party_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type domain_revision() :: dmsl_domain_thrift:'DataRevision'(). +-type domain_version_reference() :: dmsl_domain_conf_v2_thrift:'VersionReference'(). -type shop_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type wallet_ref() :: dmsl_domain_thrift:'WalletConfigRef'(). -type shop_account_id() :: dmsl_domain_thrift:'AccountID'(). @@ -62,16 +66,31 @@ compute_terms(Ref, DomainRevision, Varset, Client) -> compute_payment_institution(Ref, DomainRevision, Varset, Client) -> call(Client, 'ComputePaymentInstitution', [Ref, DomainRevision, Varset]). +-spec get_account_state_for_version(shop_account_id(), domain_version_reference(), pid()) -> + dmsl_payproc_thrift:'AccountState'() | woody_error:business_error(). +get_account_state_for_version(AccountID, VersionReference, Client) -> + call(Client, 'GetAccountStateForVersion', with_party_ref([AccountID, VersionReference])). + -spec get_account_state(shop_account_id(), domain_revision(), pid()) -> dmsl_payproc_thrift:'AccountState'() | woody_error:business_error(). get_account_state(AccountID, DomainRevision, Client) -> call(Client, 'GetAccountState', with_party_ref([AccountID, DomainRevision])). +-spec get_shop_account_for_version(shop_ref(), domain_version_reference(), pid()) -> + dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error(). +get_shop_account_for_version(ShopRef, VersionReference, Client) -> + call(Client, 'GetShopAccountForVersion', with_party_ref([ShopRef, VersionReference])). + -spec get_shop_account(shop_ref(), domain_revision(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error(). get_shop_account(ShopRef, DomainRevision, Client) -> call(Client, 'GetShopAccount', with_party_ref([ShopRef, DomainRevision])). +-spec get_wallet_account_for_version(wallet_ref(), domain_version_reference(), pid()) -> + dmsl_domain_thrift:'WalletAccount'() | woody_error:business_error(). +get_wallet_account_for_version(WalletRef, VersionReference, Client) -> + call(Client, 'GetWalletAccountForVersion', with_party_ref([WalletRef, VersionReference])). + -spec get_wallet_account(wallet_ref(), domain_revision(), pid()) -> dmsl_domain_thrift:'WalletAccount'() | woody_error:business_error(). get_wallet_account(WalletRef, DomainRevision, Client) -> diff --git a/rebar.config b/rebar.config index 9269aad..458d05e 100644 --- a/rebar.config +++ b/rebar.config @@ -32,7 +32,7 @@ {prometheus, "4.11.0"}, {prometheus_cowboy, "0.1.9"}, {woody, {git, "https://github.com/valitydev/woody_erlang.git", {tag, "v1.1.0"}}}, - {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.23"}}}, + {damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "BG-701/ft/optional-domain-revision"}}}, {payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}}, {dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {tag, "v2.0.3"}}}, {scoper, {git, "https://github.com/valitydev/scoper.git", {tag, "v1.1.0"}}}, diff --git a/rebar.lock b/rebar.lock index 8b1e47a..d4c9496 100644 --- a/rebar.lock +++ b/rebar.lock @@ -13,7 +13,7 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"b5c1dc423365397d8c2d123ba5766147551f19cc"}}, + {ref,"bcffb1cd6d16b2faf8519a9f95389b3145f67a1b"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git", From 3b5bae9bf6d01067a66e86f8711a6a38ab132cd0 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Thu, 29 Jan 2026 11:24:41 +0300 Subject: [PATCH 2/2] Removes version reference argument for new functions --- .../party_management/src/pm_party_handler.erl | 21 +++------ .../test/pm_party_tests_SUITE.erl | 44 +++++++------------ apps/pm_client/src/pm_client_party.erl | 25 +++++------ rebar.lock | 2 +- 4 files changed, 34 insertions(+), 58 deletions(-) diff --git a/apps/party_management/src/pm_party_handler.erl b/apps/party_management/src/pm_party_handler.erl index 39e57e2..1e85763 100644 --- a/apps/party_management/src/pm_party_handler.erl +++ b/apps/party_management/src/pm_party_handler.erl @@ -20,14 +20,14 @@ handle_function(Func, Args, Opts) -> -spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return(). %% Accounts -handle_function_('GetShopAccountForVersion', {PartyRef, ShopRef, VersionReference}, Opts) -> - DomainRevision = version_reference_to_revision_number(VersionReference), +handle_function_('GetShopAccountForLatestVersion', {PartyRef, ShopRef}, Opts) -> + DomainRevision = dmt_client:get_latest_version(), handle_function('GetShopAccount', {PartyRef, ShopRef, DomainRevision}, Opts); -handle_function_('GetWalletAccountForVersion', {PartyRef, WalletRef, VersionReference}, Opts) -> - DomainRevision = version_reference_to_revision_number(VersionReference), +handle_function_('GetWalletAccountForLatestVersion', {PartyRef, WalletRef}, Opts) -> + DomainRevision = dmt_client:get_latest_version(), handle_function_('GetWalletAccount', {PartyRef, WalletRef, DomainRevision}, Opts); -handle_function_('GetAccountStateForVersion', {PartyRef, AccountID, VersionReference}, Opts) -> - DomainRevision = version_reference_to_revision_number(VersionReference), +handle_function_('GetAccountStateForLatestVersion', {PartyRef, AccountID}, Opts) -> + DomainRevision = dmt_client:get_latest_version(), handle_function_('GetAccountState', {PartyRef, AccountID, DomainRevision}, Opts); handle_function_('GetShopAccount', {PartyRef, ShopRef, DomainRevision}, _Opts) -> _ = set_party_mgmt_meta(PartyRef), @@ -104,15 +104,6 @@ handle_function_('ComputeTerms', Args, _Opts) -> %% -version_reference_to_revision_number({head, #domain_conf_v2_Head{}}) -> - %% NOTE `dmt_client` is gonna normalize 'head' reference into integer-typed - %% version anyway. - dmt_client:get_latest_version(); -version_reference_to_revision_number({version, Version}) -> - Version; -version_reference_to_revision_number(Arg) -> - erlang:error({badarg, Arg}). - assert_provider_reduced(#domain_Provider{terms = Terms}) -> assert_provider_terms_reduced(Terms). diff --git a/apps/party_management/test/pm_party_tests_SUITE.erl b/apps/party_management/test/pm_party_tests_SUITE.erl index 5d5a77b..7946fd1 100644 --- a/apps/party_management/test/pm_party_tests_SUITE.erl +++ b/apps/party_management/test/pm_party_tests_SUITE.erl @@ -19,9 +19,9 @@ -export([init_per_testcase/2]). -export([end_per_testcase/2]). --export([get_shop_account_for_version/1]). --export([get_wallet_account_for_version/1]). --export([get_account_state_for_version/1]). +-export([get_shop_account_for_latest_version/1]). +-export([get_wallet_account_for_latest_version/1]). +-export([get_account_state_for_latest_version/1]). -export([get_shop_account/1]). -export([get_shop_account_non_existant_version/1]). -export([get_wallet_account/1]). @@ -80,9 +80,9 @@ all() -> groups() -> [ {accounts, [parallel], [ - get_shop_account_for_version, - get_wallet_account_for_version, - get_account_state_for_version, + get_shop_account_for_latest_version, + get_wallet_account_for_latest_version, + get_account_state_for_latest_version, get_shop_account, get_shop_account_non_existant_version, get_wallet_account, @@ -157,9 +157,9 @@ end_per_testcase(_Name, _C) -> -define(WRONG_DMT_OBJ_ID, 99999). --spec get_shop_account_for_version(config()) -> _ | no_return(). --spec get_wallet_account_for_version(config()) -> _ | no_return(). --spec get_account_state_for_version(config()) -> _ | no_return(). +-spec get_shop_account_for_latest_version(config()) -> _ | no_return(). +-spec get_wallet_account_for_latest_version(config()) -> _ | no_return(). +-spec get_account_state_for_latest_version(config()) -> _ | no_return(). -spec get_shop_account(config()) -> _ | no_return(). -spec get_shop_account_non_existant_version(config()) -> _ | no_return(). -spec get_wallet_account(config()) -> _ | no_return(). @@ -195,42 +195,28 @@ end_per_testcase(_Name, _C) -> -define(NON_EXISTANT_DOMAIN_REVISION, 42_000_000). -define(NON_EXISTANT_ACCOUNT_ID, 42_000). -get_shop_account_for_version(C) -> +get_shop_account_for_latest_version(C) -> Client = cfg(client, C), - DomainRevision = pm_domain:head(), - ?assertMatch( - #domain_ShopAccount{}, - pm_client_party:get_shop_account_for_version(?shop(?SHOP_ID), {version, DomainRevision}, Client) - ), ?assertMatch( #domain_ShopAccount{}, - pm_client_party:get_shop_account_for_version(?shop(?SHOP_ID), {head, #domain_conf_v2_Head{}}, Client) + pm_client_party:get_shop_account_for_latest_version(?shop(?SHOP_ID), Client) ). -get_wallet_account_for_version(C) -> +get_wallet_account_for_latest_version(C) -> Client = cfg(client, C), - DomainRevision = pm_domain:head(), ?assertMatch( #domain_WalletAccount{}, - pm_client_party:get_wallet_account_for_version(?wallet(?WALLET_ID), {version, DomainRevision}, Client) - ), - ?assertMatch( - #domain_WalletAccount{}, - pm_client_party:get_wallet_account_for_version(?wallet(?WALLET_ID), {head, #domain_conf_v2_Head{}}, Client) + pm_client_party:get_wallet_account_for_latest_version(?wallet(?WALLET_ID), Client) ). -get_account_state_for_version(C) -> +get_account_state_for_latest_version(C) -> Client = cfg(client, C), DomainRevision = pm_domain:head(), #domain_ShopAccount{settlement = AccountID} = pm_client_party:get_shop_account(?shop(?SHOP_ID), DomainRevision, Client), ?assertMatch( #payproc_AccountState{account_id = AccountID}, - pm_client_party:get_account_state_for_version(AccountID, {version, DomainRevision}, Client) - ), - ?assertMatch( - #payproc_AccountState{account_id = AccountID}, - pm_client_party:get_account_state_for_version(AccountID, {head, #domain_conf_v2_Head{}}, Client) + pm_client_party:get_account_state_for_latest_version(AccountID, Client) ). get_shop_account(C) -> diff --git a/apps/pm_client/src/pm_client_party.erl b/apps/pm_client/src/pm_client_party.erl index 48a307d..025f756 100644 --- a/apps/pm_client/src/pm_client_party.erl +++ b/apps/pm_client/src/pm_client_party.erl @@ -6,9 +6,9 @@ -export([compute_terms/4]). -export([compute_payment_institution/4]). --export([get_shop_account_for_version/3]). --export([get_wallet_account_for_version/3]). --export([get_account_state_for_version/3]). +-export([get_shop_account_for_latest_version/2]). +-export([get_wallet_account_for_latest_version/2]). +-export([get_account_state_for_latest_version/2]). -export([get_shop_account/3]). -export([get_wallet_account/3]). -export([get_account_state/3]). @@ -31,7 +31,6 @@ -type party_ref() :: dmsl_domain_thrift:'PartyConfigRef'(). -type domain_revision() :: dmsl_domain_thrift:'DataRevision'(). --type domain_version_reference() :: dmsl_domain_conf_v2_thrift:'VersionReference'(). -type shop_ref() :: dmsl_domain_thrift:'ShopConfigRef'(). -type wallet_ref() :: dmsl_domain_thrift:'WalletConfigRef'(). -type shop_account_id() :: dmsl_domain_thrift:'AccountID'(). @@ -66,30 +65,30 @@ compute_terms(Ref, DomainRevision, Varset, Client) -> compute_payment_institution(Ref, DomainRevision, Varset, Client) -> call(Client, 'ComputePaymentInstitution', [Ref, DomainRevision, Varset]). --spec get_account_state_for_version(shop_account_id(), domain_version_reference(), pid()) -> +-spec get_account_state_for_latest_version(shop_account_id(), pid()) -> dmsl_payproc_thrift:'AccountState'() | woody_error:business_error(). -get_account_state_for_version(AccountID, VersionReference, Client) -> - call(Client, 'GetAccountStateForVersion', with_party_ref([AccountID, VersionReference])). +get_account_state_for_latest_version(AccountID, Client) -> + call(Client, 'GetAccountStateForLatestVersion', with_party_ref([AccountID])). -spec get_account_state(shop_account_id(), domain_revision(), pid()) -> dmsl_payproc_thrift:'AccountState'() | woody_error:business_error(). get_account_state(AccountID, DomainRevision, Client) -> call(Client, 'GetAccountState', with_party_ref([AccountID, DomainRevision])). --spec get_shop_account_for_version(shop_ref(), domain_version_reference(), pid()) -> +-spec get_shop_account_for_latest_version(shop_ref(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error(). -get_shop_account_for_version(ShopRef, VersionReference, Client) -> - call(Client, 'GetShopAccountForVersion', with_party_ref([ShopRef, VersionReference])). +get_shop_account_for_latest_version(ShopRef, Client) -> + call(Client, 'GetShopAccountForLatestVersion', with_party_ref([ShopRef])). -spec get_shop_account(shop_ref(), domain_revision(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error(). get_shop_account(ShopRef, DomainRevision, Client) -> call(Client, 'GetShopAccount', with_party_ref([ShopRef, DomainRevision])). --spec get_wallet_account_for_version(wallet_ref(), domain_version_reference(), pid()) -> +-spec get_wallet_account_for_latest_version(wallet_ref(), pid()) -> dmsl_domain_thrift:'WalletAccount'() | woody_error:business_error(). -get_wallet_account_for_version(WalletRef, VersionReference, Client) -> - call(Client, 'GetWalletAccountForVersion', with_party_ref([WalletRef, VersionReference])). +get_wallet_account_for_latest_version(WalletRef, Client) -> + call(Client, 'GetWalletAccountForLatestVersion', with_party_ref([WalletRef])). -spec get_wallet_account(wallet_ref(), domain_revision(), pid()) -> dmsl_domain_thrift:'WalletAccount'() | woody_error:business_error(). diff --git a/rebar.lock b/rebar.lock index d4c9496..b730250 100644 --- a/rebar.lock +++ b/rebar.lock @@ -13,7 +13,7 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"bcffb1cd6d16b2faf8519a9f95389b3145f67a1b"}}, + {ref,"b4088eab1e7b8d2b5e34626d314b80e86e9d4c68"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git",