Skip to content

Commit 403fc57

Browse files
chris124567ChrisSchinnerl
authored andcommitted
add API test
1 parent 6882b79 commit 403fc57

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

api/api_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api_test
22

33
import (
44
"context"
5+
"math"
56
"net"
67
"net/http"
78
"path/filepath"
@@ -106,6 +107,7 @@ func newServer(t *testing.T, cm *chain.Manager, e *explorer.Explorer, listenAddr
106107
}
107108

108109
func TestAPI(t *testing.T) {
110+
const netAddr1 = "127.0.0.1:1234"
109111
pk1 := types.GeneratePrivateKey()
110112
addr1 := types.StandardUnlockHash(pk1.PublicKey())
111113

@@ -178,7 +180,7 @@ func TestAPI(t *testing.T) {
178180
},
179181
},
180182
ArbitraryData: [][]byte{
181-
testutil.CreateAnnouncement(pk1, "127.0.0.1:1234"),
183+
testutil.CreateAnnouncement(pk1, netAddr1),
182184
},
183185
}
184186
testutil.SignTransaction(cm.TipState(), pk1, &txn2)
@@ -560,6 +562,31 @@ func TestAPI(t *testing.T) {
560562
}
561563
t.Logf("Exchange rate: %f", resp)
562564
}},
565+
{"Search host by pubkey", func(t *testing.T) {
566+
pubkey := pk1.PublicKey()
567+
host, err := client.Host(pubkey)
568+
if err != nil {
569+
t.Fatal(err)
570+
}
571+
572+
testutil.Equal(t, "pubkey", pubkey, host.PublicKey)
573+
testutil.Equal(t, "net address", netAddr1, host.NetAddress)
574+
}},
575+
{"Search host by net address", func(t *testing.T) {
576+
pubkey := pk1.PublicKey()
577+
hosts, err := client.HostsList(explorer.HostQuery{
578+
NetAddresses: []string{netAddr1},
579+
}, explorer.HostSortPublicKey, explorer.HostSortAsc, 0, math.MaxInt64)
580+
if err != nil {
581+
t.Fatal(err)
582+
}
583+
584+
testutil.Equal(t, "len(hosts)", 1, len(hosts))
585+
586+
host := hosts[0]
587+
testutil.Equal(t, "pubkey", pubkey, host.PublicKey)
588+
testutil.Equal(t, "net address", netAddr1, host.NetAddress)
589+
}},
563590
}
564591

565592
for _, subtest := range subtests {

0 commit comments

Comments
 (0)