eth_call batch integration tests

This commit is contained in:
pragmaxim
2026-01-22 10:12:28 +01:00
parent 8918eec72a
commit 8542377fa3
14 changed files with 127 additions and 169 deletions

View File

@@ -12,8 +12,10 @@ import (
"time"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common"
"github.com/juju/errors"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/eth"
)
var testMap = map[string]func(t *testing.T, th *TestHandler){
@@ -27,21 +29,31 @@ var testMap = map[string]func(t *testing.T, th *TestHandler){
"GetBestBlockHash": testGetBestBlockHash,
"GetBestBlockHeight": testGetBestBlockHeight,
"GetBlockHeader": testGetBlockHeader,
"EthCallBatch": testEthCallBatch,
}
type TestHandler struct {
Coin string
Chain bchain.BlockChain
Mempool bchain.Mempool
TestData *TestData
}
type EthCallBatchData struct {
Address string `json:"address"`
Contracts []string `json:"contracts"`
BatchSize int `json:"batchSize,omitempty"`
SkipUnavailable bool `json:"skipUnavailable,omitempty"`
}
type TestData struct {
BlockHeight uint32 `json:"blockHeight"`
BlockHash string `json:"blockHash"`
BlockTime int64 `json:"blockTime"`
BlockSize int `json:"blockSize"`
BlockTxs []string `json:"blockTxs"`
TxDetails map[string]*bchain.Tx `json:"txDetails"`
BlockHeight uint32 `json:"blockHeight"`
BlockHash string `json:"blockHash"`
BlockTime int64 `json:"blockTime"`
BlockSize int `json:"blockSize"`
BlockTxs []string `json:"blockTxs"`
TxDetails map[string]*bchain.Tx `json:"txDetails"`
EthCallBatch *EthCallBatchData `json:"ethCallBatch,omitempty"`
}
func IntegrationTest(t *testing.T, coin string, chain bchain.BlockChain, mempool bchain.Mempool, testConfig json.RawMessage) {
@@ -57,6 +69,7 @@ func IntegrationTest(t *testing.T, coin string, chain bchain.BlockChain, mempool
}
h := TestHandler{
Coin: coin,
Chain: chain,
Mempool: mempool,
TestData: td,
@@ -385,6 +398,39 @@ func testGetBlockHeader(t *testing.T, h *TestHandler) {
}
}
func testEthCallBatch(t *testing.T, h *TestHandler) {
data := h.TestData.EthCallBatch
if data == nil {
t.Fatal("ethCallBatch fixture missing")
}
if data.Address == "" {
t.Fatal("ethCallBatch.address missing")
}
if len(data.Contracts) == 0 {
t.Fatal("ethCallBatch.contracts missing")
}
cfg := bchain.LoadBlockchainCfg(t, h.Coin)
contracts := make([]common.Address, 0, len(data.Contracts))
for _, contract := range data.Contracts {
if contract == "" {
t.Fatal("ethCallBatch contract address missing")
}
contracts = append(contracts, common.HexToAddress(contract))
}
bchain.RunERC20BatchBalanceTest(t, bchain.ERC20BatchCase{
Name: h.Coin,
RPCURL: cfg.RpcUrl,
RPCURLWS: cfg.RpcUrlWs,
Addr: common.HexToAddress(data.Address),
Contracts: contracts,
BatchSize: data.BatchSize,
SkipUnavailable: data.SkipUnavailable,
NewClient: eth.NewERC20BatchIntegrationClient,
})
}
func getMempool(t *testing.T, h *TestHandler) []string {
txs, err := h.Chain.GetMempoolTransactions()
if err != nil {

View File

@@ -20,6 +20,15 @@
"0x4905c5f124342aa2f18e0db56f40328737b2f6ed230dbdd39b596ac660a0ca82",
"0xde9ac37615f9d13c957dac39ebf36ce58e14e0bed639911cb7422c7046cd8a76"
],
"ethCallBatch": {
"address": "0xf70da97812cb96acdf810712aa562db8dfa3dbef",
"contracts": [
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"0xFF970A61A04b1cA14834A43f5de4533eBDDB5CC8",
"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",
"0xDA10009cBD5D07dd0CeCc66161FC93D7c9000da1"
]
},
"txDetails": {
"0x67d497582571a24ba0c05079827159c34801d598120180c515162570ed0b775c": {
"txid": "0x67d497582571a24ba0c05079827159c34801d598120180c515162570ed0b775c",

View File

@@ -6,6 +6,17 @@
"blockTxs": [
"0x59a1c3ce0f901e71c4f1c88dc829e35d29ce900ae3a74366d16aedb4a2e33992"
],
"ethCallBatch": {
"address": "0x60aE616a2155Ee3d9A68541Ba4544862310933d4",
"contracts": [
"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
"0xA7D7079b0FEAD91F3e65f86E8915Cb59c1a4C664",
"0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
"0xd586e7f844cea2f87f50152665bcbc2c279d8d70",
"0x49D5c2BdFfac6Ce2BFdB6640F4F80f226bc10bAB",
"0x60781C2586D68229fde47564546784ab3fACA982"
]
},
"txDetails": {
"0x59a1c3ce0f901e71c4f1c88dc829e35d29ce900ae3a74366d16aedb4a2e33992": {
"txid": "0x59a1c3ce0f901e71c4f1c88dc829e35d29ce900ae3a74366d16aedb4a2e33992",

View File

@@ -511,6 +511,15 @@
"0x7cf686710921fbf4a07c8cff0df098402f75669d4ce42abc80742be909ee96f2",
"0xdf70c1ba36d74eef05c830b6c7a455c310ac2312d6fc9467cd53dc661f51a4bf"
],
"ethCallBatch": {
"address": "0x242E2d70d3AdC00a9eF23CeD6E88811fCefCA788",
"contracts": [
"0x4200000000000000000000000000000000000006",
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
"0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22"
]
},
"txDetails": {
"0xc4e604ee9f9efcf229aeaf28d0f691a14edfc422c1d97710a31153d69c765f2d": {
"txid": "0xc4e604ee9f9efcf229aeaf28d0f691a14edfc422c1d97710a31153d69c765f2d",

View File

@@ -7,6 +7,16 @@
"0x970fec39c96e92669d68ac2366ffe9dab7314eefc075f1db760a9792a8bffa12",
"0x05618ba2e7e98c6cb3a9d05e6e62c0983b430103c69f1045608e812730bd61fc"
],
"ethCallBatch": {
"address": "0x21d45650db732cE5dF77685d6021d7D5d1da807f",
"contracts": [
"0xBB4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
"0x55d398326f99059fF775485246999027B3197955",
"0xe9e7CEA3Dedca5984780Bafc599bd69ADd087d56",
"0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
"0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3"
]
},
"txDetails": {
"0x970fec39c96e92669d68ac2366ffe9dab7314eefc075f1db760a9792a8bffa12": {
"txid": "0x970fec39c96e92669d68ac2366ffe9dab7314eefc075f1db760a9792a8bffa12",

View File

@@ -86,6 +86,15 @@
"0x78e650563f2d2171a5d0b7612550ce27eda81ec6f99fb359f26e825dcce5a1cf",
"0xb3762c6d6dd5a0b82ab270a8474accb6b3b5b5abe3fd7ea42b60594a2394708b"
],
"ethCallBatch": {
"address": "0x28C6c06298d514Db089934071355E5743bf21d60",
"contracts": [
"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"0xdAC17F958D2ee523a2206206994597C13D831ec7",
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"0x6B175474E89094C44Da98b954EedeAC495271d0F"
]
},
"txDetails": {
"0x3860498da623c650b1840b5137b1c2b689dfb2ce3bfb4b5d55c629ed8a99e81f": {
"txid": "0x3860498da623c650b1840b5137b1c2b689dfb2ce3bfb4b5d55c629ed8a99e81f",

View File

@@ -81,6 +81,16 @@
"0x041a2ee70fb75d9e9ca52447372d460151613fdcab200f0070deaec7349731d3",
"0xa98dc5f46b0b84a0db0633a440069c2cdf834a2531f8fc0c7e98ba672095e60f"
],
"ethCallBatch": {
"address": "0xDF90C9B995a3b10A5b8570a47101e6c6a29eb945",
"contracts": [
"0x4200000000000000000000000000000000000006",
"0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
"0x94b008aa00579c1307b0ef2c499ad98a8ce58e58",
"0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
"0x4200000000000000000000000000000000000042"
]
},
"txDetails": {
"0x30d76e1114ab8b7f7d4309f099e756987180d3a760d4a9fea80487e06d7206ec": {
"txid": "0x30d76e1114ab8b7f7d4309f099e756987180d3a760d4a9fea80487e06d7206ec",

View File

@@ -145,6 +145,16 @@
"0x63272bc328fe505cb9462e8555e309a4eec9d4110b3a89371614567789a68875",
"0xc948a4163f649e81b74913ee365c24942ede77d7ac056beb7fe8bc1760834698"
],
"ethCallBatch": {
"address": "0x501c43b2510da0ca6572e05b479e530ce3985646",
"contracts": [
"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
"0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063"
]
},
"txDetails": {
"0xa1d596e7e0dbe5576f5f4c5dbefe91b241aa91a6a31cd8ad6f0ae8117f4fde10": {
"txid": "0xa1d596e7e0dbe5576f5f4c5dbefe91b241aa91a6a31cd8ad6f0ae8117f4fde10",

View File

@@ -1,6 +1,6 @@
{
"avalanche": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"bcash": {
@@ -52,7 +52,7 @@
"sync": ["ConnectBlocksParallel", "ConnectBlocks", "HandleFork"]
},
"bsc": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"bsc_archive": {
@@ -253,23 +253,23 @@
"sync": ["ConnectBlocksParallel", "ConnectBlocks", "HandleFork"]
},
"arbitrum": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"base": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"ethereum": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"optimism": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
},
"polygon": {
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader"],
"rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "EstimateFee", "GetBlockHeader", "EthCallBatch"],
"evm_connectivity": true
}
}