Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Add integration tests for mainnet #21

Draft
wants to merge 1 commit into
base: n0cte-inttest
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions test/mainnet_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package test

import (
"encoding/json"
"io/ioutil"
"net/http"
"strings"
"testing"
)

func getDataFromTheGraph() (map[string]map[string][]struct {
ID string
Key string
Value string
}, error) {
res, err := http.Post("https://api.thegraph.com/subgraphs/name/ramilexe/blocknumstorage", "application/json", strings.NewReader(`
{
"query": "{\n syncs(first: 5) {\n id\n key\n value\n }\n storageSets(first: 5) {\n id\n key\n value\n }\n}\n",
"variables": null
}
`))
if err != nil {
return nil, err
}
defer res.Body.Close()

jsonData, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}

var data map[string]map[string][]struct {
ID string
Key string
Value string
}
if err := json.Unmarshal(jsonData, &data); err != nil {
return nil, err
}

return data, nil
}

func TestMainnet(t *testing.T) {
t.Log("Get data from api.thegraph.com")
theGraphData, err := getDataFromTheGraph()
if err != nil {
t.Fatalf(" error: %s", err)
}
if theGraphData == nil || theGraphData["data"] == nil {
t.Fatalf(" data must not be empty")
}
if theGraphData["data"]["storageSets"] == nil || theGraphData["data"]["syncs"] == nil {
t.Fatalf(" 'storageSets' and 'syncs' must not be empty")
}
t.Log(" ok")
}