Compare commits
3 Commits
route-api-
...
lash/reset
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8cbccb113
|
||
|
|
e064ec40de
|
||
|
|
02bebe605a
|
@@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
|
||||
WORKDIR /build/sarafu-vise
|
||||
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
||||
RUN go mod download
|
||||
RUN go build -tags logdebug,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||
RUN go build -tags logwarn,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ func main() {
|
||||
var err error
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
var logDbConnStr string
|
||||
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
@@ -56,7 +55,6 @@ func main() {
|
||||
flag.UintVar(&port, "p", config.Port(), "http port")
|
||||
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.StringVar(&logDbConnStr, "log-c", "db-logs", "log db connection string")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
@@ -102,11 +100,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "userdatadb: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logdb, err := menuStorageService.GetLogDb(ctx, userdataStore, logDbConnStr, "user-data")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get log db error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@@ -120,7 +113,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
lhs.SetDataStore(&userdataStore)
|
||||
lhs.SetLogDb(&logdb)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "setdatastore: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -56,7 +56,6 @@ func main() {
|
||||
var err error
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
var logDbConnStr string
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
@@ -70,7 +69,6 @@ func main() {
|
||||
flag.UintVar(&port, "p", config.Port(), "http port")
|
||||
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.StringVar(&logDbConnStr, "log-c", "db-logs", "log db connection string")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
@@ -122,12 +120,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logdb, err := menuStorageService.GetLogDb(ctx, userdataStore, logDbConnStr, "user-data")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get log db error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
//defer userdataStore.Close(ctx)
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
@@ -137,7 +129,6 @@ func main() {
|
||||
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userdataStore)
|
||||
lhs.SetLogDb(&logdb)
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
|
||||
@@ -43,7 +43,6 @@ func main() {
|
||||
var err error
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
var logDbConnStr string
|
||||
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
@@ -56,7 +55,6 @@ func main() {
|
||||
flag.UintVar(&port, "p", config.Port(), "http port")
|
||||
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.StringVar(&logDbConnStr, "log-c", "db-logs", "log db connection string")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
@@ -105,12 +103,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logdb, err := menuStorageService.GetLogDb(ctx, userdataStore, logDbConnStr, "user-data")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get log db error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
os.Exit(1)
|
||||
@@ -118,7 +110,6 @@ func main() {
|
||||
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userdataStore)
|
||||
lhs.SetLogDb(&logdb)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
|
||||
@@ -36,7 +36,6 @@ func main() {
|
||||
var err error
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
var logDbConnStr string
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
@@ -47,7 +46,6 @@ func main() {
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.StringVar(&logDbConnStr, "log-c", "db-logs", "log db connection string")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
@@ -112,12 +110,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logdb, err := menuStorageService.GetLogDb(ctx, userdatastore, logDbConnStr, "user-data")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get log db error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "get dbresource error: %v\n", err)
|
||||
@@ -126,7 +118,6 @@ func main() {
|
||||
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userdatastore)
|
||||
lhs.SetLogDb(&logdb)
|
||||
lhs.SetPersister(pe)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "localhandler service error: %v\n", err)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
var (
|
||||
logg = logging.NewVanilla().WithContextKey("SessionId")
|
||||
scriptDir = path.Join("services", "registration")
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -25,6 +27,8 @@ func main() {
|
||||
|
||||
override := config.NewOverride()
|
||||
var sessionId string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
@@ -32,6 +36,8 @@ func main() {
|
||||
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
@@ -50,7 +56,18 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
SessionId: sessionId,
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
MenuSeparator: menuSeparator,
|
||||
EngineDebug: engineDebug,
|
||||
ResetOnEmptyInput: true,
|
||||
}
|
||||
|
||||
x := cmd.NewCmd(sessionId, flagParser)
|
||||
x = x.WithEngine(cfg)
|
||||
err = x.Parse(flag.Args())
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cmd parse fail: %v\n", err)
|
||||
|
||||
8
go.mod
8
go.mod
@@ -3,10 +3,10 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250425131748-8b84f59792ce
|
||||
git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250428082711-5d221b8d565f
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250326034808-b9c2294cbf1a
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694
|
||||
github.com/alecthomas/assert/v2 v2.2.2
|
||||
github.com/gofrs/uuid v4.4.0+incompatible
|
||||
|
||||
16
go.sum
16
go.sum
@@ -1,11 +1,11 @@
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250425131748-8b84f59792ce h1:Uke2jQ4wG97gQKnTzxPyBGyhosrU1IWnRNFHtKVrmrk=
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250425131748-8b84f59792ce/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e h1:DcC9qkNl9ny3hxQmsMK6W81+5R/j4ZwYUbvewMI/rlc=
|
||||
git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250428082711-5d221b8d565f h1:OAHCP3YR1C5h1WFnnEnLs5kn6jTxQHQYWYtQaMZJIMY=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250428082711-5d221b8d565f/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306 h1:Jo+yWysWw/N5BJQtAyEMN8ePVvAyPHv+JG4lQti+1N4=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306/go.mod h1:FdLwYtzsjOIcDiW4uDgDYnB4Wdzq12uJUe0QHSSPbSo=
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250326034808-b9c2294cbf1a h1:5uLBUZC6armYgBPkuNEsQPtqT3qZxRfNP4HUdkhjm4I=
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250326034808-b9c2294cbf1a/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b h1:xiTpaqWWoF5qcnarY/9ZkT6aVdnKwqztb2gzIahJn4w=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2 h1:YFztSsexCUgFo6M0tbngRwYdgJd3LQV3RO/Jw09u3+k=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694/go.mod h1:DpibtYpnT3nG4Kn556hRAkdu4+CtiI/6MbnQHal51mQ=
|
||||
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -62,25 +62,6 @@ func InitializeTestStore(t *testing.T) (context.Context, *store.UserDataStore) {
|
||||
return ctx, store
|
||||
}
|
||||
|
||||
// InitializeTestLogdbStore sets up and returns an in-memory database and logdb store.
|
||||
func InitializeTestLogdbStore(t *testing.T) (context.Context, *store.UserDataStore) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize memDb
|
||||
db := memdb.NewMemDb()
|
||||
err := db.Connect(ctx, "")
|
||||
require.NoError(t, err, "Failed to connect to memDb")
|
||||
|
||||
// Create UserDataStore with memDb
|
||||
logdb := &store.UserDataStore{Db: db}
|
||||
|
||||
t.Cleanup(func() {
|
||||
db.Close(ctx) // Ensure the DB is closed after each test
|
||||
})
|
||||
|
||||
return ctx, logdb
|
||||
}
|
||||
|
||||
func InitializeTestSubPrefixDb(t *testing.T, ctx context.Context) *storedb.SubPrefixDb {
|
||||
db := memdb.NewMemDb()
|
||||
err := db.Connect(ctx, "")
|
||||
@@ -95,7 +76,6 @@ func InitializeTestSubPrefixDb(t *testing.T, ctx context.Context) *storedb.SubPr
|
||||
|
||||
func TestNewMenuHandlers(t *testing.T) {
|
||||
_, store := InitializeTestStore(t)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
@@ -106,7 +86,7 @@ func TestNewMenuHandlers(t *testing.T) {
|
||||
|
||||
// Test case for valid UserDataStore
|
||||
t.Run("Valid UserDataStore", func(t *testing.T) {
|
||||
handlers, err := NewMenuHandlers(fm, store, logdb, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm, store, &accountService, mockReplaceSeparator)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -130,7 +110,7 @@ func TestNewMenuHandlers(t *testing.T) {
|
||||
|
||||
// Test case for nil UserDataStore
|
||||
t.Run("Nil UserDataStore", func(t *testing.T) {
|
||||
handlers, err := NewMenuHandlers(fm, nil, logdb, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm, nil, &accountService, mockReplaceSeparator)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error, got none")
|
||||
}
|
||||
@@ -212,13 +192,8 @@ func TestInit(t *testing.T) {
|
||||
|
||||
func TestCreateAccount(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
@@ -226,8 +201,6 @@ func TestCreateAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
flag_account_created, err := fm.GetFlag("flag_account_created")
|
||||
flag_account_creation_failed, _ := fm.GetFlag("flag_account_creation_failed")
|
||||
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
@@ -244,8 +217,7 @@ func TestCreateAccount(t *testing.T) {
|
||||
PublicKey: "0xD3adB33f",
|
||||
},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_account_created},
|
||||
FlagReset: []uint32{flag_account_creation_failed},
|
||||
FlagSet: []uint32{flag_account_created},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -254,9 +226,8 @@ func TestCreateAccount(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
logDb: logDb,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
@@ -294,13 +265,8 @@ func TestWithPersister_PanicWhenAlreadySet(t *testing.T) {
|
||||
|
||||
func TestSaveFirstname(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -316,7 +282,7 @@ func TestSaveFirstname(t *testing.T) {
|
||||
// Define test data
|
||||
firstName := "John"
|
||||
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(firstName)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(firstName)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -324,10 +290,9 @@ func TestSaveFirstname(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -338,19 +303,14 @@ func TestSaveFirstname(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_FIRST_NAME entry has been updated with the temporary value
|
||||
storedFirstName, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
|
||||
storedFirstName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FIRST_NAME)
|
||||
assert.Equal(t, firstName, string(storedFirstName))
|
||||
}
|
||||
|
||||
func TestSaveFamilyname(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -368,16 +328,15 @@ func TestSaveFamilyname(t *testing.T) {
|
||||
// Define test data
|
||||
familyName := "Doeee"
|
||||
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(familyName)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(familyName)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -388,19 +347,14 @@ func TestSaveFamilyname(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_FAMILY_NAME entry has been updated with the temporary value
|
||||
storedFamilyName, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
|
||||
storedFamilyName, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME)
|
||||
assert.Equal(t, familyName, string(storedFamilyName))
|
||||
}
|
||||
|
||||
func TestSaveYoB(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -416,7 +370,7 @@ func TestSaveYoB(t *testing.T) {
|
||||
// Define test data
|
||||
yob := "1980"
|
||||
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(yob)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(yob)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -424,10 +378,9 @@ func TestSaveYoB(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -438,19 +391,14 @@ func TestSaveYoB(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_YOB entry has been updated with the temporary value
|
||||
storedYob, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
|
||||
storedYob, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_YOB)
|
||||
assert.Equal(t, yob, string(storedYob))
|
||||
}
|
||||
|
||||
func TestSaveLocation(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -466,7 +414,7 @@ func TestSaveLocation(t *testing.T) {
|
||||
// Define test data
|
||||
location := "Kilifi"
|
||||
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(location)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(location)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -474,10 +422,9 @@ func TestSaveLocation(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -488,19 +435,14 @@ func TestSaveLocation(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_LOCATION entry has been updated with the temporary value
|
||||
storedLocation, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
|
||||
storedLocation, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_LOCATION)
|
||||
assert.Equal(t, location, string(storedLocation))
|
||||
}
|
||||
|
||||
func TestSaveOfferings(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -516,7 +458,7 @@ func TestSaveOfferings(t *testing.T) {
|
||||
// Define test data
|
||||
offerings := "Bananas"
|
||||
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(offerings)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(offerings)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -524,10 +466,9 @@ func TestSaveOfferings(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -538,19 +479,14 @@ func TestSaveOfferings(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_OFFERINGS entry has been updated with the temporary value
|
||||
storedOfferings, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
|
||||
storedOfferings, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)
|
||||
assert.Equal(t, offerings, string(storedOfferings))
|
||||
}
|
||||
|
||||
func TestSaveGender(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
@@ -590,17 +526,16 @@ func TestSaveGender(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
expectedResult := resource.Result{}
|
||||
@@ -615,7 +550,7 @@ func TestSaveGender(t *testing.T) {
|
||||
assert.Equal(t, expectedResult, res)
|
||||
|
||||
// Verify that the DATA_GENDER entry has been updated with the temporary value
|
||||
storedGender, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
|
||||
storedGender, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_GENDER)
|
||||
assert.Equal(t, tt.expectedGender, string(storedGender))
|
||||
})
|
||||
}
|
||||
@@ -623,27 +558,20 @@ func TestSaveGender(t *testing.T) {
|
||||
|
||||
func TestSaveTemporaryPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
ctx, userdatastore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_invalid_pin, _ := fm.GetFlag("flag_invalid_pin")
|
||||
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
userdataStore: userdatastore,
|
||||
logDb: logDb,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
// Define test cases
|
||||
@@ -656,14 +584,14 @@ func TestSaveTemporaryPin(t *testing.T) {
|
||||
name: "Valid Pin entry",
|
||||
input: []byte("1234"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_invalid_pin},
|
||||
FlagReset: []uint32{flag_incorrect_pin},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid Pin entry",
|
||||
input: []byte("12343"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_invalid_pin},
|
||||
FlagSet: []uint32{flag_incorrect_pin},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -684,15 +612,9 @@ func TestSaveTemporaryPin(t *testing.T) {
|
||||
|
||||
func TestCheckIdentifier(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, userdatastore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -712,15 +634,14 @@ func TestCheckIdentifier(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := userdatastore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userdatastore,
|
||||
logDb: logDb,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@@ -1922,7 +1843,53 @@ func TestGetProfile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmPinChange(t *testing.T) {
|
||||
func TestVerifyNewPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
mockState := state.NewState(16)
|
||||
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
accountService: mockAccountService,
|
||||
st: mockState,
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test with valid pin",
|
||||
input: []byte("1234"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_valid_pin},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with invalid pin",
|
||||
input: []byte("123"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_valid_pin},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
//Call the function under test
|
||||
res, _ := h.VerifyNewPin(ctx, "verify_new_pin", tt.input)
|
||||
|
||||
//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")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
mockState := state.NewState(16)
|
||||
@@ -1931,8 +1898,6 @@ func TestConfirmPinChange(t *testing.T) {
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
flag_account_pin_reset, _ := fm.GetFlag("flag_account_pin_reset")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
@@ -1952,7 +1917,7 @@ func TestConfirmPinChange(t *testing.T) {
|
||||
input: []byte("1234"),
|
||||
temporarypin: "1234",
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_pin_mismatch, flag_account_pin_reset},
|
||||
FlagReset: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -2025,57 +1990,36 @@ func TestFetchCommunityBalance(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestManageVouchers(t *testing.T) {
|
||||
func TestSetDefaultVoucher(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
publicKey := "0X13242618721"
|
||||
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flag_api_error, err := fm.GetFlag("flag_api_call_error")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
publicKey := "0X13242618721"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
vouchersResp []dataserviceapi.TokenHoldings
|
||||
storedActiveVoucher string
|
||||
expectedVoucherSymbols []byte
|
||||
expectedUpdatedAddress []byte
|
||||
expectedResult resource.Result
|
||||
name string
|
||||
vouchersResp []dataserviceapi.TokenHoldings
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "No vouchers available",
|
||||
vouchersResp: []dataserviceapi.TokenHoldings{},
|
||||
expectedVoucherSymbols: []byte(""),
|
||||
expectedUpdatedAddress: []byte(""),
|
||||
name: "Test no vouchers available",
|
||||
vouchersResp: []dataserviceapi.TokenHoldings{},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_no_active_voucher},
|
||||
FlagReset: []uint32{flag_api_error},
|
||||
FlagSet: []uint32{flag_no_active_voucher},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Set default voucher when no active voucher is set",
|
||||
name: "Test set default voucher when no active voucher is set",
|
||||
vouchersResp: []dataserviceapi.TokenHoldings{
|
||||
{
|
||||
ContractAddress: "0x123",
|
||||
@@ -2084,24 +2028,7 @@ func TestManageVouchers(t *testing.T) {
|
||||
Balance: "100",
|
||||
},
|
||||
},
|
||||
expectedVoucherSymbols: []byte("1:TOKEN1"),
|
||||
expectedUpdatedAddress: []byte("0x123"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Check and update active voucher balance",
|
||||
vouchersResp: []dataserviceapi.TokenHoldings{
|
||||
{ContractAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100"},
|
||||
{ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"},
|
||||
},
|
||||
storedActiveVoucher: "SRF",
|
||||
expectedVoucherSymbols: []byte("1:SRF\n2:MILO"),
|
||||
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
},
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2110,47 +2037,90 @@ func TestManageVouchers(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
logDb: logDb,
|
||||
}
|
||||
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mockAccountService.On("FetchVouchers", string(publicKey)).Return(tt.vouchersResp, nil)
|
||||
|
||||
// Store active voucher if needed
|
||||
if tt.storedActiveVoucher != "" {
|
||||
err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte(tt.storedActiveVoucher))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte("0x41c188D45rfg6ds"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
res, err := h.SetDefaultVoucher(ctx, "set_default_voucher", []byte("some-input"))
|
||||
|
||||
res, err := h.ManageVouchers(ctx, "manage_vouchers", []byte(""))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedResult, res)
|
||||
|
||||
if tt.storedActiveVoucher != "" {
|
||||
// Validate stored voucher symbols
|
||||
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedVoucherSymbols, voucherData)
|
||||
assert.Equal(t, res, tt.expectedResult, "Expected result should be equal to the actual result")
|
||||
|
||||
// Validate stored active contract address
|
||||
updatedAddress, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedUpdatedAddress, updatedAddress)
|
||||
|
||||
mockAccountService.AssertExpectations(t)
|
||||
}
|
||||
mockAccountService.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckVouchers(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
sessionId := "session123"
|
||||
publicKey := "0X13242618721"
|
||||
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mockVouchersResponse := []dataserviceapi.TokenHoldings{
|
||||
{ContractAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100"},
|
||||
{ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"},
|
||||
}
|
||||
|
||||
// store the default voucher data
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte("SRF"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte("0x41c188D45rfg6ds"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedSym := []byte("1:SRF\n2:MILO")
|
||||
expectedUpdatedAddress := []byte("0xd4c288865Ce")
|
||||
|
||||
mockAccountService.On("FetchVouchers", string(publicKey)).Return(mockVouchersResponse, nil)
|
||||
|
||||
_, err = h.CheckVouchers(ctx, "check_vouchers", []byte(""))
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Read voucher sym data from the store
|
||||
voucherData, err := store.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Read active contract address from the store
|
||||
updatedAddress, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// assert that the data is stored correctly
|
||||
assert.Equal(t, expectedSym, voucherData)
|
||||
// assert that the address is updated
|
||||
assert.Equal(t, expectedUpdatedAddress, updatedAddress)
|
||||
|
||||
mockAccountService.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestGetVoucherList(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
@@ -2252,8 +2222,6 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
sessionId := "session123"
|
||||
@@ -2281,8 +2249,8 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
|
||||
)
|
||||
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
|
||||
|
||||
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))
|
||||
expectedResult.FlagReset = append(expectedResult.FlagReset, flag_api_error)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedResult, res)
|
||||
}
|
||||
@@ -2385,8 +2353,10 @@ func TestCheckBlockedStatus(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
||||
flag_account_pin_reset, _ := fm.GetFlag("flag_account_pin_reset")
|
||||
flag_account_blocked, err := fm.GetFlag("flag_account_blocked")
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
@@ -2401,15 +2371,13 @@ func TestCheckBlockedStatus(t *testing.T) {
|
||||
{
|
||||
name: "Currently blocked account",
|
||||
currentWrongPinAttempts: "4",
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_account_pin_reset},
|
||||
},
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
{
|
||||
name: "Account with 0 wrong PIN attempts",
|
||||
currentWrongPinAttempts: "0",
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_account_pin_reset, flag_account_blocked},
|
||||
FlagReset: []uint32{flag_account_blocked},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -2470,14 +2438,8 @@ func TestCheckTransactions(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
publicKey := "0X13242618721"
|
||||
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
_, logdb := InitializeTestLogdbStore(t)
|
||||
|
||||
logDb := store.LogDb{
|
||||
Db: logdb,
|
||||
}
|
||||
|
||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
@@ -2486,14 +2448,13 @@ func TestCheckTransactions(t *testing.T) {
|
||||
}
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
prefixDb: spdb,
|
||||
logDb: logDb,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -2945,6 +2906,173 @@ func TestValidateBlockedNumber(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveOthersTemporaryPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
blockedNumber := "+254712345678"
|
||||
testPin := "1234"
|
||||
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
sessionId string
|
||||
blockedNumber string
|
||||
testPin string
|
||||
setup func() error // Setup function for each test case
|
||||
expectedError bool
|
||||
verifyResult func(t *testing.T) // Function to verify the result
|
||||
}{
|
||||
{
|
||||
name: "Missing Session ID",
|
||||
sessionId: "", // Empty session ID
|
||||
blockedNumber: blockedNumber,
|
||||
testPin: testPin,
|
||||
setup: nil,
|
||||
expectedError: true,
|
||||
verifyResult: nil,
|
||||
},
|
||||
{
|
||||
name: "Failed to Read Blocked Number",
|
||||
sessionId: sessionId,
|
||||
blockedNumber: blockedNumber,
|
||||
testPin: testPin,
|
||||
setup: func() error {
|
||||
// Do not write the blocked number to simulate a read failure
|
||||
return nil
|
||||
},
|
||||
expectedError: true,
|
||||
verifyResult: nil,
|
||||
},
|
||||
|
||||
{
|
||||
name: "Successfully save hashed PIN",
|
||||
sessionId: sessionId,
|
||||
blockedNumber: blockedNumber,
|
||||
testPin: testPin,
|
||||
setup: func() error {
|
||||
// Write the blocked number to the store
|
||||
return userStore.WriteEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER, []byte(blockedNumber))
|
||||
},
|
||||
expectedError: false,
|
||||
verifyResult: func(t *testing.T) {
|
||||
// Read the stored hashed PIN
|
||||
othersHashedPin, err := userStore.ReadEntry(ctx, blockedNumber, storedb.DATA_TEMPORARY_VALUE)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Verify that the stored hashed PIN matches the original PIN
|
||||
if !pin.VerifyPIN(string(othersHashedPin), testPin) {
|
||||
t.Fatal("stored hashed PIN does not match the original PIN")
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Set up the context with the session ID
|
||||
ctx := context.WithValue(context.Background(), "SessionId", tt.sessionId)
|
||||
|
||||
// Run the setup function if provided
|
||||
if tt.setup != nil {
|
||||
err := tt.setup()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Call the function under test
|
||||
_, err := h.SaveOthersTemporaryPin(ctx, "save_others_temporary_pin", []byte(tt.testPin))
|
||||
|
||||
// Assert the error
|
||||
if tt.expectedError {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// Verify the result if a verification function is provided
|
||||
if tt.verifyResult != nil {
|
||||
tt.verifyResult(t)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckBlockedNumPinMisMatch(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
blockedNumber := "+254712345678"
|
||||
testPin := "1234"
|
||||
mockState := state.NewState(128)
|
||||
|
||||
ctx, userStore := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
hashedPIN, err := pin.HashPIN(testPin)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to hash testPin", "error", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: userStore,
|
||||
st: mockState,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
// Write initial data to the store
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER, []byte(blockedNumber))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = userStore.WriteEntry(ctx, blockedNumber, storedb.DATA_TEMPORARY_VALUE, []byte(hashedPIN))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Successful PIN match",
|
||||
input: []byte(testPin),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "PIN mismatch",
|
||||
input: []byte("1345"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
res, err := h.CheckBlockedNumPinMisMatch(ctx, "sym", tt.input)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedResult, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCurrentProfileInfo(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
ctx, store := InitializeTestStore(t)
|
||||
@@ -3101,6 +3229,30 @@ func TestResetOthersPin(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestResetValidPin(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
|
||||
expectedResult := resource.Result{
|
||||
FlagReset: []uint32{flag_valid_pin},
|
||||
}
|
||||
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
res, err := h.ResetValidPin(ctx, "reset_valid_pin", []byte(""))
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expectedResult, res)
|
||||
}
|
||||
|
||||
func TestResetUnregisteredNumber(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ type LocalHandlerService struct {
|
||||
DbRs *resource.DbResource
|
||||
Pe *persist.Persister
|
||||
UserdataStore *db.Db
|
||||
LogDb *db.Db
|
||||
Cfg engine.Config
|
||||
Rs resource.Resource
|
||||
first resource.EntryFunc
|
||||
@@ -58,16 +57,12 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) {
|
||||
ls.UserdataStore = db
|
||||
}
|
||||
|
||||
func (ls *LocalHandlerService) SetLogDb(db *db.Db) {
|
||||
ls.LogDb = db
|
||||
}
|
||||
|
||||
func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) (*application.MenuHandlers, error) {
|
||||
replaceSeparatorFunc := func(input string) string {
|
||||
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
|
||||
}
|
||||
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, *ls.LogDb, accountService, replaceSeparatorFunc)
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, accountService, replaceSeparatorFunc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -104,18 +99,23 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("verify_yob", appHandlers.VerifyYob)
|
||||
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", appHandlers.ResetIncorrectYob)
|
||||
ls.DbRs.AddLocalFunc("initiate_transaction", appHandlers.InitiateTransaction)
|
||||
ls.DbRs.AddLocalFunc("verify_new_pin", appHandlers.VerifyNewPin)
|
||||
ls.DbRs.AddLocalFunc("confirm_pin_change", appHandlers.ConfirmPinChange)
|
||||
ls.DbRs.AddLocalFunc("quit_with_help", appHandlers.QuitWithHelp)
|
||||
ls.DbRs.AddLocalFunc("fetch_community_balance", appHandlers.FetchCommunityBalance)
|
||||
ls.DbRs.AddLocalFunc("manage_vouchers", appHandlers.ManageVouchers)
|
||||
ls.DbRs.AddLocalFunc("set_default_voucher", appHandlers.SetDefaultVoucher)
|
||||
ls.DbRs.AddLocalFunc("check_vouchers", appHandlers.CheckVouchers)
|
||||
ls.DbRs.AddLocalFunc("get_vouchers", appHandlers.GetVoucherList)
|
||||
ls.DbRs.AddLocalFunc("view_voucher", appHandlers.ViewVoucher)
|
||||
ls.DbRs.AddLocalFunc("set_voucher", appHandlers.SetVoucher)
|
||||
ls.DbRs.AddLocalFunc("get_voucher_details", appHandlers.GetVoucherDetails)
|
||||
ls.DbRs.AddLocalFunc("reset_valid_pin", appHandlers.ResetValidPin)
|
||||
ls.DbRs.AddLocalFunc("check_pin_mismatch", appHandlers.CheckBlockedNumPinMisMatch)
|
||||
ls.DbRs.AddLocalFunc("validate_blocked_number", appHandlers.ValidateBlockedNumber)
|
||||
ls.DbRs.AddLocalFunc("retrieve_blocked_number", appHandlers.RetrieveBlockedNumber)
|
||||
ls.DbRs.AddLocalFunc("reset_unregistered_number", appHandlers.ResetUnregisteredNumber)
|
||||
ls.DbRs.AddLocalFunc("reset_others_pin", appHandlers.ResetOthersPin)
|
||||
ls.DbRs.AddLocalFunc("save_others_temporary_pin", appHandlers.SaveOthersTemporaryPin)
|
||||
ls.DbRs.AddLocalFunc("get_current_profile_info", appHandlers.GetCurrentProfileInfo)
|
||||
ls.DbRs.AddLocalFunc("check_transactions", appHandlers.CheckTransactions)
|
||||
ls.DbRs.AddLocalFunc("get_transactions", appHandlers.GetTransactionsList)
|
||||
@@ -129,7 +129,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
|
||||
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
|
||||
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
|
||||
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
|
||||
|
||||
ls.first = appHandlers.Init
|
||||
|
||||
|
||||
@@ -5,21 +5,32 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.defalsify.org/vise.git/state"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var argc map[string]int = map[string]int{
|
||||
"reset": 0,
|
||||
"admin": 1,
|
||||
}
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("cmd").WithContextKey("SessionId")
|
||||
)
|
||||
|
||||
type Cmd struct {
|
||||
sessionId string
|
||||
conn storage.ConnData
|
||||
flagParser *application.FlagManager
|
||||
cmd int
|
||||
enable bool
|
||||
exec func(ctx context.Context, ss storage.StorageService) error
|
||||
sessionId string
|
||||
conn storage.ConnData
|
||||
flagParser *application.FlagManager
|
||||
cmd int
|
||||
enable bool
|
||||
exec func(ctx context.Context, ss storage.StorageService) error
|
||||
engineConfig *engine.Config
|
||||
st *state.State
|
||||
}
|
||||
|
||||
func NewCmd(sessionId string, flagParser *application.FlagManager) *Cmd {
|
||||
@@ -29,10 +40,74 @@ func NewCmd(sessionId string, flagParser *application.FlagManager) *Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cmd) WithEngine(engineConfig engine.Config) *Cmd {
|
||||
c.engineConfig = &engineConfig
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Cmd) Exec(ctx context.Context, ss storage.StorageService) error {
|
||||
return c.exec(ctx, ss)
|
||||
}
|
||||
|
||||
func (c *Cmd) engine(ctx context.Context, rs resource.Resource, pe *persist.Persister) (engine.Engine, error) {
|
||||
if c.engineConfig == nil {
|
||||
return nil, fmt.Errorf("engine config missing")
|
||||
}
|
||||
en := engine.NewEngine(*c.engineConfig, rs)
|
||||
|
||||
st := pe.GetState()
|
||||
if st == nil {
|
||||
return nil, fmt.Errorf("persister state fail")
|
||||
}
|
||||
en = en.WithState(st)
|
||||
st.UseDebug()
|
||||
ca := pe.GetMemory()
|
||||
if ca == nil {
|
||||
return nil, fmt.Errorf("persister cache fail")
|
||||
}
|
||||
en = en.WithMemory(ca)
|
||||
logg.DebugCtxf(ctx, "state loaded", "state", st)
|
||||
return en, nil
|
||||
}
|
||||
|
||||
func (c *Cmd) execReset(ctx context.Context, ss storage.StorageService) error {
|
||||
pe, err := ss.GetPersister(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get persister error: %v", err)
|
||||
}
|
||||
rs, err := ss.GetResource(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get resource error: %v", err)
|
||||
}
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
return fmt.Errorf("get dbresource error: %v", err)
|
||||
}
|
||||
err = pe.Load(c.engineConfig.SessionId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("persister load error: %v", err)
|
||||
}
|
||||
en, err := c.engine(ctx, dbResource, pe)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ca := pe.GetMemory()
|
||||
ca.Pop()
|
||||
|
||||
_, err = en.(*engine.DefaultEngine).Reset(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
st := pe.GetState()
|
||||
logg.DebugCtxf(ctx, "state after reset", "state", st)
|
||||
|
||||
err = pe.Save(c.engineConfig.SessionId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cmd) execAdmin(ctx context.Context, ss storage.StorageService) error {
|
||||
pe, err := ss.GetPersister(ctx)
|
||||
if err != nil {
|
||||
@@ -76,13 +151,33 @@ func (c *Cmd) parseCmdAdmin(cmd string, param string, more []string) (bool, erro
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (c *Cmd) parseCmdReset(cmd string, param string, more []string) (bool, error) {
|
||||
if cmd == "reset" {
|
||||
c.enable = false
|
||||
c.exec = c.execReset
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (c *Cmd) Parse(args []string) error {
|
||||
if len(args) < 2 {
|
||||
var param string
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("Wrong number of arguments: %v", args)
|
||||
}
|
||||
cmd := args[0]
|
||||
param := args[1]
|
||||
args = args[2:]
|
||||
|
||||
n, ok := argc[cmd]
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid command: %v", cmd)
|
||||
}
|
||||
if n > 0 {
|
||||
if len(args) < n+1 {
|
||||
return fmt.Errorf("Wrong number of arguments, need: %d", n)
|
||||
}
|
||||
param = args[1]
|
||||
args = args[2:]
|
||||
}
|
||||
|
||||
r, err := c.parseCmdAdmin(cmd, param, args)
|
||||
if err != nil {
|
||||
@@ -92,5 +187,13 @@ func (c *Cmd) Parse(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
r, err = c.parseCmdReset(cmd, param, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("unknown subcommand: %s", cmd)
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/common/phone"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("smsservice")
|
||||
)
|
||||
|
||||
type SmsService struct {
|
||||
Accountservice remote.AccountService
|
||||
Userdatastore store.UserDataStore
|
||||
}
|
||||
|
||||
// SendUpsellSMS will send an invitation SMS to an unregistered phone number
|
||||
func (smsservice *SmsService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) error {
|
||||
if !phone.IsValidPhoneNumber(inviterPhone) {
|
||||
return fmt.Errorf("invalid inviter phone number %v", inviterPhone)
|
||||
}
|
||||
|
||||
if !phone.IsValidPhoneNumber(inviteePhone) {
|
||||
return fmt.Errorf("Invalid invitee phone number %v", inviteePhone)
|
||||
}
|
||||
_, err := smsservice.Accountservice.SendUpsellSMS(ctx, inviterPhone, inviteePhone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send upsell sms: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendPINResetSMS will send an SMS to a user's phonenumber in the event that the associated account's PIN has been reset.
|
||||
func (smsService *SmsService) SendPINResetSMS(ctx context.Context, adminPhoneNumber, blockedPhoneNumber string) error {
|
||||
formattedAdminPhone, err := phone.FormatPhoneNumber(adminPhoneNumber)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to format admin phone number: %w", err)
|
||||
}
|
||||
|
||||
formattedBlockedPhone, err := phone.FormatPhoneNumber(blockedPhoneNumber)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to format blocked phone number: %w", err)
|
||||
}
|
||||
|
||||
if !phone.IsValidPhoneNumber(formattedAdminPhone) {
|
||||
return fmt.Errorf("invalid admin phone number")
|
||||
}
|
||||
if !phone.IsValidPhoneNumber(formattedBlockedPhone) {
|
||||
return fmt.Errorf("invalid blocked phone number")
|
||||
}
|
||||
|
||||
err = smsService.Accountservice.SendPINResetSMS(ctx, formattedAdminPhone, formattedBlockedPhone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send pin reset sms: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendAddressSMS will triger an SMS when a user navigates to the my address node.The SMS will be sent to the associated phonenumber.
|
||||
func (smsService *SmsService) SendAddressSMS(ctx context.Context) error {
|
||||
store := smsService.Userdatastore
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
publicKey, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
originPhone, err := phone.FormatPhoneNumber(sessionId)
|
||||
if err != nil {
|
||||
logg.DebugCtxf(ctx, "Failed to format origin phonenumber", "sessionid", sessionId)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !phone.IsValidPhoneNumber(originPhone) {
|
||||
logg.InfoCtxf(ctx, "Invalid origin phone number", "origin phonenumber", originPhone)
|
||||
return fmt.Errorf("invalid origin phone number")
|
||||
}
|
||||
err = smsService.Accountservice.SendAddressSMS(ctx, string(publicKey), originPhone)
|
||||
if err != nil {
|
||||
logg.DebugCtxf(ctx, "Failed to send address sms", "error", err)
|
||||
return fmt.Errorf("Failed to send address sms: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -202,7 +202,23 @@
|
||||
},
|
||||
{
|
||||
"input": "0700000000",
|
||||
"expectedContent": "{secondary_session_id} will get a PIN reset request.\nPlease enter your PIN to confirm:\n0:Back\n9:Quit"
|
||||
"expectedContent": "Please enter new PIN for: {secondary_session_id}\n0:Back"
|
||||
},
|
||||
{
|
||||
"input": "11111",
|
||||
"expectedContent": "The PIN you have entered is invalid.Please try a 4 digit number instead.\n1:Retry\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "1",
|
||||
"expectedContent": "Please enter new PIN for: {secondary_session_id}\n0:Back"
|
||||
},
|
||||
{
|
||||
"input": "1111",
|
||||
"expectedContent": "Please confirm new PIN for: {secondary_session_id}\n0:Back"
|
||||
},
|
||||
{
|
||||
"input": "1111",
|
||||
"expectedContent": "Please enter your PIN:"
|
||||
},
|
||||
{
|
||||
"input": "1234",
|
||||
@@ -596,7 +612,7 @@
|
||||
},
|
||||
{
|
||||
"input": "1234",
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: Not Provided\n\n0:Back\n9:Quit"
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "0",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
LOAD check_identifier 0
|
||||
RELOAD check_identifier
|
||||
MAP check_identifier
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
|
||||
@@ -6,7 +6,7 @@ MOUT back 0
|
||||
HALT
|
||||
LOAD validate_amount 64
|
||||
RELOAD validate_amount
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_amount flag_invalid_amount 1
|
||||
INCMP _ 0
|
||||
LOAD get_recipient 0
|
||||
|
||||
@@ -1 +1 @@
|
||||
Failed to connect to the custodial service .Please try again.
|
||||
Failed to connect to the custodial service.Please try again.
|
||||
@@ -1,7 +1,5 @@
|
||||
LOAD reset_api_call_failure 6
|
||||
RELOAD reset_api_call_failure
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 1
|
||||
INCMP _ 1
|
||||
INCMP quit 9
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Imeshindwa kuunganisha kwenye huduma ya uangalizi. Tafadhali jaribu tena.
|
||||
@@ -1,2 +0,0 @@
|
||||
{{.retrieve_blocked_number}} will get a PIN reset request.
|
||||
Please enter your PIN to confirm:
|
||||
@@ -1,12 +0,0 @@
|
||||
LOAD retrieve_blocked_number 0
|
||||
RELOAD retrieve_blocked_number
|
||||
MAP retrieve_blocked_number
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
INCMP pin_reset_result *
|
||||
@@ -1,2 +0,0 @@
|
||||
{{.retrieve_blocked_number}} atapokea ombi la kuweka upya PIN.
|
||||
Tafadhali weka PIN yako kudhibitisha:
|
||||
@@ -1,6 +1,5 @@
|
||||
LOAD check_transactions 0
|
||||
RELOAD check_transactions
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH no_transfers flag_no_transfers 1
|
||||
LOAD authorize_account 6
|
||||
MOUT back 0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
LOAD reset_incorrect 6
|
||||
LOAD fetch_community_balance 0
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
MAP fetch_community_balance
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
CATCH pin_entry flag_account_authorized 0
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
MOUT back 0
|
||||
LOAD save_temporary_pin 6
|
||||
HALT
|
||||
INCMP _ 0
|
||||
LOAD verify_create_pin 8
|
||||
RELOAD verify_create_pin
|
||||
CATCH pin_mismatch flag_pin_mismatch 1
|
||||
INCMP account_creation *
|
||||
|
||||
@@ -8,5 +8,5 @@ HALT
|
||||
INCMP _ 0
|
||||
RELOAD authorize_account
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
CATCH update_alias flag_allow_update 1
|
||||
|
||||
1
services/registration/confirm_others_new_pin
Normal file
1
services/registration/confirm_others_new_pin
Normal file
@@ -0,0 +1 @@
|
||||
Please confirm new PIN for: {{.retrieve_blocked_number}}
|
||||
14
services/registration/confirm_others_new_pin.vis
Normal file
14
services/registration/confirm_others_new_pin.vis
Normal file
@@ -0,0 +1,14 @@
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
RELOAD retrieve_blocked_number
|
||||
MAP retrieve_blocked_number
|
||||
CATCH invalid_others_pin flag_valid_pin 0
|
||||
CATCH pin_reset_result flag_account_authorized 1
|
||||
LOAD save_others_temporary_pin 6
|
||||
RELOAD save_others_temporary_pin
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
LOAD check_pin_mismatch 6
|
||||
RELOAD check_pin_mismatch
|
||||
CATCH others_pin_mismatch flag_pin_mismatch 1
|
||||
INCMP pin_entry *
|
||||
1
services/registration/confirm_others_new_pin_swa
Normal file
1
services/registration/confirm_others_new_pin_swa
Normal file
@@ -0,0 +1 @@
|
||||
Tafadhali thibitisha PIN mpya ya: {{.retrieve_blocked_number}}
|
||||
@@ -1,7 +1,7 @@
|
||||
LOAD confirm_pin_change 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
LOAD confirm_pin_change 0
|
||||
RELOAD confirm_pin_change
|
||||
CATCH pin_mismatch flag_pin_mismatch 1
|
||||
INCMP pin_reset_success *
|
||||
CATCH pin_reset_mismatch flag_pin_mismatch 1
|
||||
INCMP * pin_reset_success
|
||||
|
||||
@@ -2,8 +2,8 @@ LOAD create_account 0
|
||||
CATCH account_creation_failed flag_account_creation_failed 1
|
||||
MOUT exit 0
|
||||
HALT
|
||||
INCMP quit 0
|
||||
LOAD save_temporary_pin 6
|
||||
RELOAD save_temporary_pin
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
CATCH . flag_incorrect_pin 1
|
||||
INCMP quit 0
|
||||
INCMP confirm_create_pin *
|
||||
|
||||
5
services/registration/create_pin_mismatch.vis
Normal file
5
services/registration/create_pin_mismatch.vis
Normal file
@@ -0,0 +1,5 @@
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP confirm_create_pin 1
|
||||
INCMP quit 9
|
||||
@@ -7,4 +7,4 @@ INCMP _ 0
|
||||
LOAD validate_blocked_number 6
|
||||
RELOAD validate_blocked_number
|
||||
CATCH unregistered_number flag_unregistered_number 1
|
||||
INCMP authorize_reset_others_pin *
|
||||
INCMP enter_others_new_pin *
|
||||
|
||||
1
services/registration/enter_others_new_pin
Normal file
1
services/registration/enter_others_new_pin
Normal file
@@ -0,0 +1 @@
|
||||
Please enter new PIN for: {{.retrieve_blocked_number}}
|
||||
9
services/registration/enter_others_new_pin.vis
Normal file
9
services/registration/enter_others_new_pin.vis
Normal file
@@ -0,0 +1,9 @@
|
||||
LOAD retrieve_blocked_number 0
|
||||
RELOAD retrieve_blocked_number
|
||||
MAP retrieve_blocked_number
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD verify_new_pin 6
|
||||
RELOAD verify_new_pin
|
||||
INCMP _ 0
|
||||
INCMP * confirm_others_new_pin
|
||||
1
services/registration/enter_others_new_pin_swa
Normal file
1
services/registration/enter_others_new_pin_swa
Normal file
@@ -0,0 +1 @@
|
||||
Tafadhali weka PIN mpya ya: {{.retrieve_blocked_number}}
|
||||
1
services/registration/invalid_others_pin
Normal file
1
services/registration/invalid_others_pin
Normal file
@@ -0,0 +1 @@
|
||||
The PIN you have entered is invalid.Please try a 4 digit number instead.
|
||||
5
services/registration/invalid_others_pin.vis
Normal file
5
services/registration/invalid_others_pin.vis
Normal file
@@ -0,0 +1,5 @@
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP enter_others_new_pin 1
|
||||
INCMP quit 9
|
||||
@@ -1 +1 @@
|
||||
The PIN you entered is invalid. The PIN must be a 4 digit number.
|
||||
The PIN you entered is invalid.The PIN must be a 4 digit number.
|
||||
@@ -1,8 +1,9 @@
|
||||
LOAD clear_temporary_value 2
|
||||
RELOAD clear_temporary_value
|
||||
LOAD manage_vouchers 160
|
||||
RELOAD manage_vouchers
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
LOAD set_default_voucher 8
|
||||
RELOAD set_default_voucher
|
||||
LOAD check_vouchers 10
|
||||
RELOAD check_vouchers
|
||||
LOAD check_balance 128
|
||||
RELOAD check_balance
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
|
||||
@@ -9,7 +9,7 @@ MOUT my_address 6
|
||||
MOUT my_account_alias 7
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP main 0
|
||||
INCMP edit_profile 1
|
||||
INCMP change_language 2
|
||||
INCMP balances 3
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
Current alias: {{.get_current_profile_info}}
|
||||
Enter your preferred alias:
|
||||
Enter your preferred alias::
|
||||
@@ -5,5 +5,4 @@ HALT
|
||||
INCMP _ 0
|
||||
LOAD request_custom_alias 0
|
||||
RELOAD request_custom_alias
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
INCMP confirm_new_alias *
|
||||
INCMP confirm_new_alias *
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
Lakabu ya sasa: {{.get_current_profile_info}}
|
||||
Weka lakabu unalopendelea:
|
||||
Weka lakabu unalopendelea::
|
||||
@@ -1,6 +1,6 @@
|
||||
LOAD reset_incorrect 6
|
||||
LOAD check_balance 0
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
MAP check_balance
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
CATCH pin_entry flag_account_authorized 0
|
||||
|
||||
@@ -2,5 +2,6 @@ MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
RELOAD save_temporary_pin
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
INCMP confirm_pin_change *
|
||||
RELOAD verify_new_pin
|
||||
CATCH invalid_pin flag_valid_pin 0
|
||||
INCMP * confirm_pin_change
|
||||
|
||||
@@ -4,5 +4,5 @@ HALT
|
||||
INCMP _ 0
|
||||
RELOAD authorize_account
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
INCMP new_pin *
|
||||
|
||||
1
services/registration/others_pin_mismatch
Normal file
1
services/registration/others_pin_mismatch
Normal file
@@ -0,0 +1 @@
|
||||
The PIN you have entered is not a match
|
||||
1
services/registration/others_pin_mismatch_swa
Normal file
1
services/registration/others_pin_mismatch_swa
Normal file
@@ -0,0 +1 @@
|
||||
PIN uliyoweka hailingani.Jaribu tena.
|
||||
@@ -1,6 +1,7 @@
|
||||
LOAD set_back 6
|
||||
LOAD authorize_account 16
|
||||
LOAD reset_allow_update 4
|
||||
LOAD verify_new_pin 2
|
||||
LOAD save_temporary_pin 1
|
||||
LOAD reset_incorrect 0
|
||||
LOAD reset_invalid_pin 6
|
||||
|
||||
1
services/registration/pin_reset_mismatch
Normal file
1
services/registration/pin_reset_mismatch
Normal file
@@ -0,0 +1 @@
|
||||
The PIN is not a match. Try again
|
||||
6
services/registration/pin_reset_mismatch.vis
Normal file
6
services/registration/pin_reset_mismatch.vis
Normal file
@@ -0,0 +1,6 @@
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 1
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
1
services/registration/pin_reset_mismatch_swa
Normal file
1
services/registration/pin_reset_mismatch_swa
Normal file
@@ -0,0 +1 @@
|
||||
PIN uliyoweka hailingani.Jaribu tena.
|
||||
@@ -1,4 +1,3 @@
|
||||
CATCH _ flag_account_authorized 0
|
||||
LOAD retrieve_blocked_number 0
|
||||
MAP retrieve_blocked_number
|
||||
LOAD reset_others_pin 6
|
||||
@@ -6,4 +5,4 @@ MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP quit 9
|
||||
INCMP quit 9
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP main 0
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
||||
@@ -9,7 +9,7 @@ flag,flag_account_authorized,15,this is set to allow a user access guarded nodes
|
||||
flag,flag_invalid_recipient,16,this is set when the transaction recipient is invalid
|
||||
flag,flag_invalid_recipient_with_invite,17,this is set when the transaction recipient is valid but not on the platform
|
||||
flag,flag_invalid_amount,18,this is set when the given transaction amount is invalid
|
||||
flag,flag_incorrect_pin,19,this is set when the provided PIN does not match the current account's PIN
|
||||
flag,flag_incorrect_pin,19,this is set when the provided PIN is invalid or does not match the current account's PIN
|
||||
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_single_edit,22,this is set to allow a user to edit a single profile item such as year of birth
|
||||
@@ -31,4 +31,3 @@ flag,flag_back_set,37,this is set when it is a back navigation
|
||||
flag,flag_account_blocked,38,this is set when an account has been blocked after the allowed incorrect PIN attempts have been exceeded
|
||||
flag,flag_invalid_pin,39,this is set when the given PIN is invalid(is less than or more than 4 digits)
|
||||
flag,flag_alias_set,40,this is set when an account alias has been assigned to a user
|
||||
flag,flag_account_pin_reset,41,this is set on an account when an admin triggers a PIN reset for them
|
||||
|
||||
|
@@ -2,14 +2,13 @@ LOAD check_blocked_status 1
|
||||
RELOAD check_blocked_status
|
||||
LOAD check_account_created 2
|
||||
RELOAD check_account_created
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH blocked_account flag_account_blocked 1
|
||||
CATCH select_language flag_language_set 0
|
||||
CATCH terms flag_account_created 0
|
||||
CATCH create_pin flag_pin_set 0
|
||||
LOAD check_account_status 0
|
||||
RELOAD check_account_status
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH account_pending flag_account_pending 1
|
||||
CATCH create_pin flag_pin_set 0
|
||||
CATCH main flag_account_success 1
|
||||
HALT
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
A PIN reset has been done on your account.
|
||||
Please enter a new four number PIN:
|
||||
@@ -1,6 +0,0 @@
|
||||
LOAD reset_invalid_pin 6
|
||||
HALT
|
||||
LOAD save_temporary_pin 1
|
||||
RELOAD save_temporary_pin
|
||||
CATCH invalid_pin flag_invalid_pin 1
|
||||
INCMP confirm_pin_change *
|
||||
@@ -1,2 +0,0 @@
|
||||
Uwekaji upya wa PIN umefanyika kwenye akaunti yako.
|
||||
Tafadhali weka PIN mpya ya nambari nne:
|
||||
@@ -5,7 +5,6 @@ MOUT back 0
|
||||
HALT
|
||||
LOAD validate_recipient 50
|
||||
RELOAD validate_recipient
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
INCMP _ 0
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
LOAD get_voucher_details 0
|
||||
RELOAD get_voucher_details
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
MAP get_voucher_details
|
||||
MOUT back 0
|
||||
HALT
|
||||
|
||||
@@ -63,10 +63,6 @@ const (
|
||||
DATA_INITIAL_LANGUAGE_CODE
|
||||
//Fully qualified account alias string
|
||||
DATA_ACCOUNT_ALIAS
|
||||
//currently suggested alias by the api awaiting user's confirmation as accepted account alias
|
||||
DATA_SUGGESTED_ALIAS
|
||||
//Key used to store a value of 1 for a user to reset their own PIN once they access the menu.
|
||||
DATA_SELF_PIN_RESET
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
type LogDb struct {
|
||||
visedb.Db
|
||||
}
|
||||
|
||||
func (db *LogDb) WriteLogEntry(ctx context.Context, sessionId string, typ db.DataTyp, v []byte) error {
|
||||
db.SetPrefix(visedb.DATATYPE_USERDATA)
|
||||
db.SetSession(sessionId)
|
||||
k := storedb.ToBytes(typ)
|
||||
return db.Put(ctx, k, v)
|
||||
}
|
||||
|
||||
func (db *LogDb) ReadLogEntry(ctx context.Context, sessionId string, typ db.DataTyp) ([]byte, error) {
|
||||
db.SetPrefix(visedb.DATATYPE_USERDATA)
|
||||
db.SetSession(sessionId)
|
||||
k := storedb.ToBytes(typ)
|
||||
return db.Get(ctx, k)
|
||||
}
|
||||
@@ -113,12 +113,6 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool, *persist.Pe
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logdb, err := menuStorageService.GetLogDb(ctx, userDataStore, "test-db-logs", "user-data")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get log db error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "dbresource cast error")
|
||||
@@ -127,7 +121,6 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool, *persist.Pe
|
||||
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userDataStore)
|
||||
lhs.SetLogDb(&logdb)
|
||||
lhs.SetPersister(pe)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
@@ -161,7 +154,6 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool, *persist.Pe
|
||||
|
||||
en := lhs.GetEngine(lhs.Cfg, rs, pe)
|
||||
cleanFn := func() {
|
||||
logdb.Close(ctx)
|
||||
err := en.Finish(ctx)
|
||||
if err != nil {
|
||||
logg.Errorf(err.Error())
|
||||
|
||||
Reference in New Issue
Block a user