Merge branch 'master' into lash/store-dumper
This commit is contained in:
@@ -80,6 +80,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
|
||||
ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
||||
ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
||||
ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
||||
ls.DbRs.AddLocalFunc("invite_valid_recipient", ussdHandlers.InviteValidRecipient)
|
||||
ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
||||
ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
||||
@@ -102,12 +103,13 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
|
||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
||||
ls.DbRs.AddLocalFunc("fetch_custodial_balances", ussdHandlers.FetchCustodialBalances)
|
||||
ls.DbRs.AddLocalFunc("fetch_community_balance", ussdHandlers.FetchCommunityBalance)
|
||||
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
||||
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
||||
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
||||
ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher)
|
||||
ls.DbRs.AddLocalFunc("set_voucher", ussdHandlers.SetVoucher)
|
||||
ls.DbRs.AddLocalFunc("get_voucher_details", ussdHandlers.GetVoucherDetails)
|
||||
ls.DbRs.AddLocalFunc("reset_valid_pin", ussdHandlers.ResetValidPin)
|
||||
ls.DbRs.AddLocalFunc("check_pin_mismatch", ussdHandlers.CheckPinMisMatch)
|
||||
ls.DbRs.AddLocalFunc("validate_blocked_number", ussdHandlers.ValidateBlockedNumber)
|
||||
@@ -115,6 +117,10 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
|
||||
ls.DbRs.AddLocalFunc("reset_unregistered_number", ussdHandlers.ResetUnregisteredNumber)
|
||||
ls.DbRs.AddLocalFunc("reset_others_pin", ussdHandlers.ResetOthersPin)
|
||||
ls.DbRs.AddLocalFunc("save_others_temporary_pin", ussdHandlers.SaveOthersTemporaryPin)
|
||||
ls.DbRs.AddLocalFunc("get_current_profile_info", ussdHandlers.GetCurrentProfileInfo)
|
||||
ls.DbRs.AddLocalFunc("check_transactions", ussdHandlers.CheckTransactions)
|
||||
ls.DbRs.AddLocalFunc("get_transactions", ussdHandlers.GetTransactionsList)
|
||||
ls.DbRs.AddLocalFunc("view_statement", ussdHandlers.ViewTransactionStatement)
|
||||
|
||||
return ussdHandlers, nil
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package ussd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
@@ -586,9 +585,9 @@ func TestGetRecipient(t *testing.T) {
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
recepient := "0xcasgatweksalw1018221"
|
||||
recepient := "0712345678"
|
||||
|
||||
err := store.WriteEntry(ctx, sessionId, common.DATA_RECIPIENT, []byte(recepient))
|
||||
err := store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(recepient))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1226,32 +1225,41 @@ func TestInitiateTransaction(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
Recipient []byte
|
||||
Amount []byte
|
||||
ActiveSym []byte
|
||||
status string
|
||||
expectedResult resource.Result
|
||||
name string
|
||||
TemporaryValue []byte
|
||||
ActiveSym []byte
|
||||
StoredAmount []byte
|
||||
TransferAmount string
|
||||
PublicKey []byte
|
||||
Recipient []byte
|
||||
ActiveDecimal []byte
|
||||
ActiveAddress []byte
|
||||
TransferResponse *models.TokenTransferResponse
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test initiate transaction",
|
||||
Amount: []byte("0.002"),
|
||||
ActiveSym: []byte("SRF"),
|
||||
Recipient: []byte("0x12415ass27192"),
|
||||
name: "Test initiate transaction",
|
||||
TemporaryValue: []byte("0711223344"),
|
||||
ActiveSym: []byte("SRF"),
|
||||
StoredAmount: []byte("1.00"),
|
||||
TransferAmount: "1000000",
|
||||
PublicKey: []byte("0X13242618721"),
|
||||
Recipient: []byte("0x12415ass27192"),
|
||||
ActiveDecimal: []byte("6"),
|
||||
ActiveAddress: []byte("0xd4c288865Ce"),
|
||||
TransferResponse: &models.TokenTransferResponse{
|
||||
TrackingId: "1234567890",
|
||||
},
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{account_authorized_flag},
|
||||
Content: "Your request has been sent. 0x12415ass27192 will receive 0.002 SRF from 254712345678.",
|
||||
Content: "Your request has been sent. 0711223344 will receive 1.00 SRF from 254712345678.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := store.WriteEntry(ctx, sessionId, common.DATA_AMOUNT, []byte(tt.Amount))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_RECIPIENT, []byte(tt.Recipient))
|
||||
err := store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(tt.TemporaryValue))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1259,9 +1267,31 @@ func TestInitiateTransaction(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_AMOUNT, []byte(tt.StoredAmount))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_PUBLIC_KEY, []byte(tt.PublicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_RECIPIENT, []byte(tt.Recipient))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_DECIMAL, []byte(tt.ActiveDecimal))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_ADDRESS, []byte(tt.ActiveAddress))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mockAccountService.On("TokenTransfer").Return(tt.TransferResponse, nil)
|
||||
|
||||
// Call the method under test
|
||||
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", tt.input)
|
||||
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", []byte(""))
|
||||
|
||||
// Assert that no errors occurred
|
||||
assert.NoError(t, err)
|
||||
@@ -1453,10 +1483,12 @@ func TestValidateRecipient(t *testing.T) {
|
||||
}
|
||||
|
||||
sessionId := "session123"
|
||||
publicKey := "0X13242618721"
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
flag_invalid_recipient, _ := fm.parser.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := fm.parser.GetFlag("flag_invalid_recipient_with_invite")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@@ -1466,19 +1498,33 @@ func TestValidateRecipient(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Test with invalid recepient",
|
||||
input: []byte("000"),
|
||||
input: []byte("9234adf5"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_invalid_recipient},
|
||||
Content: "000",
|
||||
Content: "9234adf5",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with valid recepient",
|
||||
input: []byte("0705X2"),
|
||||
name: "Test with valid unregistered recepient",
|
||||
input: []byte("0712345678"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_invalid_recipient_with_invite},
|
||||
Content: "0712345678",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with valid registered recepient",
|
||||
input: []byte("0711223344"),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
}
|
||||
|
||||
// store a public key for the valid recipient
|
||||
err = store.WriteEntry(ctx, "0711223344", common.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create the Handlers instance
|
||||
@@ -1726,58 +1772,43 @@ 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")
|
||||
func TestFetchCommunityBalance(t *testing.T) {
|
||||
|
||||
// Define test data
|
||||
sessionId := "session123"
|
||||
publicKey := "0X13242618721"
|
||||
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
balanceResponse *models.BalanceResult
|
||||
expectedResult resource.Result
|
||||
name string
|
||||
languageCode string
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test when fetch custodial balances is not a success",
|
||||
balanceResponse: &models.BalanceResult{
|
||||
Balance: "0.003 CELO",
|
||||
Nonce: json.Number("0"),
|
||||
},
|
||||
name: "Test community balance content when language is english",
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_api_error},
|
||||
Content: "Community Balance: 0.00",
|
||||
},
|
||||
languageCode: "eng",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
mockState := state.NewState(16)
|
||||
|
||||
h := &Handlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
|
||||
// Set up the expected behavior of the mock
|
||||
mockAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResponse, nil)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Language", lang.Language{
|
||||
Code: tt.languageCode,
|
||||
})
|
||||
|
||||
// Call the method
|
||||
res, _ := h.FetchCustodialBalances(ctx, "fetch_custodial_balances", []byte(""))
|
||||
res, _ := h.FetchCommunityBalance(ctx, "fetch_community_balance", []byte(""))
|
||||
|
||||
//Assert that the result set to content is what was expected
|
||||
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
|
||||
@@ -1987,7 +2018,7 @@ func TestSetVoucher(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := h.SetVoucher(ctx, "set_voucher", []byte{})
|
||||
res, err := h.SetVoucher(ctx, "set_voucher", []byte(""))
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
gdbmdb "git.defalsify.org/vise.git/db/gdbm"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -41,10 +41,13 @@ func buildConnStr() string {
|
||||
dbName := initializers.GetEnv("DB_NAME", "")
|
||||
port := initializers.GetEnv("DB_PORT", "5432")
|
||||
|
||||
return fmt.Sprintf(
|
||||
connString := fmt.Sprintf(
|
||||
"postgres://%s:%s@%s:%s/%s",
|
||||
user, password, host, port, dbName,
|
||||
)
|
||||
logg.Debugf("pg conn string", "conn", connString)
|
||||
|
||||
return connString
|
||||
}
|
||||
|
||||
func NewMenuStorageService(dbDir string, resourceDir string) *MenuStorageService {
|
||||
|
||||
@@ -28,7 +28,6 @@ func (m *MockAccountService) TrackAccountStatus(ctx context.Context, trackingId
|
||||
return args.Get(0).(*models.TrackStatusResult), args.Error(1)
|
||||
}
|
||||
|
||||
|
||||
func (m *MockAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
||||
args := m.Called(publicKey)
|
||||
return args.Get(0).([]dataserviceapi.TokenHoldings), args.Error(1)
|
||||
@@ -39,7 +38,17 @@ func (m *MockAccountService) FetchTransactions(ctx context.Context, publicKey st
|
||||
return args.Get(0).([]dataserviceapi.Last10TxResponse), args.Error(1)
|
||||
}
|
||||
|
||||
func(m MockAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||
func (m *MockAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||
args := m.Called(address)
|
||||
return args.Get(0).(*models.VoucherDataResult), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockAccountService) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||
args := m.Called()
|
||||
return args.Get(0).(*models.TokenTransferResponse), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
||||
args := m.Called()
|
||||
return args.Get(0).(*dataserviceapi.AliasAddress), args.Error(1)
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ type TestAccountService struct {
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) CreateAccount(ctx context.Context) (*models.AccountResult, error) {
|
||||
return &models.AccountResult {
|
||||
return &models.AccountResult{
|
||||
TrackingId: "075ccc86-f6ef-4d33-97d5-e91cfb37aa0d",
|
||||
PublicKey: "0x623EFAFa8868df4B934dd12a8B26CB3Dd75A7AdD",
|
||||
PublicKey: "0x623EFAFa8868df4B934dd12a8B26CB3Dd75A7AdD",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) CheckBalance(ctx context.Context, publicKey string) (*models.BalanceResult, error) {
|
||||
balanceResponse := &models.BalanceResult {
|
||||
balanceResponse := &models.BalanceResult{
|
||||
Balance: "0.003 CELO",
|
||||
Nonce: json.Number("0"),
|
||||
}
|
||||
@@ -27,26 +27,36 @@ func (tas *TestAccountService) CheckBalance(ctx context.Context, publicKey strin
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error) {
|
||||
return &models.TrackStatusResult {
|
||||
return &models.TrackStatusResult{
|
||||
Active: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
||||
return []dataserviceapi.TokenHoldings {
|
||||
dataserviceapi.TokenHoldings {
|
||||
return []dataserviceapi.TokenHoldings{
|
||||
dataserviceapi.TokenHoldings{
|
||||
ContractAddress: "0x6CC75A06ac72eB4Db2eE22F781F5D100d8ec03ee",
|
||||
TokenSymbol: "SRF",
|
||||
TokenDecimals: "6",
|
||||
Balance: "2745987",
|
||||
},
|
||||
}, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) {
|
||||
return []dataserviceapi.Last10TxResponse{}, nil
|
||||
}
|
||||
|
||||
func(m TestAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||
func (m TestAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||
return &models.VoucherDataResult{}, nil
|
||||
}
|
||||
|
||||
func (tas *TestAccountService) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||
return &models.TokenTransferResponse{
|
||||
TrackingId: "e034d147-747d-42ea-928d-b5a7cb3426af",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*dataserviceapi.AliasAddress, error) {
|
||||
return &dataserviceapi.AliasAddress{}, nil
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
package testtag
|
||||
|
||||
import "git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||
import "git.grassecon.net/urdt/ussd/remote"
|
||||
|
||||
var (
|
||||
AccountService server.AccountServiceInterface
|
||||
AccountService remote.AccountServiceInterface
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user