Skip to content

Commit

Permalink
fix: added new people limit and used that for loading people (#1075)
Browse files Browse the repository at this point in the history
* fix: added new people limit and used that for loading people

* added tests for randstring and GetNodePubkey
  • Loading branch information
kevkevinpal authored Dec 11, 2023
1 parent bc0e4ca commit 2d7ac1c
Show file tree
Hide file tree
Showing 6 changed files with 1,400 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install cover
- name: Install cover
run: go get golang.org/x/tools/cmd/cover
- name: Tests
run: go test ./config ./auth ./db ./handlers ./routes ./utils -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out 2.9
10 changes: 9 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ func GetNodePubKey() string {
client := &http.Client{}
req, err := http.NewRequest(http.MethodGet, url, nil)

if err != nil {
log.Printf("Request Failed: %s", err)
}

req.Header.Set("x-user-token", RelayAuthKey)
req.Header.Set("Content-Type", "application/json")
res, _ := client.Do(req)
res, err := client.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
Expand All @@ -209,6 +213,10 @@ func GetNodePubKey() string {
defer res.Body.Close()
body, err := io.ReadAll(res.Body)

if err != nil {
log.Printf("Request Failed: %s", err)
}

if isProxy {
proxyContacts := ProxyContacts{}
err = json.Unmarshal(body, &proxyContacts)
Expand Down
51 changes: 50 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package config

import "testing"
import (
"fmt"
"github.com/h2non/gock"
"os"
"testing"
)

func TestInitConfig(t *testing.T) {
InitConfig()
Expand All @@ -16,4 +21,48 @@ func TestInitConfig(t *testing.T) {
if JwtKey == "" {
t.Error("Could not load random jwtKey")
}

if RelayAuthKey != "" {
t.Error("Could not load RelayAuthKey")
}
}

func TestGenerateRandomString(t *testing.T) {

testRandString := GenerateRandomString()

if testRandString == "" {
t.Error("randstring should not be empty")
}

if len(testRandString) < 24 {
t.Error("randstring cannot be less than length 24")
}
if len(testRandString) > 24 {
t.Error("randstring cannot be greater than lenght 24")
}
}

func TestGetNodePubKey(t *testing.T) {
defer gock.Off()

//response := map[string]string{"identity_pubkey": "1234"}
//success := map[string]bool{"success": true}
response := NodeGetInfoResponse{IdentityPubkey: "1234"}
nodeGetInfo := NodeGetInfo{Success: true, Response: response}

gock.New("https://relay.com").
Get("/getinfo").
Persist().
Reply(200).
JSON(nodeGetInfo)

os.Setenv("RELAY_URL", "https://relay.com")
InitConfig()
nodePubKey := GetNodePubKey()
fmt.Print(nodePubKey)
if nodePubKey != "1234" {
t.Error("Node pubkey is incorrect")
}

}
3 changes: 2 additions & 1 deletion frontend/app/src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { uiStore } from './ui';
import { getUserAvatarPlaceholder } from './lib';

export const queryLimit = 10;
export const peopleQueryLimit = 500;

function makeTorSaveURL(host: string, key: string) {
return `sphinx.chat://?action=save&host=${host}&key=${key}`;
Expand Down Expand Up @@ -699,7 +700,7 @@ export class MainStore {
})
private async fetchPeople(search: string, queryParams?: any): Promise<Person[]> {
const params = { ...queryParams, search };
const query = this.appendQueryParams('people', queryLimit, {
const query = this.appendQueryParams('people', peopleQueryLimit, {
...params,
sortBy: 'last_login'
});
Expand Down
55 changes: 19 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,29 @@ module github.com/stakwork/sphinx-tribes
go 1.2

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/ambelovsky/go-structs v1.1.0 // indirect
github.com/ambelovsky/gosf v0.0.0-20201109201340-237aea4d6109
github.com/ambelovsky/gosf-socketio v0.0.0-20220810204405-0f97832ec7af // indirect
github.com/DATA-DOG/go-sqlmock v1.5.1
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/lru v1.1.2 // indirect
github.com/fiatjaf/go-lnurl v1.12.1
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3
github.com/fiatjaf/go-lnurl v1.13.1
github.com/form3tech-oss/jwt-go v3.2.5+incompatible
github.com/go-chi/chi v4.1.1+incompatible
github.com/go-chi/chi v1.5.5
github.com/go-chi/jwtauth v1.2.0
github.com/go-co-op/gocron v1.25.0
github.com/go-errors/errors v1.5.1 // indirect
github.com/gobuffalo/logger v1.0.4 // indirect
github.com/gobuffalo/packr/v2 v2.8.1
github.com/gobuffalo/packr/v2 v2.8.3
github.com/google/go-github/v39 v39.2.0
github.com/gorilla/websocket v1.5.0
github.com/imroc/req v0.3.0
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jinzhu/gorm v1.9.12
github.com/joho/godotenv v1.3.0
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/lib/pq v1.10.7
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lnd v0.17.0-beta.rc6 // indirect
github.com/lightningnetwork/lnd/tor v1.1.3 // indirect
github.com/miekg/dns v1.1.56 // indirect
github.com/nbd-wtf/ln-decodepay v1.11.1 // indirect
github.com/gorilla/websocket v1.5.1
github.com/h2non/gock v1.2.0
github.com/imroc/req v0.3.2
github.com/jinzhu/gorm v1.9.16
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/nbd-wtf/ln-decodepay v1.11.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/rs/cors v1.7.0
github.com/rs/xid v1.4.0
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/oauth2 v0.4.0
google.golang.org/api v0.112.0
gorm.io/driver/postgres v1.5.0
gorm.io/gorm v1.25.0
github.com/rs/cors v1.10.1
github.com/rs/xid v1.5.0
github.com/stretchr/testify v1.8.4
golang.org/x/oauth2 v0.15.0
google.golang.org/api v0.153.0
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

replace google.golang.org/api => google.golang.org/api v0.63.0
Loading

0 comments on commit 2d7ac1c

Please sign in to comment.