Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Sep 22, 2023
1 parent bbb1f89 commit f9a78b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
52 changes: 29 additions & 23 deletions integration/manualtests/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 1 addition & 7 deletions tools/walletextension/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"crypto/tls"
"embed"
"fmt"
"io/fs"
Expand Down Expand Up @@ -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}
}
2 changes: 1 addition & 1 deletion tools/walletextension/userconn/user_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f9a78b8

Please sign in to comment.