fix(wallet) filter by sub-transaction chain ID
Closes status-desktop #12077
This commit is contained in:
parent
c3d2ff0723
commit
555aae4d0f
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
type PayloadType = int
|
type PayloadType = int
|
||||||
|
|
||||||
// Beware: pleas update multiTransactionTypeToActivityType if changing this enum
|
// Beware: please update multiTransactionTypeToActivityType if changing this enum
|
||||||
const (
|
const (
|
||||||
MultiTransactionPT PayloadType = iota + 1
|
MultiTransactionPT PayloadType = iota + 1
|
||||||
SimpleTransactionPT
|
SimpleTransactionPT
|
||||||
|
|
|
@ -1039,6 +1039,9 @@ func TestGetActivityEntriesFilterByNetworksOfSubTransactions(t *testing.T) {
|
||||||
|
|
||||||
trs[3].ChainID = 1234
|
trs[3].ChainID = 1234
|
||||||
mt2 := transfer.GenerateTestSwapMultiTransaction(trs[3], testutils.SntSymbol, 100)
|
mt2 := transfer.GenerateTestSwapMultiTransaction(trs[3], testutils.SntSymbol, 100)
|
||||||
|
// insertMultiTransaction will insert 0 instead of NULL
|
||||||
|
mt2.FromNetworkID = common.NewAndSet(uint64(0))
|
||||||
|
mt2.ToNetworkID = common.NewAndSet(uint64(0))
|
||||||
trs[3].MultiTransactionID = transfer.InsertTestMultiTransaction(t, deps.db, &mt2)
|
trs[3].MultiTransactionID = transfer.InsertTestMultiTransaction(t, deps.db, &mt2)
|
||||||
|
|
||||||
for i := range trs {
|
for i := range trs {
|
||||||
|
@ -1055,19 +1058,24 @@ func TestGetActivityEntriesFilterByNetworksOfSubTransactions(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 3, len(entries))
|
require.Equal(t, 3, len(entries))
|
||||||
|
|
||||||
// Extract sub-transactions by pending
|
|
||||||
chainIDs = []common.ChainID{trs[0].ChainID, trs[1].ChainID}
|
chainIDs = []common.ChainID{trs[0].ChainID, trs[1].ChainID}
|
||||||
entries, err = getActivityEntries(context.Background(), deps, toTrs, chainIDs, filter, 0, 15)
|
entries, err = getActivityEntries(context.Background(), deps, toTrs, chainIDs, filter, 0, 15)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(entries))
|
require.Equal(t, 1, len(entries))
|
||||||
require.Equal(t, entries[0].id, mt1.MultiTransactionID)
|
require.Equal(t, entries[0].id, mt1.MultiTransactionID)
|
||||||
|
|
||||||
// Extract sub-transactions by
|
// Filter by pending_transactions sub-transacitons
|
||||||
chainIDs = []common.ChainID{trs[2].ChainID}
|
chainIDs = []common.ChainID{trs[2].ChainID}
|
||||||
entries, err = getActivityEntries(context.Background(), deps, toTrs, chainIDs, filter, 0, 15)
|
entries, err = getActivityEntries(context.Background(), deps, toTrs, chainIDs, filter, 0, 15)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(entries))
|
require.Equal(t, 1, len(entries))
|
||||||
require.Equal(t, entries[0].id, mt1.MultiTransactionID)
|
require.Equal(t, entries[0].id, mt1.MultiTransactionID)
|
||||||
|
|
||||||
|
chainIDs = []common.ChainID{trs[3].ChainID}
|
||||||
|
entries, err = getActivityEntries(context.Background(), deps, toTrs, chainIDs, filter, 0, 15)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, len(entries))
|
||||||
|
require.Equal(t, entries[0].id, mt2.MultiTransactionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetActivityEntriesCheckToAndFrom(t *testing.T) {
|
func TestGetActivityEntriesCheckToAndFrom(t *testing.T) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ filter_addresses(address) AS (
|
||||||
SELECT
|
SELECT
|
||||||
HEX(address)
|
HEX(address)
|
||||||
FROM
|
FROM
|
||||||
% s
|
%s
|
||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -58,7 +58,7 @@ filter_addresses(address) AS (
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
VALUES
|
VALUES
|
||||||
% s
|
%s
|
||||||
)
|
)
|
||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
|
@ -70,19 +70,19 @@ filter_addresses(address) AS (
|
||||||
),
|
),
|
||||||
filter_to_addresses(address) AS (
|
filter_to_addresses(address) AS (
|
||||||
VALUES
|
VALUES
|
||||||
% s
|
%s
|
||||||
),
|
),
|
||||||
assets_token_codes(token_code) AS (
|
assets_token_codes(token_code) AS (
|
||||||
VALUES
|
VALUES
|
||||||
% s
|
%s
|
||||||
),
|
),
|
||||||
assets_erc20(chain_id, token_address) AS (
|
assets_erc20(chain_id, token_address) AS (
|
||||||
VALUES
|
VALUES
|
||||||
% s
|
%s
|
||||||
),
|
),
|
||||||
filter_networks(network_id) AS (
|
filter_networks(network_id) AS (
|
||||||
VALUES
|
VALUES
|
||||||
% s
|
%s
|
||||||
),
|
),
|
||||||
tr_status AS (
|
tr_status AS (
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -401,7 +401,7 @@ WHERE
|
||||||
)
|
)
|
||||||
AND (
|
AND (
|
||||||
filterActivityTypeAll
|
filterActivityTypeAll
|
||||||
OR (multi_transactions.type IN (% s))
|
OR (multi_transactions.type IN (%s))
|
||||||
)
|
)
|
||||||
AND (
|
AND (
|
||||||
filterAllAddresses
|
filterAllAddresses
|
||||||
|
@ -460,8 +460,8 @@ WHERE
|
||||||
multi_transactions.to_network_id IN filter_networks
|
multi_transactions.to_network_id IN filter_networks
|
||||||
)
|
)
|
||||||
OR (
|
OR (
|
||||||
multi_transactions.from_network_id IS NULL
|
COALESCE(multi_transactions.from_network_id, 0) = 0
|
||||||
AND multi_transactions.to_network_id IS NULL
|
AND COALESCE(multi_transactions.to_network_id, 0) = 0
|
||||||
AND (
|
AND (
|
||||||
EXISTS (
|
EXISTS (
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
@ -45,6 +45,8 @@ type TestMultiTransaction struct {
|
||||||
FromAmount int64
|
FromAmount int64
|
||||||
ToAmount int64
|
ToAmount int64
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
|
FromNetworkID *uint64
|
||||||
|
ToNetworkID *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func SeedToToken(seed int) *token.Token {
|
func SeedToToken(seed int) *token.Token {
|
||||||
|
@ -321,9 +323,9 @@ func InsertTestMultiTransaction(tb testing.TB, db *sql.DB, tr *TestMultiTransact
|
||||||
toAmount := (*hexutil.Big)(big.NewInt(tr.ToAmount))
|
toAmount := (*hexutil.Big)(big.NewInt(tr.ToAmount))
|
||||||
|
|
||||||
result, err := db.Exec(`
|
result, err := db.Exec(`
|
||||||
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, to_amount, type, timestamp
|
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, to_amount, type, timestamp, from_network_id, to_network_id
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
tr.FromAddress, fromTokenType, fromAmount.String(), tr.ToAddress, toTokenType, toAmount.String(), tr.MultiTransactionType, tr.Timestamp)
|
tr.FromAddress, fromTokenType, fromAmount.String(), tr.ToAddress, toTokenType, toAmount.String(), tr.MultiTransactionType, tr.Timestamp, tr.FromNetworkID, tr.ToNetworkID)
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
rowID, err := result.LastInsertId()
|
rowID, err := result.LastInsertId()
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
|
|
Loading…
Reference in New Issue