Commit 49ab9c86 authored by Mark Tyneway's avatar Mark Tyneway Committed by Liam Horne

l2geth: test errors returning from remote

parent 648392e0
package rollup package rollup
import ( import (
"errors"
"fmt" "fmt"
"math/big" "math/big"
"testing" "testing"
...@@ -8,8 +9,9 @@ import ( ...@@ -8,8 +9,9 @@ import (
"github.com/jarcoal/httpmock" "github.com/jarcoal/httpmock"
) )
const url = "http://localhost:9999"
func TestRollupClientGetL1GasPrice(t *testing.T) { func TestRollupClientGetL1GasPrice(t *testing.T) {
url := "http://localhost:9999"
endpoint := fmt.Sprintf("%s/eth/gasprice", url) endpoint := fmt.Sprintf("%s/eth/gasprice", url)
// url/chain-id does not matter, we'll mock the responses // url/chain-id does not matter, we'll mock the responses
client := NewClient(url, big.NewInt(1)) client := NewClient(url, big.NewInt(1))
...@@ -41,3 +43,28 @@ func TestRollupClientGetL1GasPrice(t *testing.T) { ...@@ -41,3 +43,28 @@ func TestRollupClientGetL1GasPrice(t *testing.T) {
t.Fatal("gasPrice is not parsed properly in the client") t.Fatal("gasPrice is not parsed properly in the client")
} }
} }
func TestRollupClientCannotConnect(t *testing.T) {
endpoint := fmt.Sprintf("%s/eth/context/latest", url)
client := NewClient(url, big.NewInt(1))
httpmock.ActivateNonDefault(client.client.GetClient())
response, _ := httpmock.NewJsonResponder(
400,
map[string]interface{}{},
)
httpmock.RegisterResponder(
"GET",
endpoint,
response,
)
context, err := client.GetLatestEthContext()
if context != nil {
t.Fatal("returned value is not nil")
}
if !errors.Is(err, errHTTPError) {
t.Fatalf("Incorrect error returned: %s", err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment