diff --git a/Makefile b/Makefile index 42ccfc69c..89f9af72b 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ install: go install github.com/tendermint/basecoin/cmd/... test: - go test --race `${NOVENDOR}` + go test `${NOVENDOR}` #go run tests/tendermint/*.go get_deps: diff --git a/glide.lock b/glide.lock index 661701940..7c681e9a9 100644 --- a/glide.lock +++ b/glide.lock @@ -65,7 +65,7 @@ imports: - name: github.com/tendermint/go-config version: e64b424499acd0eb9856b88e10c0dff41628c0d6 - name: github.com/tendermint/go-crypto - version: 8c9b889ccfe1f891ce8ab36c843f15794ce8f30f + version: 562b4cc9ef0d20217f6e95679f9e83cb7bc98b17 - name: github.com/tendermint/go-data version: f199ef165cd5a50d569b179201702c5ec8899013 - name: github.com/tendermint/go-db diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index e96cbc56b..d93333b00 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin/app" - "github.com/tendermint/basecoin/testutils" "github.com/tendermint/basecoin/types" crypto "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" @@ -27,7 +26,7 @@ func TestCounterPlugin(t *testing.T) { bcApp.RegisterPlugin(counterPlugin) // Account initialization - test1PrivAcc := testutils.PrivAccountFromSecret("test1") + test1PrivAcc := types.PrivAccountFromSecret("test1") // Seed Basecoin with account test1Acc := test1PrivAcc.Account diff --git a/plugins/ibc/ibc_test.go b/plugins/ibc/ibc_test.go index 51ee5f31f..0f2ab8854 100644 --- a/plugins/ibc/ibc_test.go +++ b/plugins/ibc/ibc_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/testutils" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" 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++ { name := cmn.Fmt("%v_val_%v", chainID, i) - privAcc := testutils.PrivAccountFromSecret(name) + privAcc := types.PrivAccountFromSecret(name) genDoc.Validators = append(genDoc.Validators, tm.GenesisValidator{ PubKey: privAcc.PubKey.PubKey, Amount: 1, diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 27618ca36..5481bfd3a 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -5,7 +5,6 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/tendermint/basecoin/testutils" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" crypto "github.com/tendermint/go-crypto" @@ -38,10 +37,10 @@ func main() { }() // Get the root account - root := testutils.PrivAccountFromSecret("test") + root := types.PrivAccountFromSecret("test") sequence := int(0) // Make a bunch of PrivAccounts - privAccounts := testutils.RandAccounts(1000, 1000000, 0) + privAccounts := types.RandAccounts(1000, 1000000, 0) privAccountSequences := make(map[string]int) // Send coins to each account diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 62f16eb6e..4d250394b 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/tendermint/basecoin/app" - "github.com/tendermint/basecoin/testutils" "github.com/tendermint/basecoin/types" cmn "github.com/tendermint/go-common" crypto "github.com/tendermint/go-crypto" @@ -19,8 +18,8 @@ func TestSendTx(t *testing.T) { bcApp.SetOption("base/chainID", chainID) t.Log(bcApp.Info()) - test1PrivAcc := testutils.PrivAccountFromSecret("test1") - test2PrivAcc := testutils.PrivAccountFromSecret("test2") + test1PrivAcc := types.PrivAccountFromSecret("test1") + test2PrivAcc := types.PrivAccountFromSecret("test2") // Seed Basecoin with account test1Acc := test1PrivAcc.Account @@ -66,14 +65,14 @@ func TestSequence(t *testing.T) { t.Log(bcApp.Info()) // Get the test account - test1PrivAcc := testutils.PrivAccountFromSecret("test1") + test1PrivAcc := types.PrivAccountFromSecret("test1") test1Acc := test1PrivAcc.Account test1Acc.Balance = types.Coins{{"", 1 << 53}} t.Log(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc)))) sequence := int(1) // Make a bunch of PrivAccounts - privAccounts := testutils.RandAccounts(1000, 1000000, 0) + privAccounts := types.RandAccounts(1000, 1000000, 0) privAccountSequences := make(map[string]int) // Send coins to each account diff --git a/testutils/testing.go b/testutils/testing.go deleted file mode 100644 index 930b3a714..000000000 --- a/testutils/testing.go +++ /dev/null @@ -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 -} diff --git a/types/test_helpers.go b/types/test_helpers.go new file mode 100644 index 000000000..c7ce21ff0 --- /dev/null +++ b/types/test_helpers.go @@ -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 +} diff --git a/types/tx_test.go b/types/tx_test.go index 982ceb1bf..5bfb3bc4c 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -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{