mirror of
https://github.com/grassrootseconomics/cic-chain-events.git
synced 2024-11-22 07:46:46 +01:00
Mohamed Sohail
20fc30c34a
* feat: init base logic for rpc fetcher * feat: rpc block fetcher, move filters to internal * move filters to internal folder * rpc block fetcher * add benchmarks: goos: linux goarch: amd64 pkg: github.com/grassrootseconomics/cic-chain-events/pkg/fetch cpu: AMD EPYC Processor Benchmark_RPC Benchmark_RPC/RPC_Block_Fetcher_Benchmark Benchmark_RPC/RPC_Block_Fetcher_Benchmark-4 25 46000646 ns/op 221697 B/op 844 allocs/op Benchmark_GraphQL Benchmark_GraphQL/GraphQL_Block_Fetcher_Benchmark Benchmark_GraphQL/GraphQL_Block_Fetcher_Benchmark-4 56 21219962 ns/op 56686 B/op 94 allocs/op PASS ok github.com/grassrootseconomics/cic-chain-events/pkg/fetch 2.920s * inline-docs: Describe RPC fetcher
50 lines
904 B
Go
50 lines
904 B
Go
package fetch
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
celo "github.com/grassrootseconomics/cic-celo-sdk"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
var (
|
|
rpcEndpoint = os.Getenv("TEST_RPC_ENDPOINT")
|
|
)
|
|
|
|
type RPCTestSuite struct {
|
|
suite.Suite
|
|
fetch Fetch
|
|
}
|
|
|
|
func (s *RPCTestSuite) SetupSuite() {
|
|
celoProvider, err := celo.NewProvider(celo.ProviderOpts{
|
|
ChainId: celo.MainnetChainId,
|
|
RpcEndpoint: rpcEndpoint,
|
|
})
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
s.fetch = NewRPCFetcher(RPCOpts{
|
|
RPCProvider: celoProvider,
|
|
})
|
|
}
|
|
|
|
func (s *RPCTestSuite) Test_E2E_Fetch_Existing_Block() {
|
|
resp, err := s.fetch.Block(context.Background(), 14974600)
|
|
s.NoError(err)
|
|
s.Len(resp.Data.Block.Transactions, 3)
|
|
}
|
|
|
|
func (s *RPCTestSuite) Test_E2E_Fetch_Non_Existing_Block() {
|
|
_, err := s.fetch.Block(context.Background(), 14974600000)
|
|
s.Error(err)
|
|
}
|
|
|
|
func TestRPCSuite(t *testing.T) {
|
|
suite.Run(t, new(RPCTestSuite))
|
|
}
|