2024-01-04 04:37:42 +00:00
|
|
|
// These tests are for development only to be run manually
|
|
|
|
// There is more work needed to automate them not to depend on an existing account and internet connection
|
|
|
|
|
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-02-08 12:47:09 +00:00
|
|
|
eth "github.com/ethereum/go-ethereum/common"
|
2024-01-04 04:37:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/status-im/status-desktop/test/status-go/integration/helpers"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2024-02-08 12:47:09 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/transfer"
|
2023-12-17 04:18:20 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/walletevent"
|
2024-01-04 04:37:42 +00:00
|
|
|
"github.com/status-im/status-go/transactions"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestPendingTx_NotificationStatus tests that a pending transaction is created, then updated and finally deleted.
|
|
|
|
func TestPendingTx_NotificationStatus(t *testing.T) {
|
2023-12-17 04:18:20 +00:00
|
|
|
td, close := setupAccountsAndTransactions(t)
|
|
|
|
defer close()
|
2024-01-04 04:37:42 +00:00
|
|
|
|
2023-12-17 04:18:20 +00:00
|
|
|
sendTransaction(t, td)
|
2024-01-04 04:37:42 +00:00
|
|
|
|
2024-02-08 12:47:09 +00:00
|
|
|
// Wait for transaction to be included in block
|
|
|
|
confirmationPayloads, err := helpers.WaitForWalletEventsGetMap(
|
2023-12-17 04:18:20 +00:00
|
|
|
td.eventQueue, []walletevent.EventType{
|
|
|
|
transactions.EventPendingTransactionUpdate,
|
2024-02-08 12:47:09 +00:00
|
|
|
transactions.EventPendingTransactionStatusChanged,
|
2024-01-04 04:37:42 +00:00
|
|
|
},
|
2023-12-17 04:18:20 +00:00
|
|
|
60*time.Second,
|
|
|
|
)
|
2024-01-04 04:37:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-02-08 12:47:09 +00:00
|
|
|
// Validate that we received update event
|
|
|
|
for _, payload := range confirmationPayloads {
|
|
|
|
if payload.EventName == transactions.EventPendingTransactionUpdate {
|
|
|
|
require.False(t, payload.JsonData["deleted"].(bool))
|
|
|
|
} else {
|
|
|
|
require.Equal(t, transactions.Success, payload.JsonData["status"].(transactions.TxStatus))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start history download ...
|
|
|
|
_, err = helpers.CallPrivateMethod("wallet_checkRecentHistoryForChainIDs", []interface{}{[]uint64{5}, []types.Address{td.sender.Address, td.recipient.Address}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
downloadDoneFn := helpers.WaitForTxDownloaderToFinishForAccountsCondition(t, []eth.Address{eth.Address(td.sender.Address), eth.Address(td.recipient.Address)})
|
|
|
|
|
|
|
|
// ... and wait for the new transaction download to trigger deletion from pending_transactions
|
|
|
|
_, err = helpers.WaitForWalletEventsWithOptionals(
|
|
|
|
td.eventQueue,
|
|
|
|
[]walletevent.EventType{transfer.EventRecentHistoryReady},
|
|
|
|
60*time.Second,
|
|
|
|
func(e *walletevent.Event) bool {
|
|
|
|
if e.Type == transfer.EventFetchingHistoryError {
|
|
|
|
require.Fail(t, "History download failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return downloadDoneFn(e)
|
|
|
|
},
|
|
|
|
[]walletevent.EventType{transfer.EventFetchingHistoryError},
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
2024-01-04 04:37:42 +00:00
|
|
|
}
|