2017-09-12 18:04:45 +02:00
|
|
|
package jsonrpc
|
|
|
|
|
|
|
|
import (
|
2019-01-22 18:48:04 +01:00
|
|
|
"encoding/json"
|
2019-01-17 21:38:45 +01:00
|
|
|
"fmt"
|
2019-09-25 12:47:12 +02:00
|
|
|
"math/rand"
|
2019-05-28 18:29:14 +02:00
|
|
|
"os"
|
2019-01-17 21:38:45 +01:00
|
|
|
"strconv"
|
2019-05-21 19:12:00 +02:00
|
|
|
"strings"
|
2017-09-12 18:04:45 +02:00
|
|
|
"testing"
|
2019-01-18 21:52:57 +01:00
|
|
|
"time"
|
2019-01-17 21:38:45 +01:00
|
|
|
|
2019-01-18 19:10:23 +01:00
|
|
|
"github.com/shopspring/decimal"
|
2019-04-03 00:44:30 +02:00
|
|
|
|
2019-10-10 05:07:33 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/extras/errors"
|
2019-08-27 00:25:47 +02:00
|
|
|
|
2019-10-10 05:07:33 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/extras/util"
|
2017-09-12 18:04:45 +02:00
|
|
|
)
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func prettyPrint(i interface{}) {
|
|
|
|
s, _ := json.MarshalIndent(i, "", "\t")
|
|
|
|
fmt.Println(string(s))
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:47:12 +02:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
code := m.Run()
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func TestClient_AccountFund(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
accounts, err := d.AccountList(1, 20)
|
2019-04-21 20:29:25 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-21 20:29:25 +02:00
|
|
|
}
|
2019-12-06 20:43:19 +01:00
|
|
|
account := (accounts.Items)[0].ID
|
2019-04-21 20:29:25 +02:00
|
|
|
balanceString, err := d.AccountBalance(&account)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-21 20:29:25 +02:00
|
|
|
}
|
2019-08-27 00:25:47 +02:00
|
|
|
balance, err := strconv.ParseFloat(balanceString.Available.String(), 64)
|
2019-04-21 20:29:25 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-21 20:29:25 +02:00
|
|
|
}
|
2019-06-12 02:54:18 +02:00
|
|
|
got, err := d.AccountFund(account, account, fmt.Sprintf("%f", balance/2.0), 40, false)
|
2019-04-21 20:29:25 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-21 20:29:25 +02:00
|
|
|
}
|
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
2019-01-17 21:38:45 +01:00
|
|
|
func TestClient_AccountList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.AccountList(1, 20)
|
2019-01-17 21:38:45 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-17 21:38:45 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-17 21:38:45 +01:00
|
|
|
}
|
|
|
|
|
2019-05-21 19:12:00 +02:00
|
|
|
func TestClient_SingleAccountList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-09-25 12:47:12 +02:00
|
|
|
name := "test" + fmt.Sprintf("%d", rand.Int()) + "@lbry.com"
|
|
|
|
createdAccount, err := d.AccountCreate(name, false)
|
2019-05-21 19:12:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
account, err := d.SingleAccountList(createdAccount.ID)
|
2019-12-06 20:43:19 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-09-25 12:47:12 +02:00
|
|
|
prettyPrint(*createdAccount)
|
|
|
|
prettyPrint(*account)
|
2019-05-21 19:12:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-06 20:43:19 +01:00
|
|
|
if account.Items[0].Name != name {
|
|
|
|
t.Fatalf("account name mismatch: %v != %v", account.Items[0].Name, name)
|
2019-09-25 12:47:12 +02:00
|
|
|
}
|
2019-05-21 19:12:00 +02:00
|
|
|
}
|
|
|
|
|
2019-01-17 21:38:45 +01:00
|
|
|
func TestClient_AccountBalance(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.AccountBalance(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-17 21:38:45 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-17 21:38:45 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 19:10:23 +01:00
|
|
|
func TestClient_AddressUnused(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.AddressUnused(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ChannelList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2021-04-13 00:29:18 +02:00
|
|
|
got, err := d.ChannelList(nil, 1, 50, nil)
|
2019-01-18 19:10:23 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
|
|
|
|
2019-08-27 00:25:47 +02:00
|
|
|
var channelID string
|
|
|
|
|
|
|
|
func TestClient_ChannelCreate(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 1.337, ChannelCreateOptions{
|
2019-08-27 00:25:47 +02:00
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
|
|
|
Title: util.PtrToString("Mess with the channels"),
|
|
|
|
Description: util.PtrToString("And you'll get what you deserve"),
|
|
|
|
Tags: []string{"we", "got", "tags"},
|
|
|
|
Languages: []string{"en-US"},
|
|
|
|
Locations: []Location{{
|
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
},
|
|
|
|
Email: util.PtrToString("niko@lbry.com"),
|
|
|
|
WebsiteURL: util.PtrToString("https://lbry.com"),
|
|
|
|
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
channelID = got.Outputs[0].ClaimID
|
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func TestClient_StreamCreate(t *testing.T) {
|
2019-05-28 18:29:14 +02:00
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
2019-01-18 19:10:23 +01:00
|
|
|
d := NewClient("")
|
|
|
|
addressResponse, err := d.AddressUnused(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
|
|
|
address := string(*addressResponse)
|
2019-12-06 20:43:19 +01:00
|
|
|
f, e := os.OpenFile("/tmp/test.txt", os.O_RDONLY|os.O_CREATE, 0666)
|
|
|
|
if e != nil {
|
|
|
|
t.Error(e)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _ = f.WriteString("test")
|
|
|
|
got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/tmp/test.txt", 1.437, StreamCreateOptions{
|
2019-04-11 21:04:37 +02:00
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
2019-06-11 18:40:48 +02:00
|
|
|
Title: util.PtrToString("This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix())),
|
|
|
|
Description: util.PtrToString("My Special Description"),
|
2019-04-03 00:44:30 +02:00
|
|
|
Tags: []string{"nsfw", "test"},
|
|
|
|
Languages: []string{"en-US", "fr-CH"},
|
2019-04-15 20:13:23 +02:00
|
|
|
Locations: []Location{{
|
2019-04-03 00:44:30 +02:00
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
PostalCode: util.PtrToString("6900"),
|
|
|
|
Latitude: nil,
|
|
|
|
Longitude: nil,
|
2019-04-11 21:04:37 +02:00
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-01-18_16-37-39-098537783.png"),
|
|
|
|
AccountID: nil,
|
|
|
|
ClaimAddress: &address,
|
2019-04-15 20:13:23 +02:00
|
|
|
Preview: nil,
|
2019-01-18 19:10:23 +01:00
|
|
|
},
|
2019-04-11 21:04:37 +02:00
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
Fee: &Fee{
|
2019-04-11 21:04:37 +02:00
|
|
|
FeeCurrency: "LBC",
|
|
|
|
FeeAmount: decimal.NewFromFloat(1.0),
|
|
|
|
FeeAddress: &address,
|
2019-04-03 00:44:30 +02:00
|
|
|
},
|
|
|
|
Author: util.PtrToString("Niko"),
|
|
|
|
License: util.PtrToString("FREE"),
|
|
|
|
LicenseURL: nil,
|
|
|
|
ReleaseTime: nil,
|
|
|
|
Duration: nil,
|
|
|
|
Preview: nil,
|
|
|
|
AllowDuplicateName: nil,
|
|
|
|
ChannelName: nil,
|
2019-08-27 00:25:47 +02:00
|
|
|
ChannelID: util.PtrToString(channelID),
|
2019-04-03 00:44:30 +02:00
|
|
|
ChannelAccountID: nil,
|
2019-01-18 19:10:23 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
2019-01-18 21:52:57 +01:00
|
|
|
|
2019-05-09 16:05:19 +02:00
|
|
|
func TestClient_ChannelUpdate(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-08-27 00:25:47 +02:00
|
|
|
got, err := d.ChannelUpdate(channelID, ChannelUpdateOptions{
|
2019-09-27 15:36:23 +02:00
|
|
|
Bid: util.PtrToString("0.01"),
|
2019-05-09 16:05:19 +02:00
|
|
|
ClearLanguages: util.PtrToBool(true),
|
|
|
|
ClearLocations: util.PtrToBool(true),
|
|
|
|
ClearTags: util.PtrToBool(true),
|
|
|
|
ChannelCreateOptions: ChannelCreateOptions{
|
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
2019-06-11 18:40:48 +02:00
|
|
|
Title: util.PtrToString("Mess with the channels"),
|
|
|
|
Description: util.PtrToString("And you'll get what you deserve"),
|
2019-05-09 16:05:19 +02:00
|
|
|
Tags: []string{"we", "got", "more", "tags"},
|
|
|
|
Languages: []string{"en-US"},
|
|
|
|
Locations: []Location{{
|
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
},
|
|
|
|
Email: util.PtrToString("niko@lbry.com"),
|
|
|
|
WebsiteURL: util.PtrToString("https://lbry.com"),
|
|
|
|
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
}})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-05-09 16:05:19 +02:00
|
|
|
}
|
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
func TestClient_ChannelAbandon(t *testing.T) {
|
2019-01-18 21:52:57 +01:00
|
|
|
d := NewClient("")
|
2019-04-21 20:29:25 +02:00
|
|
|
channelName := "@TestToDelete" + fmt.Sprintf("%d", time.Now().Unix())
|
|
|
|
channelResponse, err := d.ChannelCreate(channelName, 13.37, ChannelCreateOptions{
|
2019-04-15 20:13:23 +02:00
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
2019-06-11 18:40:48 +02:00
|
|
|
Title: util.PtrToString("Mess with the channels"),
|
|
|
|
Description: util.PtrToString("And you'll get what you deserve"),
|
2019-04-15 20:13:23 +02:00
|
|
|
Tags: []string{"we", "got", "tags"},
|
|
|
|
Languages: []string{"en-US"},
|
|
|
|
Locations: []Location{{
|
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
},
|
2019-05-09 16:05:19 +02:00
|
|
|
Email: util.PtrToString("niko@lbry.com"),
|
|
|
|
WebsiteURL: util.PtrToString("https://lbry.com"),
|
|
|
|
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
2019-04-15 20:13:23 +02:00
|
|
|
})
|
2019-01-18 21:52:57 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-04-18 19:07:47 +02:00
|
|
|
txID := channelResponse.Outputs[0].Txid
|
|
|
|
nout := channelResponse.Outputs[0].Nout
|
2019-01-18 21:52:57 +01:00
|
|
|
time.Sleep(10 * time.Second)
|
2019-04-03 00:44:30 +02:00
|
|
|
got, err := d.ChannelAbandon(txID, nout, nil, false)
|
2019-01-18 21:52:57 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_AddressList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.AddressList(nil, nil, 1, 20)
|
2019-01-18 21:52:57 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ClaimList(t *testing.T) {
|
2019-05-28 18:29:14 +02:00
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
2019-01-18 21:52:57 +01:00
|
|
|
d := NewClient("")
|
2019-04-03 00:44:30 +02:00
|
|
|
got, err := d.ClaimList(nil, 1, 10)
|
2019-01-18 21:52:57 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-10-10 04:28:54 +02:00
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_StreamList(t *testing.T) {
|
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
|
|
|
d := NewClient("")
|
2021-04-13 00:29:18 +02:00
|
|
|
got, err := d.StreamList(nil, 1, 20)
|
2019-10-10 04:28:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 18:31:01 +02:00
|
|
|
func TestClient_TransactionList(t *testing.T) {
|
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
|
|
|
d := NewClient("")
|
2020-09-01 19:45:55 +02:00
|
|
|
got, err := d.TransactionList(nil, nil, 1, 20)
|
2019-09-24 18:31:01 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:25:47 +02:00
|
|
|
func TestClient_SupportTest(t *testing.T) {
|
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
|
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
|
|
|
Title: util.PtrToString("Mess with the channels"),
|
|
|
|
Description: util.PtrToString("And you'll get what you deserve"),
|
|
|
|
Tags: []string{"we", "got", "tags"},
|
|
|
|
Languages: []string{"en-US"},
|
|
|
|
Locations: []Location{{
|
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
},
|
|
|
|
Email: util.PtrToString("niko@lbry.com"),
|
|
|
|
WebsiteURL: util.PtrToString("https://lbry.com"),
|
|
|
|
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
2019-12-06 20:43:19 +01:00
|
|
|
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil)
|
2019-08-27 00:25:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got2)
|
|
|
|
|
|
|
|
got3, err := d.SupportList(nil, 1, 10)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
found := false
|
|
|
|
for _, support := range got3.Items {
|
|
|
|
if support.ClaimID == got.Outputs[0].ClaimID {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
t.Error(errors.Err("support not found"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got3)
|
|
|
|
got4, err := d.SupportAbandon(util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got4)
|
|
|
|
}
|
|
|
|
|
2020-03-31 04:05:43 +02:00
|
|
|
func TestClient_TxoSpendTest(t *testing.T) {
|
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
|
|
|
|
ClaimCreateOptions: ClaimCreateOptions{
|
|
|
|
Title: util.PtrToString("Mess with the channels"),
|
|
|
|
Description: util.PtrToString("And you'll get what you deserve"),
|
|
|
|
Tags: []string{"we", "got", "tags"},
|
|
|
|
Languages: []string{"en-US"},
|
|
|
|
Locations: []Location{{
|
|
|
|
Country: util.PtrToString("CH"),
|
|
|
|
State: util.PtrToString("Ticino"),
|
|
|
|
City: util.PtrToString("Lugano"),
|
|
|
|
}},
|
|
|
|
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
},
|
|
|
|
Email: util.PtrToString("niko@lbry.com"),
|
|
|
|
WebsiteURL: util.PtrToString("https://lbry.com"),
|
|
|
|
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got2)
|
|
|
|
|
|
|
|
got3, err := d.SupportList(nil, 1, 10)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
found := false
|
|
|
|
for _, support := range got3.Items {
|
|
|
|
if support.ClaimID == got.Outputs[0].ClaimID {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
t.Error(errors.Err("support not found"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got3)
|
|
|
|
got4, err := d.TxoSpend(util.PtrToString("support"), util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got4)
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
got3, err = d.SupportList(nil, 1, 10)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
found = false
|
|
|
|
for _, support := range got3.Items {
|
|
|
|
if support.ClaimID == got.Outputs[0].ClaimID {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if found {
|
|
|
|
t.Error(errors.Err("support found even though it should have been abandoned"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got3)
|
|
|
|
got4, err = d.TxoSpend(util.PtrToString("channel"), util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*got4)
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
|
|
|
|
got5, err := d.ClaimList(nil, 1, 50)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, claim := range got5.Claims {
|
|
|
|
if claim.ClaimID == got.Outputs[0].ClaimID {
|
|
|
|
t.Error(errors.Err("claim found even though it should have been abandoned"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prettyPrint(*got5)
|
|
|
|
}
|
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
func TestClient_ClaimSearch(t *testing.T) {
|
2019-01-18 21:52:57 +01:00
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil, 1, 20)
|
2019-01-18 21:52:57 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Status(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.Status()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_UTXOList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.UTXOList(nil, 1, 20)
|
2019-01-22 18:48:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Version(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
got, err := d.Version()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func TestClient_GetFile(t *testing.T) {
|
2019-05-28 19:27:04 +02:00
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
2019-01-22 18:48:04 +01:00
|
|
|
d := NewClient("")
|
2019-05-28 18:29:14 +02:00
|
|
|
got, err := d.Get("lbry://test1559058649")
|
2019-01-22 18:48:04 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-01-22 18:48:04 +01:00
|
|
|
}
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func TestClient_FileList(t *testing.T) {
|
2019-05-28 18:29:14 +02:00
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
2019-02-22 15:54:52 +01:00
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
got, err := d.FileList(1, 20)
|
2019-02-22 15:54:52 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-02-22 15:54:52 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Resolve(t *testing.T) {
|
2019-05-28 19:27:04 +02:00
|
|
|
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
|
2019-04-21 20:29:25 +02:00
|
|
|
d := NewClient("")
|
2019-05-28 18:29:14 +02:00
|
|
|
got, err := d.Resolve("test1559058649")
|
2019-02-22 15:54:52 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-02-22 15:54:52 +01:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-02-22 15:54:52 +01:00
|
|
|
}
|
2019-04-10 23:23:24 +02:00
|
|
|
|
2019-04-15 20:13:23 +02:00
|
|
|
func TestClient_AccountSet(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-12-06 20:43:19 +01:00
|
|
|
accounts, err := d.AccountList(1, 20)
|
2019-04-15 20:13:23 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-15 20:13:23 +02:00
|
|
|
}
|
2019-12-06 20:43:19 +01:00
|
|
|
account := (accounts.Items)[0].ID
|
2019-04-15 20:13:23 +02:00
|
|
|
|
2019-06-12 22:18:03 +02:00
|
|
|
got, err := d.AccountSet(account, AccountSettings{ChangeMaxUses: util.PtrToInt(10000)})
|
2019-04-15 20:13:23 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-15 20:13:23 +02:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*got)
|
2019-04-15 20:13:23 +02:00
|
|
|
}
|
2019-05-21 20:17:22 +02:00
|
|
|
|
2019-04-10 23:23:24 +02:00
|
|
|
func TestClient_AccountCreate(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-09-25 12:47:12 +02:00
|
|
|
name := "lbry#user#id:" + fmt.Sprintf("%d", rand.Int())
|
2019-05-21 20:17:22 +02:00
|
|
|
account, err := d.AccountCreate(name, false)
|
2019-04-10 23:23:24 +02:00
|
|
|
if err != nil {
|
2019-05-21 20:17:22 +02:00
|
|
|
t.Fatal(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-05-21 20:17:22 +02:00
|
|
|
}
|
|
|
|
if account.Name != name {
|
|
|
|
t.Errorf("account name mismatch, expected %q, got %q", name, account.Name)
|
2019-09-24 20:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
prettyPrint(*account)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_AccountAdd(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
name := "test" + fmt.Sprintf("%d", time.Now().Unix()) + "@lbry.com"
|
|
|
|
pubKey := "tpubDA9GDAntyJu4hD3wU7175p7CuV6DWbYXfyb2HedBA3yuBp9HZ4n3QE4Ex6RHCSiEuVp2nKAL1Lzf2ZLo9ApaFgNaJjG6Xo1wB3iEeVbrDZp"
|
|
|
|
account, err := d.AccountAdd(name, nil, nil, &pubKey, util.PtrToBool(true), nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if account.Name != name {
|
|
|
|
t.Errorf("account name mismatch, expected %q, got %q", name, account.Name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if account.PublicKey != pubKey {
|
|
|
|
t.Errorf("public key mismatch, expected %q, got %q", name, account.Name)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-04-10 23:23:24 +02:00
|
|
|
}
|
2019-04-21 20:29:25 +02:00
|
|
|
prettyPrint(*account)
|
2019-04-10 23:23:24 +02:00
|
|
|
}
|
2019-05-21 19:12:00 +02:00
|
|
|
|
|
|
|
func TestClient_AccountRemove(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-09-25 12:47:12 +02:00
|
|
|
name := "lbry#user#id:" + fmt.Sprintf("%d", rand.Int())
|
|
|
|
createdAccount, err := d.AccountCreate(name, false)
|
2019-05-21 19:12:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-05-21 19:12:00 +02:00
|
|
|
}
|
|
|
|
removedAccount, err := d.AccountRemove(createdAccount.ID)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2019-05-28 18:29:14 +02:00
|
|
|
return
|
2019-05-21 19:12:00 +02:00
|
|
|
}
|
2019-05-22 19:58:42 +02:00
|
|
|
if removedAccount.ID != createdAccount.ID {
|
|
|
|
t.Error("accounts IDs mismatch")
|
|
|
|
}
|
2019-05-21 19:12:00 +02:00
|
|
|
|
2019-05-22 19:58:42 +02:00
|
|
|
account, err := d.SingleAccountList(createdAccount.ID)
|
2019-05-28 18:29:14 +02:00
|
|
|
if err != nil {
|
2019-12-06 20:43:19 +01:00
|
|
|
if strings.Contains(err.Error(), "Couldn't find account:") {
|
2019-05-28 18:29:14 +02:00
|
|
|
prettyPrint(*removedAccount)
|
|
|
|
return
|
|
|
|
}
|
2019-09-25 12:47:12 +02:00
|
|
|
t.Fatal(err)
|
2019-05-21 19:12:00 +02:00
|
|
|
}
|
2019-05-28 18:29:14 +02:00
|
|
|
t.Error("account was not removed")
|
2019-05-22 19:58:42 +02:00
|
|
|
prettyPrint(*account)
|
2019-05-21 19:12:00 +02:00
|
|
|
}
|
2019-07-26 05:33:52 +02:00
|
|
|
|
|
|
|
func TestClient_ChannelExport(t *testing.T) {
|
|
|
|
d := NewClient("")
|
2019-08-27 00:25:47 +02:00
|
|
|
response, err := d.ChannelExport(channelID, nil, nil)
|
2019-07-26 05:33:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if response == nil || len(*response) == 0 {
|
|
|
|
t.Error("nothing returned!")
|
|
|
|
}
|
|
|
|
t.Log("Export:", *response)
|
|
|
|
}
|
2019-09-25 12:47:12 +02:00
|
|
|
|
2019-10-03 15:03:31 +02:00
|
|
|
func TestClient_ChannelImport(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
2019-10-03 19:51:24 +02:00
|
|
|
// A channel created just for automated testing purposes
|
|
|
|
channelName := "@LbryAutomatedTestChannel"
|
|
|
|
channelkey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
|
|
|
|
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
|
|
|
|
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
|
|
|
|
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
|
|
|
|
"zt8tRYCJWaPdj713uENZZMo3gxuAMb1NwSnx8tbwETp7WPkpFLL6HZ9jKpB8BURHM" +
|
|
|
|
"F1RFD1PRyqbC6YezPyPQ2oninKKHdBduvXZG5KF2G2Q3ixsuE2ntifBBo1f5PotRk" +
|
|
|
|
"UanXKEafWxvXAayJjpsmZ4bFt7n6Xg4438WZXBiZKCPobLJAiHfe72n618kE6PCNU" +
|
|
|
|
"77cyU5Rk8J3CuY6QzZPzwuiXz2GLfkUMCYd9jGT6g53XbE6SwCsmGnd9NJkBAaJf5" +
|
|
|
|
"1FAYRURrhHnp79PAoHftEWtZEuU8MCPMdSRjzxYMRS4ScUzg5viDMTAkE8frsfCVZ" +
|
|
|
|
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
|
|
|
|
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
|
|
|
|
"Jb3FnSr1T4MRKESeN3W"
|
|
|
|
response, err := d.ChannelImport(channelkey, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2021-04-13 00:29:18 +02:00
|
|
|
channels, err := d.ChannelList(nil, 1, 50, nil)
|
2019-12-06 20:43:19 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-10-03 19:51:24 +02:00
|
|
|
seen := false
|
|
|
|
for _, c := range channels.Items {
|
|
|
|
if c.Name == channelName {
|
|
|
|
seen = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !seen {
|
|
|
|
t.Error("couldn't find imported channel")
|
|
|
|
}
|
|
|
|
t.Log("Response:", *response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ChannelImportWithWalletID(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
2019-10-03 15:03:31 +02:00
|
|
|
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
|
|
|
wallet, err := d.WalletCreate(id, nil)
|
2019-12-06 20:43:19 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-10-03 15:03:31 +02:00
|
|
|
// A channel created just for automated testing purposes
|
|
|
|
channelName := "@LbryAutomatedTestChannel"
|
2019-12-06 20:43:19 +01:00
|
|
|
channelKey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
|
2019-10-03 15:03:31 +02:00
|
|
|
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
|
|
|
|
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
|
|
|
|
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
|
|
|
|
"zt8tRYCJWaPdj713uENZZMo3gxuAMb1NwSnx8tbwETp7WPkpFLL6HZ9jKpB8BURHM" +
|
|
|
|
"F1RFD1PRyqbC6YezPyPQ2oninKKHdBduvXZG5KF2G2Q3ixsuE2ntifBBo1f5PotRk" +
|
|
|
|
"UanXKEafWxvXAayJjpsmZ4bFt7n6Xg4438WZXBiZKCPobLJAiHfe72n618kE6PCNU" +
|
|
|
|
"77cyU5Rk8J3CuY6QzZPzwuiXz2GLfkUMCYd9jGT6g53XbE6SwCsmGnd9NJkBAaJf5" +
|
|
|
|
"1FAYRURrhHnp79PAoHftEWtZEuU8MCPMdSRjzxYMRS4ScUzg5viDMTAkE8frsfCVZ" +
|
|
|
|
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
|
|
|
|
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
|
|
|
|
"Jb3FnSr1T4MRKESeN3W"
|
2019-12-06 20:43:19 +01:00
|
|
|
response, err := d.ChannelImport(channelKey, &wallet.ID)
|
2019-10-03 15:03:31 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2021-04-13 00:29:18 +02:00
|
|
|
channels, err := d.ChannelList(nil, 1, 50, &wallet.ID)
|
2019-12-06 20:43:19 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-10-03 15:03:31 +02:00
|
|
|
seen := false
|
|
|
|
for _, c := range channels.Items {
|
|
|
|
if c.Name == channelName {
|
|
|
|
seen = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !seen {
|
|
|
|
t.Error("couldn't find imported channel")
|
|
|
|
}
|
|
|
|
t.Log("Response:", *response)
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:47:12 +02:00
|
|
|
func TestClient_WalletCreate(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
|
|
|
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
|
|
|
wallet, err := d.WalletCreate(id, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if wallet.ID != id {
|
|
|
|
prettyPrint(*wallet)
|
|
|
|
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, wallet.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_WalletCreateWithOpts(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
|
|
|
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
|
|
|
wallet, err := d.WalletCreate(id, &WalletCreateOpts{CreateAccount: true, SingleKey: true})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
accounts, err := d.AccountListForWallet(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
prettyPrint(wallet)
|
|
|
|
prettyPrint(accounts)
|
2019-12-06 20:43:19 +01:00
|
|
|
if accounts.Items[0].Name == "" {
|
2019-09-25 12:47:12 +02:00
|
|
|
t.Fatalf("account name is empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 13:00:37 +02:00
|
|
|
func TestClient_WalletList(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
|
|
|
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
2019-12-06 20:43:19 +01:00
|
|
|
wList, err := d.WalletList(id, 1, 20)
|
2019-09-25 13:00:37 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("wallet %v was unexpectedly found", id)
|
|
|
|
}
|
2019-10-18 07:40:17 +02:00
|
|
|
if !strings.Contains(err.Error(), fmt.Sprintf("Couldn't find wallet: %v.", id)) {
|
2019-09-25 13:00:37 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.WalletCreate(id, &WalletCreateOpts{CreateAccount: true, SingleKey: true})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:43:19 +01:00
|
|
|
wList, err = d.WalletList(id, 1, 20)
|
2019-09-25 13:00:37 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-06 20:43:19 +01:00
|
|
|
if len(wList.Items) < 1 {
|
2019-09-25 13:00:37 +02:00
|
|
|
t.Fatal("wallet list is empty")
|
|
|
|
}
|
2019-12-06 20:43:19 +01:00
|
|
|
if (wList.Items)[0].ID != id {
|
|
|
|
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (wList.Items)[0].ID)
|
2019-09-25 13:00:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:47:12 +02:00
|
|
|
func TestClient_WalletRemoveWalletAdd(t *testing.T) {
|
|
|
|
d := NewClient("")
|
|
|
|
|
|
|
|
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
|
|
|
|
wallet, err := d.WalletCreate(id, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.WalletRemove(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
addedWallet, err := d.WalletAdd(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if addedWallet.ID != wallet.ID {
|
|
|
|
prettyPrint(*addedWallet)
|
|
|
|
t.Fatalf("wallet ID mismatch, expected %q, got %q", wallet.ID, addedWallet.Name)
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 22:03:45 +02:00
|
|
|
|
|
|
|
func TestClient_TransactionSummary(t *testing.T) {
|
2021-04-16 21:53:22 +02:00
|
|
|
d := NewClient("https://api.lbry.tv/api/v1/proxy")
|
2021-04-15 22:03:45 +02:00
|
|
|
r, err := d.TransactionShow("d104a1616c6af581e2046819de678f370d624e97cf176f95acaec4b183a42db6")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if len(r.Outputs) != 2 {
|
|
|
|
t.Fatal("found wrong transaction")
|
|
|
|
}
|
|
|
|
if r.Outputs[0].Amount != "5.0" {
|
|
|
|
t.Error("found wrong lbc amount for transaction.")
|
|
|
|
}
|
|
|
|
}
|