From b8bbd88078356e007809b0576200e7dad942d462 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 31 Oct 2024 14:26:28 +0300 Subject: [PATCH] retain the temporary data for it to be overwritten --- internal/utils/vouchers.go | 17 +---------------- internal/utils/vouchers_test.go | 19 ------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/internal/utils/vouchers.go b/internal/utils/vouchers.go index 73a95a6..dc6cc4a 100644 --- a/internal/utils/vouchers.go +++ b/internal/utils/vouchers.go @@ -143,7 +143,7 @@ func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId str return data, nil } -// UpdateVoucherData sets the active voucher data and clears the temporary voucher data in the DataStore. +// UpdateVoucherData sets the active voucher data in the DataStore. func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error { // Active voucher data entries activeEntries := map[DataTyp][]byte{ @@ -153,14 +153,6 @@ func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, d DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress), } - // Clear temporary voucher data entries - tempEntries := map[DataTyp][]byte{ - DATA_TEMPORARY_SYM: []byte(""), - DATA_TEMPORARY_BAL: []byte(""), - DATA_TEMPORARY_DECIMAL: []byte(""), - DATA_TEMPORARY_ADDRESS: []byte(""), - } - // Write active data for key, value := range activeEntries { if err := store.WriteEntry(ctx, sessionId, key, value); err != nil { @@ -168,12 +160,5 @@ func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, d } } - // Clear temporary data - for key, value := range tempEntries { - if err := store.WriteEntry(ctx, sessionId, key, value); err != nil { - return err - } - } - return nil } diff --git a/internal/utils/vouchers_test.go b/internal/utils/vouchers_test.go index 953182e..a609d27 100644 --- a/internal/utils/vouchers_test.go +++ b/internal/utils/vouchers_test.go @@ -31,11 +31,6 @@ func InitializeTestDb(t *testing.T) (context.Context, *UserDataStore) { return ctx, store } -// AssertEmptyValue checks if a value is empty/nil/zero -func AssertEmptyValue(t *testing.T, value []byte, msgAndArgs ...interface{}) { - assert.Equal(t, len(value), 0, msgAndArgs...) -} - func TestMatchVoucher(t *testing.T) { symbols := "1:SRF\n2:MILO" balances := "1:100\n2:200" @@ -205,18 +200,4 @@ func TestUpdateVoucherData(t *testing.T) { require.NoError(t, err) require.Equal(t, expectedValue, storedValue, "Active data mismatch for key %v", key) } - - // Verify temporary data was cleared - tempKeys := []DataTyp{ - DATA_TEMPORARY_SYM, - DATA_TEMPORARY_BAL, - DATA_TEMPORARY_DECIMAL, - DATA_TEMPORARY_ADDRESS, - } - - for _, key := range tempKeys { - storedValue, err := store.ReadEntry(ctx, sessionId, key) - require.NoError(t, err) - AssertEmptyValue(t, storedValue, "Temporary data not cleared for key %v", key) - } }