mirror of
https://github.com/status-im/status-go.git
synced 2025-01-10 06:36:32 +00:00
c020222f1b
Add the possibility of retrieving the metadata of wallet activity based on the given filter criteria. Current implementation relies that after fetching the metadata, user will follow up with more requests for details. However, after some experimenting I'm considering extracting all required information for the summary viewing while filtering. This way there will be no need for another batch requests for transfers, multi-transactions and pending transactions to show the summary. Only when user wants to see the details for one will specifically request it. For this first prototype, the filter criteria is limited to: - time - type - addresses Major changes: - Add the filter definition to be used in propagating the filter information - Add GetActivityEntries API to return the list of activity entries for the given addresses/chainIDs by a view in the complete list - GetTransfersForIdentities to batch retrieve further details of the transfers - GetPendingTransactionsForIdentities to batch retrieve further details of the pending transactions - Added a new package testutils for tests. - Added tests Updates status-desktop #10366 Closes status-desktop #10633
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package transfer
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type TestTransaction struct {
|
|
Hash common.Hash
|
|
ChainID uint64
|
|
From common.Address // [sender]
|
|
To common.Address // [address]
|
|
Timestamp int64
|
|
Value int64
|
|
BlkNumber int64
|
|
MultiTransactionID MultiTransactionIDType
|
|
MultiTransactionType MultiTransactionType
|
|
}
|
|
|
|
func GenerateTestTransactions(t *testing.T, db *sql.DB, firstStartIndex int, count int) (result []TestTransaction) {
|
|
for i := firstStartIndex; i < (firstStartIndex + count); i++ {
|
|
tr := TestTransaction{
|
|
Hash: common.HexToHash(fmt.Sprintf("0x1%d", i)),
|
|
ChainID: uint64(i),
|
|
From: common.HexToAddress(fmt.Sprintf("0x2%d", i)),
|
|
To: common.HexToAddress(fmt.Sprintf("0x3%d", i)),
|
|
Timestamp: int64(i),
|
|
Value: int64(i),
|
|
BlkNumber: int64(i),
|
|
MultiTransactionID: NoMultiTransactionID,
|
|
MultiTransactionType: MultiTransactionSend,
|
|
}
|
|
result = append(result, tr)
|
|
}
|
|
return
|
|
}
|
|
|
|
func InsertTestTransfer(t *testing.T, db *sql.DB, tr *TestTransaction) {
|
|
// Respect `FOREIGN KEY(network_id,address,blk_hash)` of `transfers` table
|
|
blkHash := common.HexToHash("4")
|
|
_, err := db.Exec(`
|
|
INSERT OR IGNORE INTO blocks(
|
|
network_id, address, blk_number, blk_hash
|
|
) VALUES (?, ?, ?, ?);
|
|
INSERT INTO transfers (network_id, hash, address, blk_hash, tx,
|
|
sender, receipt, log, type, blk_number, timestamp, loaded,
|
|
multi_transaction_id, base_gas_fee
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, "test", ?, ?, 0, ?, 0)`,
|
|
tr.ChainID, tr.To, tr.BlkNumber, blkHash,
|
|
tr.ChainID, tr.Hash, tr.To, blkHash, &JSONBlob{}, tr.From, &JSONBlob{}, &JSONBlob{}, tr.BlkNumber, tr.Timestamp, tr.MultiTransactionID)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func InsertTestMultiTransaction(t *testing.T, db *sql.DB, tr *TestTransaction) MultiTransactionIDType {
|
|
result, err := db.Exec(`
|
|
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, type, timestamp
|
|
) VALUES (?, 'ETH', 0, ?, 'SNT', ?, ?)`,
|
|
tr.From, tr.To, tr.MultiTransactionType, tr.Timestamp)
|
|
require.NoError(t, err)
|
|
rowID, err := result.LastInsertId()
|
|
require.NoError(t, err)
|
|
return MultiTransactionIDType(rowID)
|
|
}
|