chore(wallet) retrieve all required activity header data as metadata

Add missing fields to activity metadata.

Updates status-desktop #11173
This commit is contained in:
Stefan 2023-07-18 16:57:44 +01:00 committed by Stefan Dunca
parent 12dc86fe1b
commit 8926990c2d
4 changed files with 256 additions and 66 deletions

View File

@ -34,44 +34,71 @@ var (
ZeroAddress = eth.Address{} ZeroAddress = eth.Address{}
) )
type TransferType = int
const (
TransferTypeEth TransferType = iota + 1
TransferTypeErc20
TransferTypeErc721
TransferTypeErc1155
)
type Entry struct { type Entry struct {
payloadType PayloadType payloadType PayloadType
transaction *transfer.TransactionIdentity transaction *transfer.TransactionIdentity
id transfer.MultiTransactionIDType id transfer.MultiTransactionIDType
timestamp int64 timestamp int64
activityType Type activityType Type
activityStatus Status activityStatus Status
amountOut *hexutil.Big // Used for activityType SendAT, SwapAT, BridgeAT amountOut *hexutil.Big // Used for activityType SendAT, SwapAT, BridgeAT
amountIn *hexutil.Big // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT amountIn *hexutil.Big // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT
tokenOut *Token // Used for activityType SendAT, SwapAT, BridgeAT tokenOut *Token // Used for activityType SendAT, SwapAT, BridgeAT
tokenIn *Token // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT tokenIn *Token // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT
sender *eth.Address
recipient *eth.Address
chainIDOut *common.ChainID
chainIDIn *common.ChainID
transferType *TransferType
contractAddress *eth.Address
} }
type jsonSerializationTemplate struct { type jsonSerializationTemplate struct {
PayloadType PayloadType `json:"payloadType"` PayloadType PayloadType `json:"payloadType"`
Transaction *transfer.TransactionIdentity `json:"transaction"` Transaction *transfer.TransactionIdentity `json:"transaction"`
ID transfer.MultiTransactionIDType `json:"id"` ID transfer.MultiTransactionIDType `json:"id"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
ActivityType Type `json:"activityType"` ActivityType Type `json:"activityType"`
ActivityStatus Status `json:"activityStatus"` ActivityStatus Status `json:"activityStatus"`
AmountOut *hexutil.Big `json:"amountOut"` AmountOut *hexutil.Big `json:"amountOut"`
AmountIn *hexutil.Big `json:"amountIn"` AmountIn *hexutil.Big `json:"amountIn"`
TokenOut *Token `json:"tokenOut,omitempty"` TokenOut *Token `json:"tokenOut,omitempty"`
TokenIn *Token `json:"tokenIn,omitempty"` TokenIn *Token `json:"tokenIn,omitempty"`
Sender *eth.Address `json:"sender,omitempty"`
Recipient *eth.Address `json:"recipient,omitempty"`
ChainIDOut *common.ChainID `json:"chainIdOut,omitempty"`
ChainIDIn *common.ChainID `json:"chainIdIn,omitempty"`
TransferType *TransferType `json:"transferType,omitempty"`
ContractAddress *eth.Address `json:"contractAddress,omitempty"`
} }
func (e *Entry) MarshalJSON() ([]byte, error) { func (e *Entry) MarshalJSON() ([]byte, error) {
return json.Marshal(jsonSerializationTemplate{ return json.Marshal(jsonSerializationTemplate{
PayloadType: e.payloadType, PayloadType: e.payloadType,
Transaction: e.transaction, Transaction: e.transaction,
ID: e.id, ID: e.id,
Timestamp: e.timestamp, Timestamp: e.timestamp,
ActivityType: e.activityType, ActivityType: e.activityType,
ActivityStatus: e.activityStatus, ActivityStatus: e.activityStatus,
AmountOut: e.amountOut, AmountOut: e.amountOut,
AmountIn: e.amountIn, AmountIn: e.amountIn,
TokenOut: e.tokenOut, TokenOut: e.tokenOut,
TokenIn: e.tokenIn, TokenIn: e.tokenIn,
Sender: e.sender,
Recipient: e.recipient,
ChainIDOut: e.chainIDOut,
ChainIDIn: e.chainIDIn,
TransferType: e.transferType,
ContractAddress: e.contractAddress,
}) })
} }
@ -87,20 +114,29 @@ func (e *Entry) UnmarshalJSON(data []byte) error {
e.id = aux.ID e.id = aux.ID
e.timestamp = aux.Timestamp e.timestamp = aux.Timestamp
e.activityType = aux.ActivityType e.activityType = aux.ActivityType
e.activityStatus = aux.ActivityStatus
e.amountOut = aux.AmountOut e.amountOut = aux.AmountOut
e.amountIn = aux.AmountIn e.amountIn = aux.AmountIn
e.tokenOut = aux.TokenOut
e.tokenIn = aux.TokenIn
e.sender = aux.Sender
e.recipient = aux.Recipient
e.chainIDOut = aux.ChainIDOut
e.chainIDIn = aux.ChainIDIn
e.transferType = aux.TransferType
e.contractAddress = aux.ContractAddress
return nil return nil
} }
func newActivityEntryWithPendingTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status, amountIn *hexutil.Big, amountOut *hexutil.Big, tokenOut *Token, tokenIn *Token) Entry { func newActivityEntryWithPendingTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status) Entry {
return newActivityEntryWithTransaction(true, transaction, timestamp, activityType, activityStatus, amountIn, amountOut, tokenOut, tokenIn) return newActivityEntryWithTransaction(true, transaction, timestamp, activityType, activityStatus)
} }
func newActivityEntryWithSimpleTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status, amountIn *hexutil.Big, amountOut *hexutil.Big, tokenOut *Token, tokenIn *Token) Entry { func newActivityEntryWithSimpleTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status) Entry {
return newActivityEntryWithTransaction(false, transaction, timestamp, activityType, activityStatus, amountIn, amountOut, tokenOut, tokenIn) return newActivityEntryWithTransaction(false, transaction, timestamp, activityType, activityStatus)
} }
func newActivityEntryWithTransaction(pending bool, transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status, amountIn *hexutil.Big, amountOut *hexutil.Big, tokenOut *Token, tokenIn *Token) Entry { func newActivityEntryWithTransaction(pending bool, transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status) Entry {
payloadType := SimpleTransactionPT payloadType := SimpleTransactionPT
if pending { if pending {
payloadType = PendingTransactionPT payloadType = PendingTransactionPT
@ -113,24 +149,16 @@ func newActivityEntryWithTransaction(pending bool, transaction *transfer.Transac
timestamp: timestamp, timestamp: timestamp,
activityType: activityType, activityType: activityType,
activityStatus: activityStatus, activityStatus: activityStatus,
amountIn: amountIn,
amountOut: amountOut,
tokenOut: tokenOut,
tokenIn: tokenIn,
} }
} }
func NewActivityEntryWithMultiTransaction(id transfer.MultiTransactionIDType, timestamp int64, activityType Type, activityStatus Status, amountIn *hexutil.Big, amountOut *hexutil.Big, tokenOut *Token, tokenIn *Token) Entry { func NewActivityEntryWithMultiTransaction(id transfer.MultiTransactionIDType, timestamp int64, activityType Type, activityStatus Status) Entry {
return Entry{ return Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
id: id, id: id,
timestamp: timestamp, timestamp: timestamp,
activityType: activityType, activityType: activityType,
activityStatus: activityStatus, activityStatus: activityStatus,
amountIn: amountIn,
amountOut: amountOut,
tokenOut: tokenOut,
tokenIn: tokenIn,
} }
} }
@ -346,7 +374,11 @@ const (
transfers.token_address AS token_address, transfers.token_address AS token_address,
NULL AS token_code, NULL AS token_code,
NULL AS from_token_code, NULL AS from_token_code,
NULL AS to_token_code NULL AS to_token_code,
NULL AS out_network_id,
NULL AS in_network_id,
transfers.type AS type,
transfers.contract_address AS contract_address
FROM transfers, filter_conditions FROM transfers, filter_conditions
LEFT JOIN LEFT JOIN
filter_addresses from_join ON HEX(transfers.tx_from_address) = from_join.address filter_addresses from_join ON HEX(transfers.tx_from_address) = from_join.address
@ -417,7 +449,11 @@ const (
NULL AS token_address, NULL AS token_address,
pending_transactions.symbol AS token_code, pending_transactions.symbol AS token_code,
NULL AS from_token_code, NULL AS from_token_code,
NULL AS to_token_code NULL AS to_token_code,
NULL AS out_network_id,
NULL AS in_network_id,
pending_transactions.type AS type,
NULL as contract_address
FROM pending_transactions, filter_conditions FROM pending_transactions, filter_conditions
LEFT JOIN LEFT JOIN
filter_addresses from_join ON HEX(pending_transactions.from_address) = from_join.address filter_addresses from_join ON HEX(pending_transactions.from_address) = from_join.address
@ -467,7 +503,11 @@ const (
NULL AS token_address, NULL AS token_address,
NULL AS token_code, NULL AS token_code,
multi_transactions.from_asset AS from_token_code, multi_transactions.from_asset AS from_token_code,
multi_transactions.to_asset AS to_token_code multi_transactions.to_asset AS to_token_code,
multi_transactions.from_network_id AS out_network_id,
multi_transactions.to_network_id AS in_network_id,
NULL AS type,
NULL as contract_address
FROM multi_transactions, filter_conditions FROM multi_transactions, filter_conditions
LEFT JOIN tr_status ON multi_transactions.ROWID = tr_status.multi_transaction_id LEFT JOIN tr_status ON multi_transactions.ROWID = tr_status.multi_transaction_id
LEFT JOIN pending_status ON multi_transactions.ROWID = pending_status.multi_transaction_id LEFT JOIN pending_status ON multi_transactions.ROWID = pending_status.multi_transaction_id
@ -600,19 +640,19 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
var entries []Entry var entries []Entry
for rows.Next() { for rows.Next() {
var transferHash, pendingHash []byte var transferHash, pendingHash []byte
var chainID, multiTxID, aggregatedCount sql.NullInt64 var chainID, outChainIDDB, inChainIDDB, multiTxID, aggregatedCount sql.NullInt64
var timestamp int64 var timestamp int64
var dbMtType, dbTrType sql.NullByte var dbMtType, dbTrType sql.NullByte
var toAddress, fromAddress eth.Address var toAddress, fromAddress eth.Address
var toAddressDB, ownerAddressDB sql.RawBytes var toAddressDB, ownerAddressDB, contractAddressDB sql.RawBytes
var tokenAddress *eth.Address var tokenAddress *eth.Address
var aggregatedStatus int var aggregatedStatus int
var dbTrAmount sql.NullString var dbTrAmount sql.NullString
var dbMtFromAmount, dbMtToAmount sql.NullString var dbMtFromAmount, dbMtToAmount, contractType sql.NullString
var tokenCode, fromTokenCode, toTokenCode sql.NullString var tokenCode, fromTokenCode, toTokenCode sql.NullString
err := rows.Scan(&transferHash, &pendingHash, &chainID, &multiTxID, &timestamp, &dbMtType, &dbTrType, &fromAddress, err := rows.Scan(&transferHash, &pendingHash, &chainID, &multiTxID, &timestamp, &dbMtType, &dbTrType, &fromAddress,
&toAddressDB, &ownerAddressDB, &dbTrAmount, &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount, &toAddressDB, &ownerAddressDB, &dbTrAmount, &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount,
&tokenAddress, &tokenCode, &fromTokenCode, &toTokenCode) &tokenAddress, &tokenCode, &fromTokenCode, &toTokenCode, &outChainIDDB, &inChainIDDB, &contractType, &contractAddressDB)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -635,7 +675,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
// Can be mapped directly because the values are injected into the query // Can be mapped directly because the values are injected into the query
activityStatus := Status(aggregatedStatus) activityStatus := Status(aggregatedStatus)
var tokenOut, tokenIn *Token var tokenOut, tokenIn *Token
var outChainID, inChainID *common.ChainID
var entry Entry var entry Entry
if transferHash != nil && chainID.Valid { if transferHash != nil && chainID.Valid {
// Extract activity type: SendAT/ReceiveAT // Extract activity type: SendAT/ReceiveAT
@ -644,7 +684,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
ownerAddress := eth.BytesToAddress(ownerAddressDB) ownerAddress := eth.BytesToAddress(ownerAddressDB)
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount) inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount)
// Extract tokens // Extract tokens and chains
var involvedToken *Token var involvedToken *Token
if tokenAddress != nil && *tokenAddress != ZeroAddress { if tokenAddress != nil && *tokenAddress != ZeroAddress {
involvedToken = &Token{TokenType: Erc20, ChainID: common.ChainID(chainID.Int64), Address: *tokenAddress} involvedToken = &Token{TokenType: Erc20, ChainID: common.ChainID(chainID.Int64), Address: *tokenAddress}
@ -653,8 +693,12 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
} }
if activityType == SendAT { if activityType == SendAT {
tokenOut = involvedToken tokenOut = involvedToken
outChainID = new(common.ChainID)
*outChainID = common.ChainID(chainID.Int64)
} else { } else {
tokenIn = involvedToken tokenIn = involvedToken
inChainID = new(common.ChainID)
*inChainID = common.ChainID(chainID.Int64)
} }
entry = newActivityEntryWithSimpleTransaction( entry = newActivityEntryWithSimpleTransaction(
@ -662,7 +706,10 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
Hash: eth.BytesToHash(transferHash), Hash: eth.BytesToHash(transferHash),
Address: ownerAddress, Address: ownerAddress,
}, },
timestamp, activityType, activityStatus, inAmount, outAmount, tokenOut, tokenIn) timestamp, activityType, activityStatus)
// Complete the data
entry.amountOut = outAmount
entry.amountIn = inAmount
} else if pendingHash != nil && chainID.Valid { } else if pendingHash != nil && chainID.Valid {
// Extract activity type: SendAT/ReceiveAT // Extract activity type: SendAT/ReceiveAT
activityType, _ := getActivityType(dbTrType) activityType, _ := getActivityType(dbTrType)
@ -674,31 +721,65 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
cID := common.ChainID(chainID.Int64) cID := common.ChainID(chainID.Int64)
tokenOut = deps.tokenFromSymbol(&cID, tokenCode.String) tokenOut = deps.tokenFromSymbol(&cID, tokenCode.String)
} }
outChainID = new(common.ChainID)
*outChainID = common.ChainID(chainID.Int64)
entry = newActivityEntryWithPendingTransaction( entry = newActivityEntryWithPendingTransaction(
&transfer.TransactionIdentity{ChainID: common.ChainID(chainID.Int64), &transfer.TransactionIdentity{ChainID: common.ChainID(chainID.Int64),
Hash: eth.BytesToHash(pendingHash), Hash: eth.BytesToHash(pendingHash),
}, },
timestamp, activityType, activityStatus, inAmount, outAmount, tokenOut, tokenIn) timestamp, activityType, activityStatus)
// Complete the data
entry.amountOut = outAmount
entry.amountIn = inAmount
} else if multiTxID.Valid { } else if multiTxID.Valid {
mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount) mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount)
// Extract activity type: SendAT/SwapAT/BridgeAT // Extract activity type: SendAT/SwapAT/BridgeAT
activityType := multiTransactionTypeToActivityType(transfer.MultiTransactionType(dbMtType.Byte)) activityType := multiTransactionTypeToActivityType(transfer.MultiTransactionType(dbMtType.Byte))
if outChainIDDB.Valid && outChainIDDB.Int64 != 0 {
outChainID = new(common.ChainID)
*outChainID = common.ChainID(outChainIDDB.Int64)
}
if inChainIDDB.Valid && inChainIDDB.Int64 != 0 {
inChainID = new(common.ChainID)
*inChainID = common.ChainID(inChainIDDB.Int64)
}
// Extract tokens // Extract tokens
if fromTokenCode.Valid { if fromTokenCode.Valid {
tokenOut = deps.tokenFromSymbol(nil, fromTokenCode.String) tokenOut = deps.tokenFromSymbol(outChainID, fromTokenCode.String)
} }
if toTokenCode.Valid { if toTokenCode.Valid {
tokenIn = deps.tokenFromSymbol(nil, toTokenCode.String) tokenIn = deps.tokenFromSymbol(inChainID, toTokenCode.String)
} }
entry = NewActivityEntryWithMultiTransaction(transfer.MultiTransactionIDType(multiTxID.Int64), entry = NewActivityEntryWithMultiTransaction(transfer.MultiTransactionIDType(multiTxID.Int64),
timestamp, activityType, activityStatus, mtInAmount, mtOutAmount, tokenOut, tokenIn) timestamp, activityType, activityStatus)
// Complete the data
entry.amountOut = mtOutAmount
entry.amountIn = mtInAmount
} else { } else {
return nil, errors.New("invalid row data") return nil, errors.New("invalid row data")
} }
// Complete common data
entry.tokenOut = tokenOut
entry.tokenIn = tokenIn
entry.sender = &fromAddress
entry.recipient = &toAddress
entry.sender = &fromAddress
entry.recipient = &toAddress
entry.chainIDOut = outChainID
entry.chainIDIn = inChainID
if contractType.Valid {
entry.transferType = contractTypeFromDBType(contractType.String)
}
if len(contractAddressDB) > 0 {
entry.contractAddress = new(eth.Address)
*entry.contractAddress = eth.BytesToAddress(contractAddressDB)
}
entries = append(entries, entry) entries = append(entries, entry)
} }
@ -757,3 +838,18 @@ func getMtInAndOutAmounts(dbFromAmount sql.NullString, dbToAmount sql.NullString
outAmount = (*hexutil.Big)(big.NewInt(0)) outAmount = (*hexutil.Big)(big.NewInt(0))
return return
} }
func contractTypeFromDBType(dbType string) (transferType *TransferType) {
transferType = new(TransferType)
switch common.Type(dbType) {
case common.EthTransfer:
*transferType = TransferTypeEth
case common.Erc20Transfer:
*transferType = TransferTypeErc20
case common.Erc721Transfer:
*transferType = TransferTypeErc721
default:
return nil
}
return transferType
}

View File

@ -175,6 +175,16 @@ func TTrToToken(t *testing.T, tt *transfer.TestTransaction) *Token {
} }
} }
func expectedTokenType(tokenAddress eth.Address) *TransferType {
transferType := new(TransferType)
if (tokenAddress != eth.Address{}) {
*transferType = TransferTypeErc20
} else {
*transferType = TransferTypeEth
}
return transferType
}
func TestGetActivityEntriesAll(t *testing.T) { func TestGetActivityEntriesAll(t *testing.T) {
deps, close := setupTestActivityDB(t) deps, close := setupTestActivityDB(t)
defer close() defer close()
@ -204,6 +214,11 @@ func TestGetActivityEntriesAll(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &td.tr1.TestTransaction), tokenOut: TTrToToken(t, &td.tr1.TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &td.tr1.From,
recipient: &td.tr1.To,
chainIDOut: &td.tr1.ChainID,
chainIDIn: nil,
transferType: expectedTokenType(td.tr1.Token.Address),
}, entries[3]) }, entries[3])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: PendingTransactionPT, payloadType: PendingTransactionPT,
@ -216,6 +231,11 @@ func TestGetActivityEntriesAll(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &td.pendingTr.TestTransaction), tokenOut: TTrToToken(t, &td.pendingTr.TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &td.pendingTr.From,
recipient: &td.pendingTr.To,
chainIDOut: &td.pendingTr.ChainID,
chainIDIn: nil,
transferType: expectedTokenType(eth.Address{}),
}, entries[2]) }, entries[2])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
@ -228,6 +248,8 @@ func TestGetActivityEntriesAll(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)), amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken), tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken), tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
sender: &td.multiTx1.FromAddress,
recipient: &td.multiTx1.ToAddress,
}, entries[1]) }, entries[1])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
@ -240,6 +262,8 @@ func TestGetActivityEntriesAll(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)), amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)),
tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken), tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken),
tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken), tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken),
sender: &td.multiTx2.FromAddress,
recipient: &td.multiTx2.ToAddress,
}, entries[0]) }, entries[0])
} }
@ -311,6 +335,7 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
entries, err := getActivityEntries(context.Background(), deps, []eth.Address{}, []common.ChainID{}, filter, 0, 15) entries, err := getActivityEntries(context.Background(), deps, []eth.Address{}, []common.ChainID{}, filter, 0, 15)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 8, len(entries)) require.Equal(t, 8, len(entries))
// Check start and end content // Check start and end content
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -323,6 +348,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[5].TestTransaction), tokenOut: TTrToToken(t, &trs[5].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[5].From,
recipient: &trs[5].To,
chainIDOut: &trs[5].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[5].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
@ -335,6 +365,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)), amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken), tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken), tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
sender: &td.multiTx1.FromAddress,
recipient: &td.multiTx1.ToAddress,
chainIDOut: nil,
chainIDIn: nil,
transferType: nil,
}, entries[7]) }, entries[7])
// Test complete interval // Test complete interval
@ -342,6 +377,7 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
entries, err = getActivityEntries(context.Background(), deps, []eth.Address{}, []common.ChainID{}, filter, 0, 15) entries, err = getActivityEntries(context.Background(), deps, []eth.Address{}, []common.ChainID{}, filter, 0, 15)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 5, len(entries)) require.Equal(t, 5, len(entries))
// Check start and end content // Check start and end content
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -354,6 +390,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[2].TestTransaction), tokenOut: TTrToToken(t, &trs[2].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[2].From,
recipient: &trs[2].To,
chainIDOut: &trs[2].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[2].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
@ -366,6 +407,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)), amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken), tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken), tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
sender: &td.multiTx1.FromAddress,
recipient: &td.multiTx1.ToAddress,
chainIDOut: nil,
chainIDIn: nil,
transferType: nil,
}, entries[4]) }, entries[4])
// Test end only // Test end only
@ -385,6 +431,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[2].TestTransaction), tokenOut: TTrToToken(t, &trs[2].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[2].From,
recipient: &trs[2].To,
chainIDOut: &trs[2].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[2].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -397,6 +448,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &td.tr1.TestTransaction), tokenOut: TTrToToken(t, &td.tr1.TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &td.tr1.From,
recipient: &td.tr1.To,
chainIDOut: &td.tr1.ChainID,
chainIDIn: nil,
transferType: expectedTokenType(td.tr1.Token.Address),
}, entries[6]) }, entries[6])
} }
@ -436,6 +492,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[8].TestTransaction), tokenOut: TTrToToken(t, &trs[8].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[8].From,
recipient: &trs[8].To,
chainIDOut: &trs[8].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[8].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -448,6 +509,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[6].TestTransaction), tokenOut: TTrToToken(t, &trs[6].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[6].From,
recipient: &trs[6].To,
chainIDOut: &trs[6].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[6].Token.Address),
}, entries[2]) }, entries[2])
// Move window 2 entries forward // Move window 2 entries forward
@ -466,6 +532,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[6].TestTransaction), tokenOut: TTrToToken(t, &trs[6].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[6].From,
recipient: &trs[6].To,
chainIDOut: &trs[6].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[6].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -478,6 +549,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[4].TestTransaction), tokenOut: TTrToToken(t, &trs[4].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[4].From,
recipient: &trs[4].To,
chainIDOut: &trs[4].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[4].Token.Address),
}, entries[2]) }, entries[2])
// Move window 4 more entries to test filter cap // Move window 4 more entries to test filter cap
@ -496,6 +572,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[2].TestTransaction), tokenOut: TTrToToken(t, &trs[2].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[2].From,
recipient: &trs[2].To,
chainIDOut: &trs[2].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[2].Token.Address),
}, entries[0]) }, entries[0])
} }
@ -611,6 +692,11 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(trs[4].Value)), amountIn: (*hexutil.Big)(big.NewInt(trs[4].Value)),
tokenOut: nil, tokenOut: nil,
tokenIn: TTrToToken(t, &trs[4].TestTransaction), tokenIn: TTrToToken(t, &trs[4].TestTransaction),
sender: &trs[4].From,
recipient: &trs[4].To,
chainIDOut: nil,
chainIDIn: &trs[4].ChainID,
transferType: expectedTokenType(trs[4].Token.Address),
}, entries[0]) }, entries[0])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: SimpleTransactionPT, payloadType: SimpleTransactionPT,
@ -623,6 +709,11 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(0)), amountIn: (*hexutil.Big)(big.NewInt(0)),
tokenOut: TTrToToken(t, &trs[1].TestTransaction), tokenOut: TTrToToken(t, &trs[1].TestTransaction),
tokenIn: nil, tokenIn: nil,
sender: &trs[1].From,
recipient: &trs[1].To,
chainIDOut: &trs[1].ChainID,
chainIDIn: nil,
transferType: expectedTokenType(trs[1].Token.Address),
}, entries[1]) }, entries[1])
require.Equal(t, Entry{ require.Equal(t, Entry{
payloadType: MultiTransactionPT, payloadType: MultiTransactionPT,
@ -635,6 +726,10 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)), amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)),
tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken), tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken),
tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken), tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken),
sender: &td.multiTx2.FromAddress,
recipient: &td.multiTx2.ToAddress,
chainIDOut: nil,
chainIDIn: nil,
}, entries[2]) }, entries[2])
} }

View File

@ -7,7 +7,6 @@ import (
"testing" "testing"
eth "github.com/ethereum/go-ethereum/common" eth "github.com/ethereum/go-ethereum/common"
eth_common "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/appdatabase" "github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/services/wallet/testutils" "github.com/status-im/status-go/services/wallet/testutils"
@ -26,7 +25,7 @@ func setupTestFilterDB(t *testing.T) (db *sql.DB, close func()) {
} }
// insertTestData inserts 6 extractable activity entries: 2 transfers, 2 pending transactions and 2 multi transactions // insertTestData inserts 6 extractable activity entries: 2 transfers, 2 pending transactions and 2 multi transactions
func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []transfer.TestTransfer, toTrs []eth_common.Address, multiTxs []transfer.TestMultiTransaction) { func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []transfer.TestTransfer, toTrs []eth.Address, multiTxs []transfer.TestMultiTransaction) {
// Add 6 extractable transactions // Add 6 extractable transactions
trs, _, toTrs = transfer.GenerateTestTransfers(t, db, 0, 7) trs, _, toTrs = transfer.GenerateTestTransfers(t, db, 0, 7)
multiTxs = []transfer.TestMultiTransaction{ multiTxs = []transfer.TestMultiTransaction{
@ -35,10 +34,10 @@ func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []
} }
for j := range nullifyToForIndexes { for j := range nullifyToForIndexes {
if nullifyToForIndexes[j] == 1 { if nullifyToForIndexes[j] == 1 {
multiTxs[0].ToAddress = eth_common.Address{} multiTxs[0].ToAddress = eth.Address{}
} }
if nullifyToForIndexes[j] == 2 { if nullifyToForIndexes[j] == 2 {
multiTxs[1].ToAddress = eth_common.Address{} multiTxs[1].ToAddress = eth.Address{}
} }
} }
@ -48,7 +47,7 @@ func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []
for i := range trs { for i := range trs {
if i < 5 { if i < 5 {
var nullifyAddresses []eth_common.Address var nullifyAddresses []eth.Address
for j := range nullifyToForIndexes { for j := range nullifyToForIndexes {
if i == nullifyToForIndexes[j] { if i == nullifyToForIndexes[j] {
nullifyAddresses = append(nullifyAddresses, trs[i].To) nullifyAddresses = append(nullifyAddresses, trs[i].To)
@ -60,7 +59,7 @@ func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []
} else { } else {
for j := range nullifyToForIndexes { for j := range nullifyToForIndexes {
if i == nullifyToForIndexes[j] { if i == nullifyToForIndexes[j] {
trs[i].To = eth_common.Address{} trs[i].To = eth.Address{}
} }
} }
transfer.InsertTestPendingTransaction(t, db, &trs[i]) transfer.InsertTestPendingTransaction(t, db, &trs[i])
@ -190,7 +189,7 @@ func TestGetOldestTimestamp_NullAddresses(t *testing.T) {
defer close() defer close()
trs, _, _ := transfer.GenerateTestTransfers(t, db, 0, 3) trs, _, _ := transfer.GenerateTestTransfers(t, db, 0, 3)
nullifyAddresses := []eth_common.Address{ nullifyAddresses := []eth.Address{
trs[0].To, trs[2].To, trs[1].From, trs[0].To, trs[2].To, trs[1].From,
} }
for i := range trs { for i := range trs {

View File

@ -291,7 +291,7 @@ func InsertTestPendingTransaction(tb testing.TB, db *sql.DB, tr *TestTransfer) {
_, err := db.Exec(` _, err := db.Exec(`
INSERT INTO pending_transactions (network_id, hash, timestamp, from_address, to_address, INSERT INTO pending_transactions (network_id, hash, timestamp, from_address, to_address,
symbol, gas_price, gas_limit, value, data, type, additional_data, multi_transaction_id symbol, gas_price, gas_limit, value, data, type, additional_data, multi_transaction_id
) VALUES (?, ?, ?, ?, ?, 'ETH', 0, 0, ?, '', 'test', '', ?)`, ) VALUES (?, ?, ?, ?, ?, 'ETH', 0, 0, ?, '', 'eth', '', ?)`,
tr.ChainID, tr.Hash, tr.Timestamp, tr.From, tr.To, tr.Value, tr.MultiTransactionID) tr.ChainID, tr.Hash, tr.Timestamp, tr.From, tr.To, tr.Value, tr.MultiTransactionID)
require.NoError(tb, err) require.NoError(tb, err)
} }