Skip to content

Commit

Permalink
test cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Feb 9, 2024
1 parent 6d3081d commit 839955f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions rpc/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package rpc

import (
"context"
"encoding/json"
"flag"
"fmt"
"math/big"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -211,3 +214,44 @@ func TestSyncing(t *testing.T) {

}
}

func TestCookieManagement(t *testing.T) {
// Don't return anything unless cookie is set.
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if _, err := r.Cookie("session_id"); err == http.ErrNoCookie {
http.SetCookie(w, &http.Cookie{
Name: "session_id",
Value: "12345",
Path: "/",
})
} else {
var result string
err := mock_starknet_chainId(&result, "")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"result": result,
})
}
}))
defer server.Close()

client, err := NewProvider(server.URL)
require.Nil(t, err)

resp, err := client.ChainID(context.Background())
require.NotNil(t, err)
require.Equal(t, resp, "")

resp, err = client.ChainID(context.Background())
require.Nil(t, err)
require.Equal(t, resp, "SN_GOERLI")

resp, err = client.ChainID(context.Background())
require.Nil(t, err)
require.Equal(t, resp, "SN_GOERLI")
}

0 comments on commit 839955f

Please sign in to comment.