Compare commits
24 Commits
lash/subpr
...
menu-api-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
353e24de33
|
||
|
|
1c57c95d93
|
||
|
|
128a354b34
|
||
|
|
81c4189c8e
|
||
|
|
b8e12e5215
|
||
|
|
4f04362835
|
||
|
|
f73b7a8b04
|
||
|
|
0be570ae2d
|
||
|
|
6a36bc43b5
|
||
|
|
1d27a88908
|
||
|
|
4889e6d18b
|
||
|
|
368c25125a
|
||
|
|
283793a2ae
|
||
|
|
bec7e5c69f
|
||
|
|
d638aba85e
|
||
|
|
df7788dd0b
|
||
|
|
4a62773098
|
||
|
|
26d315b032
|
||
|
|
1927544533
|
||
|
|
c641a0c669
|
||
|
|
952da86931
|
||
|
|
be6391686f
|
||
|
|
65794c1b20
|
||
| b058f9d770 |
@@ -87,7 +87,7 @@ func main() {
|
|||||||
cfg := engine.Config{
|
cfg := engine.Config{
|
||||||
Root: "root",
|
Root: "root",
|
||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(128),
|
||||||
}
|
}
|
||||||
|
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func main() {
|
|||||||
cfg := engine.Config{
|
cfg := engine.Config{
|
||||||
Root: "root",
|
Root: "root",
|
||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(128),
|
||||||
}
|
}
|
||||||
|
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func main() {
|
|||||||
cfg := engine.Config{
|
cfg := engine.Config{
|
||||||
Root: "root",
|
Root: "root",
|
||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(128),
|
||||||
}
|
}
|
||||||
|
|
||||||
if engineDebug {
|
if engineDebug {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func main() {
|
|||||||
Root: "root",
|
Root: "root",
|
||||||
SessionId: sessionId,
|
SessionId: sessionId,
|
||||||
OutputSize: uint32(size),
|
OutputSize: uint32(size),
|
||||||
FlagCount: uint32(16),
|
FlagCount: uint32(128),
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceDir := scriptDir
|
resourceDir := scriptDir
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CreateAccountURL = "https://custodial.sarafu.africa/api/account/create"
|
CreateAccountURL = "http://localhost:5003/api/v2/account/create"
|
||||||
TrackStatusURL = "https://custodial.sarafu.africa/api/track/"
|
BalanceURL = "https://custodial.sarafu.africa/api/account/status/"
|
||||||
BalanceURL = "https://custodial.sarafu.africa/api/account/status/"
|
TrackURL = "http://localhost:5003/api/v2/account/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
|
|||||||
ls.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
ls.DbRs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
||||||
ls.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
ls.DbRs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
||||||
ls.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
ls.DbRs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
||||||
ls.DbRs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance)
|
|
||||||
ls.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
ls.DbRs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
||||||
ls.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
ls.DbRs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
||||||
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
||||||
@@ -93,6 +92,7 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
|
|||||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
||||||
|
ls.DbRs.AddLocalFunc("fetch_custodial_balances", ussdHandlers.FetchCustodialBalances)
|
||||||
|
|
||||||
return ussdHandlers, nil
|
return ussdHandlers, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -9,104 +10,175 @@ import (
|
|||||||
"git.grassecon.net/urdt/ussd/internal/models"
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var apiResponse struct {
|
||||||
|
Ok bool `json:"ok"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
type AccountServiceInterface interface {
|
type AccountServiceInterface interface {
|
||||||
CheckBalance(publicKey string) (string, error)
|
CheckBalance(publicKey string) (*models.BalanceResponse, error)
|
||||||
CreateAccount() (*models.AccountResponse, error)
|
CreateAccount() (*OKResponse, *ErrResponse)
|
||||||
CheckAccountStatus(trackingId string) (string, error)
|
CheckAccountStatus(trackingId string) (*models.TrackStatusResponse, error)
|
||||||
|
TrackAccountStatus(publicKey string) (*OKResponse, *ErrResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID.
|
|
||||||
//
|
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - trackingId: A unique identifier for the account.This should be obtained from a previous call to
|
// - trackingId: A unique identifier for the account.This should be obtained from a previous call to
|
||||||
// CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the
|
// CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the
|
||||||
// AccountResponse struct can be used here to check the account status during a transaction.
|
// AccountResponse struct can be used here to check the account status during a transaction.
|
||||||
//
|
//
|
||||||
//
|
|
||||||
// Returns:
|
// Returns:
|
||||||
// - string: The status of the transaction as a string. If there is an error during the request or processing, this will be an empty string.
|
// - string: The status of the transaction as a string. If there is an error during the request or processing, this will be an empty string.
|
||||||
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
||||||
// If no error occurs, this will be nil.
|
// If no error occurs, this will be nil
|
||||||
//
|
func (as *AccountService) CheckAccountStatus(trackingId string) (*models.TrackStatusResponse, error) {
|
||||||
func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) {
|
resp, err := http.Get(config.BalanceURL + trackingId)
|
||||||
resp, err := http.Get(config.TrackStatusURL + trackingId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var trackResp models.TrackStatusResponse
|
var trackResp models.TrackStatusResponse
|
||||||
err = json.Unmarshal(body, &trackResp)
|
err = json.Unmarshal(body, &trackResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &trackResp, nil
|
||||||
|
|
||||||
status := trackResp.Result.Transaction.Status
|
|
||||||
|
|
||||||
return status, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *AccountService) TrackAccountStatus(publicKey string) (*OKResponse, *ErrResponse) {
|
||||||
|
var errResponse ErrResponse
|
||||||
|
var okResponse OKResponse
|
||||||
|
var err error
|
||||||
|
// Construct the URL with the path parameter
|
||||||
|
url := fmt.Sprintf("%s/%s", config.TrackURL, publicKey)
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
// Set headers
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("X-GE-KEY", "xd")
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Read the response body
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Unmarshal into the generic struct
|
||||||
|
err = json.Unmarshal([]byte(body), &apiResponse)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
if apiResponse.Ok {
|
||||||
|
err = json.Unmarshal([]byte(body), &okResponse)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
return &okResponse, nil
|
||||||
|
} else {
|
||||||
|
err := json.Unmarshal([]byte(body), &errResponse)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CheckBalance retrieves the balance for a given public key from the custodial balance API endpoint.
|
// CheckBalance retrieves the balance for a given public key from the custodial balance API endpoint.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - publicKey: The public key associated with the account whose balance needs to be checked.
|
// - publicKey: The public key associated with the account whose balance needs to be checked.
|
||||||
func (as *AccountService) CheckBalance(publicKey string) (string, error) {
|
func (as *AccountService) CheckBalance(publicKey string) (*models.BalanceResponse, error) {
|
||||||
|
|
||||||
resp, err := http.Get(config.BalanceURL + publicKey)
|
resp, err := http.Get(config.BalanceURL + publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "0.0", err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "0.0", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var balanceResp models.BalanceResponse
|
var balanceResp models.BalanceResponse
|
||||||
err = json.Unmarshal(body, &balanceResp)
|
err = json.Unmarshal(body, &balanceResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "0.0", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &balanceResp, nil
|
||||||
balance := balanceResp.Result.Balance
|
|
||||||
return balance, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateAccount creates a new account in the custodial system.
|
||||||
//CreateAccount creates a new account in the custodial system.
|
|
||||||
// Returns:
|
// Returns:
|
||||||
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account.
|
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account.
|
||||||
// If there is an error during the request or processing, this will be nil.
|
// If there is an error during the request or processing, this will be nil.
|
||||||
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
||||||
// If no error occurs, this will be nil.
|
// If no error occurs, this will be nil.
|
||||||
func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
|
func (as *AccountService) CreateAccount() (*OKResponse, *ErrResponse) {
|
||||||
resp, err := http.Post(config.CreateAccountURL, "application/json", nil)
|
|
||||||
|
var errResponse ErrResponse
|
||||||
|
var okResponse OKResponse
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Create a new request
|
||||||
|
req, err := http.NewRequest("POST", config.CreateAccountURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("X-GE-KEY", "xd")
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
}
|
}
|
||||||
|
err = json.Unmarshal([]byte(body), &apiResponse)
|
||||||
var accountResp models.AccountResponse
|
|
||||||
err = json.Unmarshal(body, &accountResp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
if apiResponse.Ok {
|
||||||
|
err = json.Unmarshal([]byte(body), &okResponse)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
return &okResponse, nil
|
||||||
|
} else {
|
||||||
|
err := json.Unmarshal([]byte(body), &errResponse)
|
||||||
|
if err != nil {
|
||||||
|
errResponse.Description = err.Error()
|
||||||
|
return nil, &errResponse
|
||||||
|
}
|
||||||
|
return nil, &errResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
return &accountResp, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
60
internal/handlers/server/api.go
Normal file
60
internal/handlers/server/api.go
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
type (
|
||||||
|
OKResponse struct {
|
||||||
|
Ok bool `json:"ok"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Result map[string]any `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrResponse struct {
|
||||||
|
Ok bool `json:"ok"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
ErrCode string `json:"errorCode"`
|
||||||
|
}
|
||||||
|
|
||||||
|
TransferRequest struct {
|
||||||
|
From string `json:"from" validate:"required,eth_addr_checksum"`
|
||||||
|
To string `json:"to" validate:"required,eth_addr_checksum"`
|
||||||
|
TokenAddress string `json:"tokenAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
Amount string `json:"amount" validate:"required,number,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolSwapRequest struct {
|
||||||
|
From string `json:"from" validate:"required,eth_addr_checksum"`
|
||||||
|
FromTokenAddress string `json:"fromTokenAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
ToTokenAddress string `json:"toTokenAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
PoolAddress string `json:"poolAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
Amount string `json:"amount" validate:"required,number,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolDepositRequest struct {
|
||||||
|
From string `json:"from" validate:"required,eth_addr_checksum"`
|
||||||
|
TokenAddress string `json:"tokenAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
PoolAddress string `json:"poolAddress" validate:"required,eth_addr_checksum"`
|
||||||
|
Amount string `json:"amount" validate:"required,number,gt=0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountAddressParam struct {
|
||||||
|
Address string `param:"address" validate:"required,eth_addr_checksum"`
|
||||||
|
}
|
||||||
|
|
||||||
|
TrackingIDParam struct {
|
||||||
|
TrackingID string `param:"trackingId" validate:"required,uuid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
OTXByAccountRequest struct {
|
||||||
|
Address string `param:"address" validate:"required,eth_addr_checksum"`
|
||||||
|
PerPage int `query:"perPage" validate:"required,number,gt=0"`
|
||||||
|
Cursor int `query:"cursor" validate:"number"`
|
||||||
|
Next bool `query:"next"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrCodeInternalServerError = "E01"
|
||||||
|
ErrCodeInvalidJSON = "E02"
|
||||||
|
ErrCodeInvalidAPIKey = "E03"
|
||||||
|
ErrCodeValidationFailed = "E04"
|
||||||
|
ErrCodeAccountNotExists = "E05"
|
||||||
|
)
|
||||||
@@ -27,6 +27,8 @@ var (
|
|||||||
logg = logging.NewVanilla().WithDomain("ussdmenuhandler")
|
logg = logging.NewVanilla().WithDomain("ussdmenuhandler")
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
translationDir = path.Join(scriptDir, "locale")
|
translationDir = path.Join(scriptDir, "locale")
|
||||||
|
okResponse *server.OKResponse
|
||||||
|
errResponse *server.ErrResponse
|
||||||
)
|
)
|
||||||
|
|
||||||
// FlagManager handles centralized flag management
|
// FlagManager handles centralized flag management
|
||||||
@@ -136,11 +138,16 @@ func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error {
|
func (h *Handlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error {
|
||||||
accountResp, err := h.accountService.CreateAccount()
|
okResponse, errResponse := h.accountService.CreateAccount()
|
||||||
|
if errResponse != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
trackingId := okResponse.Result["trackingId"].(string)
|
||||||
|
publicKey := okResponse.Result["publicKey"].(string)
|
||||||
|
|
||||||
data := map[utils.DataTyp]string{
|
data := map[utils.DataTyp]string{
|
||||||
utils.DATA_TRACKING_ID: accountResp.Result.TrackingId,
|
utils.DATA_TRACKING_ID: trackingId,
|
||||||
utils.DATA_PUBLIC_KEY: accountResp.Result.PublicKey,
|
utils.DATA_PUBLIC_KEY: publicKey,
|
||||||
utils.DATA_CUSTODIAL_ID: accountResp.Result.CustodialId.String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range data {
|
for key, value := range data {
|
||||||
@@ -152,7 +159,7 @@ func (h *Handlers) createAccountNoExist(ctx context.Context, sessionId string, r
|
|||||||
}
|
}
|
||||||
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
||||||
res.FlagSet = append(res.FlagSet, flag_account_created)
|
res.FlagSet = append(res.FlagSet, flag_account_created)
|
||||||
return err
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +198,6 @@ func (h *Handlers) SavePin(ctx context.Context, sym string, input []byte) (resou
|
|||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
||||||
|
|
||||||
accountPIN := string(input)
|
accountPIN := string(input)
|
||||||
// Validate that the PIN is a 4-digit number
|
// Validate that the PIN is a 4-digit number
|
||||||
if !isValidPIN(accountPIN) {
|
if !isValidPIN(accountPIN) {
|
||||||
@@ -290,8 +296,6 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
//AccountPin, _ := utils.ReadEntry(ctx, h.userdataStore, sessionId, utils.DATA_ACCOUNT_PIN)
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN)
|
AccountPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACCOUNT_PIN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -370,7 +374,6 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(input) == 4 {
|
if len(input) == 4 {
|
||||||
yob := string(input)
|
yob := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -413,7 +416,6 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
gender := strings.Split(symbol, "_")[1]
|
gender := strings.Split(symbol, "_")[1]
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender))
|
||||||
@@ -432,7 +434,6 @@ func (h *Handlers) SaveOfferings(ctx context.Context, sym string, input []byte)
|
|||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
offerings := string(input)
|
offerings := string(input)
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
@@ -458,7 +459,6 @@ func (h *Handlers) ResetAllowUpdate(ctx context.Context, sym string, input []byt
|
|||||||
// ResetAccountAuthorized resets the account authorization flag after a successful PIN entry.
|
// ResetAccountAuthorized resets the account authorization flag after a successful PIN entry.
|
||||||
func (h *Handlers) ResetAccountAuthorized(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) ResetAccountAuthorized(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
|
||||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||||
@@ -468,12 +468,10 @@ func (h *Handlers) ResetAccountAuthorized(ctx context.Context, sym string, input
|
|||||||
// CheckIdentifier retrieves the PublicKey from the JSON data file.
|
// CheckIdentifier retrieves the PublicKey from the JSON data file.
|
||||||
func (h *Handlers) CheckIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) CheckIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
|
|
||||||
@@ -487,12 +485,10 @@ func (h *Handlers) CheckIdentifier(ctx context.Context, sym string, input []byte
|
|||||||
func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
||||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
||||||
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
||||||
@@ -525,9 +521,7 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
|
|||||||
// ResetIncorrectPin resets the incorrect pin flag after a new PIN attempt.
|
// ResetIncorrectPin resets the incorrect pin flag after a new PIN attempt.
|
||||||
func (h *Handlers) ResetIncorrectPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) ResetIncorrectPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
|
||||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@@ -539,29 +533,27 @@ func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []b
|
|||||||
|
|
||||||
flag_account_success, _ := h.flagManager.GetFlag("flag_account_success")
|
flag_account_success, _ := h.flagManager.GetFlag("flag_account_success")
|
||||||
flag_account_pending, _ := h.flagManager.GetFlag("flag_account_pending")
|
flag_account_pending, _ := h.flagManager.GetFlag("flag_account_pending")
|
||||||
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
trackingId, err := store.ReadEntry(ctx, sessionId, utils.DATA_TRACKING_ID)
|
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
okResponse, errResponse = h.accountService.TrackAccountStatus(string(publicKey))
|
||||||
status, err := h.accountService.CheckAccountStatus(string(trackingId))
|
if errResponse != nil {
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error checking account status:", err)
|
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(status))
|
isActive := okResponse.Result["active"].(bool)
|
||||||
if err != nil {
|
if !ok {
|
||||||
return res, nil
|
return res, err
|
||||||
}
|
}
|
||||||
|
if isActive {
|
||||||
if status == "SUCCESS" {
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_account_success)
|
res.FlagSet = append(res.FlagSet, flag_account_success)
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_pending)
|
res.FlagReset = append(res.FlagReset, flag_account_pending)
|
||||||
} else {
|
} else {
|
||||||
@@ -641,6 +633,8 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
var res resource.Result
|
var res resource.Result
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
@@ -652,15 +646,60 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
balance, err := h.accountService.CheckBalance(string(publicKey))
|
balanceResponse, err := h.accountService.CheckBalance(string(publicKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
if !balanceResponse.Ok {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
|
balance := balanceResponse.Result.Balance
|
||||||
res.Content = balance
|
res.Content = balance
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handlers) FetchCustodialBalances(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("missing session")
|
||||||
|
}
|
||||||
|
symbol, _ := h.st.Where()
|
||||||
|
balanceType := strings.Split(symbol, "_")[0]
|
||||||
|
|
||||||
|
store := h.userdataStore
|
||||||
|
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
balanceResponse, err := h.accountService.CheckBalance(string(publicKey))
|
||||||
|
if err != nil {
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
if !balanceResponse.Ok {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
|
balance := balanceResponse.Result.Balance
|
||||||
|
|
||||||
|
switch balanceType {
|
||||||
|
case "my":
|
||||||
|
res.Content = fmt.Sprintf("Your balance is %s", balance)
|
||||||
|
case "community":
|
||||||
|
res.Content = fmt.Sprintf("Your community balance is %s", balance)
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ValidateRecipient validates that the given input is a valid phone number.
|
// ValidateRecipient validates that the given input is a valid phone number.
|
||||||
func (h *Handlers) ValidateRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) ValidateRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
@@ -757,10 +796,11 @@ func (h *Handlers) MaxAmount(ctx context.Context, sym string, input []byte) (res
|
|||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
|
|
||||||
balance, err := h.accountService.CheckBalance(string(publicKey))
|
balanceResp, err := h.accountService.CheckBalance(string(publicKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
balance := balanceResp.Result.Balance
|
||||||
|
|
||||||
res.Content = balance
|
res.Content = balance
|
||||||
|
|
||||||
@@ -779,18 +819,25 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
|
|||||||
}
|
}
|
||||||
|
|
||||||
flag_invalid_amount, _ := h.flagManager.GetFlag("flag_invalid_amount")
|
flag_invalid_amount, _ := h.flagManager.GetFlag("flag_invalid_amount")
|
||||||
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||||
|
|
||||||
amountStr := string(input)
|
amountStr := string(input)
|
||||||
|
|
||||||
balanceStr, err := h.accountService.CheckBalance(string(publicKey))
|
balanceRes, err := h.accountService.CheckBalance(string(publicKey))
|
||||||
|
balanceStr := balanceRes.Result.Balance
|
||||||
|
|
||||||
|
if !balanceRes.Ok {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res.Content = balanceStr
|
res.Content = balanceStr
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
|
|
||||||
// Parse the balance
|
// Parse the balance
|
||||||
balanceParts := strings.Split(balanceStr, " ")
|
balanceParts := strings.Split(balanceStr, " ")
|
||||||
@@ -882,36 +929,6 @@ func (h *Handlers) GetAmount(ctx context.Context, sym string, input []byte) (res
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuickWithBalance retrieves the balance for a given public key from the custodial balance API endpoint before
|
|
||||||
// gracefully exiting the session.
|
|
||||||
func (h *Handlers) QuitWithBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
var err error
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
|
||||||
if !ok {
|
|
||||||
return res, fmt.Errorf("missing session")
|
|
||||||
}
|
|
||||||
|
|
||||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
|
||||||
|
|
||||||
code := codeFromCtx(ctx)
|
|
||||||
l := gotext.NewLocale(translationDir, code)
|
|
||||||
l.AddDomain("default")
|
|
||||||
|
|
||||||
store := h.userdataStore
|
|
||||||
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
balance, err := h.accountService.CheckBalance(string(publicKey))
|
|
||||||
if err != nil {
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
res.Content = l.Get("Your account balance is %s", balance)
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitiateTransaction returns a confirmation and resets the transaction data
|
// InitiateTransaction returns a confirmation and resets the transaction data
|
||||||
// on the gdbm store.
|
// on the gdbm store.
|
||||||
func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
@@ -945,16 +962,23 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProfileInfo retrieves and formats the profile information of a user from a Gdbm backed storage.
|
|
||||||
func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
var defaultValue string
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
|
language, ok := ctx.Value("Language").(lang.Language)
|
||||||
// Default value when an entry is not found
|
if !ok {
|
||||||
defaultValue := "Not Provided"
|
return res, fmt.Errorf("value for 'Language' is not of type lang.Language")
|
||||||
|
}
|
||||||
|
code := language.Code
|
||||||
|
if code == "swa" {
|
||||||
|
defaultValue = "Haipo"
|
||||||
|
} else {
|
||||||
|
defaultValue = "Not Provided"
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to handle nil byte slices and convert them to string
|
// Helper function to handle nil byte slices and convert them to string
|
||||||
getEntryOrDefault := func(entry []byte, err error) string {
|
getEntryOrDefault := func(entry []byte, err error) string {
|
||||||
@@ -991,12 +1015,23 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte)
|
|||||||
return res, fmt.Errorf("invalid year of birth: %v", err)
|
return res, fmt.Errorf("invalid year of birth: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch language.Code {
|
||||||
// Format the result
|
case "eng":
|
||||||
res.Content = fmt.Sprintf(
|
res.Content = fmt.Sprintf(
|
||||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
name, gender, age, location, offerings,
|
name, gender, age, location, offerings,
|
||||||
)
|
)
|
||||||
|
case "swa":
|
||||||
|
res.Content = fmt.Sprintf(
|
||||||
|
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||||
|
name, gender, age, location, offerings,
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
res.Content = fmt.Sprintf(
|
||||||
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
|
name, gender, age, location, offerings,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,15 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
|
"git.defalsify.org/vise.git/lang"
|
||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||||
"git.grassecon.net/urdt/ussd/internal/mocks"
|
"git.grassecon.net/urdt/ussd/internal/mocks"
|
||||||
"git.grassecon.net/urdt/ussd/internal/models"
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
"git.grassecon.net/urdt/ussd/internal/utils"
|
"git.grassecon.net/urdt/ussd/internal/utils"
|
||||||
@@ -25,75 +29,125 @@ var (
|
|||||||
flagsPath = path.Join(baseDir, "services", "registration", "pp.csv")
|
flagsPath = path.Join(baseDir, "services", "registration", "pp.csv")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateAccount(t *testing.T) {
|
type Transaction struct {
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
TransferValue json.Number `json:"transferValue"`
|
||||||
|
TxHash string `json:"txHash"`
|
||||||
|
TxType string `json:"txType"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewHandlers(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
|
t.Run("Valid UserDataStore", func(t *testing.T) {
|
||||||
|
mockStore := &mocks.MockUserDataStore{}
|
||||||
|
handlers, err := NewHandlers(fm.parser, mockStore)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if handlers == nil {
|
||||||
|
t.Fatal("expected handlers to be non-nil")
|
||||||
|
}
|
||||||
|
if handlers.userdataStore == nil {
|
||||||
|
t.Fatal("expected userdataStore to be set in handlers")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test case for nil userdataStore
|
||||||
|
t.Run("Nil UserDataStore", func(t *testing.T) {
|
||||||
|
appFlags := &asm.FlagParser{}
|
||||||
|
|
||||||
|
handlers, err := NewHandlers(appFlags, nil)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, got none")
|
||||||
|
}
|
||||||
|
if handlers != nil {
|
||||||
|
t.Fatal("expected handlers to be nil")
|
||||||
|
}
|
||||||
|
if err.Error() != "cannot create handler with nil userdata store" {
|
||||||
|
t.Fatalf("expected specific error, got %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateAccount(t *testing.T) {
|
||||||
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf(err.Error())
|
||||||
|
}
|
||||||
// Create required mocks
|
// Create required mocks
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
flag_account_created, err := fm.GetFlag("flag_account_created")
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
expectedResult := resource.Result{}
|
|
||||||
accountCreatedFlag, err := fm.GetFlag("flag_account_created")
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
expectedResult.FlagSet = append(expectedResult.FlagSet, accountCreatedFlag)
|
|
||||||
|
|
||||||
// Define session ID and mock data
|
// Define session ID and mock data
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
typ := utils.DATA_ACCOUNT_CREATED
|
notFoundErr := db.ErrNotFound{}
|
||||||
fakeError := db.ErrNotFound{}
|
|
||||||
// Create context with session ID
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Define expected interactions with the mock
|
tests := []struct {
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, typ).Return([]byte("123"), fakeError)
|
name string
|
||||||
expectedAccountResp := &models.AccountResponse{
|
serverResponse *server.OKResponse
|
||||||
Ok: true,
|
expectedResult resource.Result
|
||||||
Result: struct {
|
}{
|
||||||
CustodialId json.Number `json:"custodialId"`
|
{
|
||||||
PublicKey string `json:"publicKey"`
|
name: "Test account creation success",
|
||||||
TrackingId string `json:"trackingId"`
|
serverResponse: &server.OKResponse{
|
||||||
}{
|
Ok: true,
|
||||||
CustodialId: "12",
|
Description: "Account creation successed",
|
||||||
PublicKey: "0x8E0XSCSVA",
|
Result: map[string]any{
|
||||||
TrackingId: "d95a7e83-196c-4fd0-866fSGAGA",
|
"trackingId": "1234567890",
|
||||||
|
"publicKey": "1235QERYU",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagSet: []uint32{flag_account_created},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mockCreateAccountService.On("CreateAccount").Return(expectedAccountResp, nil)
|
for _, tt := range tests {
|
||||||
data := map[utils.DataTyp]string{
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
utils.DATA_TRACKING_ID: expectedAccountResp.Result.TrackingId,
|
|
||||||
utils.DATA_PUBLIC_KEY: expectedAccountResp.Result.PublicKey,
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
utils.DATA_CUSTODIAL_ID: expectedAccountResp.Result.CustodialId.String(),
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
|
// Create a Handlers instance with the mock data store
|
||||||
|
h := &Handlers{
|
||||||
|
userdataStore: mockDataStore,
|
||||||
|
accountService: mockCreateAccountService,
|
||||||
|
flagManager: fm.parser,
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[utils.DataTyp]string{
|
||||||
|
utils.DATA_TRACKING_ID: tt.serverResponse.Result["trackingId"].(string),
|
||||||
|
utils.DATA_PUBLIC_KEY: tt.serverResponse.Result["publicKey"].(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_ACCOUNT_CREATED).Return([]byte(""), notFoundErr)
|
||||||
|
mockCreateAccountService.On("CreateAccount").Return(tt.serverResponse, nil)
|
||||||
|
|
||||||
|
for key, value := range data {
|
||||||
|
mockDataStore.On("WriteEntry", ctx, sessionId, key, []byte(value)).Return(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the method you want to test
|
||||||
|
res, err := h.CreateAccount(ctx, "create_account", []byte("some-input"))
|
||||||
|
|
||||||
|
// Assert that no errors occurred
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// Assert that the account created flag has been set to the result
|
||||||
|
assert.Equal(t, res, tt.expectedResult, "Expected result should be equal to the actual result")
|
||||||
|
|
||||||
|
// Assert that expectations were met
|
||||||
|
mockDataStore.AssertExpectations(t)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range data {
|
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, key, []byte(value)).Return(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a Handlers instance with the mock data store
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockDataStore,
|
|
||||||
accountService: mockCreateAccountService,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the method you want to test
|
|
||||||
res, err := h.CreateAccount(ctx, "create_account", []byte("some-input"))
|
|
||||||
|
|
||||||
// Assert that no errors occurred
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
//Assert that the account created flag has been set to the result
|
|
||||||
assert.Equal(t, res, expectedResult, "Expected result should be equal to the actual result")
|
|
||||||
|
|
||||||
// Assert that expectations were met
|
|
||||||
mockDataStore.AssertExpectations(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithPersister(t *testing.T) {
|
func TestWithPersister(t *testing.T) {
|
||||||
@@ -442,7 +496,10 @@ func TestMaxAmount(t *testing.T) {
|
|||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
publicKey := "0xcasgatweksalw1018221"
|
publicKey := "0xcasgatweksalw1018221"
|
||||||
expectedBalance := "0.003CELO"
|
|
||||||
|
expectedBalance := &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
mockStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
||||||
@@ -458,7 +515,7 @@ func TestMaxAmount(t *testing.T) {
|
|||||||
res, _ := h.MaxAmount(ctx, "max_amount", []byte("check_balance"))
|
res, _ := h.MaxAmount(ctx, "max_amount", []byte("check_balance"))
|
||||||
|
|
||||||
//Assert that the balance that was set as the result content is what was returned by Check Balance
|
//Assert that the balance that was set as the result content is what was returned by Check Balance
|
||||||
assert.Equal(t, expectedBalance, res.Content)
|
assert.Equal(t, expectedBalance.Result.Balance, res.Content)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,12 +594,10 @@ func TestGetRecipient(t *testing.T) {
|
|||||||
func TestGetFlag(t *testing.T) {
|
func TestGetFlag(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
expectedFlag := uint32(9)
|
expectedFlag := uint32(9)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
flag, err := fm.GetFlag("flag_account_created")
|
flag, err := fm.GetFlag("flag_account_created")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
@@ -1012,53 +1067,115 @@ func TestVerifyPin(t *testing.T) {
|
|||||||
|
|
||||||
func TestCheckAccountStatus(t *testing.T) {
|
func TestCheckAccountStatus(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
|
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
flag_account_success, _ := fm.GetFlag("flag_account_success")
|
flag_account_success, _ := fm.GetFlag("flag_account_success")
|
||||||
flag_account_pending, _ := fm.GetFlag("flag_account_pending")
|
flag_account_pending, _ := fm.GetFlag("flag_account_pending")
|
||||||
|
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockDataStore,
|
|
||||||
accountService: mockCreateAccountService,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
status string
|
serverResponse *server.OKResponse
|
||||||
|
response *models.TrackStatusResponse
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test when account status is Success",
|
name: "Test when account is on the Sarafu network",
|
||||||
input: []byte("TrackingId1234"),
|
input: []byte("TrackingId1234"),
|
||||||
status: "SUCCESS",
|
serverResponse: &server.OKResponse{
|
||||||
|
Ok: true,
|
||||||
|
Description: "Account creation successed",
|
||||||
|
Result: map[string]any{
|
||||||
|
"active": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
response: &models.TrackStatusResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Transaction struct {
|
||||||
|
CreatedAt time.Time "json:\"createdAt\""
|
||||||
|
Status string "json:\"status\""
|
||||||
|
TransferValue json.Number "json:\"transferValue\""
|
||||||
|
TxHash string "json:\"txHash\""
|
||||||
|
TxType string "json:\"txType\""
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
Transaction: Transaction{
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
Status: "SUCCESS",
|
||||||
|
TransferValue: json.Number("0.5"),
|
||||||
|
TxHash: "0x123abc456def",
|
||||||
|
TxType: "transfer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{flag_account_success},
|
FlagSet: []uint32{flag_account_success},
|
||||||
FlagReset: []uint32{flag_account_pending},
|
FlagReset: []uint32{flag_api_error, flag_account_pending},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test when the account is not yet on the sarafu network",
|
||||||
|
input: []byte("TrackingId1234"),
|
||||||
|
response: &models.TrackStatusResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Transaction struct {
|
||||||
|
CreatedAt time.Time "json:\"createdAt\""
|
||||||
|
Status string "json:\"status\""
|
||||||
|
TransferValue json.Number "json:\"transferValue\""
|
||||||
|
TxHash string "json:\"txHash\""
|
||||||
|
TxType string "json:\"txType\""
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
Transaction: Transaction{
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
Status: "SUCCESS",
|
||||||
|
TransferValue: json.Number("0.5"),
|
||||||
|
TxHash: "0x123abc456def",
|
||||||
|
TxType: "transfer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
serverResponse: &server.OKResponse{
|
||||||
|
Ok: true,
|
||||||
|
Description: "Account creation successed",
|
||||||
|
Result: map[string]any{
|
||||||
|
"active": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagSet: []uint32{flag_account_pending},
|
||||||
|
FlagReset: []uint32{flag_api_error, flag_account_success},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
typ := utils.DATA_TRACKING_ID
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
|
h := &Handlers{
|
||||||
|
userdataStore: mockDataStore,
|
||||||
|
accountService: mockCreateAccountService,
|
||||||
|
flagManager: fm.parser,
|
||||||
|
}
|
||||||
|
|
||||||
|
status := tt.response.Result.Transaction.Status
|
||||||
// Define expected interactions with the mock
|
// Define expected interactions with the mock
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, typ).Return(tt.input, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.input, nil)
|
||||||
|
|
||||||
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.status, nil)
|
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.response, nil)
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(tt.status)).Return(nil)
|
mockCreateAccountService.On("TrackAccountStatus", string(tt.input)).Return(tt.serverResponse, nil)
|
||||||
|
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(status)).Return(nil).Maybe()
|
||||||
|
|
||||||
// Call the method under test
|
// Call the method under test
|
||||||
res, _ := h.CheckAccountStatus(ctx, "check_status", tt.input)
|
res, _ := h.CheckAccountStatus(ctx, "check_account_status", tt.input)
|
||||||
|
|
||||||
// Assert that no errors occurred
|
// Assert that no errors occurred
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -1358,66 +1475,6 @@ func TestIsValidPIN(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuitWithBalance(t *testing.T) {
|
|
||||||
fm, err := NewFlagManager(flagsPath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(err.Error())
|
|
||||||
}
|
|
||||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
|
||||||
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
|
|
||||||
sessionId := "session123"
|
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
|
||||||
|
|
||||||
h := &Handlers{
|
|
||||||
userdataStore: mockDataStore,
|
|
||||||
accountService: mockCreateAccountService,
|
|
||||||
flagManager: fm.parser,
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input []byte
|
|
||||||
publicKey []byte
|
|
||||||
balance string
|
|
||||||
expectedResult resource.Result
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Test quit with balance",
|
|
||||||
balance: "0.02CELO",
|
|
||||||
publicKey: []byte("0xrqeqrequuq"),
|
|
||||||
expectedResult: resource.Result{
|
|
||||||
FlagReset: []uint32{flag_account_authorized},
|
|
||||||
Content: fmt.Sprintf("Your account balance is %s", "0.02CELO"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.publicKey, nil)
|
|
||||||
mockCreateAccountService.On("CheckBalance", string(tt.publicKey)).Return(tt.balance, nil)
|
|
||||||
|
|
||||||
// Call the method under test
|
|
||||||
res, _ := h.QuitWithBalance(ctx, "test_quit_with_balance", tt.input)
|
|
||||||
|
|
||||||
// Assert that no errors occurred
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
//Assert that the account created flag has been set to the result
|
|
||||||
assert.Equal(t, res, tt.expectedResult, "Expected result should be equal to the actual result")
|
|
||||||
|
|
||||||
// Assert that expectations were met
|
|
||||||
mockDataStore.AssertExpectations(t)
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidateAmount(t *testing.T) {
|
func TestValidateAmount(t *testing.T) {
|
||||||
fm, err := NewFlagManager(flagsPath)
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
|
||||||
@@ -1425,6 +1482,7 @@ func TestValidateAmount(t *testing.T) {
|
|||||||
t.Logf(err.Error())
|
t.Logf(err.Error())
|
||||||
}
|
}
|
||||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
||||||
|
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
@@ -1438,39 +1496,69 @@ func TestValidateAmount(t *testing.T) {
|
|||||||
flagManager: fm.parser,
|
flagManager: fm.parser,
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
publicKey []byte
|
publicKey []byte
|
||||||
balance string
|
balanceResponse *models.BalanceResponse
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test with valid amount",
|
name: "Test with valid amount",
|
||||||
input: []byte("0.001"),
|
input: []byte("0.001"),
|
||||||
balance: "0.003 CELO",
|
balanceResponse: &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
publicKey: []byte("0xrqeqrequuq"),
|
publicKey: []byte("0xrqeqrequuq"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
Content: "0.001",
|
Content: "0.001",
|
||||||
|
FlagReset: []uint32{flag_api_error},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with amount larger than balance",
|
name: "Test with amount larger than balance",
|
||||||
input: []byte("0.02"),
|
input: []byte("0.02"),
|
||||||
balance: "0.003 CELO",
|
balanceResponse: &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
publicKey: []byte("0xrqeqrequuq"),
|
publicKey: []byte("0xrqeqrequuq"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{flag_invalid_amount},
|
FlagSet: []uint32{flag_invalid_amount},
|
||||||
Content: "0.02",
|
FlagReset: []uint32{flag_api_error},
|
||||||
|
Content: "0.02",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with invalid amount",
|
name: "Test with invalid amount",
|
||||||
input: []byte("0.02ms"),
|
input: []byte("0.02ms"),
|
||||||
balance: "0.003 CELO",
|
balanceResponse: &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
publicKey: []byte("0xrqeqrequuq"),
|
publicKey: []byte("0xrqeqrequuq"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagSet: []uint32{flag_invalid_amount},
|
FlagSet: []uint32{flag_invalid_amount},
|
||||||
Content: "0.02ms",
|
FlagReset: []uint32{flag_api_error},
|
||||||
|
Content: "0.02ms",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1479,7 +1567,7 @@ func TestValidateAmount(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.publicKey, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.publicKey, nil)
|
||||||
mockCreateAccountService.On("CheckBalance", string(tt.publicKey)).Return(tt.balance, nil)
|
mockCreateAccountService.On("CheckBalance", string(tt.publicKey)).Return(tt.balanceResponse, nil)
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, tt.input).Return(nil).Maybe()
|
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, tt.input).Return(nil).Maybe()
|
||||||
|
|
||||||
// Call the method under test
|
// Call the method under test
|
||||||
@@ -1558,31 +1646,83 @@ func TestValidateRecipient(t *testing.T) {
|
|||||||
|
|
||||||
func TestCheckBalance(t *testing.T) {
|
func TestCheckBalance(t *testing.T) {
|
||||||
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
publicKey := "0X13242618721"
|
publicKey := "0X13242618721"
|
||||||
balance := "0.003 CELO"
|
fm, _ := NewFlagManager(flagsPath)
|
||||||
|
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||||
expectedResult := resource.Result{
|
|
||||||
Content: "0.003 CELO",
|
|
||||||
}
|
|
||||||
|
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
h := &Handlers{
|
tests := []struct {
|
||||||
userdataStore: mockDataStore,
|
name string
|
||||||
accountService: mockCreateAccountService,
|
balanceResonse *models.BalanceResponse
|
||||||
//flagManager: fm.parser,
|
expectedResult resource.Result
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test when checking a balance is not a success",
|
||||||
|
balanceResonse: &models.BalanceResponse{
|
||||||
|
Ok: false,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagSet: []uint32{flag_api_error},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test when checking a balance is a success",
|
||||||
|
balanceResonse: &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
Content: "0.003 CELO",
|
||||||
|
FlagReset: []uint32{flag_api_error},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
//mock call operations
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
|
||||||
mockCreateAccountService.On("CheckBalance", string(publicKey)).Return(balance, nil)
|
|
||||||
|
|
||||||
res, _ := h.CheckBalance(ctx, "check_balance", []byte("123456"))
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, res, expectedResult, "Result should contain flag(s) that have been reset")
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
|
// Create the Handlers instance with the mock store
|
||||||
|
h := &Handlers{
|
||||||
|
userdataStore: mockDataStore,
|
||||||
|
flagManager: fm.parser,
|
||||||
|
st: mockState,
|
||||||
|
accountService: mockCreateAccountService,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the expected behavior of the mock
|
||||||
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
||||||
|
mockCreateAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResonse, nil)
|
||||||
|
|
||||||
|
// Call the method
|
||||||
|
res, _ := h.CheckBalance(ctx, "check_balance", []byte(""))
|
||||||
|
|
||||||
|
// Assert that expectations were met
|
||||||
|
mockDataStore.AssertExpectations(t)
|
||||||
|
|
||||||
|
//Assert that the result set to content is what was expected
|
||||||
|
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1592,23 +1732,50 @@ func TestGetProfile(t *testing.T) {
|
|||||||
|
|
||||||
mockDataStore := new(mocks.MockUserDataStore)
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
mockCreateAccountService := new(mocks.MockAccountService)
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockDataStore,
|
userdataStore: mockDataStore,
|
||||||
accountService: mockCreateAccountService,
|
accountService: mockCreateAccountService,
|
||||||
|
st: mockState,
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
keys []utils.DataTyp
|
languageCode string
|
||||||
profileInfo []string
|
keys []utils.DataTyp
|
||||||
result resource.Result
|
profileInfo []string
|
||||||
|
result resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test with full profile information",
|
name: "Test with full profile information in eng",
|
||||||
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "eng",
|
||||||
|
result: resource.Result{
|
||||||
|
Content: fmt.Sprintf(
|
||||||
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
|
"John Doee", "Male", "48", "Kilifi", "Bananas",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test with with profile information in swa ",
|
||||||
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
|
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "swa",
|
||||||
|
result: resource.Result{
|
||||||
|
Content: fmt.Sprintf(
|
||||||
|
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||||
|
"John Doee", "Male", "48", "Kilifi", "Bananas",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test with with profile information with language that is not yet supported",
|
||||||
|
keys: []utils.DataTyp{utils.DATA_FAMILY_NAME, utils.DATA_FIRST_NAME, utils.DATA_GENDER, utils.DATA_OFFERINGS, utils.DATA_LOCATION, utils.DATA_YOB},
|
||||||
|
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||||
|
languageCode: "nor",
|
||||||
result: resource.Result{
|
result: resource.Result{
|
||||||
Content: fmt.Sprintf(
|
Content: fmt.Sprintf(
|
||||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||||
@@ -1619,9 +1786,14 @@ func TestGetProfile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
ctx = context.WithValue(ctx, "Language", lang.Language{
|
||||||
|
Code: tt.languageCode,
|
||||||
|
})
|
||||||
for index, key := range tt.keys {
|
for index, key := range tt.keys {
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, key).Return([]byte(tt.profileInfo[index]), nil).Maybe()
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte(""))
|
res, _ := h.GetProfileInfo(ctx, "get_profile_info", []byte(""))
|
||||||
|
|
||||||
// Assert that expectations were met
|
// Assert that expectations were met
|
||||||
@@ -1778,3 +1950,85 @@ func TestConfirmPin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFetchCustodialBalances(t *testing.T) {
|
||||||
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf(err.Error())
|
||||||
|
}
|
||||||
|
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
|
// Define test data
|
||||||
|
sessionId := "session123"
|
||||||
|
publicKey := "0X13242618721"
|
||||||
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
balanceResonse *models.BalanceResponse
|
||||||
|
expectedResult resource.Result
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test when fetch custodial balances is not a success",
|
||||||
|
balanceResonse: &models.BalanceResponse{
|
||||||
|
Ok: false,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagSet: []uint32{flag_api_error},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test when fetch custodial balances is a success",
|
||||||
|
balanceResonse: &models.BalanceResponse{
|
||||||
|
Ok: true,
|
||||||
|
Result: struct {
|
||||||
|
Balance string `json:"balance"`
|
||||||
|
Nonce json.Number `json:"nonce"`
|
||||||
|
}{
|
||||||
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagReset: []uint32{flag_api_error},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
mockDataStore := new(mocks.MockUserDataStore)
|
||||||
|
mockCreateAccountService := new(mocks.MockAccountService)
|
||||||
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
|
// Create the Handlers instance with the mock store
|
||||||
|
h := &Handlers{
|
||||||
|
userdataStore: mockDataStore,
|
||||||
|
flagManager: fm.parser,
|
||||||
|
st: mockState,
|
||||||
|
accountService: mockCreateAccountService,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the expected behavior of the mock
|
||||||
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
|
||||||
|
mockCreateAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResonse, nil)
|
||||||
|
|
||||||
|
// Call the method
|
||||||
|
res, _ := h.FetchCustodialBalances(ctx, "fetch_custodial_balances", []byte(""))
|
||||||
|
|
||||||
|
// Assert that expectations were met
|
||||||
|
mockDataStore.AssertExpectations(t)
|
||||||
|
|
||||||
|
//Assert that the result set to content is what was expected
|
||||||
|
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||||
"git.grassecon.net/urdt/ussd/internal/models"
|
"git.grassecon.net/urdt/ussd/internal/models"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
@@ -10,17 +11,40 @@ type MockAccountService struct {
|
|||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAccountService) CreateAccount() (*models.AccountResponse, error) {
|
func (m *MockAccountService) CreateAccount() (*server.OKResponse, *server.ErrResponse) {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
return args.Get(0).(*models.AccountResponse), args.Error(1)
|
okResponse, ok := args.Get(0).(*server.OKResponse)
|
||||||
|
errResponse, err := args.Get(1).(*server.ErrResponse)
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return okResponse, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err {
|
||||||
|
return nil, errResponse
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAccountService) CheckBalance(publicKey string) (string, error) {
|
func (m *MockAccountService) CheckBalance(publicKey string) (*models.BalanceResponse, error) {
|
||||||
args := m.Called(publicKey)
|
args := m.Called(publicKey)
|
||||||
return args.String(0), args.Error(1)
|
return args.Get(0).(*models.BalanceResponse), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAccountService) CheckAccountStatus(trackingId string) (string, error) {
|
func (m *MockAccountService) CheckAccountStatus(trackingId string) (*models.TrackStatusResponse, error) {
|
||||||
args := m.Called(trackingId)
|
args := m.Called(trackingId)
|
||||||
return args.String(0), args.Error(1)
|
return args.Get(0).(*models.TrackStatusResponse), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockAccountService) TrackAccountStatus(publicKey string) (*server.OKResponse, *server.ErrResponse) {
|
||||||
|
args := m.Called(publicKey)
|
||||||
|
okResponse, ok := args.Get(0).(*server.OKResponse)
|
||||||
|
errResponse, err := args.Get(1).(*server.ErrResponse)
|
||||||
|
if ok {
|
||||||
|
return okResponse, nil
|
||||||
|
}
|
||||||
|
if err {
|
||||||
|
return nil, errResponse
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
type AccountResponse struct {
|
type AccountResponse struct {
|
||||||
Ok bool `json:"ok"`
|
Ok bool `json:"ok"`
|
||||||
Result struct {
|
Description string `json:"description"` // Include the description field
|
||||||
CustodialId json.Number `json:"custodialId"`
|
Result struct {
|
||||||
PublicKey string `json:"publicKey"`
|
PublicKey string `json:"publicKey"`
|
||||||
TrackingId string `json:"trackingId"`
|
TrackingId string `json:"trackingId"`
|
||||||
} `json:"result"`
|
} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type TrackStatusResponse struct {
|
type TrackStatusResponse struct {
|
||||||
Ok bool `json:"ok"`
|
Ok bool `json:"ok"`
|
||||||
Result struct {
|
Result struct {
|
||||||
@@ -17,4 +16,4 @@ type TrackStatusResponse struct {
|
|||||||
TxType string `json:"txType"`
|
TxType string `json:"txType"`
|
||||||
}
|
}
|
||||||
} `json:"result"`
|
} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ MOUT back 0
|
|||||||
HALT
|
HALT
|
||||||
LOAD validate_amount 64
|
LOAD validate_amount 64
|
||||||
RELOAD validate_amount
|
RELOAD validate_amount
|
||||||
|
CATCH api_failure flag_api_call_error 1
|
||||||
CATCH invalid_amount flag_invalid_amount 1
|
CATCH invalid_amount flag_invalid_amount 1
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
LOAD get_recipient 12
|
LOAD get_recipient 12
|
||||||
|
|||||||
1
services/registration/api_failure
Normal file
1
services/registration/api_failure
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Failed to connect to the custodial service.Please try again.
|
||||||
5
services/registration/api_failure.vis
Normal file
5
services/registration/api_failure.vis
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
MOUT retry 0
|
||||||
|
MOUT quit 9
|
||||||
|
HALT
|
||||||
|
INCMP _ 0
|
||||||
|
INCMP quit 9
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
LOAD reset_account_authorized 0
|
LOAD reset_account_authorized 0
|
||||||
|
RELOAD reset_account_authorized
|
||||||
MOUT my_balance 1
|
MOUT my_balance 1
|
||||||
MOUT community_balance 2
|
MOUT community_balance 2
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Your community balance is: 0.00SRF
|
{{.fetch_custodial_balances}}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
LOAD reset_incorrect 0
|
LOAD reset_incorrect 6
|
||||||
|
LOAD fetch_custodial_balances 0
|
||||||
|
CATCH api_failure flag_api_call_error 1
|
||||||
|
MAP fetch_custodial_balances
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH pin_entry flag_account_authorized 0
|
CATCH pin_entry flag_account_authorized 0
|
||||||
LOAD quit_with_balance 0
|
MOUT back 0
|
||||||
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
|
INCMP _ 0
|
||||||
|
INCMP quit 9
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
LOAD check_balance 64
|
LOAD check_balance 64
|
||||||
RELOAD check_balance
|
RELOAD check_balance
|
||||||
|
CATCH api_failure flag_api_call_error 1
|
||||||
MAP check_balance
|
MAP check_balance
|
||||||
MOUT send 1
|
MOUT send 1
|
||||||
MOUT vouchers 2
|
MOUT vouchers 2
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Your balance is: 0.00 SRF
|
{{.fetch_custodial_balances}}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
LOAD reset_incorrect 0
|
LOAD reset_incorrect 6
|
||||||
|
LOAD fetch_custodial_balances 0
|
||||||
|
CATCH api_failure flag_api_call_error 1
|
||||||
|
MAP fetch_custodial_balances
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH pin_entry flag_account_authorized 0
|
CATCH pin_entry flag_account_authorized 0
|
||||||
LOAD quit_with_balance 0
|
MOUT back 0
|
||||||
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
|
INCMP _ 0
|
||||||
|
INCMP quit 9
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ flag,flag_valid_pin,20,this is set when the given PIN is valid
|
|||||||
flag,flag_allow_update,21,this is set to allow a user to update their profile data
|
flag,flag_allow_update,21,this is set to allow a user to update their profile data
|
||||||
flag,flag_single_edit,22,this is set to allow a user to edit a single profile item such as year of birth
|
flag,flag_single_edit,22,this is set to allow a user to edit a single profile item such as year of birth
|
||||||
flag,flag_incorrect_date_format,23,this is set when the given year of birth is invalid
|
flag,flag_incorrect_date_format,23,this is set when the given year of birth is invalid
|
||||||
|
flag,flag_api_call_error,25,this is set when communication to an external service fails
|
||||||
|
|||||||
|
@@ -1,6 +1,8 @@
|
|||||||
CATCH select_language flag_language_set 0
|
CATCH select_language flag_language_set 0
|
||||||
CATCH terms flag_account_created 0
|
CATCH terms flag_account_created 0
|
||||||
LOAD check_account_status 0
|
LOAD check_account_status 0
|
||||||
|
RELOAD check_account_status
|
||||||
|
CATCH api_failure flag_api_call_error 1
|
||||||
CATCH account_pending flag_account_pending 1
|
CATCH account_pending flag_account_pending 1
|
||||||
CATCH create_pin flag_pin_set 0
|
CATCH create_pin flag_pin_set 0
|
||||||
CATCH main flag_account_success 1
|
CATCH main flag_account_success 1
|
||||||
|
|||||||
1
services/registration/view_menu_swa
Normal file
1
services/registration/view_menu_swa
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Angalia Wasifu
|
||||||
Reference in New Issue
Block a user