Compare commits

...

34 Commits

Author SHA1 Message Date
Carlosokumu
1e832727fc add invalid alias hint node 2025-05-02 12:37:22 +03:00
Carlosokumu
548eb9b886 add flag to catch invalid alias hints 2025-05-02 11:15:47 +03:00
Carlosokumu
45e139ff92 request for alias only after correct PIN entry 2025-04-30 17:28:30 +03:00
Carlosokumu
361661c4f3 add confirm menu option 2025-04-30 17:27:33 +03:00
Carlosokumu
2078d95401 update confirm new alias node 2025-04-30 17:27:09 +03:00
Carlosokumu
4f95c32325 add cancel menu options 2025-04-30 17:26:26 +03:00
Carlosokumu
13551b70d5 update confirm alias node 2025-04-30 17:13:10 +03:00
Carlosokumu
6ebc1d0951 add node to allow api calls to the alias registration endpoint 2025-04-30 17:12:36 +03:00
Carlosokumu
537a6e1e09 register an handler to save an alias hint to the temporary value 2025-04-30 17:11:41 +03:00
carlos
db5d55d8e3 Merge pull request 'route-api-errors' (#46) from route-api-errors into master
Reviewed-on: #46
2025-04-29 13:55:54 +02:00
Carlosokumu
06cab56427 fix failing tests: menuhandlers missing the logdb 2025-04-29 13:25:31 +03:00
Carlosokumu
d0c181bca2 Merge branch 'master' into route-api-errors 2025-04-29 12:58:46 +03:00
Carlosokumu
58242c8d55 fix failing test: TestManageVouchers 2025-04-02 10:53:36 +03:00
Carlosokumu
cab90ed89a set and reset flag_api_error flag 2025-04-02 10:48:04 +03:00
Carlosokumu
73c3486400 catch api call failure when manage vouchers is called 2025-04-02 10:47:33 +03:00
Carlosokumu
3c84fb5ae7 Merge branch 'master' into route-api-errors 2025-04-02 10:38:47 +03:00
Carlosokumu
04880b58a8 fix failing test 2025-04-01 12:49:10 +03:00
Carlosokumu
0458ac9498 fix failing test 2025-04-01 12:38:57 +03:00
Carlosokumu
a7e8c184f5 add some spacing 2025-04-01 11:59:31 +03:00
Carlosokumu
3615348efd add swahili template 2025-04-01 11:57:59 +03:00
Carlosokumu
d0be79d817 set account creation failed flag 2025-04-01 11:30:00 +03:00
Carlosokumu
7883063e53 feat: set and reset api call failure flags 2025-03-31 15:42:27 +03:00
Carlosokumu
f562ce8adf check for api call failure when setting the dafault voucher 2025-03-31 15:41:49 +03:00
Carlosokumu
cd2f4328a8 check for api call failure when checking transactions 2025-03-31 15:41:19 +03:00
Carlosokumu
95b9a6e486 catch api call failure when fetching voucher details 2025-03-28 16:09:53 +03:00
Carlosokumu
9674a04cbc add handler to reset api call failure flag,set flag when requesting an alias fails 2025-03-28 15:51:56 +03:00
Carlosokumu
6c46c097fb add explicit api call failure flag reset 2025-03-28 15:47:34 +03:00
Carlosokumu
c814c4ae5c register handler to reset api call failure flag 2025-03-28 15:46:57 +03:00
Carlosokumu
bbecec0310 catch api call error when requesting an alias 2025-03-28 15:46:21 +03:00
Carlosokumu
eaa89c29df Merge branch 'master' into route-api-errors 2025-03-28 15:22:40 +03:00
Carlosokumu
e832f46d22 return to top on retry 2025-03-26 14:40:54 +03:00
Carlosokumu
039117f40e add api call failure catch 2025-03-26 14:40:32 +03:00
Carlosokumu
3532f72fbd remove unneccessary catch 2025-03-26 14:39:37 +03:00
Carlosokumu
04c7e20457 set api call error flag to failing api calls 2025-03-26 14:38:47 +03:00
23 changed files with 105 additions and 29 deletions

View File

@@ -199,10 +199,16 @@ func (h *MenuHandlers) SetLanguage(ctx context.Context, sym string, input []byte
// handles the account creation when no existing account is present for the session and stores associated data in the user data store.
func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error {
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
flag_account_creation_failed, _ := h.flagManager.GetFlag("flag_account_creation_failed")
r, err := h.accountService.CreateAccount(ctx)
if err != nil {
return err
res.FlagSet = append(res.FlagSet, flag_account_creation_failed)
logg.ErrorCtxf(ctx, "failed to create an account", "error", err)
return nil
}
res.FlagReset = append(res.FlagReset, flag_account_creation_failed)
trackingId := r.TrackingId
publicKey := r.PublicKey
@@ -430,6 +436,14 @@ func (h *MenuHandlers) ResetInvalidPIN(ctx context.Context, sym string, input []
return res, nil
}
// ResetApiCallFailure resets the api call failure flag
func (h *MenuHandlers) ResetApiCallFailure(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagReset = append(res.FlagReset, flag_api_error)
return res, nil
}
// ConfirmPinChange validates user's new PIN. If input matches the temporary PIN, saves it as the new account PIN.
func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
@@ -1440,7 +1454,7 @@ func (h *MenuHandlers) CheckAccountStatus(ctx context.Context, sym string, input
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
logg.ErrorCtxf(ctx, "failed on TrackAccountStatus", "error", err)
return res, err
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_api_error)
@@ -1606,6 +1620,7 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input
}
flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient")
flag_invalid_recipient_with_invite, _ := h.flagManager.GetFlag("flag_invalid_recipient_with_invite")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
recipient := string(input)
@@ -1679,10 +1694,13 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input
logg.InfoCtxf(ctx, "Resolving with fqdn alias", "alias", fqdn)
AliasAddress, err = h.accountService.CheckAliasAddress(ctx, fqdn)
if err == nil {
res.FlagReset = append(res.FlagReset, flag_api_error)
AliasAddressResult = AliasAddress.Address
continue
} else {
res.FlagSet = append(res.FlagSet, flag_api_error)
logg.ErrorCtxf(ctx, "failed to resolve alias", "alias", recipient, "error_alias_check", err)
return res, nil
}
}
}
@@ -2004,6 +2022,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
}
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil {
@@ -2014,9 +2033,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
// Fetch vouchers from API
vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
res.FlagSet = append(res.FlagSet, flag_api_error)
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_api_error)
if len(vouchersResp) == 0 {
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
@@ -2231,6 +2251,7 @@ func (h *MenuHandlers) GetVoucherDetails(ctx context.Context, sym string, input
res.FlagSet = append(res.FlagSet, flag_api_error)
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_api_error)
res.Content = fmt.Sprintf(
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation,
@@ -2265,6 +2286,7 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
return res, err
}
res.FlagReset = append(res.FlagReset, flag_api_error)
// Return if there are no transactions
if len(transactionsResp) == 0 {
@@ -2506,6 +2528,8 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
return res, nil
}
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
store := h.userdataStore
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
if err != nil {
@@ -2529,9 +2553,12 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
sanitizedInput := sanitizeAliasHint(string(input))
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_api_error)
alias := aliasResult.Alias
logg.InfoCtxf(ctx, "Suggested alias ", "alias", alias)

View File

@@ -226,6 +226,8 @@ func TestCreateAccount(t *testing.T) {
}
flag_account_created, err := fm.GetFlag("flag_account_created")
flag_account_creation_failed, _ := fm.GetFlag("flag_account_creation_failed")
if err != nil {
t.Logf(err.Error())
}
@@ -242,7 +244,8 @@ func TestCreateAccount(t *testing.T) {
PublicKey: "0xD3adB33f",
},
expectedResult: resource.Result{
FlagSet: []uint32{flag_account_created},
FlagSet: []uint32{flag_account_created},
FlagReset: []uint32{flag_account_creation_failed},
},
},
}
@@ -620,9 +623,15 @@ func TestSaveGender(t *testing.T) {
func TestSaveTemporaryPin(t *testing.T) {
sessionId := "session123"
ctx, store := InitializeTestStore(t)
ctx, userdatastore := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
_, logdb := InitializeTestLogdbStore(t)
logDb := store.LogDb{
Db: logdb,
}
fm, err := NewFlagManager(flagsPath)
if err != nil {
log.Fatal(err)
@@ -633,7 +642,8 @@ func TestSaveTemporaryPin(t *testing.T) {
// Create the MenuHandlers instance with the mock flag manager
h := &MenuHandlers{
flagManager: fm,
userdataStore: store,
userdataStore: userdatastore,
logDb: logDb,
}
// Define test cases
@@ -674,9 +684,15 @@ func TestSaveTemporaryPin(t *testing.T) {
func TestCheckIdentifier(t *testing.T) {
sessionId := "session123"
ctx, store := InitializeTestStore(t)
ctx, userdatastore := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId)
_, logdb := InitializeTestLogdbStore(t)
logDb := store.LogDb{
Db: logdb,
}
// Define test cases
tests := []struct {
name string
@@ -696,14 +712,15 @@ func TestCheckIdentifier(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
err := userdatastore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
if err != nil {
t.Fatal(err)
}
// Create the MenuHandlers instance with the mock store
h := &MenuHandlers{
userdataStore: store,
userdataStore: userdatastore,
logDb: logDb,
}
// Call the method
@@ -2025,6 +2042,11 @@ func TestManageVouchers(t *testing.T) {
t.Fatal(err)
}
flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher")
if err != nil {
t.Fatal(err)
}
flag_api_error, err := fm.GetFlag("flag_api_call_error")
if err != nil {
t.Fatal(err)
}
@@ -2048,7 +2070,8 @@ func TestManageVouchers(t *testing.T) {
expectedVoucherSymbols: []byte(""),
expectedUpdatedAddress: []byte(""),
expectedResult: resource.Result{
FlagSet: []uint32{flag_no_active_voucher},
FlagSet: []uint32{flag_no_active_voucher},
FlagReset: []uint32{flag_api_error},
},
},
{
@@ -2064,7 +2087,7 @@ func TestManageVouchers(t *testing.T) {
expectedVoucherSymbols: []byte("1:TOKEN1"),
expectedUpdatedAddress: []byte("0x123"),
expectedResult: resource.Result{
FlagReset: []uint32{flag_no_active_voucher},
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
},
},
{
@@ -2077,7 +2100,7 @@ func TestManageVouchers(t *testing.T) {
expectedVoucherSymbols: []byte("1:SRF\n2:MILO"),
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
expectedResult: resource.Result{
FlagReset: []uint32{flag_no_active_voucher},
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
},
},
}
@@ -2229,6 +2252,8 @@ func TestGetVoucherDetails(t *testing.T) {
if err != nil {
t.Logf(err.Error())
}
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
mockAccountService := new(mocks.MockAccountService)
sessionId := "session123"
@@ -2256,8 +2281,8 @@ func TestGetVoucherDetails(t *testing.T) {
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
)
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))
expectedResult.FlagReset = append(expectedResult.FlagReset, flag_api_error)
assert.NoError(t, err)
assert.Equal(t, expectedResult, res)
}

View File

@@ -129,6 +129,9 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
ls.DbRs.AddLocalFunc("save_alias_hint", appHandlers.SaveAliasHint)
ls.first = appHandlers.Init

View File

@@ -0,0 +1,4 @@
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_allow_update 0
LOAD request_custom_alias 0
MOVE confirm_new_alias

View File

@@ -1 +1 @@
Failed to connect to the custodial service.Please try again.
Failed to connect to the custodial service .Please try again.

View File

@@ -1,5 +1,7 @@
LOAD reset_api_call_failure 6
RELOAD reset_api_call_failure
MOUT retry 1
MOUT quit 9
HALT
INCMP _ 1
INCMP ^ 1
INCMP quit 9

View File

@@ -0,0 +1 @@
Imeshindwa kuunganisha kwenye huduma ya uangalizi. Tafadhali jaribu tena.

View File

@@ -0,0 +1 @@
Cancel

View File

@@ -0,0 +1 @@
Ghairi

View File

@@ -1,5 +1,6 @@
LOAD check_transactions 0
RELOAD check_transactions
CATCH api_failure flag_api_call_error 1
CATCH no_transfers flag_no_transfers 1
LOAD authorize_account 6
MOUT back 0

View File

@@ -1,2 +1,2 @@
Your full alias will be: {{.get_suggested_alias}}
Please enter your PIN to confirm:
Please choose `Ok` to accept or `Cancel` to stop:

View File

@@ -1,12 +1,10 @@
LOAD reset_invalid_pin 6
RELOAD reset_invalid_pin
LOAD get_suggested_alias 0
RELOAD get_suggested_alias
MAP get_suggested_alias
MOUT back 0
MOUT ok 1
MOUT cancel 2
MOUT quit 9
HALT
INCMP _ 0
RELOAD authorize_account
CATCH incorrect_pin flag_incorrect_pin 1
CATCH invalid_pin flag_invalid_pin 1
CATCH update_alias flag_allow_update 1
INCMP update_alias 1
INCMP ^ 2
INCMP quit 9

View File

@@ -1,2 +1,2 @@
Lakabu yako kamili itakuwa: {{.get_suggested_alias}}
Tafadhali weka PIN yako ili kuthibitisha:
Tafadhali chagua `Sawa` kukubali au `Ghairi` kusitisha:

View File

@@ -0,0 +1 @@
The alias hint is invalid. It should only contain letters, with no numbers or special characters.

View File

@@ -0,0 +1,5 @@
MOUT retry 1
MOUT quit 9
HALT
INCMP _ 1
INCMP quit 9

View File

@@ -0,0 +1 @@
Kichocheo cha alias si halali. Ni herufi pekee zinazoruhusiwa, hakuna namba au alama.

View File

@@ -2,6 +2,7 @@ LOAD clear_temporary_value 2
RELOAD clear_temporary_value
LOAD manage_vouchers 160
RELOAD manage_vouchers
CATCH api_failure flag_api_call_error 1
LOAD check_balance 128
RELOAD check_balance
CATCH api_failure flag_api_call_error 1

View File

@@ -2,7 +2,6 @@ LOAD get_current_profile_info 0
MAP get_current_profile_info
MOUT back 0
HALT
LOAD save_alias_hint 0
INCMP _ 0
LOAD request_custom_alias 0
RELOAD request_custom_alias
INCMP confirm_new_alias *
INCMP allow_request_alias *

View File

@@ -0,0 +1 @@
Ok

View File

@@ -0,0 +1 @@
Sawa

View File

@@ -32,3 +32,4 @@ flag,flag_account_blocked,38,this is set when an account has been blocked after
flag,flag_invalid_pin,39,this is set when the given PIN is invalid(is less than or more than 4 digits)
flag,flag_alias_set,40,this is set when an account alias has been assigned to a user
flag,flag_account_pin_reset,41,this is set on an account when an admin triggers a PIN reset for them
flag,flag_invalid_alias_hint,42,this is set when the provided alias hint fails to meet the required criteria.
1 flag flag_language_set 8 checks whether the user has set their prefered language
32 flag flag_invalid_pin 39 this is set when the given PIN is invalid(is less than or more than 4 digits)
33 flag flag_alias_set 40 this is set when an account alias has been assigned to a user
34 flag flag_account_pin_reset 41 this is set on an account when an admin triggers a PIN reset for them
35 flag flag_invalid_alias_hint 42 this is set when the provided alias hint fails to meet the required criteria.

View File

@@ -5,6 +5,7 @@ MOUT back 0
HALT
LOAD validate_recipient 50
RELOAD validate_recipient
CATCH api_failure flag_api_call_error 1
CATCH invalid_recipient flag_invalid_recipient 1
CATCH invite_recipient flag_invalid_recipient_with_invite 1
INCMP _ 0

View File

@@ -1,5 +1,7 @@
CATCH no_voucher flag_no_active_voucher 1
LOAD get_voucher_details 0
RELOAD get_voucher_details
CATCH api_failure flag_api_call_error 1
MAP get_voucher_details
MOUT back 0
HALT