Skip to content

Commit

Permalink
test(wallet) add dev integration tests for ERC1155 route estimator
Browse files Browse the repository at this point in the history
Used for debugging ERC1155 route estimation issues

Updates: #14212
  • Loading branch information
stefandunca committed Apr 3, 2024
1 parent ad6cb9b commit 450bed0
Showing 1 changed file with 80 additions and 19 deletions.
99 changes: 80 additions & 19 deletions test/status-go/integration/wallet/sendtransactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,94 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
eth "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"
"github.com/status-im/status-go/services/wallet/common"
)

type dataPayload struct {
transferType wallet.SendType
accountFrom eth.Address
accountTo eth.Address
amount *hexutil.Big
tokenIdentity string // Format: "<HexTokenAddress>:<TokenID>"
disabledFromChainIDs []uint64
disabledToChainIDs []uint64
preferredChainIDs []uint64
gasFeeMode wallet.GasFeeMode
fromLockedAmount map[uint64]*hexutil.Big
}

func dataToCallingPayload(data dataPayload) []interface{} {
return []interface{}{
data.transferType,
data.accountFrom,
data.accountTo,
data.amount,
data.tokenIdentity,
data.disabledFromChainIDs,
data.disabledToChainIDs,
data.preferredChainIDs,
data.gasFeeMode,
data.fromLockedAmount,
}
}

func basicPayload() dataPayload {
defaultDisabled := []uint64{common.OptimismSepolia, common.ArbitrumSepolia}
return dataPayload{
transferType: wallet.Transfer,
tokenIdentity: "",
accountFrom: eth.HexToAddress("0xe2d622c817878da5143bbe06866ca8e35273ba8a"),
accountTo: eth.HexToAddress("0xbd54a96c0ae19a220c8e1234f54c940dfab34639"),
amount: (*hexutil.Big)(big.NewInt(1)),
disabledFromChainIDs: defaultDisabled,
disabledToChainIDs: defaultDisabled,
preferredChainIDs: []uint64{common.EthereumSepolia},
gasFeeMode: wallet.GasFeeMedium,
fromLockedAmount: map[uint64]*hexutil.Big{},
}
}

func customBasicPayload(transType wallet.SendType, tokenIdentity string) dataPayload {
payload := basicPayload()
payload.transferType = transType
payload.tokenIdentity = tokenIdentity
return payload
}

func erc721Payload(tokenIdentity string) dataPayload {
return customBasicPayload(wallet.ERC721Transfer, tokenIdentity)
}

func erc1155Payload(tokenIdentity string) dataPayload {
return customBasicPayload(wallet.ERC1155Transfer, tokenIdentity)
}

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*/

tests := []struct {
name string
data dataPayload
}{
{"ERC721", erc721Payload("0x9f64932be34d5d897c4253d17707b50921f372b6:37")},
{"ERC1155", erc1155Payload("0x1ed60fedff775d500dde21a974cd4e92e0047cc8:32")},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, close := setupAccountsAndTransactions(t)
defer close()

payload := dataToCallingPayload(tt.data)
res, err := helpers.CallPrivateMethodAndGetT[wallet.SuggestedRoutes]("wallet_getSuggestedRoutes", payload)
require.NoError(t, err)
require.Greater(t, len(res.Candidates), 0)
})
}
//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)
}

0 comments on commit 450bed0

Please sign in to comment.