You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

  1. package eth
  2. import (
  3. "fmt"
  4. "net/http"
  5. "strconv"
  6. "strings"
  7. )
  8. func addBlock(url string) {
  9. method := "POST"
  10. payload := strings.NewReader("{\n \"jsonrpc\":\"2.0\",\n \"method\":\"evm_mine\",\n \"params\":[],\n \"id\":1\n}")
  11. client := &http.Client{}
  12. req, err := http.NewRequest(method, url, payload)
  13. if err != nil {
  14. fmt.Println(err)
  15. }
  16. req.Header.Add("Content-Type", "application/json")
  17. res, err := client.Do(req)
  18. if err != nil {
  19. fmt.Println(err)
  20. }
  21. defer func() {
  22. if err := res.Body.Close(); err != nil {
  23. fmt.Println("Error when closing:", err)
  24. }
  25. }()
  26. }
  27. func addBlocks(numBlocks int64, url string) {
  28. for i := int64(0); i < numBlocks; i++ {
  29. addBlock(url)
  30. }
  31. }
  32. func addTime(seconds float64, url string) {
  33. secondsStr := strconv.FormatFloat(seconds, 'E', -1, 32)
  34. method := "POST"
  35. payload := strings.NewReader("{\n \"jsonrpc\":\"2.0\",\n \"method\":\"evm_increaseTime\",\n \"params\":[" + secondsStr + "],\n \"id\":1\n}")
  36. client := &http.Client{}
  37. req, err := http.NewRequest(method, url, payload)
  38. if err != nil {
  39. fmt.Println(err)
  40. }
  41. req.Header.Add("Content-Type", "application/json")
  42. res, err := client.Do(req)
  43. if err != nil {
  44. fmt.Println(err)
  45. }
  46. defer func() {
  47. if err := res.Body.Close(); err != nil {
  48. fmt.Println("Error when closing:", err)
  49. }
  50. }()
  51. }