MCPcopy Create free account
hub / github.com/erpc/erpc / TestHttpServer_ProviderBasedUpstreams

Function TestHttpServer_ProviderBasedUpstreams

erpc/http_server_test.go:4527–5091  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4525}
4526
4527func TestHttpServer_ProviderBasedUpstreams(t *testing.T) {
4528 t.Run("SimpleCallExistingNetwork", func(t *testing.T) {
4529 cfg := &common.Config{
4530 Server: &common.ServerConfig{
4531 MaxTimeout: common.Duration(5 * time.Second).Ptr(),
4532 },
4533 Projects: []*common.ProjectConfig{
4534 {
4535 Id: "test_project",
4536 Networks: []*common.NetworkConfig{
4537 {
4538 Architecture: common.ArchitectureEvm,
4539 Evm: &common.EvmNetworkConfig{
4540 ChainId: 123,
4541 },
4542 },
4543 },
4544 Providers: []*common.ProviderConfig{
4545 {
4546 Id: "alchemy-prod",
4547 Vendor: "alchemy",
4548 Settings: map[string]interface{}{
4549 "apiKey": "test-key",
4550 },
4551 UpstreamIdTemplate: "<PROVIDER>-<NETWORK>",
4552 },
4553 },
4554 },
4555 },
4556 }
4557
4558 util.ResetGock()
4559 defer util.ResetGock()
4560 _ = util.SetupMocksForUpstream("https://eth-mainnet.g.alchemy.com", map[string]interface{}{
4561 "chainId": "0x1",
4562 })
4563
4564 gock.New("https://eth-mainnet.g.alchemy.com").
4565 Post("/v2/test-key").
4566 Filter(func(request *http.Request) bool {
4567 return strings.Contains(util.SafeReadBody(request), "eth_getBalance")
4568 }).
4569 Reply(200).
4570 JSON(map[string]interface{}{
4571 "jsonrpc": "2.0",
4572 "id": 1,
4573 "result": "0x123456",
4574 })
4575
4576 sendRequest, _, _, shutdown, _ := createServerTestFixtures(cfg, t)
4577 defer shutdown()
4578
4579 statusCode, _, body := sendRequest(`{"jsonrpc":"2.0","method":"eth_getBalance","params":[],"id":1234}`, nil, map[string]string{
4580 "chainId": "1",
4581 })
4582 assert.Equal(t, http.StatusOK, statusCode)
4583 assert.Contains(t, body, "0x123456")
4584 })

Callers

nothing calls this directly

Calls 14

DurationTypeAlias · 0.92
ResetGockFunction · 0.92
SetupMocksForUpstreamFunction · 0.92
SafeReadBodyFunction · 0.92
NewStaticDurationFunction · 0.92
BoolPtrFunction · 0.92
IntPtrFunction · 0.92
createServerTestFixturesFunction · 0.85
PtrMethod · 0.80
GetNetworkUpstreamsMethod · 0.80
RunMethod · 0.65
ConfigMethod · 0.65

Tested by

no test coverage detected