| 298 | } |
| 299 | |
| 300 | func SetupMocksForUpstream(host string, details map[string]interface{}) int { |
| 301 | if details == nil { |
| 302 | details = make(map[string]interface{}) |
| 303 | } |
| 304 | if _, ok := details["chainId"]; !ok { |
| 305 | details["chainId"] = "0x7b" |
| 306 | } |
| 307 | gock.New(host). |
| 308 | Post(""). |
| 309 | Persist(). |
| 310 | Filter(func(request *http.Request) bool { |
| 311 | return strings.Contains(SafeReadBody(request), "eth_chainId") |
| 312 | }). |
| 313 | Reply(200). |
| 314 | JSON([]byte(fmt.Sprintf(`{"result":"%s","_note":"detectFeatures expected mock for eth_chainId"}`, details["chainId"]))) |
| 315 | |
| 316 | if _, ok := details["latestBlock"]; !ok { |
| 317 | details["latestBlock"] = "0x33338888" |
| 318 | } |
| 319 | gock.New(host). |
| 320 | Post(""). |
| 321 | Persist(). |
| 322 | Filter(func(request *http.Request) bool { |
| 323 | return strings.Contains(SafeReadBody(request), "eth_getBlockByNumber") && (strings.Contains(SafeReadBody(request), "latest") || strings.Contains(SafeReadBody(request), details["latestBlock"].(string))) |
| 324 | }). |
| 325 | Reply(200). |
| 326 | JSON([]byte(fmt.Sprintf(`{"result":{"number":"%s"},"_note":"evm state poller expected mock for latest block"}`, details["latestBlock"]))) |
| 327 | |
| 328 | if _, ok := details["finalizedBlock"]; !ok { |
| 329 | details["finalizedBlock"] = "0x33337777" |
| 330 | } |
| 331 | gock.New(host). |
| 332 | Post(""). |
| 333 | Persist(). |
| 334 | Filter(func(request *http.Request) bool { |
| 335 | return strings.Contains(SafeReadBody(request), "eth_getBlockByNumber") && (strings.Contains(SafeReadBody(request), "finalized") || strings.Contains(SafeReadBody(request), details["finalizedBlock"].(string))) |
| 336 | }). |
| 337 | Reply(200). |
| 338 | JSON([]byte(fmt.Sprintf(`{"result":{"number":"%s"},"_note":"evm state poller expected mock for finalized block"}`, details["finalizedBlock"]))) |
| 339 | |
| 340 | if _, ok := details["syncing"]; !ok { |
| 341 | details["syncing"] = false |
| 342 | } |
| 343 | gock.New(host). |
| 344 | Post(""). |
| 345 | Persist(). |
| 346 | Filter(func(request *http.Request) bool { |
| 347 | return strings.Contains(SafeReadBody(request), "eth_syncing") |
| 348 | }). |
| 349 | Reply(200). |
| 350 | JSON([]byte(fmt.Sprintf(`{"result":%v,"_note":"evm state poller expected mock for eth_syncing"}`, details["syncing"]))) |
| 351 | |
| 352 | return 4 |
| 353 | } |
| 354 | |
| 355 | func ResetGock() { |
| 356 | time.Sleep(100 * time.Millisecond) |