voucher-data #138

Merged
lash merged 18 commits from voucher-data into master 2024-10-31 13:44:19 +01:00
4 changed files with 29 additions and 37 deletions
Showing only changes of commit 8b399781e8 - Show all commits

View File

@ -58,14 +58,6 @@ func (fm *FlagManager) GetFlag(label string) (uint32, error) {
return fm.parser.GetFlag(label)
}
// VoucherMetadata helps organize voucher data fields
type VoucherMetadata struct {
Symbol string
Balance string
Decimal string
Address string
}
type Handlers struct {
pe *persist.Persister
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

Should we use ussd-data-service/pkg/api/api.go TokenHoldings instead?

Should we use ussd-data-service/pkg/api/api.go TokenHoldings instead?

This is actually a struct for the strings that are returned as formatted values, to be stored in the subPrefixDb

For example
data := VoucherMetadata{
Symbols: "1:SRF\n2:MILO",
Balances: "1:100\n2:200",
Decimals: "1:6\n2:4",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
}

This is actually a struct for the strings that are returned as formatted values, to be stored in the subPrefixDb For example data := VoucherMetadata{ Symbols: "1:SRF\n2:MILO", Balances: "1:100\n2:200", Decimals: "1:6\n2:4", Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa", }
st *state.State
@ -1122,10 +1114,10 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
// Store all voucher data
dataMap := map[string]string{
"sym": data.Symbol,
"bal": data.Balance,
"deci": data.Decimal,
"addr": data.Address,
"sym": data.Symbols,
"bal": data.Balances,
"deci": data.Decimals,
"addr": data.Addresses,
}
for key, value := range dataMap {

View File

@ -2096,19 +2096,19 @@ func TestSetVoucher(t *testing.T) {
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
// Define the temporary voucher data
tempData := &VoucherMetadata{
Symbol: "SRF",
Balance: "200",
Decimal: "6",
Address: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
tempData := &dataserviceapi.TokenHoldings{
TokenSymbol: "SRF",
Balance: "200",
TokenDecimals: "6",
ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
}
// Define the expected active entries
activeEntries := map[utils.DataTyp][]byte{
utils.DATA_ACTIVE_SYM: []byte(tempData.Symbol),
utils.DATA_ACTIVE_SYM: []byte(tempData.TokenSymbol),
utils.DATA_ACTIVE_BAL: []byte(tempData.Balance),
utils.DATA_ACTIVE_DECIMAL: []byte(tempData.Decimal),
utils.DATA_ACTIVE_ADDRESS: []byte(tempData.Address),
utils.DATA_ACTIVE_DECIMAL: []byte(tempData.TokenDecimals),
utils.DATA_ACTIVE_ADDRESS: []byte(tempData.ContractAddress),
}
// Define the temporary entries to be cleared
@ -2120,10 +2120,10 @@ func TestSetVoucher(t *testing.T) {
}
// Mocking ReadEntry calls for temporary data retrieval
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_SYM).Return([]byte(tempData.Symbol), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_SYM).Return([]byte(tempData.TokenSymbol), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_BAL).Return([]byte(tempData.Balance), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_DECIMAL).Return([]byte(tempData.Decimal), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_ADDRESS).Return([]byte(tempData.Address), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_DECIMAL).Return([]byte(tempData.TokenDecimals), nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_ADDRESS).Return([]byte(tempData.ContractAddress), nil)
// Mocking WriteEntry calls for setting active data
for key, value := range activeEntries {
@ -2143,7 +2143,7 @@ func TestSetVoucher(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, string(tempData.Symbol), res.Content)
assert.Equal(t, string(tempData.TokenSymbol), res.Content)
mockDataStore.AssertExpectations(t)
}

View File

@ -9,12 +9,12 @@ import (
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
)
// VoucherMetadata helps organize voucher data fields
// VoucherMetadata helps organize data fields
type VoucherMetadata struct {
Symbol string
Balance string
Decimal string
Address string
Symbols string
Balances string
Decimals string
Addresses string
}
// ProcessVouchers converts holdings into formatted strings
@ -29,10 +29,10 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.ContractAddress))
}
data.Symbol = strings.Join(symbols, "\n")
data.Balance = strings.Join(balances, "\n")
data.Decimal = strings.Join(decimals, "\n")
data.Address = strings.Join(addresses, "\n")
data.Symbols = strings.Join(symbols, "\n")
data.Balances = strings.Join(balances, "\n")
data.Decimals = strings.Join(decimals, "\n")
data.Addresses = strings.Join(addresses, "\n")
return data
}

View File

@ -68,10 +68,10 @@ func TestProcessVouchers(t *testing.T) {
}
expectedResult := VoucherMetadata{
Symbol: "1:SRF\n2:MILO",
Balance: "1:100\n2:200",
Decimal: "1:6\n2:4",
Address: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
Symbols: "1:SRF\n2:MILO",
Balances: "1:100\n2:200",
Decimals: "1:6\n2:4",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
}
result := ProcessVouchers(holdings)