voucher-data #138

Merged
lash merged 18 commits from voucher-data into master 2024-10-31 13:44:19 +01:00
2 changed files with 1 additions and 35 deletions
Showing only changes of commit b8bbd88078 - Show all commits

View File

@ -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 {
Alfred-mk marked this conversation as resolved
Review

Do we need to clear them here? Can't we just overwrite later?

Do we need to clear them here? Can't we just overwrite later?
Review

They can be left and overwritten with any new temporary data

I wanted to work on this functionality on a different PR, where we'll make use of a single temporary data row

They can be left and overwritten with any new temporary data I wanted to work on this functionality on a different PR, where we'll make use of a single temporary data row
Review

ok just drop the lines then?

ok just drop the lines then?
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
}

View File

@ -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)
}
}