-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaccount_test.go
109 lines (103 loc) · 2.57 KB
/
account_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package fio
import (
"encoding/json"
"github.com/fioprotocol/fio-go/eos"
"os"
"testing"
)
func newApi() (*Account, *API, *TxOptions, error) {
nodeos := "http://dev:8889"
if os.Getenv("NODEOS") != "" {
nodeos = os.Getenv("NODEOS")
}
return NewWifConnect("5JBbUG5SDpLWxvBKihMeXLENinUzdNKNeozLas23Mj6ZNhz3hLS", nodeos)
}
func TestAPI_GetFioAccount(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
a, err := api.GetFioAccount("qbxn5zhw2ypw")
if err != nil {
t.Error(err)
}
if a == nil {
t.Error("nil response")
return
}
_, err = json.MarshalIndent(a, "", " ")
if err != nil {
t.Error(err)
}
if a.AccountName != eos.AccountName("qbxn5zhw2ypw") {
t.Error("account name was not correct")
}
}
func TestNewAccountFromWif(t *testing.T) {
account, err := NewAccountFromWif(`5JfNfukKhyCe4MSTBMiMdT77d8MCetEpceDQqRh4DuJQ1CAEdQF`)
if err != nil {
t.Error(err)
return
}
if account.Actor != eos.AccountName("tccyed5wnyj5") {
t.Error("bad actor")
}
if account.PubKey != `FIO6JN7BrPKPM8BqPs9zSPwbK3nWJ4EKvpjb4k9CFBQ6BbtrL2AHV` {
t.Error("bad pub key")
}
}
func TestAccount_GetNames(t *testing.T) {
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
account, _ := NewAccountFromWif(`5KQ6f9ZgUtagD3LZ4wcMKhhvK9qy4BuwL3L1pkm6E2v62HCne2R`)
names, _, err := account.GetNames(api)
if err != nil {
t.Error(err)
return
}
if names == 0 {
t.Error("did not find name")
return
}
if account.Addresses[0].FioAddress != "bp1@dapixdev" {
t.Error("did not have correct address")
}
}
func TestActorFromPub(t *testing.T) {
type testAccounts struct {
Pubkey string
Account string
Valid bool
}
tests := []testAccounts{
{"FIO586ZYe3CA2D3cpuYJk565Ny7RhgWxCwnX7kojZSaun2RbTocAf", "y5x3sk44d43p", true},
{"EOS6sUfyCJZHj4xQWiK79Zmz9CsfFfQ9ci2jZqGiLo3yYiw9pcgAG", "", false},
{"FIO586ZYe3CA2D3cpuYJk565Ny7RhgWxCwnX7kojZSaun2RbTocA1", "", false},
{"FIOhellothere", "", false},
{"PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "ymwzn5vje5ay", true},
{"PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5C1", "", false},
}
for _, pk := range tests {
act, err := ActorFromPub(pk.Pubkey)
switch pk.Valid {
case true:
if err != nil {
t.Error(pk.Pubkey, "should be a valid public key")
}
if pk.Account != string(act) {
t.Error(pk.Pubkey, "should map to", pk.Account, "but got", act)
}
case false:
if err == nil {
t.Error(pk.Pubkey, "should be an invalid public key")
}
if act != "" {
t.Error(pk.Pubkey, "should not have mapped to an account, got", act)
}
}
}
}