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:
parent
12dc86fe1b
commit
8926990c2d
|
@ -34,44 +34,71 @@ var (
|
|||
ZeroAddress = eth.Address{}
|
||||
)
|
||||
|
||||
type TransferType = int
|
||||
|
||||
const (
|
||||
TransferTypeEth TransferType = iota + 1
|
||||
TransferTypeErc20
|
||||
TransferTypeErc721
|
||||
TransferTypeErc1155
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
payloadType PayloadType
|
||||
transaction *transfer.TransactionIdentity
|
||||
id transfer.MultiTransactionIDType
|
||||
timestamp int64
|
||||
activityType Type
|
||||
activityStatus Status
|
||||
amountOut *hexutil.Big // Used for activityType SendAT, SwapAT, BridgeAT
|
||||
amountIn *hexutil.Big // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT
|
||||
tokenOut *Token // Used for activityType SendAT, SwapAT, BridgeAT
|
||||
tokenIn *Token // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT
|
||||
payloadType PayloadType
|
||||
transaction *transfer.TransactionIdentity
|
||||
id transfer.MultiTransactionIDType
|
||||
timestamp int64
|
||||
activityType Type
|
||||
activityStatus Status
|
||||
amountOut *hexutil.Big // Used for activityType SendAT, SwapAT, BridgeAT
|
||||
amountIn *hexutil.Big // Used for activityType ReceiveAT, BuyAT, SwapAT, BridgeAT
|
||||
tokenOut *Token // Used for activityType SendAT, 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 {
|
||||
PayloadType PayloadType `json:"payloadType"`
|
||||
Transaction *transfer.TransactionIdentity `json:"transaction"`
|
||||
ID transfer.MultiTransactionIDType `json:"id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
ActivityType Type `json:"activityType"`
|
||||
ActivityStatus Status `json:"activityStatus"`
|
||||
AmountOut *hexutil.Big `json:"amountOut"`
|
||||
AmountIn *hexutil.Big `json:"amountIn"`
|
||||
TokenOut *Token `json:"tokenOut,omitempty"`
|
||||
TokenIn *Token `json:"tokenIn,omitempty"`
|
||||
PayloadType PayloadType `json:"payloadType"`
|
||||
Transaction *transfer.TransactionIdentity `json:"transaction"`
|
||||
ID transfer.MultiTransactionIDType `json:"id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
ActivityType Type `json:"activityType"`
|
||||
ActivityStatus Status `json:"activityStatus"`
|
||||
AmountOut *hexutil.Big `json:"amountOut"`
|
||||
AmountIn *hexutil.Big `json:"amountIn"`
|
||||
TokenOut *Token `json:"tokenOut,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) {
|
||||
return json.Marshal(jsonSerializationTemplate{
|
||||
PayloadType: e.payloadType,
|
||||
Transaction: e.transaction,
|
||||
ID: e.id,
|
||||
Timestamp: e.timestamp,
|
||||
ActivityType: e.activityType,
|
||||
ActivityStatus: e.activityStatus,
|
||||
AmountOut: e.amountOut,
|
||||
AmountIn: e.amountIn,
|
||||
TokenOut: e.tokenOut,
|
||||
TokenIn: e.tokenIn,
|
||||
PayloadType: e.payloadType,
|
||||
Transaction: e.transaction,
|
||||
ID: e.id,
|
||||
Timestamp: e.timestamp,
|
||||
ActivityType: e.activityType,
|
||||
ActivityStatus: e.activityStatus,
|
||||
AmountOut: e.amountOut,
|
||||
AmountIn: e.amountIn,
|
||||
TokenOut: e.tokenOut,
|
||||
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.timestamp = aux.Timestamp
|
||||
e.activityType = aux.ActivityType
|
||||
e.activityStatus = aux.ActivityStatus
|
||||
e.amountOut = aux.AmountOut
|
||||
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
|
||||
}
|
||||
|
||||
func newActivityEntryWithPendingTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status, amountIn *hexutil.Big, amountOut *hexutil.Big, tokenOut *Token, tokenIn *Token) Entry {
|
||||
return newActivityEntryWithTransaction(true, transaction, timestamp, activityType, activityStatus, amountIn, amountOut, tokenOut, tokenIn)
|
||||
func newActivityEntryWithPendingTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status) Entry {
|
||||
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 {
|
||||
return newActivityEntryWithTransaction(false, transaction, timestamp, activityType, activityStatus, amountIn, amountOut, tokenOut, tokenIn)
|
||||
func newActivityEntryWithSimpleTransaction(transaction *transfer.TransactionIdentity, timestamp int64, activityType Type, activityStatus Status) Entry {
|
||||
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
|
||||
if pending {
|
||||
payloadType = PendingTransactionPT
|
||||
|
@ -113,24 +149,16 @@ func newActivityEntryWithTransaction(pending bool, transaction *transfer.Transac
|
|||
timestamp: timestamp,
|
||||
activityType: activityType,
|
||||
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{
|
||||
payloadType: MultiTransactionPT,
|
||||
id: id,
|
||||
timestamp: timestamp,
|
||||
activityType: activityType,
|
||||
activityStatus: activityStatus,
|
||||
amountIn: amountIn,
|
||||
amountOut: amountOut,
|
||||
tokenOut: tokenOut,
|
||||
tokenIn: tokenIn,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,7 +374,11 @@ const (
|
|||
transfers.token_address AS token_address,
|
||||
NULL AS 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
|
||||
LEFT JOIN
|
||||
filter_addresses from_join ON HEX(transfers.tx_from_address) = from_join.address
|
||||
|
@ -417,7 +449,11 @@ const (
|
|||
NULL AS token_address,
|
||||
pending_transactions.symbol AS 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
|
||||
LEFT JOIN
|
||||
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_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
|
||||
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
|
||||
|
@ -600,19 +640,19 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
var entries []Entry
|
||||
for rows.Next() {
|
||||
var transferHash, pendingHash []byte
|
||||
var chainID, multiTxID, aggregatedCount sql.NullInt64
|
||||
var chainID, outChainIDDB, inChainIDDB, multiTxID, aggregatedCount sql.NullInt64
|
||||
var timestamp int64
|
||||
var dbMtType, dbTrType sql.NullByte
|
||||
var toAddress, fromAddress eth.Address
|
||||
var toAddressDB, ownerAddressDB sql.RawBytes
|
||||
var toAddressDB, ownerAddressDB, contractAddressDB sql.RawBytes
|
||||
var tokenAddress *eth.Address
|
||||
var aggregatedStatus int
|
||||
var dbTrAmount sql.NullString
|
||||
var dbMtFromAmount, dbMtToAmount sql.NullString
|
||||
var dbMtFromAmount, dbMtToAmount, contractType sql.NullString
|
||||
var tokenCode, fromTokenCode, toTokenCode sql.NullString
|
||||
err := rows.Scan(&transferHash, &pendingHash, &chainID, &multiTxID, ×tamp, &dbMtType, &dbTrType, &fromAddress,
|
||||
&toAddressDB, &ownerAddressDB, &dbTrAmount, &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount,
|
||||
&tokenAddress, &tokenCode, &fromTokenCode, &toTokenCode)
|
||||
&tokenAddress, &tokenCode, &fromTokenCode, &toTokenCode, &outChainIDDB, &inChainIDDB, &contractType, &contractAddressDB)
|
||||
if err != nil {
|
||||
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
|
||||
activityStatus := Status(aggregatedStatus)
|
||||
var tokenOut, tokenIn *Token
|
||||
|
||||
var outChainID, inChainID *common.ChainID
|
||||
var entry Entry
|
||||
if transferHash != nil && chainID.Valid {
|
||||
// Extract activity type: SendAT/ReceiveAT
|
||||
|
@ -644,7 +684,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
ownerAddress := eth.BytesToAddress(ownerAddressDB)
|
||||
inAmount, outAmount := getTrInAndOutAmounts(activityType, dbTrAmount)
|
||||
|
||||
// Extract tokens
|
||||
// Extract tokens and chains
|
||||
var involvedToken *Token
|
||||
if tokenAddress != nil && *tokenAddress != ZeroAddress {
|
||||
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 {
|
||||
tokenOut = involvedToken
|
||||
outChainID = new(common.ChainID)
|
||||
*outChainID = common.ChainID(chainID.Int64)
|
||||
} else {
|
||||
tokenIn = involvedToken
|
||||
inChainID = new(common.ChainID)
|
||||
*inChainID = common.ChainID(chainID.Int64)
|
||||
}
|
||||
|
||||
entry = newActivityEntryWithSimpleTransaction(
|
||||
|
@ -662,7 +706,10 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
Hash: eth.BytesToHash(transferHash),
|
||||
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 {
|
||||
// Extract activity type: SendAT/ReceiveAT
|
||||
activityType, _ := getActivityType(dbTrType)
|
||||
|
@ -674,31 +721,65 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses
|
|||
cID := common.ChainID(chainID.Int64)
|
||||
tokenOut = deps.tokenFromSymbol(&cID, tokenCode.String)
|
||||
}
|
||||
outChainID = new(common.ChainID)
|
||||
*outChainID = common.ChainID(chainID.Int64)
|
||||
|
||||
entry = newActivityEntryWithPendingTransaction(
|
||||
&transfer.TransactionIdentity{ChainID: common.ChainID(chainID.Int64),
|
||||
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 {
|
||||
mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount)
|
||||
|
||||
// Extract activity type: SendAT/SwapAT/BridgeAT
|
||||
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
|
||||
if fromTokenCode.Valid {
|
||||
tokenOut = deps.tokenFromSymbol(nil, fromTokenCode.String)
|
||||
tokenOut = deps.tokenFromSymbol(outChainID, fromTokenCode.String)
|
||||
}
|
||||
if toTokenCode.Valid {
|
||||
tokenIn = deps.tokenFromSymbol(nil, toTokenCode.String)
|
||||
tokenIn = deps.tokenFromSymbol(inChainID, toTokenCode.String)
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -757,3 +838,18 @@ func getMtInAndOutAmounts(dbFromAmount sql.NullString, dbToAmount sql.NullString
|
|||
outAmount = (*hexutil.Big)(big.NewInt(0))
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
deps, close := setupTestActivityDB(t)
|
||||
defer close()
|
||||
|
@ -204,6 +214,11 @@ func TestGetActivityEntriesAll(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &td.tr1.TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &td.tr1.From,
|
||||
recipient: &td.tr1.To,
|
||||
chainIDOut: &td.tr1.ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(td.tr1.Token.Address),
|
||||
}, entries[3])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: PendingTransactionPT,
|
||||
|
@ -216,6 +231,11 @@ func TestGetActivityEntriesAll(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &td.pendingTr.TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &td.pendingTr.From,
|
||||
recipient: &td.pendingTr.To,
|
||||
chainIDOut: &td.pendingTr.ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(eth.Address{}),
|
||||
}, entries[2])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: MultiTransactionPT,
|
||||
|
@ -228,6 +248,8 @@ func TestGetActivityEntriesAll(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
|
||||
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
|
||||
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
|
||||
sender: &td.multiTx1.FromAddress,
|
||||
recipient: &td.multiTx1.ToAddress,
|
||||
}, entries[1])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: MultiTransactionPT,
|
||||
|
@ -240,6 +262,8 @@ func TestGetActivityEntriesAll(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)),
|
||||
tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken),
|
||||
tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken),
|
||||
sender: &td.multiTx2.FromAddress,
|
||||
recipient: &td.multiTx2.ToAddress,
|
||||
}, entries[0])
|
||||
}
|
||||
|
||||
|
@ -311,6 +335,7 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
entries, err := getActivityEntries(context.Background(), deps, []eth.Address{}, []common.ChainID{}, filter, 0, 15)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 8, len(entries))
|
||||
|
||||
// Check start and end content
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -323,6 +348,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[5].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[5].From,
|
||||
recipient: &trs[5].To,
|
||||
chainIDOut: &trs[5].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[5].Token.Address),
|
||||
}, entries[0])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: MultiTransactionPT,
|
||||
|
@ -335,6 +365,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
|
||||
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
|
||||
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
|
||||
sender: &td.multiTx1.FromAddress,
|
||||
recipient: &td.multiTx1.ToAddress,
|
||||
chainIDOut: nil,
|
||||
chainIDIn: nil,
|
||||
transferType: nil,
|
||||
}, entries[7])
|
||||
|
||||
// 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)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 5, len(entries))
|
||||
|
||||
// Check start and end content
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -354,6 +390,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[2].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[2].From,
|
||||
recipient: &trs[2].To,
|
||||
chainIDOut: &trs[2].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[2].Token.Address),
|
||||
}, entries[0])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: MultiTransactionPT,
|
||||
|
@ -366,6 +407,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx1.ToAmount)),
|
||||
tokenOut: tokenFromSymbol(nil, td.multiTx1.FromToken),
|
||||
tokenIn: tokenFromSymbol(nil, td.multiTx1.ToToken),
|
||||
sender: &td.multiTx1.FromAddress,
|
||||
recipient: &td.multiTx1.ToAddress,
|
||||
chainIDOut: nil,
|
||||
chainIDIn: nil,
|
||||
transferType: nil,
|
||||
}, entries[4])
|
||||
|
||||
// Test end only
|
||||
|
@ -385,6 +431,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[2].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[2].From,
|
||||
recipient: &trs[2].To,
|
||||
chainIDOut: &trs[2].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[2].Token.Address),
|
||||
}, entries[0])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -397,6 +448,11 @@ func TestGetActivityEntriesFilterByTime(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &td.tr1.TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &td.tr1.From,
|
||||
recipient: &td.tr1.To,
|
||||
chainIDOut: &td.tr1.ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(td.tr1.Token.Address),
|
||||
}, entries[6])
|
||||
}
|
||||
|
||||
|
@ -436,6 +492,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[8].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[8].From,
|
||||
recipient: &trs[8].To,
|
||||
chainIDOut: &trs[8].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[8].Token.Address),
|
||||
}, entries[0])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -448,6 +509,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[6].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[6].From,
|
||||
recipient: &trs[6].To,
|
||||
chainIDOut: &trs[6].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[6].Token.Address),
|
||||
}, entries[2])
|
||||
|
||||
// Move window 2 entries forward
|
||||
|
@ -466,6 +532,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[6].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[6].From,
|
||||
recipient: &trs[6].To,
|
||||
chainIDOut: &trs[6].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[6].Token.Address),
|
||||
}, entries[0])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -478,6 +549,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[4].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[4].From,
|
||||
recipient: &trs[4].To,
|
||||
chainIDOut: &trs[4].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[4].Token.Address),
|
||||
}, entries[2])
|
||||
|
||||
// Move window 4 more entries to test filter cap
|
||||
|
@ -496,6 +572,11 @@ func TestGetActivityEntriesCheckOffsetAndLimit(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[2].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[2].From,
|
||||
recipient: &trs[2].To,
|
||||
chainIDOut: &trs[2].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[2].Token.Address),
|
||||
}, entries[0])
|
||||
}
|
||||
|
||||
|
@ -611,6 +692,11 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(trs[4].Value)),
|
||||
tokenOut: nil,
|
||||
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])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: SimpleTransactionPT,
|
||||
|
@ -623,6 +709,11 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
tokenOut: TTrToToken(t, &trs[1].TestTransaction),
|
||||
tokenIn: nil,
|
||||
sender: &trs[1].From,
|
||||
recipient: &trs[1].To,
|
||||
chainIDOut: &trs[1].ChainID,
|
||||
chainIDIn: nil,
|
||||
transferType: expectedTokenType(trs[1].Token.Address),
|
||||
}, entries[1])
|
||||
require.Equal(t, Entry{
|
||||
payloadType: MultiTransactionPT,
|
||||
|
@ -635,6 +726,10 @@ func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
|
|||
amountIn: (*hexutil.Big)(big.NewInt(td.multiTx2.ToAmount)),
|
||||
tokenOut: tokenFromSymbol(nil, td.multiTx2.FromToken),
|
||||
tokenIn: tokenFromSymbol(nil, td.multiTx2.ToToken),
|
||||
sender: &td.multiTx2.FromAddress,
|
||||
recipient: &td.multiTx2.ToAddress,
|
||||
chainIDOut: nil,
|
||||
chainIDIn: nil,
|
||||
}, entries[2])
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"testing"
|
||||
|
||||
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/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
|
||||
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
|
||||
trs, _, toTrs = transfer.GenerateTestTransfers(t, db, 0, 7)
|
||||
multiTxs = []transfer.TestMultiTransaction{
|
||||
|
@ -35,10 +34,10 @@ func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []
|
|||
}
|
||||
for j := range nullifyToForIndexes {
|
||||
if nullifyToForIndexes[j] == 1 {
|
||||
multiTxs[0].ToAddress = eth_common.Address{}
|
||||
multiTxs[0].ToAddress = eth.Address{}
|
||||
}
|
||||
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 {
|
||||
if i < 5 {
|
||||
var nullifyAddresses []eth_common.Address
|
||||
var nullifyAddresses []eth.Address
|
||||
for j := range nullifyToForIndexes {
|
||||
if i == nullifyToForIndexes[j] {
|
||||
nullifyAddresses = append(nullifyAddresses, trs[i].To)
|
||||
|
@ -60,7 +59,7 @@ func insertTestData(t *testing.T, db *sql.DB, nullifyToForIndexes []int) (trs []
|
|||
} else {
|
||||
for j := range nullifyToForIndexes {
|
||||
if i == nullifyToForIndexes[j] {
|
||||
trs[i].To = eth_common.Address{}
|
||||
trs[i].To = eth.Address{}
|
||||
}
|
||||
}
|
||||
transfer.InsertTestPendingTransaction(t, db, &trs[i])
|
||||
|
@ -190,7 +189,7 @@ func TestGetOldestTimestamp_NullAddresses(t *testing.T) {
|
|||
defer close()
|
||||
|
||||
trs, _, _ := transfer.GenerateTestTransfers(t, db, 0, 3)
|
||||
nullifyAddresses := []eth_common.Address{
|
||||
nullifyAddresses := []eth.Address{
|
||||
trs[0].To, trs[2].To, trs[1].From,
|
||||
}
|
||||
for i := range trs {
|
||||
|
|
|
@ -291,7 +291,7 @@ func InsertTestPendingTransaction(tb testing.TB, db *sql.DB, tr *TestTransfer) {
|
|||
_, err := db.Exec(`
|
||||
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
|
||||
) VALUES (?, ?, ?, ?, ?, 'ETH', 0, 0, ?, '', 'test', '', ?)`,
|
||||
) VALUES (?, ?, ?, ?, ?, 'ETH', 0, 0, ?, '', 'eth', '', ?)`,
|
||||
tr.ChainID, tr.Hash, tr.Timestamp, tr.From, tr.To, tr.Value, tr.MultiTransactionID)
|
||||
require.NoError(tb, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue