-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathaccountwgs_test.go
107 lines (83 loc) · 2.29 KB
/
accountwgs_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
package baseapp
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/line/lfb-sdk/crypto/keys/secp256k1"
"github.com/line/lfb-sdk/testutil/testdata"
sdk "github.com/line/lfb-sdk/types"
)
func TestConvertByteSliceToString(t *testing.T) {
b := []byte{65, 66, 67, 0, 65, 66, 67}
s := string(b)
require.Equal(t, len(b), len(s))
require.Equal(t, uint8(0), s[3])
}
func TestRegister(t *testing.T) {
app := setupBaseApp(t)
privs := newTestPrivKeys(3)
tx := newTestTx(privs)
waits, signals := app.checkAccountWGs.Register(tx)
require.Equal(t, 0, len(waits))
require.Equal(t, 3, len(signals))
for _, signal := range signals {
require.Equal(t, app.checkAccountWGs.wgs[signal.acc], signal.wg)
}
}
func TestDontPanicWithNil(t *testing.T) {
app := setupBaseApp(t)
require.NotPanics(t, func() { app.checkAccountWGs.Wait(nil) })
require.NotPanics(t, func() { app.checkAccountWGs.Done(nil) })
}
func TestGetUniqSigners(t *testing.T) {
privs := newTestPrivKeys(3)
addrs := getAddrs(privs)
addrs = append(addrs, addrs[1], addrs[0])
require.Equal(t, 5, len(addrs))
tx := newTestTx(privs)
signers := getUniqSigners(tx)
// length should be reduced because `duplicated` is removed
require.Less(t, len(signers), len(addrs))
// check uniqueness
for i, iv := range signers {
for j, jv := range signers {
if i != j {
require.True(t, iv != jv)
}
}
}
}
type AccountLockTestTx struct {
Msgs []sdk.Msg
}
var _ sdk.Tx = AccountLockTestTx{}
func (tx AccountLockTestTx) GetMsgs() []sdk.Msg {
return tx.Msgs
}
func (tx AccountLockTestTx) ValidateBasic() error {
return nil
}
func (tx AccountLockTestTx) GetSigBlockHeight() uint64 {
return 0
}
func newTestPrivKeys(num int) []*secp256k1.PrivKey {
privs := make([]*secp256k1.PrivKey, 0, num)
for i := 0; i < num; i++ {
privs = append(privs, secp256k1.GenPrivKey())
}
return privs
}
func getAddrs(privs []*secp256k1.PrivKey) []sdk.AccAddress {
addrs := make([]sdk.AccAddress, 0, len(privs))
for _, priv := range privs {
addrs = append(addrs, sdk.BytesToAccAddress(priv.PubKey().Address()))
}
return addrs
}
func newTestTx(privs []*secp256k1.PrivKey) sdk.Tx {
addrs := getAddrs(privs)
msgs := make([]sdk.Msg, len(addrs))
for i, addr := range addrs {
msgs[i] = testdata.NewTestMsg(addr)
}
return AccountLockTestTx{Msgs: msgs}
}