test(wallet) add dev integration tests for ERC1155 route estimator

Used for debugging ERC1155 route estimation issues

Updates: #14212
This commit is contained in:
Stefan 2024-04-01 11:33:28 +03:00 committed by Stefan Dunca
parent ad0a7d3ba4
commit 7e146d662d
1 changed files with 82 additions and 21 deletions

View File

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