2022-09-01 21:21:53 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/lbryio/herald.go/db"
|
|
|
|
"github.com/lbryio/lbcd/chaincfg"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetChunk(t *testing.T) {
|
|
|
|
dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb"
|
|
|
|
// dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
|
|
|
secondaryPath := "asdf"
|
|
|
|
db, toDefer, err := db.GetProdDB(dbPath, secondaryPath)
|
|
|
|
defer toDefer()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("DB not found")
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-07 20:49:34 +02:00
|
|
|
s := &BlockchainService{
|
2022-09-01 21:21:53 +02:00
|
|
|
DB: db,
|
|
|
|
Chain: &chaincfg.MainNetParams,
|
|
|
|
}
|
|
|
|
|
|
|
|
for index := 0; index < 10; index++ {
|
2022-09-07 20:49:34 +02:00
|
|
|
req := BlockGetChunkReq(index)
|
|
|
|
var resp *blockGetChunkResp
|
|
|
|
err := s.Get_chunk(nil, &req, &resp)
|
2022-09-01 21:21:53 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("index: %v handler err: %v", index, err)
|
|
|
|
}
|
|
|
|
marshalled, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("index: %v unmarshal err: %v", index, err)
|
|
|
|
}
|
|
|
|
t.Logf("index: %v resp: %v", index, string(marshalled))
|
|
|
|
if len(*resp) != (CHUNK_SIZE * HEADER_SIZE * 2) {
|
|
|
|
t.Errorf("index: %v bad length: %v", index, len(*resp))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetHeader(t *testing.T) {
|
|
|
|
dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb"
|
|
|
|
// dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
|
|
|
secondaryPath := "asdf"
|
|
|
|
db, toDefer, err := db.GetProdDB(dbPath, secondaryPath)
|
|
|
|
defer toDefer()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("DB not found")
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-07 20:49:34 +02:00
|
|
|
s := &BlockchainService{
|
2022-09-01 21:21:53 +02:00
|
|
|
DB: db,
|
|
|
|
Chain: &chaincfg.MainNetParams,
|
|
|
|
}
|
|
|
|
|
|
|
|
for height := 1000; height < 1010; height++ {
|
2022-09-07 20:49:34 +02:00
|
|
|
req := BlockGetHeaderReq(height)
|
|
|
|
var resp *BlockGetHeaderResp
|
|
|
|
err := s.Get_header(nil, &req, &resp)
|
2022-09-01 21:21:53 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("height: %v handler err: %v", height, err)
|
|
|
|
}
|
|
|
|
marshalled, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("height: %v unmarshal err: %v", height, err)
|
|
|
|
}
|
|
|
|
t.Logf("height: %v resp: %v", height, string(marshalled))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBalance(t *testing.T) {
|
|
|
|
dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb"
|
|
|
|
// dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
|
|
|
secondaryPath := "asdf"
|
|
|
|
db, toDefer, err := db.GetProdDB(dbPath, secondaryPath)
|
|
|
|
defer toDefer()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("DB not found")
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-07 20:49:34 +02:00
|
|
|
s := &BlockchainAddressService{
|
|
|
|
BlockchainService{
|
|
|
|
DB: db,
|
|
|
|
Chain: &chaincfg.MainNetParams,
|
|
|
|
},
|
2022-09-01 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addrs := []string{
|
|
|
|
"bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG",
|
|
|
|
"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, addr := range addrs {
|
2022-09-07 20:49:34 +02:00
|
|
|
req := AddressGetBalanceReq{addr}
|
|
|
|
var resp *AddressGetBalanceResp
|
|
|
|
err := s.Get_balance(nil, &req, &resp)
|
2022-09-01 21:21:53 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v handler err: %v", addr, err)
|
|
|
|
}
|
|
|
|
marshalled, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v unmarshal err: %v", addr, err)
|
|
|
|
}
|
|
|
|
t.Logf("address: %v resp: %v", addr, string(marshalled))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetHistory(t *testing.T) {
|
|
|
|
dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb"
|
|
|
|
// dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
|
|
|
secondaryPath := "asdf"
|
|
|
|
db, toDefer, err := db.GetProdDB(dbPath, secondaryPath)
|
|
|
|
defer toDefer()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("DB not found")
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-07 20:49:34 +02:00
|
|
|
s := &BlockchainAddressService{
|
|
|
|
BlockchainService{
|
|
|
|
DB: db,
|
|
|
|
Chain: &chaincfg.MainNetParams,
|
|
|
|
},
|
2022-09-01 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addrs := []string{
|
|
|
|
"bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG",
|
|
|
|
"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, addr := range addrs {
|
2022-09-07 20:49:34 +02:00
|
|
|
req := AddressGetHistoryReq{addr}
|
|
|
|
var resp *AddressGetHistoryResp
|
|
|
|
err := s.Get_history(nil, &req, &resp)
|
2022-09-01 21:21:53 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v handler err: %v", addr, err)
|
|
|
|
}
|
|
|
|
marshalled, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v unmarshal err: %v", addr, err)
|
|
|
|
}
|
|
|
|
t.Logf("address: %v resp: %v", addr, string(marshalled))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListUnspent(t *testing.T) {
|
|
|
|
dbPath := "/Users/swdev1/hub/scribe_db.599529/lbry-rocksdb"
|
|
|
|
// dbPath := "/mnt/d/data/snapshot_1072108/lbry-rocksdb/"
|
|
|
|
secondaryPath := "asdf"
|
|
|
|
db, toDefer, err := db.GetProdDB(dbPath, secondaryPath)
|
|
|
|
defer toDefer()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("DB not found")
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-07 20:49:34 +02:00
|
|
|
s := &BlockchainAddressService{
|
|
|
|
BlockchainService{
|
|
|
|
DB: db,
|
|
|
|
Chain: &chaincfg.MainNetParams,
|
|
|
|
},
|
2022-09-01 21:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addrs := []string{
|
|
|
|
"bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG",
|
|
|
|
"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, addr := range addrs {
|
2022-09-07 20:49:34 +02:00
|
|
|
req := AddressListUnspentReq{addr}
|
|
|
|
var resp *AddressListUnspentResp
|
|
|
|
err := s.Listunspent(nil, &req, &resp)
|
2022-09-01 21:21:53 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v handler err: %v", addr, err)
|
|
|
|
}
|
|
|
|
marshalled, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("address: %v unmarshal err: %v", addr, err)
|
|
|
|
}
|
|
|
|
t.Logf("address: %v resp: %v", addr, string(marshalled))
|
|
|
|
}
|
|
|
|
}
|