-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtpid_test.go
75 lines (71 loc) · 1.66 KB
/
tpid_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
package fio
import (
"math/rand"
"strings"
"testing"
"time"
)
func TestTpid(t *testing.T) {
if ok := SetTpid("bad@address@shouldfail"); ok {
t.Error("should not be able to set invalid tpid")
}
current := CurrentTpid()
if ok := SetTpid("adam@dapixdev"); !ok {
t.Error("could not set new tpid")
}
if current == CurrentTpid() {
t.Error("tpid did not change")
}
_, api, _, err := newApi()
if err != nil {
t.Error(err)
return
}
account, err := NewAccountFromWif("5KQ6f9ZgUtagD3LZ4wcMKhhvK9qy4BuwL3L1pkm6E2v62HCne2R")
if err != nil {
t.Error(err)
return
}
var opts = &TxOptions{}
api, opts, err = NewConnection(account.KeyBag, api.BaseURL)
if err != nil {
t.Error(err)
return
}
// this might fail since there aren't likely any rewards, so first try to generate some:
faucet, fApi, fOpts, err := newApi()
if err != nil {
t.Error(err)
return
}
rand.Seed(time.Now().UnixNano())
for i := 0; i < 10; i++ {
randomAccount, err := NewRandomAccount()
if err != nil {
t.Error(err)
break
}
_, err = fApi.SignPushTransaction(NewTransaction(
[]*Action{NewRegDomain(faucet.Actor, word(), randomAccount.PubKey)},
fOpts,
), fOpts.ChainID, CompressionNone)
if err != nil {
t.Error(err)
break
}
}
_, packed, err := api.SignTransaction(NewTransaction(
[]*Action{NewPayTpidRewards(account.Actor)}, opts),
opts.ChainID, CompressionNone,
)
if err != nil {
t.Error(err)
return
}
j, err := api.PushTransactionRaw(packed)
if err != nil && !strings.Contains(err.Error(), "An invalid request was sent in") {
t.Error(err)
} else if !strings.Contains(string(j), "tpids_paid") {
t.Error("expected tpid payout: " + string(j))
}
}