Merge pull request 'Consolidate temp data storage' (#150) from consolidate-temp-data-storage into master
Reviewed-on: #150
This commit is contained in:
commit
45945ae9c5
@ -221,7 +221,7 @@ func (h *Handlers) VerifyNewPin(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveTemporaryPin saves the valid PIN input to the DATA_TEMPORARY_PIN
|
// SaveTemporaryPin saves the valid PIN input to the DATA_TEMPORARY_VALUE
|
||||||
// during the account creation process
|
// during the account creation process
|
||||||
// and during the change PIN process
|
// and during the change PIN process
|
||||||
func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
@ -246,7 +246,7 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
|
|||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
res.FlagReset = append(res.FlagReset, flag_incorrect_pin)
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(accountPIN))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -263,7 +263,7 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt
|
|||||||
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
|
flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch")
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN)
|
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -294,7 +294,7 @@ func (h *Handlers) VerifyCreatePin(ctx context.Context, sym string, input []byte
|
|||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN)
|
temporaryPin, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -338,13 +338,13 @@ func (h *Handlers) SaveFirstname(ctx context.Context, sym string, input []byte)
|
|||||||
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryFirstName, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_FIRST_NAME)
|
temporaryFirstName, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_FIRST_NAME, []byte(temporaryFirstName))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_FIRST_NAME, []byte(temporaryFirstName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_FIRST_NAME, []byte(firstName))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(firstName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -368,13 +368,13 @@ func (h *Handlers) SaveFamilyname(ctx context.Context, sym string, input []byte)
|
|||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryFamilyName, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_FAMILY_NAME)
|
temporaryFamilyName, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_FAMILY_NAME, []byte(temporaryFamilyName))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_FAMILY_NAME, []byte(temporaryFamilyName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_FAMILY_NAME, []byte(familyName))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(familyName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -396,13 +396,13 @@ func (h *Handlers) SaveYob(ctx context.Context, sym string, input []byte) (resou
|
|||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryYob, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_YOB)
|
temporaryYob, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_YOB, []byte(temporaryYob))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_YOB, []byte(temporaryYob))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_YOB, []byte(yob))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(yob))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -426,13 +426,13 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) (
|
|||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryLocation, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_LOCATION)
|
temporaryLocation, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_LOCATION, []byte(temporaryLocation))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_LOCATION, []byte(temporaryLocation))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_LOCATION, []byte(location))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(location))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -456,13 +456,13 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re
|
|||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryGender, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_GENDER)
|
temporaryGender, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(temporaryGender))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(temporaryGender))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_GENDER, []byte(gender))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(gender))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -486,13 +486,13 @@ func (h *Handlers) SaveOfferings(ctx context.Context, sym string, input []byte)
|
|||||||
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
allowUpdate := h.st.MatchFlag(flag_allow_update, true)
|
||||||
|
|
||||||
if allowUpdate {
|
if allowUpdate {
|
||||||
temporaryOfferings, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_OFFERINGS)
|
temporaryOfferings, _ := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE)
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_OFFERINGS, []byte(temporaryOfferings))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_OFFERINGS, []byte(temporaryOfferings))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_OFFERINGS, []byte(offerings))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(offerings))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func TestSaveFirstname(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_FIRST_NAME, []byte(firstName)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(firstName)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -219,7 +219,7 @@ func TestSaveFamilyname(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_FAMILY_NAME, []byte(familyName)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(familyName)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -281,7 +281,7 @@ func TestSaveTemporaryPin(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(tt.input)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(tt.input)).Return(nil)
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, err := h.SaveTemporaryPin(ctx, "save_pin", tt.input)
|
res, err := h.SaveTemporaryPin(ctx, "save_pin", tt.input)
|
||||||
@ -310,7 +310,7 @@ func TestSaveYoB(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_YOB, []byte(yob)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(yob)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -343,7 +343,7 @@ func TestSaveLocation(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_LOCATION, []byte(yob)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(yob)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -376,7 +376,7 @@ func TestSaveOfferings(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||||
|
|
||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_OFFERINGS, []byte(offerings)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(offerings)).Return(nil)
|
||||||
|
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
@ -442,10 +442,10 @@ func TestSaveGender(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Set up expectations for the mock database
|
// Set up expectations for the mock database
|
||||||
if tt.expectCall {
|
if tt.expectCall {
|
||||||
expectedKey := utils.DATA_TEMPORARY_GENDER
|
expectedKey := utils.DATA_TEMPORARY_VALUE
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, expectedKey, []byte(tt.expectedGender)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, expectedKey, []byte(tt.expectedGender)).Return(nil)
|
||||||
} else {
|
} else {
|
||||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_GENDER, []byte(tt.expectedGender)).Return(nil)
|
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender)).Return(nil)
|
||||||
}
|
}
|
||||||
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
|
||||||
// Create the Handlers instance with the mock store
|
// Create the Handlers instance with the mock store
|
||||||
@ -463,9 +463,9 @@ func TestSaveGender(t *testing.T) {
|
|||||||
|
|
||||||
// Verify expectations
|
// Verify expectations
|
||||||
if tt.expectCall {
|
if tt.expectCall {
|
||||||
mockStore.AssertCalled(t, "WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_GENDER, []byte(tt.expectedGender))
|
mockStore.AssertCalled(t, "WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender))
|
||||||
} else {
|
} else {
|
||||||
mockStore.AssertNotCalled(t, "WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_GENDER, []byte(tt.expectedGender))
|
mockStore.AssertNotCalled(t, "WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(tt.expectedGender))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1041,7 +1041,7 @@ func TestVerifyCreatePin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
typ := utils.DATA_TEMPORARY_PIN
|
typ := utils.DATA_TEMPORARY_VALUE
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -1834,7 +1834,7 @@ func TestConfirmPin(t *testing.T) {
|
|||||||
// Set up the expected behavior of the mock
|
// Set up the expected behavior of the mock
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(tt.temporarypin)).Return(nil)
|
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(tt.temporarypin)).Return(nil)
|
||||||
|
|
||||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN).Return(tt.temporarypin, nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE).Return(tt.temporarypin, nil)
|
||||||
|
|
||||||
//Call the function under test
|
//Call the function under test
|
||||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
||||||
@ -2106,16 +2106,9 @@ func TestViewVoucher(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up expectations for mockDataStore
|
// Set up expectations for mockDataStore
|
||||||
expectedData := map[utils.DataTyp]string{
|
expectedData := fmt.Sprintf("%s,%s,%s,%s", "SRF", "100", "6", "0xd4c288865Ce")
|
||||||
utils.DATA_TEMPORARY_SYM: "SRF",
|
|
||||||
utils.DATA_TEMPORARY_BAL: "100",
|
|
||||||
utils.DATA_TEMPORARY_DECIMAL: "6",
|
|
||||||
utils.DATA_TEMPORARY_ADDRESS: "0xd4c288865Ce",
|
|
||||||
}
|
|
||||||
|
|
||||||
for dataType, dataValue := range expectedData {
|
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE, []byte(expectedData)).Return(nil)
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, dataType, []byte(dataValue)).Return(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := h.ViewVoucher(ctx, "view_voucher", []byte("1"))
|
res, err := h.ViewVoucher(ctx, "view_voucher", []byte("1"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -2139,6 +2132,8 @@ func TestSetVoucher(t *testing.T) {
|
|||||||
ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
|
ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expectedData := fmt.Sprintf("%s,%s,%s,%s", "SRF", "200", "6", "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.TokenSymbol),
|
utils.DATA_ACTIVE_SYM: []byte(tempData.TokenSymbol),
|
||||||
@ -2147,30 +2142,14 @@ func TestSetVoucher(t *testing.T) {
|
|||||||
utils.DATA_ACTIVE_ADDRESS: []byte(tempData.ContractAddress),
|
utils.DATA_ACTIVE_ADDRESS: []byte(tempData.ContractAddress),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the temporary entries to be cleared
|
|
||||||
tempEntries := map[utils.DataTyp][]byte{
|
|
||||||
utils.DATA_TEMPORARY_SYM: []byte(""),
|
|
||||||
utils.DATA_TEMPORARY_BAL: []byte(""),
|
|
||||||
utils.DATA_TEMPORARY_DECIMAL: []byte(""),
|
|
||||||
utils.DATA_TEMPORARY_ADDRESS: []byte(""),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.TokenSymbol), nil)
|
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_VALUE).Return([]byte(expectedData), 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.TokenDecimals), 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 {
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, key, value).Return(nil)
|
mockDataStore.On("WriteEntry", ctx, sessionId, key, value).Return(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mocking WriteEntry calls for clearing temporary data
|
|
||||||
for key, value := range tempEntries {
|
|
||||||
mockDataStore.On("WriteEntry", ctx, sessionId, key, value).Return(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: mockDataStore,
|
userdataStore: mockDataStore,
|
||||||
}
|
}
|
||||||
|
@ -14,30 +14,20 @@ const (
|
|||||||
DATA_CUSTODIAL_ID
|
DATA_CUSTODIAL_ID
|
||||||
DATA_ACCOUNT_PIN
|
DATA_ACCOUNT_PIN
|
||||||
DATA_ACCOUNT_STATUS
|
DATA_ACCOUNT_STATUS
|
||||||
DATA_TEMPORARY_FIRST_NAME
|
|
||||||
DATA_FIRST_NAME
|
DATA_FIRST_NAME
|
||||||
DATA_TEMPORARY_FAMILY_NAME
|
|
||||||
DATA_FAMILY_NAME
|
DATA_FAMILY_NAME
|
||||||
DATA_TEMPORARY_YOB
|
|
||||||
DATA_YOB
|
DATA_YOB
|
||||||
DATA_TEMPORARY_LOCATION
|
|
||||||
DATA_LOCATION
|
DATA_LOCATION
|
||||||
DATA_TEMPORARY_GENDER
|
|
||||||
DATA_GENDER
|
DATA_GENDER
|
||||||
DATA_TEMPORARY_OFFERINGS
|
|
||||||
DATA_OFFERINGS
|
DATA_OFFERINGS
|
||||||
DATA_RECIPIENT
|
DATA_RECIPIENT
|
||||||
DATA_AMOUNT
|
DATA_AMOUNT
|
||||||
DATA_TEMPORARY_PIN
|
DATA_TEMPORARY_VALUE
|
||||||
DATA_VOUCHER_LIST
|
DATA_VOUCHER_LIST
|
||||||
DATA_TEMPORARY_SYM
|
|
||||||
DATA_ACTIVE_SYM
|
DATA_ACTIVE_SYM
|
||||||
DATA_TEMPORARY_BAL
|
|
||||||
DATA_ACTIVE_BAL
|
DATA_ACTIVE_BAL
|
||||||
DATA_PUBLIC_KEY_REVERSE
|
DATA_PUBLIC_KEY_REVERSE
|
||||||
DATA_TEMPORARY_DECIMAL
|
|
||||||
DATA_ACTIVE_DECIMAL
|
DATA_ACTIVE_DECIMAL
|
||||||
DATA_TEMPORARY_ADDRESS
|
|
||||||
DATA_ACTIVE_ADDRESS
|
DATA_ACTIVE_ADDRESS
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -77,7 +77,7 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
|
|||||||
|
|
||||||
for i, sym := range symList {
|
for i, sym := range symList {
|
||||||
parts := strings.SplitN(sym, ":", 2)
|
parts := strings.SplitN(sym, ":", 2)
|
||||||
|
|
||||||
if input == parts[0] || strings.EqualFold(input, parts[1]) {
|
if input == parts[0] || strings.EqualFold(input, parts[1]) {
|
||||||
symbol = parts[1]
|
symbol = parts[1]
|
||||||
if i < len(balList) {
|
if i < len(balList) {
|
||||||
@ -97,45 +97,30 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
|
|||||||
|
|
||||||
// StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore.
|
// StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore.
|
||||||
func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
|
func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
|
||||||
entries := map[DataTyp][]byte{
|
tempData := fmt.Sprintf("%s,%s,%s,%s", data.TokenSymbol, data.Balance, data.TokenDecimals, data.ContractAddress)
|
||||||
DATA_TEMPORARY_SYM: []byte(data.TokenSymbol),
|
|
||||||
DATA_TEMPORARY_BAL: []byte(data.Balance),
|
if err := store.WriteEntry(ctx, sessionId, DATA_TEMPORARY_VALUE, []byte(tempData)); err != nil {
|
||||||
DATA_TEMPORARY_DECIMAL: []byte(data.TokenDecimals),
|
return err
|
||||||
DATA_TEMPORARY_ADDRESS: []byte(data.ContractAddress),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range entries {
|
|
||||||
if err := store.WriteEntry(ctx, sessionId, key, value); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTemporaryVoucherData retrieves temporary voucher metadata from the DataStore.
|
// GetTemporaryVoucherData retrieves temporary voucher metadata from the DataStore.
|
||||||
func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
|
func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
|
||||||
keys := []DataTyp{
|
temp_data, err := store.ReadEntry(ctx, sessionId, DATA_TEMPORARY_VALUE)
|
||||||
DATA_TEMPORARY_SYM,
|
if err != nil {
|
||||||
DATA_TEMPORARY_BAL,
|
return nil, err
|
||||||
DATA_TEMPORARY_DECIMAL,
|
|
||||||
DATA_TEMPORARY_ADDRESS,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
values := strings.SplitN(string(temp_data), ",", 4)
|
||||||
|
|
||||||
data := &dataserviceapi.TokenHoldings{}
|
data := &dataserviceapi.TokenHoldings{}
|
||||||
values := make([][]byte, len(keys))
|
|
||||||
|
|
||||||
for i, key := range keys {
|
data.TokenSymbol = values[0]
|
||||||
value, err := store.ReadEntry(ctx, sessionId, key)
|
data.Balance = values[1]
|
||||||
if err != nil {
|
data.TokenDecimals = values[2]
|
||||||
return nil, err
|
data.ContractAddress = values[3]
|
||||||
}
|
|
||||||
values[i] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
data.TokenSymbol = string(values[0])
|
|
||||||
data.Balance = string(values[1])
|
|
||||||
data.TokenDecimals = string(values[2])
|
|
||||||
data.ContractAddress = string(values[3])
|
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/storage"
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
@ -126,18 +127,12 @@ func TestStoreTemporaryVoucher(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Verify stored data
|
// Verify stored data
|
||||||
expectedEntries := map[DataTyp][]byte{
|
expectedData := fmt.Sprintf("%s,%s,%s,%s", "SRF", "200", "6", "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9")
|
||||||
DATA_TEMPORARY_SYM: []byte("SRF"),
|
|
||||||
DATA_TEMPORARY_BAL: []byte("200"),
|
storedValue, err := store.ReadEntry(ctx, sessionId, DATA_TEMPORARY_VALUE)
|
||||||
DATA_TEMPORARY_DECIMAL: []byte("6"),
|
require.NoError(t, err)
|
||||||
DATA_TEMPORARY_ADDRESS: []byte("0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9"),
|
require.Equal(t, expectedData, string(storedValue), "Mismatch for key %v", DATA_TEMPORARY_VALUE)
|
||||||
}
|
|
||||||
|
|
||||||
for key, expectedValue := range expectedEntries {
|
|
||||||
storedValue, err := store.ReadEntry(ctx, sessionId, key)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, expectedValue, storedValue, "Mismatch for key %v", key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTemporaryVoucherData(t *testing.T) {
|
func TestGetTemporaryVoucherData(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user