Compare commits
No commits in common. "33bba73a65341f584eb16d3fe74c4d20ed75873e" and "a17150962e91650300dba046d21c6fc68e3b1d20" have entirely different histories.
33bba73a65
...
a17150962e
@ -78,6 +78,9 @@ 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 len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if input == parts[0] || strings.EqualFold(input, parts[1]) {
|
if input == parts[0] || strings.EqualFold(input, parts[1]) {
|
||||||
symbol = parts[1]
|
symbol = parts[1]
|
||||||
@ -151,6 +154,14 @@ func UpdateVoucherData(ctx context.Context, store common.DataStore, sessionId st
|
|||||||
common.DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress),
|
common.DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear temporary voucher data entries
|
||||||
|
tempEntries := map[common.DataTyp][]byte{
|
||||||
|
common.DATA_TEMPORARY_SYM: []byte(""),
|
||||||
|
common.DATA_TEMPORARY_BAL: []byte(""),
|
||||||
|
common.DATA_TEMPORARY_DECIMAL: []byte(""),
|
||||||
|
common.DATA_TEMPORARY_ADDRESS: []byte(""),
|
||||||
|
}
|
||||||
|
|
||||||
// Write active data
|
// Write active data
|
||||||
for key, value := range activeEntries {
|
for key, value := range activeEntries {
|
||||||
if err := store.WriteEntry(ctx, sessionId, key, value); err != nil {
|
if err := store.WriteEntry(ctx, sessionId, key, value); err != nil {
|
||||||
@ -158,5 +169,12 @@ func UpdateVoucherData(ctx context.Context, store common.DataStore, sessionId st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear temporary data
|
||||||
|
for key, value := range tempEntries {
|
||||||
|
if err := store.WriteEntry(ctx, sessionId, key, value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,11 @@ func InitializeTestDb(t *testing.T) (context.Context, *common.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"
|
||||||
@ -201,4 +206,18 @@ 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 := []common.DataTyp{
|
||||||
|
common.DATA_TEMPORARY_SYM,
|
||||||
|
common.DATA_TEMPORARY_BAL,
|
||||||
|
common.DATA_TEMPORARY_DECIMAL,
|
||||||
|
common.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