diff --git a/integration/manualtests/connection_test.go b/integration/manualtests/connection_test.go index 37a19e11fe..00bf8d46ec 100644 --- a/integration/manualtests/connection_test.go +++ b/integration/manualtests/connection_test.go @@ -11,40 +11,46 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/obscuronet/go-obscuro/tools/walletextension/common" "github.com/stretchr/testify/require" - "github.com/valyala/fasthttp" "io" "log" "net/http" - "os" "strings" "testing" + "time" ) func TestSubscribeToOG(t *testing.T) { - if os.Getenv(_IDEFlag) == "" { - t.Skipf("set flag %s to run this test in the IDE", _IDEFlag) - } - + //if os.Getenv(_IDEFlag) == "" { + // t.Skipf("set flag %s to run this test in the IDE", _IDEFlag) + //} + // Using http - ogHTTPAddress := "dev-testnet.obscu.ro:443" + //ogHTTPAddress := "dev-testnet.obscu.ro:443" ogWSAddress := "dev-testnet.obscu.ro:81" - - // join the network - statusCode, body, err := fasthttp.Get(nil, fmt.Sprintf("https://%s/join/", ogHTTPAddress)) - require.NoError(t, err) // dialing to the given TCP address timed out - fmt.Println(statusCode) - fmt.Println(body) - - // sign the message - messagePayload := signMessage(string(body)) - - // register an account - body, err = registerAccount(ogHTTPAddress, messagePayload) - require.NoError(t, err) - fmt.Println(body) + //ogWSAddress := "51.132.131.47:81" + + //// join the network + //statusCode, userID, err := fasthttp.Get(nil, fmt.Sprintf("https://%s/v1/join/", ogHTTPAddress)) + //require.NoError(t, err) // dialing to the given TCP address timed out + //fmt.Println(statusCode) + //fmt.Println(userID) + // + //// sign the message + //messagePayload := signMessage(string(userID)) + // + //// register an account + //var regAccountResp []byte + //regAccountResp, err = registerAccount(ogHTTPAddress, string(userID), messagePayload) + //require.NoError(t, err) + //fmt.Println(regAccountResp) // Using WS -> + for i := 0; i < 50; i++ { + ethclient.Dial("ws://" + ogWSAddress) + time.Sleep(100 * time.Millisecond) + } + // Connect to WebSocket server using the standard geth client client, err := ethclient.Dial("ws://" + ogWSAddress) require.NoError(t, err) @@ -80,11 +86,11 @@ func TestSubscribeToOG(t *testing.T) { } } -func registerAccount(baseAddress, payload string) ([]byte, error) { +func registerAccount(baseAddress, userID, payload string) ([]byte, error) { req, err := http.NewRequestWithContext( context.Background(), http.MethodPost, - "https://"+baseAddress+"/authenticate/", + "https://"+baseAddress+"/authenticate/?u="+userID, strings.NewReader(payload), ) if err != nil { diff --git a/tools/walletextension/api/server.go b/tools/walletextension/api/server.go index a8e5a2963f..0b7684c16a 100644 --- a/tools/walletextension/api/server.go +++ b/tools/walletextension/api/server.go @@ -2,7 +2,6 @@ package api import ( "context" - "crypto/tls" "embed" "fmt" "io/fs" @@ -89,10 +88,5 @@ func createWSServer(address string, routes []Route) *http.Server { serveMux.HandleFunc(route.Name, route.Func) } - return &http.Server{ - Addr: address, - Handler: serveMux, - ReadHeaderTimeout: 10 * time.Second, - TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)), - } + return &http.Server{Addr: address, Handler: serveMux, ReadHeaderTimeout: 10 * time.Second} } diff --git a/tools/walletextension/userconn/user_conn.go b/tools/walletextension/userconn/user_conn.go index a733a1d9a2..c8b228fdd5 100644 --- a/tools/walletextension/userconn/user_conn.go +++ b/tools/walletextension/userconn/user_conn.go @@ -139,7 +139,7 @@ func (w *userConnWS) WriteResponse(msg []byte) error { // HandleError logs and prints the error, and writes it to the websocket as a JSON object with a single key, "error". func (w *userConnWS) HandleError(msg string) { - w.logger.Error(msg) + w.logger.Error("error in user WS connection - " + msg) errMsg, err := json.Marshal(map[string]interface{}{ common.JSONKeyErr: msg,