voucher-data #138
@ -143,7 +143,7 @@ func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId str
 | 
				
			|||||||
	return data, nil
 | 
						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 {
 | 
					func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
 | 
				
			||||||
	// Active voucher data entries
 | 
						// Active voucher data entries
 | 
				
			||||||
	activeEntries := map[DataTyp][]byte{
 | 
						activeEntries := map[DataTyp][]byte{
 | 
				
			||||||
@ -153,14 +153,6 @@ func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, d
 | 
				
			|||||||
		DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress),
 | 
							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
 | 
						// Write active data
 | 
				
			||||||
	for key, value := range activeEntries {
 | 
						for key, value := range activeEntries {
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 
					
					Alfred-mk marked this conversation as resolved
					
				 
				 | 
				|||||||
		if err := store.WriteEntry(ctx, sessionId, key, value); err != nil {
 | 
							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
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -31,11 +31,6 @@ func InitializeTestDb(t *testing.T) (context.Context, *UserDataStore) {
 | 
				
			|||||||
	return ctx, store
 | 
						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) {
 | 
					func TestMatchVoucher(t *testing.T) {
 | 
				
			||||||
	symbols := "1:SRF\n2:MILO"
 | 
						symbols := "1:SRF\n2:MILO"
 | 
				
			||||||
	balances := "1:100\n2:200"
 | 
						balances := "1:100\n2:200"
 | 
				
			||||||
@ -205,18 +200,4 @@ func TestUpdateVoucherData(t *testing.T) {
 | 
				
			|||||||
		require.NoError(t, err)
 | 
							require.NoError(t, err)
 | 
				
			||||||
		require.Equal(t, expectedValue, storedValue, "Active data mismatch for key %v", key)
 | 
							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)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
Do we need to clear them here? Can't we just overwrite later?
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
ok just drop the lines then?