-
Notifications
You must be signed in to change notification settings - Fork 210
/
types.go
133 lines (117 loc) · 3.63 KB
/
types.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package testutil
import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"strings"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
dbm "github.com/tendermint/tm-db"
types "github.com/akash-network/akash-api/go/node/types/v1beta3"
"github.com/akash-network/node/app"
)
func RandRangeInt(min, max int) int {
return rand.Intn(max-min) + min // nolint: gosec
}
func RandRangeUint(min, max uint) uint {
val := rand.Uint64() // nolint: gosec
val %= uint64(max - min)
val += uint64(min)
return uint(val)
}
func RandRangeUint64(min, max uint64) uint64 {
val := rand.Uint64() // nolint: gosec
val %= max - min
val += min
return val
}
func ResourceUnits(_ testing.TB) types.Resources {
return types.Resources{
ID: 1,
CPU: &types.CPU{
Units: types.NewResourceValue(uint64(RandCPUUnits())),
},
Memory: &types.Memory{
Quantity: types.NewResourceValue(RandMemoryQuantity()),
},
GPU: &types.GPU{
Units: types.NewResourceValue(uint64(RandGPUUnits())),
},
Storage: types.Volumes{
types.Storage{
Quantity: types.NewResourceValue(RandStorageQuantity()),
},
},
}
}
func NewApp(val network.Validator) servertypes.Application {
return app.NewApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, 0, make(map[int64]bool), val.Ctx.Config.RootDir,
simapp.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
// DefaultConfig returns a default configuration suitable for nearly all
// testing requirements.
func DefaultConfig() network.Config {
encCfg := app.MakeEncodingConfig()
origGenesisState := app.ModuleBasics().DefaultGenesis(encCfg.Marshaler)
genesisState := make(map[string]json.RawMessage)
for k, v := range origGenesisState {
data, err := v.MarshalJSON()
if err != nil {
panic(err)
}
buf := &bytes.Buffer{}
_, err = buf.Write(data)
if err != nil {
panic(err)
}
stringData := buf.String()
stringDataAfter := strings.ReplaceAll(stringData, `"stake"`, `"uakt"`)
if stringData == stringDataAfter {
genesisState[k] = v
continue
}
var val map[string]interface{}
err = json.Unmarshal(buf.Bytes(), &val)
if err != nil {
panic(err)
}
replacementV := json.RawMessage(stringDataAfter)
genesisState[k] = replacementV
}
return network.Config{
Codec: encCfg.Marshaler,
TxConfig: encCfg.TxConfig,
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewApp,
GenesisState: genesisState,
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.NewRand().Str(6),
NumValidators: 4,
BondDenom: CoinDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", CoinDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000000000000, sdk.DefaultPowerReduction),
StakingTokens: sdk.TokensFromConsensusPower(100000, sdk.DefaultPowerReduction),
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
PruningStrategy: storetypes.PruningOptionNothing,
CleanupDir: true,
SigningAlgo: string(hd.Secp256k1Type),
KeyringOptions: []keyring.Option{},
}
}