Rehabilitate voucherlist generation

This commit is contained in:
lash 2025-01-12 15:00:08 +00:00
parent 97740fd728
commit e86959106d
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 46 additions and 36 deletions

View File

@ -60,5 +60,4 @@ func TestCustodialRegistration(t *testing.T) {
if err != nil {
t.Fatal(err)
}
}

View File

@ -19,9 +19,9 @@ import (
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
// "git.grassecon.net/grassrootseconomics/sarafu-vise-events/event"
"git.grassecon.net/grassrootseconomics/common/hex"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
)
const (
@ -198,6 +198,20 @@ func TestHandleMsg(t *testing.T) {
t.Fatal("no transaction data")
}
mh, err := application.NewMenuHandlers(nil, userStore, nil, nil, testutil.ReplaceSeparatorFunc)
if err != nil {
t.Fatal(err)
}
ctx = context.WithValue(ctx, "SessionId", testutil.AliceSession)
rrs, err := mh.GetVoucherList(ctx, "", []byte{})
if err != nil {
t.Fatal(err)
}
expect = fmt.Sprintf("1:%s", tokenSymbol)
if rrs.Content != expect {
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
}
// userDb.SetPrefix(event.DATATYPE_USERSUB)
// userDb.SetSession(testutil.AliceSession)
// k := append([]byte("vouchers"), []byte("sym")...)

View File

@ -75,36 +75,26 @@ func updateTokenList(ctx context.Context, userStore *store.UserDataStore, identi
// TODO: make sure subprefixdb is thread safe when using gdbm
// TODO: why is address session here unless explicitly set
//userStore.Db.SetPrefix(DATATYPE_USERSUB)
pfxDb := toPrefixDb(userStore, identity.SessionId)
//k := append([]byte("vouchers"), []byte("sym")...)
//err = userStore.Db.Put(ctx, k, []byte(metadata.Symbols))
typ := storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS)
err = pfxDb.Put(ctx, typ, []byte(metadata.Symbols))
if err != nil {
return err
}
//k = append([]byte("vouchers"), []byte("bal")...)
//err = userStore.Db.Put(ctx, k, []byte(metadata.Balances))
typ = storedb.ToBytes(storedb.DATA_VOUCHER_BALANCES)
err = pfxDb.Put(ctx, typ, []byte(metadata.Balances))
if err != nil {
return err
}
//k = append([]byte("vouchers"), []byte("deci")...)
//err = userStore.Db.Put(ctx, k, []byte(metadata.Decimals))
typ = storedb.ToBytes(storedb.DATA_VOUCHER_DECIMALS)
err = pfxDb.Put(ctx, typ, []byte(metadata.Decimals))
if err != nil {
return err
}
//k = append([]byte("vouchers"), []byte("addr")...)
//err = userStore.Db.Put(ctx, k, []byte(metadata.Addresses))
typ = storedb.ToBytes(storedb.DATA_VOUCHER_ADDRESSES)
err = pfxDb.Put(ctx, typ, []byte(metadata.Addresses))
if err != nil {
@ -116,7 +106,6 @@ func updateTokenList(ctx context.Context, userStore *store.UserDataStore, identi
// set default token to given symbol.
func updateDefaultToken(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity, activeSym string) error {
//pfxDb := store.StoreToPrefixDb(userStore, []byte("vouchers"))
pfxDb := toPrefixDb(userStore, identity.SessionId)
// TODO: the activeSym input should instead be newline separated list?
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)

View File

@ -33,8 +33,10 @@ const (
txTimestamp = 1730592500
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
bogusSym = "/-21380u"
)
func TestTokenTransfer(t *testing.T) {
err := config.LoadConfig()
if err != nil {
@ -131,22 +133,19 @@ func TestTokenTransfer(t *testing.T) {
t.Fatal("no transaction data")
}
mh, err := application.NewMenuHandlers(nil, userStore, nil, nil, nil)
mh, err := application.NewMenuHandlers(nil, userStore, nil, nil, testutil.ReplaceSeparatorFunc)
if err != nil {
t.Fatal(err)
}
_ = mh
// userDb.SetPrefix(DATATYPE_USERSUB)
// userDb.SetSession(testutil.AliceSession)
// k := append([]byte("vouchers"), []byte("sym")...)
// v, err = userDb.Get(ctx, k)
// if err != nil {
// t.Fatal(err)
// }
// if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
// t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
// }
ctx = context.WithValue(ctx, "SessionId", testutil.AliceSession)
rrs, err := mh.GetVoucherList(ctx, "", []byte{})
if err != nil {
t.Fatal(err)
}
expect = fmt.Sprintf("1:%s", tokenSymbol)
if rrs.Content != expect {
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
}
}
func TestTokenMint(t *testing.T) {
@ -243,14 +242,18 @@ func TestTokenMint(t *testing.T) {
t.Fatal("no transaction data")
}
// userDb.SetPrefix(DATATYPE_USERSUB)
// userDb.SetSession(testutil.AliceSession)
// k := append([]byte("vouchers"), []byte("sym")...)
// v, err = userDb.Get(ctx, k)
// if err != nil {
// t.Fatal(err)
// }
// if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
// t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
// }
mh, err := application.NewMenuHandlers(nil, userStore, nil, nil, testutil.ReplaceSeparatorFunc)
if err != nil {
t.Fatal(err)
}
ctx = context.WithValue(ctx, "SessionId", testutil.AliceSession)
rrs, err := mh.GetVoucherList(ctx, "", []byte{})
if err != nil {
t.Fatal(err)
}
expect = fmt.Sprintf("1:%s", tokenSymbol)
if rrs.Content != expect {
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
}
}

View File

@ -0,0 +1,5 @@
package testutil
func ReplaceSeparatorFunc(s string) string {
return s
}