Update go-crypto, move testutils into types

This commit is contained in:
Ethan Frey
2017-02-25 00:12:15 +01:00
parent 4ad645f318
commit 1fd2d17cd9
9 changed files with 57 additions and 74 deletions
+45
View File
@@ -0,0 +1,45 @@
package types
// Helper functions for testing
import (
cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
)
// Creates a PrivAccount from secret.
// The amount is not set.
func PrivAccountFromSecret(secret string) PrivAccount {
privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret))
privAccount := PrivAccount{
PrivKeyS: crypto.PrivKeyS{privKey},
Account: Account{
PubKey: crypto.PubKeyS{privKey.PubKey()},
},
}
return privAccount
}
// Make `num` random accounts
func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount {
privAccs := make([]PrivAccount, num)
for i := 0; i < num; i++ {
balance := minAmount
if maxAmount > minAmount {
balance += cmn.RandInt64() % (maxAmount - minAmount)
}
privKey := crypto.GenPrivKeyEd25519()
pubKey := crypto.PubKeyS{privKey.PubKey()}
privAccs[i] = PrivAccount{
PrivKeyS: crypto.PrivKeyS{privKey},
Account: Account{
PubKey: pubKey,
Balance: Coins{Coin{"", balance}},
},
}
}
return privAccs
}
+2 -13
View File
@@ -67,21 +67,10 @@ func TestAppTxSignable(t *testing.T) {
cmn.Fmt("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signBytesHex))
}
// d'oh, can't use the version in testutils due to circular imports :(
func makePrivAcct() PrivAccount {
privKey := crypto.PrivKeyS{crypto.GenPrivKeyEd25519()}
return PrivAccount{
PrivKeyS: privKey,
Account: Account{
PubKey: crypto.PubKeyS{privKey.PubKey()},
},
}
}
func TestSendTxJSON(t *testing.T) {
chainID := "test_chain_id"
test1PrivAcc := makePrivAcct()
test2PrivAcc := makePrivAcct()
test1PrivAcc := PrivAccountFromSecret("sendtx1")
test2PrivAcc := PrivAccountFromSecret("sendtx2")
// Construct a SendTx signature
tx := &SendTx{