Compare commits

..

22 Commits

Author SHA1 Message Date
58242c8d55
fix failing test: TestManageVouchers 2025-04-02 10:53:36 +03:00
cab90ed89a
set and reset flag_api_error flag 2025-04-02 10:48:04 +03:00
73c3486400
catch api call failure when manage vouchers is called 2025-04-02 10:47:33 +03:00
3c84fb5ae7
Merge branch 'master' into route-api-errors 2025-04-02 10:38:47 +03:00
04880b58a8
fix failing test 2025-04-01 12:49:10 +03:00
0458ac9498
fix failing test 2025-04-01 12:38:57 +03:00
a7e8c184f5
add some spacing 2025-04-01 11:59:31 +03:00
3615348efd
add swahili template 2025-04-01 11:57:59 +03:00
d0be79d817
set account creation failed flag 2025-04-01 11:30:00 +03:00
7883063e53
feat: set and reset api call failure flags 2025-03-31 15:42:27 +03:00
f562ce8adf
check for api call failure when setting the dafault voucher 2025-03-31 15:41:49 +03:00
cd2f4328a8
check for api call failure when checking transactions 2025-03-31 15:41:19 +03:00
95b9a6e486
catch api call failure when fetching voucher details 2025-03-28 16:09:53 +03:00
9674a04cbc
add handler to reset api call failure flag,set flag when requesting an alias fails 2025-03-28 15:51:56 +03:00
6c46c097fb
add explicit api call failure flag reset 2025-03-28 15:47:34 +03:00
c814c4ae5c
register handler to reset api call failure flag 2025-03-28 15:46:57 +03:00
bbecec0310
catch api call error when requesting an alias 2025-03-28 15:46:21 +03:00
eaa89c29df
Merge branch 'master' into route-api-errors 2025-03-28 15:22:40 +03:00
e832f46d22
return to top on retry 2025-03-26 14:40:54 +03:00
039117f40e
add api call failure catch 2025-03-26 14:40:32 +03:00
3532f72fbd
remove unneccessary catch 2025-03-26 14:39:37 +03:00
04c7e20457
set api call error flag to failing api calls 2025-03-26 14:38:47 +03:00
16 changed files with 64 additions and 26 deletions

View File

@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
WORKDIR /build/sarafu-vise
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
RUN go mod download
RUN go build -tags logdebug,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
RUN go build -tags logwarn,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
FROM debian:bookworm-slim

2
go.mod
View File

@ -3,7 +3,7 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
go 1.23.4
require (
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805
git.defalsify.org/vise.git v0.3.1
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2

2
go.sum
View File

@ -1,7 +1,5 @@
git.defalsify.org/vise.git v0.3.1 h1:A6FhMcur09ft/JzUPGXR+KpA17fltfeBnasyvLMZmq4=
git.defalsify.org/vise.git v0.3.1/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805 h1:FnT39aqXcP5YWhwPDBABopSjCu2SlbPFoOVitSpAVxU=
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b h1:xiTpaqWWoF5qcnarY/9ZkT6aVdnKwqztb2gzIahJn4w=

View File

@ -186,10 +186,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
@ -245,7 +251,6 @@ func (h *MenuHandlers) CreateAccount(ctx context.Context, sym string, input []by
func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
flag_language_set, _ := h.flagManager.GetFlag("flag_language_set")
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
store := h.userdataStore
@ -257,17 +262,11 @@ func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, inpu
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil {
if db.IsNotFound(err) {
// reset major flags
res.FlagReset = append(res.FlagReset, flag_language_set)
res.FlagReset = append(res.FlagReset, flag_account_created)
return res, nil
if !db.IsNotFound(err) {
return res, err
}
return res, nil
}
res.FlagSet = append(res.FlagSet, flag_account_created)
return res, nil
}
@ -494,6 +493,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
@ -1410,7 +1417,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)
@ -1576,6 +1583,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)
@ -1649,10 +1657,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
}
}
}
@ -1967,6 +1978,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 {
@ -1977,9 +1989,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)
@ -2190,6 +2203,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,
@ -2223,6 +2237,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 {
@ -2460,6 +2475,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 {
@ -2483,9 +2500,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

@ -201,6 +201,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())
}
@ -217,7 +219,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},
},
},
}
@ -2002,6 +2005,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)
}
@ -2025,7 +2033,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},
},
},
{
@ -2041,7 +2050,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},
},
},
{
@ -2054,7 +2063,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},
},
},
}
@ -2205,6 +2214,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"
@ -2232,8 +2243,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

@ -128,6 +128,7 @@ 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.first = appHandlers.Init

View File

@ -612,7 +612,7 @@
},
{
"input": "1234",
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit"
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: Not Provided\n\n0:Back\n9:Quit"
},
{
"input": "0",

View File

@ -6,7 +6,6 @@ MOUT back 0
HALT
LOAD validate_amount 64
RELOAD validate_amount
CATCH api_failure flag_api_call_error 1
CATCH invalid_amount flag_invalid_amount 1
INCMP _ 0
LOAD get_recipient 0

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

@ -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

@ -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

@ -5,4 +5,5 @@ HALT
INCMP _ 0
LOAD request_custom_alias 0
RELOAD request_custom_alias
CATCH api_failure flag_api_call_error 1
INCMP confirm_new_alias *

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