Rehabilitate voucherlist generation
This commit is contained in:
parent
97740fd728
commit
e86959106d
@ -60,5 +60,4 @@ func TestCustodialRegistration(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
"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/common/hex"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -198,6 +198,20 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
t.Fatal("no transaction data")
|
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.SetPrefix(event.DATATYPE_USERSUB)
|
||||||
// userDb.SetSession(testutil.AliceSession)
|
// userDb.SetSession(testutil.AliceSession)
|
||||||
// k := append([]byte("vouchers"), []byte("sym")...)
|
// k := append([]byte("vouchers"), []byte("sym")...)
|
||||||
|
@ -75,36 +75,26 @@ func updateTokenList(ctx context.Context, userStore *store.UserDataStore, identi
|
|||||||
|
|
||||||
// TODO: make sure subprefixdb is thread safe when using gdbm
|
// TODO: make sure subprefixdb is thread safe when using gdbm
|
||||||
// TODO: why is address session here unless explicitly set
|
// TODO: why is address session here unless explicitly set
|
||||||
//userStore.Db.SetPrefix(DATATYPE_USERSUB)
|
|
||||||
pfxDb := toPrefixDb(userStore, identity.SessionId)
|
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)
|
typ := storedb.ToBytes(storedb.DATA_VOUCHER_SYMBOLS)
|
||||||
err = pfxDb.Put(ctx, typ, []byte(metadata.Symbols))
|
err = pfxDb.Put(ctx, typ, []byte(metadata.Symbols))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//k = append([]byte("vouchers"), []byte("bal")...)
|
|
||||||
//err = userStore.Db.Put(ctx, k, []byte(metadata.Balances))
|
|
||||||
typ = storedb.ToBytes(storedb.DATA_VOUCHER_BALANCES)
|
typ = storedb.ToBytes(storedb.DATA_VOUCHER_BALANCES)
|
||||||
err = pfxDb.Put(ctx, typ, []byte(metadata.Balances))
|
err = pfxDb.Put(ctx, typ, []byte(metadata.Balances))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//k = append([]byte("vouchers"), []byte("deci")...)
|
|
||||||
//err = userStore.Db.Put(ctx, k, []byte(metadata.Decimals))
|
|
||||||
typ = storedb.ToBytes(storedb.DATA_VOUCHER_DECIMALS)
|
typ = storedb.ToBytes(storedb.DATA_VOUCHER_DECIMALS)
|
||||||
err = pfxDb.Put(ctx, typ, []byte(metadata.Decimals))
|
err = pfxDb.Put(ctx, typ, []byte(metadata.Decimals))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//k = append([]byte("vouchers"), []byte("addr")...)
|
|
||||||
//err = userStore.Db.Put(ctx, k, []byte(metadata.Addresses))
|
|
||||||
typ = storedb.ToBytes(storedb.DATA_VOUCHER_ADDRESSES)
|
typ = storedb.ToBytes(storedb.DATA_VOUCHER_ADDRESSES)
|
||||||
err = pfxDb.Put(ctx, typ, []byte(metadata.Addresses))
|
err = pfxDb.Put(ctx, typ, []byte(metadata.Addresses))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,7 +106,6 @@ func updateTokenList(ctx context.Context, userStore *store.UserDataStore, identi
|
|||||||
|
|
||||||
// set default token to given symbol.
|
// set default token to given symbol.
|
||||||
func updateDefaultToken(ctx context.Context, userStore *store.UserDataStore, identity lookup.Identity, activeSym string) error {
|
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)
|
pfxDb := toPrefixDb(userStore, identity.SessionId)
|
||||||
// TODO: the activeSym input should instead be newline separated list?
|
// TODO: the activeSym input should instead be newline separated list?
|
||||||
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)
|
tokenData, err := store.GetVoucherData(ctx, pfxDb, activeSym)
|
||||||
|
@ -33,8 +33,10 @@ const (
|
|||||||
txTimestamp = 1730592500
|
txTimestamp = 1730592500
|
||||||
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
||||||
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
||||||
|
bogusSym = "/-21380u"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestTokenTransfer(t *testing.T) {
|
func TestTokenTransfer(t *testing.T) {
|
||||||
err := config.LoadConfig()
|
err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -131,22 +133,19 @@ func TestTokenTransfer(t *testing.T) {
|
|||||||
t.Fatal("no transaction data")
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
_ = mh
|
ctx = context.WithValue(ctx, "SessionId", testutil.AliceSession)
|
||||||
|
rrs, err := mh.GetVoucherList(ctx, "", []byte{})
|
||||||
// userDb.SetPrefix(DATATYPE_USERSUB)
|
if err != nil {
|
||||||
// userDb.SetSession(testutil.AliceSession)
|
t.Fatal(err)
|
||||||
// k := append([]byte("vouchers"), []byte("sym")...)
|
}
|
||||||
// v, err = userDb.Get(ctx, k)
|
expect = fmt.Sprintf("1:%s", tokenSymbol)
|
||||||
// if err != nil {
|
if rrs.Content != expect {
|
||||||
// t.Fatal(err)
|
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
|
||||||
// }
|
}
|
||||||
// if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
|
|
||||||
// t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTokenMint(t *testing.T) {
|
func TestTokenMint(t *testing.T) {
|
||||||
@ -243,14 +242,18 @@ func TestTokenMint(t *testing.T) {
|
|||||||
t.Fatal("no transaction data")
|
t.Fatal("no transaction data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// userDb.SetPrefix(DATATYPE_USERSUB)
|
|
||||||
// userDb.SetSession(testutil.AliceSession)
|
mh, err := application.NewMenuHandlers(nil, userStore, nil, nil, testutil.ReplaceSeparatorFunc)
|
||||||
// k := append([]byte("vouchers"), []byte("sym")...)
|
if err != nil {
|
||||||
// v, err = userDb.Get(ctx, k)
|
t.Fatal(err)
|
||||||
// if err != nil {
|
}
|
||||||
// t.Fatal(err)
|
ctx = context.WithValue(ctx, "SessionId", testutil.AliceSession)
|
||||||
// }
|
rrs, err := mh.GetVoucherList(ctx, "", []byte{})
|
||||||
// if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
|
if err != nil {
|
||||||
// t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
|
expect = fmt.Sprintf("1:%s", tokenSymbol)
|
||||||
|
if rrs.Content != expect {
|
||||||
|
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
internal/testutil/format.go
Normal file
5
internal/testutil/format.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package testutil
|
||||||
|
|
||||||
|
func ReplaceSeparatorFunc(s string) string {
|
||||||
|
return s
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user