voucher-data #138
@ -58,14 +58,6 @@ func (fm *FlagManager) GetFlag(label string) (uint32, error) {
 | 
				
			|||||||
	return fm.parser.GetFlag(label)
 | 
						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 {
 | 
					type Handlers struct {
 | 
				
			||||||
	pe             *persist.Persister
 | 
						pe             *persist.Persister
 | 
				
			||||||
	st             *state.State
 | 
						st             *state.State
 | 
				
			||||||
@ -1122,10 +1114,10 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Store all voucher data
 | 
						// Store all voucher data
 | 
				
			||||||
	dataMap := map[string]string{
 | 
						dataMap := map[string]string{
 | 
				
			||||||
		"sym":  data.Symbol,
 | 
							"sym":  data.Symbols,
 | 
				
			||||||
		"bal":  data.Balance,
 | 
							"bal":  data.Balances,
 | 
				
			||||||
		"deci": data.Decimal,
 | 
							"deci": data.Decimals,
 | 
				
			||||||
		"addr": data.Address,
 | 
							"addr": data.Addresses,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for key, value := range dataMap {
 | 
						for key, value := range dataMap {
 | 
				
			||||||
 | 
				
			|||||||
@ -2096,19 +2096,19 @@ func TestSetVoucher(t *testing.T) {
 | 
				
			|||||||
	ctx := context.WithValue(context.Background(), "SessionId", sessionId)
 | 
						ctx := context.WithValue(context.Background(), "SessionId", sessionId)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Define the temporary voucher data
 | 
						// Define the temporary voucher data
 | 
				
			||||||
	tempData := &VoucherMetadata{
 | 
						tempData := &dataserviceapi.TokenHoldings{
 | 
				
			||||||
		Symbol:  "SRF",
 | 
							TokenSymbol:     "SRF",
 | 
				
			||||||
		Balance: "200",
 | 
							Balance:         "200",
 | 
				
			||||||
		Decimal: "6",
 | 
							TokenDecimals:   "6",
 | 
				
			||||||
		Address: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
 | 
							ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Define the expected active entries
 | 
						// Define the expected active entries
 | 
				
			||||||
	activeEntries := map[utils.DataTyp][]byte{
 | 
						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_BAL:     []byte(tempData.Balance),
 | 
				
			||||||
		utils.DATA_ACTIVE_DECIMAL: []byte(tempData.Decimal),
 | 
							utils.DATA_ACTIVE_DECIMAL: []byte(tempData.TokenDecimals),
 | 
				
			||||||
		utils.DATA_ACTIVE_ADDRESS: []byte(tempData.Address),
 | 
							utils.DATA_ACTIVE_ADDRESS: []byte(tempData.ContractAddress),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Define the temporary entries to be cleared
 | 
						// Define the temporary entries to be cleared
 | 
				
			||||||
@ -2120,10 +2120,10 @@ func TestSetVoucher(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Mocking ReadEntry calls for temporary data retrieval
 | 
						// 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_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_DECIMAL).Return([]byte(tempData.TokenDecimals), nil)
 | 
				
			||||||
	mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_ADDRESS).Return([]byte(tempData.Address), nil)
 | 
						mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_ADDRESS).Return([]byte(tempData.ContractAddress), nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Mocking WriteEntry calls for setting active data
 | 
						// Mocking WriteEntry calls for setting active data
 | 
				
			||||||
	for key, value := range activeEntries {
 | 
						for key, value := range activeEntries {
 | 
				
			||||||
@ -2143,7 +2143,7 @@ func TestSetVoucher(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert.Equal(t, string(tempData.Symbol), res.Content)
 | 
						assert.Equal(t, string(tempData.TokenSymbol), res.Content)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mockDataStore.AssertExpectations(t)
 | 
						mockDataStore.AssertExpectations(t)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,12 +9,12 @@ import (
 | 
				
			|||||||
	dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
 | 
						dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// VoucherMetadata helps organize voucher data fields
 | 
					// VoucherMetadata helps organize data fields
 | 
				
			||||||
type VoucherMetadata struct {
 | 
					type VoucherMetadata struct {
 | 
				
			||||||
	Symbol  string
 | 
						Symbols   string
 | 
				
			||||||
	Balance string
 | 
						Balances  string
 | 
				
			||||||
	Decimal string
 | 
						Decimals  string
 | 
				
			||||||
	Address string
 | 
						Addresses string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ProcessVouchers converts holdings into formatted strings
 | 
					// 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))
 | 
							addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.ContractAddress))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	data.Symbol = strings.Join(symbols, "\n")
 | 
						data.Symbols = strings.Join(symbols, "\n")
 | 
				
			||||||
	data.Balance = strings.Join(balances, "\n")
 | 
						data.Balances = strings.Join(balances, "\n")
 | 
				
			||||||
	data.Decimal = strings.Join(decimals, "\n")
 | 
						data.Decimals = strings.Join(decimals, "\n")
 | 
				
			||||||
	data.Address = strings.Join(addresses, "\n")
 | 
						data.Addresses = strings.Join(addresses, "\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return data
 | 
						return data
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -68,10 +68,10 @@ func TestProcessVouchers(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	expectedResult := VoucherMetadata{
 | 
						expectedResult := VoucherMetadata{
 | 
				
			||||||
		Symbol:  "1:SRF\n2:MILO",
 | 
							Symbols:   "1:SRF\n2:MILO",
 | 
				
			||||||
		Balance: "1:100\n2:200",
 | 
							Balances:  "1:100\n2:200",
 | 
				
			||||||
		Decimal: "1:6\n2:4",
 | 
							Decimals:  "1:6\n2:4",
 | 
				
			||||||
		Address: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
 | 
							Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := ProcessVouchers(holdings)
 | 
						result := ProcessVouchers(holdings)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user