cosmos-sdk/common/testing.go

62 lines
1.4 KiB
Go
Raw Normal View History

//functions used in testing throughout
package common
import (
2016-02-16 12:29:54 -08:00
"github.com/tendermint/basecoin/types"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
)
// Creates a PrivAccount from secret.
// The amount is not set.
func PrivAccountFromSecret(secret string) types.PrivAccount {
2016-03-15 15:01:53 -07:00
privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret))
privAccount := types.PrivAccount{
PrivKey: privKey,
Account: types.Account{
2016-03-20 03:00:43 -07:00
PubKey: privKey.PubKey(),
Sequence: 0,
},
}
return privAccount
}
// Make `num` random accounts
2016-03-20 03:00:43 -07:00
func RandAccounts(num int, minAmount int64, maxAmount int64) []types.PrivAccount {
privAccs := make([]types.PrivAccount, num)
for i := 0; i < num; i++ {
balance := minAmount
if maxAmount > minAmount {
2016-03-20 03:00:43 -07:00
balance += RandInt64() % (maxAmount - minAmount)
}
privKey := crypto.GenPrivKeyEd25519()
pubKey := privKey.PubKey()
privAccs[i] = types.PrivAccount{
PrivKey: privKey,
Account: types.Account{
2016-03-20 03:00:43 -07:00
PubKey: pubKey,
Sequence: 0,
2016-04-01 15:19:07 -07:00
Balance: types.Coins{types.Coin{"", balance}},
},
}
}
return privAccs
}
2017-01-13 01:27:07 -08:00
//make input term for the AppTx or SendTx Types
func MakeInput(pubKey crypto.PubKey, coins types.Coins, sequence int) types.TxInput {
input := types.TxInput{
Address: pubKey.Address(),
PubKey: pubKey,
Coins: coins,
Sequence: sequence,
}
if sequence > 1 {
input.PubKey = nil
}
return input
}