Update go-crypto, move testutils into types
This commit is contained in:
parent
4ad645f318
commit
1fd2d17cd9
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ install:
|
||||||
go install github.com/tendermint/basecoin/cmd/...
|
go install github.com/tendermint/basecoin/cmd/...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test --race `${NOVENDOR}`
|
go test `${NOVENDOR}`
|
||||||
#go run tests/tendermint/*.go
|
#go run tests/tendermint/*.go
|
||||||
|
|
||||||
get_deps:
|
get_deps:
|
||||||
|
|
|
@ -65,7 +65,7 @@ imports:
|
||||||
- name: github.com/tendermint/go-config
|
- name: github.com/tendermint/go-config
|
||||||
version: e64b424499acd0eb9856b88e10c0dff41628c0d6
|
version: e64b424499acd0eb9856b88e10c0dff41628c0d6
|
||||||
- name: github.com/tendermint/go-crypto
|
- name: github.com/tendermint/go-crypto
|
||||||
version: 8c9b889ccfe1f891ce8ab36c843f15794ce8f30f
|
version: 562b4cc9ef0d20217f6e95679f9e83cb7bc98b17
|
||||||
- name: github.com/tendermint/go-data
|
- name: github.com/tendermint/go-data
|
||||||
version: f199ef165cd5a50d569b179201702c5ec8899013
|
version: f199ef165cd5a50d569b179201702c5ec8899013
|
||||||
- name: github.com/tendermint/go-db
|
- name: github.com/tendermint/go-db
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/basecoin/app"
|
"github.com/tendermint/basecoin/app"
|
||||||
"github.com/tendermint/basecoin/testutils"
|
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
|
@ -27,7 +26,7 @@ func TestCounterPlugin(t *testing.T) {
|
||||||
bcApp.RegisterPlugin(counterPlugin)
|
bcApp.RegisterPlugin(counterPlugin)
|
||||||
|
|
||||||
// Account initialization
|
// Account initialization
|
||||||
test1PrivAcc := testutils.PrivAccountFromSecret("test1")
|
test1PrivAcc := types.PrivAccountFromSecret("test1")
|
||||||
|
|
||||||
// Seed Basecoin with account
|
// Seed Basecoin with account
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/basecoin/testutils"
|
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
cmn "github.com/tendermint/go-common"
|
cmn "github.com/tendermint/go-common"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
@ -29,7 +28,7 @@ func genGenesisDoc(chainID string, numVals int) (*tm.GenesisDoc, []types.PrivAcc
|
||||||
|
|
||||||
for i := 0; i < numVals; i++ {
|
for i := 0; i < numVals; i++ {
|
||||||
name := cmn.Fmt("%v_val_%v", chainID, i)
|
name := cmn.Fmt("%v_val_%v", chainID, i)
|
||||||
privAcc := testutils.PrivAccountFromSecret(name)
|
privAcc := types.PrivAccountFromSecret(name)
|
||||||
genDoc.Validators = append(genDoc.Validators, tm.GenesisValidator{
|
genDoc.Validators = append(genDoc.Validators, tm.GenesisValidator{
|
||||||
PubKey: privAcc.PubKey.PubKey,
|
PubKey: privAcc.PubKey.PubKey,
|
||||||
Amount: 1,
|
Amount: 1,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/basecoin/testutils"
|
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
cmn "github.com/tendermint/go-common"
|
cmn "github.com/tendermint/go-common"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
@ -38,10 +37,10 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Get the root account
|
// Get the root account
|
||||||
root := testutils.PrivAccountFromSecret("test")
|
root := types.PrivAccountFromSecret("test")
|
||||||
sequence := int(0)
|
sequence := int(0)
|
||||||
// Make a bunch of PrivAccounts
|
// Make a bunch of PrivAccounts
|
||||||
privAccounts := testutils.RandAccounts(1000, 1000000, 0)
|
privAccounts := types.RandAccounts(1000, 1000000, 0)
|
||||||
privAccountSequences := make(map[string]int)
|
privAccountSequences := make(map[string]int)
|
||||||
|
|
||||||
// Send coins to each account
|
// Send coins to each account
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/tendermint/basecoin/app"
|
"github.com/tendermint/basecoin/app"
|
||||||
"github.com/tendermint/basecoin/testutils"
|
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
cmn "github.com/tendermint/go-common"
|
cmn "github.com/tendermint/go-common"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
@ -19,8 +18,8 @@ func TestSendTx(t *testing.T) {
|
||||||
bcApp.SetOption("base/chainID", chainID)
|
bcApp.SetOption("base/chainID", chainID)
|
||||||
t.Log(bcApp.Info())
|
t.Log(bcApp.Info())
|
||||||
|
|
||||||
test1PrivAcc := testutils.PrivAccountFromSecret("test1")
|
test1PrivAcc := types.PrivAccountFromSecret("test1")
|
||||||
test2PrivAcc := testutils.PrivAccountFromSecret("test2")
|
test2PrivAcc := types.PrivAccountFromSecret("test2")
|
||||||
|
|
||||||
// Seed Basecoin with account
|
// Seed Basecoin with account
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
|
@ -66,14 +65,14 @@ func TestSequence(t *testing.T) {
|
||||||
t.Log(bcApp.Info())
|
t.Log(bcApp.Info())
|
||||||
|
|
||||||
// Get the test account
|
// Get the test account
|
||||||
test1PrivAcc := testutils.PrivAccountFromSecret("test1")
|
test1PrivAcc := types.PrivAccountFromSecret("test1")
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
test1Acc.Balance = types.Coins{{"", 1 << 53}}
|
test1Acc.Balance = types.Coins{{"", 1 << 53}}
|
||||||
t.Log(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc))))
|
t.Log(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc))))
|
||||||
|
|
||||||
sequence := int(1)
|
sequence := int(1)
|
||||||
// Make a bunch of PrivAccounts
|
// Make a bunch of PrivAccounts
|
||||||
privAccounts := testutils.RandAccounts(1000, 1000000, 0)
|
privAccounts := types.RandAccounts(1000, 1000000, 0)
|
||||||
privAccountSequences := make(map[string]int)
|
privAccountSequences := make(map[string]int)
|
||||||
// Send coins to each account
|
// Send coins to each account
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
// Functions used in testing throughout
|
|
||||||
package testutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"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 {
|
|
||||||
privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret))
|
|
||||||
privAccount := types.PrivAccount{
|
|
||||||
PrivKeyS: crypto.PrivKeyS{privKey},
|
|
||||||
Account: types.Account{
|
|
||||||
PubKey: crypto.PubKeyS{privKey.PubKey()},
|
|
||||||
Sequence: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return privAccount
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make `num` random accounts
|
|
||||||
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 {
|
|
||||||
balance += RandInt64() % (maxAmount - minAmount)
|
|
||||||
}
|
|
||||||
|
|
||||||
privKey := crypto.GenPrivKeyEd25519()
|
|
||||||
pubKey := crypto.PubKeyS{privKey.PubKey()}
|
|
||||||
privAccs[i] = types.PrivAccount{
|
|
||||||
PrivKeyS: crypto.PrivKeyS{privKey},
|
|
||||||
Account: types.Account{
|
|
||||||
PubKey: pubKey,
|
|
||||||
Sequence: 0,
|
|
||||||
Balance: types.Coins{types.Coin{"", balance}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return privAccs
|
|
||||||
}
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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))
|
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) {
|
func TestSendTxJSON(t *testing.T) {
|
||||||
chainID := "test_chain_id"
|
chainID := "test_chain_id"
|
||||||
test1PrivAcc := makePrivAcct()
|
test1PrivAcc := PrivAccountFromSecret("sendtx1")
|
||||||
test2PrivAcc := makePrivAcct()
|
test2PrivAcc := PrivAccountFromSecret("sendtx2")
|
||||||
|
|
||||||
// Construct a SendTx signature
|
// Construct a SendTx signature
|
||||||
tx := &SendTx{
|
tx := &SendTx{
|
||||||
|
|
Loading…
Reference in New Issue