/
address.go
38 lines (32 loc) · 965 Bytes
/
address.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
package testing
import (
addr "github.com/chenjianmei111/go-address"
"github.com/stretchr/testify/require"
"math/rand"
"testing"
)
func NewIDAddr(t testing.TB, id uint64) addr.Address {
address, err := addr.NewIDAddress(id)
require.NoError(t, err)
return address
}
func NewSECP256K1Addr(t testing.TB, pubkey string) addr.Address {
// the pubkey of a secp256k1 address is hashed for consistent length.
address, err := addr.NewSecp256k1Address([]byte(pubkey))
require.NoError(t, err)
return address
}
func NewBLSAddr(t testing.TB, seed int64) addr.Address {
// the pubkey of a bls address is not hashed and must be the correct length.
buf := make([]byte, 48)
r := rand.New(rand.NewSource(seed))
r.Read(buf)
address, err := addr.NewBLSAddress(buf)
require.NoError(t, err)
return address
}
func NewActorAddr(t testing.TB, data string) addr.Address {
address, err := addr.NewActorAddress([]byte(data))
require.NoError(t, err)
return address
}