github.com/filecoin-project/specs-actors/v4@v4.0.2/support/testing/address.go (about)

     1  package testing
     2  
     3  import (
     4  	addr "github.com/filecoin-project/go-address"
     5  	"github.com/stretchr/testify/require"
     6  	"math/rand"
     7  	"testing"
     8  )
     9  
    10  func NewIDAddr(t testing.TB, id uint64) addr.Address {
    11  	address, err := addr.NewIDAddress(id)
    12  	require.NoError(t, err)
    13  	return address
    14  }
    15  
    16  func NewSECP256K1Addr(t testing.TB, pubkey string) addr.Address {
    17  	// the pubkey of a secp256k1 address is hashed for consistent length.
    18  	address, err := addr.NewSecp256k1Address([]byte(pubkey))
    19  	require.NoError(t, err)
    20  	return address
    21  }
    22  
    23  func NewBLSAddr(t testing.TB, seed int64) addr.Address {
    24  	// the pubkey of a bls address is not hashed and must be the correct length.
    25  	buf := make([]byte, 48)
    26  	r := rand.New(rand.NewSource(seed))
    27  	r.Read(buf)
    28  
    29  	address, err := addr.NewBLSAddress(buf)
    30  	require.NoError(t, err)
    31  	return address
    32  }
    33  
    34  func NewActorAddr(t testing.TB, data string) addr.Address {
    35  	address, err := addr.NewActorAddress([]byte(data))
    36  	require.NoError(t, err)
    37  	return address
    38  }