-
Notifications
You must be signed in to change notification settings - Fork 136
/
test_utils.go
51 lines (45 loc) · 1.06 KB
/
test_utils.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
package types
import (
"encoding/hex"
"math/big"
"math/rand"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Creates a random nonzero uint64 test value
func NonzeroUint64() (ret uint64) {
for ret == 0 {
ret = rand.Uint64() //nolint:gosec
}
return
}
// Creates a random nonempty 20 byte sdk.AccAddress string test value
func NonemptySdkAccAddress() (ret sdk.AccAddress) {
for ret.Empty() {
addr := make([]byte, 20)
rand.Read(addr) //nolint:gosec
ret = sdk.AccAddress(addr)
}
return
}
// Creates a random nonempty 20 byte address hex string test value
func NonemptyEthAddress() (ret string) {
for ret == "" {
addr := make([]byte, 20)
rand.Read(addr) //nolint:gosec
ret = hex.EncodeToString(addr)
}
ret = "0x" + ret
return
}
// Creates a random nonzero sdk.Int test value
func NonzeroSdkInt() (ret math.Int) {
amount := big.NewInt(0)
for amount.Cmp(big.NewInt(0)) == 0 {
amountBz := make([]byte, 32)
rand.Read(amountBz) //nolint:gosec
amount = big.NewInt(0).SetBytes(amountBz)
}
ret = math.NewIntFromBigInt(amount)
return
}