Skip to content

Commit

Permalink
End-to-end indexer test (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Wellington Barbosa <[email protected]>
Signed-off-by: Wellington Barbosa <[email protected]>
Co-authored-by: Wellington Barbosa <[email protected]>
Co-authored-by: Wellington Barbosa <[email protected]>
  • Loading branch information
3 people authored Jun 19, 2023
1 parent fbe5c2f commit 498ff60
Show file tree
Hide file tree
Showing 21 changed files with 593 additions and 234 deletions.
12 changes: 0 additions & 12 deletions common/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,24 @@ type EthClient interface {
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
BlockNumber(ctx context.Context) (uint64, error)
CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
ChainID(ctx context.Context) (*big.Int, error)
Close()
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
NetworkID(ctx context.Context) (*big.Int, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
PeerCount(ctx context.Context) (uint64, error)
PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
PendingTransactionCount(ctx context.Context) (uint, error)
SendTransaction(ctx context.Context, tx *types.Transaction) error
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
}
70 changes: 0 additions & 70 deletions common/mock/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,12 @@ func (mock *MockEthClient) BlockByNumber(ctx context.Context, number *big.Int) (
return result.(*types.Block), args.Error(1)
}

func (mock *MockEthClient) BlockNumber(ctx context.Context) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) ChainID(ctx context.Context) (*big.Int, error) {
args := mock.Called()
result := args.Get(0)
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) Close() {
mock.Called()
}

func (mock *MockEthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
Expand All @@ -72,12 +50,6 @@ func (mock *MockEthClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) {
args := mock.Called()
result := args.Get(0)
return result.(*ethereum.FeeHistory), args.Error(1)
}

func (mock *MockEthClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
args := mock.Called()
result := args.Get(0)
Expand All @@ -96,30 +68,12 @@ func (mock *MockEthClient) HeaderByNumber(ctx context.Context, number *big.Int)
return result.(*types.Header), args.Error(1)
}

func (mock *MockEthClient) NetworkID(ctx context.Context) (*big.Int, error) {
args := mock.Called()
result := args.Get(0)
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PeerCount(ctx context.Context) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) {
args := mock.Called()
result := args.Get(0)
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
Expand All @@ -138,18 +92,6 @@ func (mock *MockEthClient) PendingNonceAt(ctx context.Context, account common.Ad
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) PendingTransactionCount(ctx context.Context) (uint, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint), args.Error(1)
}

func (mock *MockEthClient) SendTransaction(ctx context.Context, tx *types.Transaction) error {
args := mock.Called()
return args.Error(0)
Expand Down Expand Up @@ -185,12 +127,6 @@ func (mock *MockEthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, erro
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
args := mock.Called()
result := args.Get(0)
return result.(*ethereum.SyncProgress), args.Error(1)
}

func (mock *MockEthClient) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) {
args := mock.Called()
result1 := args.Get(0)
Expand All @@ -215,9 +151,3 @@ func (mock *MockEthClient) TransactionReceipt(ctx context.Context, txHash common
result := args.Get(0)
return result.(*types.Receipt), args.Error(1)
}

func (mock *MockEthClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) {
args := mock.Called()
result := args.Get(0)
return result.(common.Address), args.Error(1)
}
42 changes: 0 additions & 42 deletions common/mock/rpc_ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,3 @@ func (mock *MockRPCEthClient) CallContext(ctx context.Context, result interface{
mokcArgs := mock.Called(args...)
return mokcArgs.Error(0)
}

func (mock *MockRPCEthClient) Close() {
mock.Called()
}

func (mock *MockRPCEthClient) EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
mokcArgs := mock.Called()
result := mokcArgs.Get(0)
return result.(*rpc.ClientSubscription), mokcArgs.Error(1)
}

func (mock *MockRPCEthClient) Notify(ctx context.Context, method string, args ...interface{}) error {
mokcArgs := mock.Called()
return mokcArgs.Error(0)
}

func (mock *MockRPCEthClient) RegisterName(name string, receiver interface{}) error {
args := mock.Called()
return args.Error(0)
}

func (mock *MockRPCEthClient) SetHeader(key string, value string) {
mock.Called()
}

func (mock *MockRPCEthClient) ShhSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
mokcArgs := mock.Called()
result := mokcArgs.Get(0)
return result.(*rpc.ClientSubscription), mokcArgs.Error(1)
}

func (mock *MockRPCEthClient) Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
mokcArgs := mock.Called()
result := mokcArgs.Get(0)
return result.(*rpc.ClientSubscription), mokcArgs.Error(1)
}

func (mock *MockRPCEthClient) SupportedModules() (map[string]string, error) {
args := mock.Called()
result := args.Get(0)
return result.(map[string]string), args.Error(1)
}
8 changes: 0 additions & 8 deletions common/rpc_ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,4 @@ type RPCEthClient interface {
BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
Call(result interface{}, method string, args ...interface{}) error
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
Close()
EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
Notify(ctx context.Context, method string, args ...interface{}) error
RegisterName(name string, receiver interface{}) error
SetHeader(key string, value string)
ShhSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
SupportedModules() (map[string]string, error)
}
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/ethereum/go-ethereum v1.10.26
github.com/onsi/ginkgo/v2 v2.9.7
github.com/onsi/gomega v1.27.7
github.com/rs/zerolog v1.29.1
github.com/stretchr/testify v1.8.3
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Expand All @@ -18,25 +17,27 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
Expand All @@ -54,6 +55,7 @@ require (
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
Loading

0 comments on commit 498ff60

Please sign in to comment.