sarafu-vise-events/event/custodial_test.go

64 lines
1.7 KiB
Go
Raw Normal View History

2024-11-04 00:53:36 +01:00
package event
import (
"context"
"testing"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/state"
"git.defalsify.org/vise.git/cache"
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
2025-01-13 18:47:21 +01:00
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
"git.grassecon.net/grassrootseconomics/common/hex"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
2025-01-13 18:47:21 +01:00
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
2025-01-14 08:39:52 +01:00
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
2025-01-13 18:47:21 +01:00
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
2024-11-04 00:53:36 +01:00
)
2024-11-04 00:53:36 +01:00
func TestCustodialRegistration(t *testing.T) {
err := config.LoadConfig()
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
storageService := mocks.NewMemStorageService(ctx)
userDb := storageService.Db
2024-11-04 00:53:36 +01:00
2025-01-14 08:39:52 +01:00
alice, err := hex.NormalizeHex(apimocks.AliceChecksum)
2024-11-04 00:53:36 +01:00
if err != nil {
t.Fatal(err)
}
userDb.SetSession(alice)
userDb.SetPrefix(db.DATATYPE_USERDATA)
2025-01-14 08:39:52 +01:00
err = userDb.Put(ctx, storedb.PackKey(storedb.DATA_PUBLIC_KEY_REVERSE, []byte{}), []byte(apimocks.AliceSession))
2024-11-04 00:53:36 +01:00
if err != nil {
t.Fatal(err)
}
st := state.NewState(248)
ca := cache.NewCache()
pr, _ := storageService.GetPersister(ctx)
2024-11-04 00:53:36 +01:00
pr = pr.WithContent(st, ca)
2025-01-14 08:39:52 +01:00
err = pr.Save(apimocks.AliceSession)
2024-11-04 00:53:36 +01:00
if err != nil {
t.Fatal(err)
}
2025-01-13 18:47:21 +01:00
ev := &apievent.EventCustodialRegistration{
2025-01-14 08:39:52 +01:00
Account: apimocks.AliceChecksum,
2024-11-04 00:53:36 +01:00
}
2025-01-13 18:47:21 +01:00
// Use dev service or mock service instead
eu := viseevent.NewEventsUpdater(&http.HTTPAccountService{}, storageService)
eh := eu.ToEventsHandler()
err = eh.Handle(ctx, apievent.EventRegistrationTag, ev)
2024-11-04 00:53:36 +01:00
if err != nil {
t.Fatal(err)
}
}