-
Notifications
You must be signed in to change notification settings - Fork 264
/
common.go
64 lines (55 loc) · 1.55 KB
/
common.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
package testfactory
import (
"bytes"
"sort"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
gethcommon "github.com/ethereum/go-ethereum/common"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
func Repeat[T any](s T, count int) []T {
ss := make([]T, count)
for i := 0; i < count; i++ {
ss[i] = s
}
return ss
}
// GenerateRandNamespacedRawData returns random data of length count. Each chunk
// of random data is of size shareSize and is prefixed with a random blob
// namespace.
func GenerateRandNamespacedRawData(count int) (result [][]byte) {
for i := 0; i < count; i++ {
rawData := tmrand.Bytes(appconsts.ShareSize)
namespace := namespace.RandomBlobNamespace().Bytes()
copy(rawData, namespace)
result = append(result, rawData)
}
sortByteArrays(result)
return result
}
func sortByteArrays(src [][]byte) {
sort.Slice(src, func(i, j int) bool { return bytes.Compare(src[i], src[j]) < 0 })
}
func RandomAccountNames(count int) []string {
accounts := make([]string, 0, count)
for i := 0; i < count; i++ {
accounts = append(accounts, tmrand.Str(10))
}
return accounts
}
func RandomEVMAddress() gethcommon.Address {
return gethcommon.BytesToAddress(tmrand.Bytes(gethcommon.AddressLength))
}
func GetAddress(keys keyring.Keyring, account string) sdk.AccAddress {
rec, err := keys.Key(account)
if err != nil {
panic(err)
}
addr, err := rec.GetAddress()
if err != nil {
panic(err)
}
return addr
}