From ad0a7d3ba46589cf29194dc8c212e60ba6255918 Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 29 Mar 2024 19:10:58 +0200 Subject: [PATCH] test(wallet) add dev integration tests for ERC721 route estimator Used for debugging ERC721 route estimation issues Updates: #14212 --- test/status-go/integration/go.mod | 4 +- test/status-go/integration/go.sum | 4 +- test/status-go/integration/helpers/helpers.go | 6 ++- .../wallet/activityfiltering_test.go | 6 +-- test/status-go/integration/wallet/common.go | 26 +++++++------ .../wallet/pendingtransactions_test.go | 4 +- .../wallet/sendtransactions_test.go | 39 +++++++++++++++++++ 7 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 test/status-go/integration/wallet/sendtransactions_test.go diff --git a/test/status-go/integration/go.mod b/test/status-go/integration/go.mod index d9fc0d6b8e..f386e7605d 100644 --- a/test/status-go/integration/go.mod +++ b/test/status-go/integration/go.mod @@ -21,7 +21,7 @@ replace github.com/mutecomm/go-sqlcipher/v4 v4.4.2 => github.com/status-im/go-sq require ( github.com/ethereum/go-ethereum v1.10.26 - github.com/status-im/status-go v0.171.7 + github.com/status-im/status-go v0.177.1 github.com/stretchr/testify v1.8.4 ) @@ -241,7 +241,7 @@ require ( github.com/urfave/cli/v2 v2.24.4 // indirect github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873 // indirect + github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971 // indirect github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 // indirect github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b // indirect github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230916171929-1dd9494ff065 // indirect diff --git a/test/status-go/integration/go.sum b/test/status-go/integration/go.sum index c37fb1053e..d595f9c14e 100644 --- a/test/status-go/integration/go.sum +++ b/test/status-go/integration/go.sum @@ -2096,8 +2096,8 @@ github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3 h1:Kk0KYXZE/u github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873 h1:pnUvFENjM/h7HVF8VsNWTmOXx/rYs62P7H2EFjAnwVw= -github.com/waku-org/go-waku v0.8.1-0.20240130093642-77ea359ef873/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM= +github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971 h1:HSR8JmscSmCtpIAzFO5sNZRyYZbO8nw7rGM3QcC9bak= +github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM= github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA= github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE= diff --git a/test/status-go/integration/helpers/helpers.go b/test/status-go/integration/helpers/helpers.go index b2c36ea09f..8bb6a48658 100644 --- a/test/status-go/integration/helpers/helpers.go +++ b/test/status-go/integration/helpers/helpers.go @@ -366,7 +366,11 @@ func CallPrivateMethod(method string, params []interface{}) (string, error) { } func CallPrivateMethodAndGetT[T any](method string, params []interface{}) (*T, error) { - resJson, err := CallPrivateMethodWithTimeout(method, params, 60*time.Second) + return CallPrivateMethodAndGetTWithTimeout[T](method, params, 60*time.Second) +} + +func CallPrivateMethodAndGetTWithTimeout[T any](method string, params []interface{}, timeout time.Duration) (*T, error) { + resJson, err := CallPrivateMethodWithTimeout(method, params, timeout) if err != nil { return nil, err } diff --git a/test/status-go/integration/wallet/activityfiltering_test.go b/test/status-go/integration/wallet/activityfiltering_test.go index 6a549e963b..86cd1fa24d 100644 --- a/test/status-go/integration/wallet/activityfiltering_test.go +++ b/test/status-go/integration/wallet/activityfiltering_test.go @@ -24,7 +24,7 @@ func TestActivityIncrementalUpdates_NoFilterNewPendingTransactions(t *testing.T) td, close := setupAccountsAndTransactions(t) defer close() - rawSessionID, err := helpers.CallPrivateMethodAndGetT[int32]("wallet_startActivityFilterSession", []interface{}{[]types.Address{td.sender.Address}, false, []common.ChainID{5}, activity.Filter{}, 3}) + rawSessionID, err := helpers.CallPrivateMethodAndGetT[int32]("wallet_startActivityFilterSession", []interface{}{[]types.Address{td.operableAccounts[0].Address}, false, []common.ChainID{5}, activity.Filter{}, 3}) require.NoError(t, err) require.NotNil(t, rawSessionID) sessionID := activity.SessionID(*rawSessionID) @@ -51,10 +51,10 @@ func TestActivityIncrementalUpdates_NoFilterNewPendingTransactions(t *testing.T) // require.True(t, *update.HasNewOnTop) // Start history download to cleanup pending transactions - _, err = helpers.CallPrivateMethod("wallet_checkRecentHistoryForChainIDs", []interface{}{[]uint64{5}, []types.Address{td.sender.Address, td.recipient.Address}}) + _, err = helpers.CallPrivateMethod("wallet_checkRecentHistoryForChainIDs", []interface{}{[]uint64{5}, []types.Address{td.operableAccounts[0].Address, td.watchAccounts[0].Address}}) require.NoError(t, err) - downloadDoneFn := helpers.WaitForTxDownloaderToFinishForAccountsCondition(t, []eth.Address{eth.Address(td.sender.Address), eth.Address(td.recipient.Address)}) + downloadDoneFn := helpers.WaitForTxDownloaderToFinishForAccountsCondition(t, []eth.Address{eth.Address(td.operableAccounts[0].Address), eth.Address(td.watchAccounts[0].Address)}) update = nil // Wait for EventRecentHistoryReady. diff --git a/test/status-go/integration/wallet/common.go b/test/status-go/integration/wallet/common.go index e6a56cfc12..1c5bcd7c07 100644 --- a/test/status-go/integration/wallet/common.go +++ b/test/status-go/integration/wallet/common.go @@ -16,16 +16,20 @@ import ( ) type testUserData struct { - sender accounts.Account - recipient accounts.Account - hashedPassword string - eventQueue chan helpers.GoEvent + operableAccounts []accounts.Account + watchAccounts []accounts.Account + hashedPassword string + eventQueue chan helpers.GoEvent } func setupAccountsAndTransactions(t *testing.T) (td testUserData, close func()) { + return setupAccountsAndTransactionsWithTimeout(t, 60*time.Second) +} + +func setupAccountsAndTransactionsWithTimeout(t *testing.T, timeout time.Duration) (td testUserData, close func()) { eventQueue, conf, _ := helpers.LoginToTestAccount(t) - _, err := helpers.WaitForEvent(eventQueue, helpers.NodeReadyEvent, 60*time.Second) + _, err := helpers.WaitForEvent(eventQueue, helpers.NodeReadyEvent, timeout) require.NoError(t, err) opAccounts, err := helpers.GetWalletOperableAccounts() @@ -37,8 +41,8 @@ func setupAccountsAndTransactions(t *testing.T) (td testUserData, close func()) require.Greater(t, len(watchAccounts), 0) return testUserData{ - opAccounts[0], - watchAccounts[0], + opAccounts, + watchAccounts, conf.HashedPassword, eventQueue, }, func() { @@ -49,8 +53,8 @@ func setupAccountsAndTransactions(t *testing.T) (td testUserData, close func()) // sendTransaction generates multi_transactions and pending entries then it creates and publishes a transaction func sendTransaction(t *testing.T, td testUserData) { mTCommand := transfer.MultiTransactionCommand{ - FromAddress: common.Address(td.sender.Address), - ToAddress: common.Address(td.recipient.Address), + FromAddress: common.Address(td.operableAccounts[0].Address), + ToAddress: common.Address(td.watchAccounts[0].Address), FromAsset: "ETH", ToAsset: "ETH", FromAmount: (*hexutil.Big)(new(big.Int).SetUint64(100000)), @@ -61,8 +65,8 @@ func sendTransaction(t *testing.T, td testUserData) { BridgeName: "Transfer", ChainID: 5, TransferTx: &transactions.SendTxArgs{ - From: td.sender.Address, - To: &td.recipient.Address, + From: td.operableAccounts[0].Address, + To: &td.watchAccounts[0].Address, Value: (*hexutil.Big)(new(big.Int).Set(mTCommand.FromAmount.ToInt())), }, }, diff --git a/test/status-go/integration/wallet/pendingtransactions_test.go b/test/status-go/integration/wallet/pendingtransactions_test.go index 1d754be02e..a5b6da5f50 100644 --- a/test/status-go/integration/wallet/pendingtransactions_test.go +++ b/test/status-go/integration/wallet/pendingtransactions_test.go @@ -45,10 +45,10 @@ func TestPendingTx_NotificationStatus(t *testing.T) { } // Start history download ... - _, err = helpers.CallPrivateMethod("wallet_checkRecentHistoryForChainIDs", []interface{}{[]uint64{5}, []types.Address{td.sender.Address, td.recipient.Address}}) + _, err = helpers.CallPrivateMethod("wallet_checkRecentHistoryForChainIDs", []interface{}{[]uint64{5}, []types.Address{td.operableAccounts[0].Address, td.watchAccounts[0].Address}}) require.NoError(t, err) - downloadDoneFn := helpers.WaitForTxDownloaderToFinishForAccountsCondition(t, []eth.Address{eth.Address(td.sender.Address), eth.Address(td.recipient.Address)}) + downloadDoneFn := helpers.WaitForTxDownloaderToFinishForAccountsCondition(t, []eth.Address{eth.Address(td.operableAccounts[0].Address), eth.Address(td.watchAccounts[0].Address)}) // ... and wait for the new transaction download to trigger deletion from pending_transactions _, err = helpers.WaitForWalletEventsWithOptionals( diff --git a/test/status-go/integration/wallet/sendtransactions_test.go b/test/status-go/integration/wallet/sendtransactions_test.go new file mode 100644 index 0000000000..28e3a6e3d0 --- /dev/null +++ b/test/status-go/integration/wallet/sendtransactions_test.go @@ -0,0 +1,39 @@ +// 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 ( + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/stretchr/testify/require" + + "github.com/status-im/status-desktop/test/status-go/integration/helpers" + + "github.com/status-im/status-go/services/wallet" +) + +func TestSendTransaction_Collectible(t *testing.T) { + _, close := setupAccountsAndTransactions(t) + defer close() + + payload := []interface{}{ + wallet.ERC721Transfer, + common.HexToAddress("0xe2d622c817878da5143bbe06866ca8e35273ba8a"), /*accountFrom*/ + common.HexToAddress("0xbd54a96c0ae19a220c8e1234f54c940dfab34639"), /*accountTo*/ + (*hexutil.Big)(big.NewInt(1)), /*amount*/ + "0x9f64932be34d5d897c4253d17707b50921f372b6:28", /*tokenID*/ + []uint64{11155420, 421614}, /*disabledFromChainIDs*/ + []uint64{11155420, 421614}, /*disabledToChainIDs*/ + []uint64{11155111}, /*preferredChainIDs*/ + wallet.GasFeeMedium, + map[uint64]*hexutil.Big{}, /*fromLockedAmount*/ + } + //res, err := helpers.CallPrivateMethodAndGetTWithTimeout[wallet.SuggestedRoutes]("wallet_getSuggestedRoutes", payload¸, 10000*time.Minute) + res, err := helpers.CallPrivateMethodAndGetT[wallet.SuggestedRoutes]("wallet_getSuggestedRoutes", payload) + require.NoError(t, err) + require.Greater(t, len(res.Candidates), 0) +}