diff --git a/Makefile b/Makefile index 893fe21c042d..d22c6561df99 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install: test: go test --race `${NOVENDOR}` - go run tests/tmsp/*.go + #go run tests/tendermint/*.go get_deps: go get -d github.com/tendermint/basecoin/... diff --git a/tests/tmsp/main.go b/app/tmsp_test.go similarity index 65% rename from tests/tmsp/main.go rename to app/tmsp_test.go index 26d7d6dbae36..61107585325c 100644 --- a/tests/tmsp/main.go +++ b/app/tmsp_test.go @@ -1,35 +1,29 @@ -package main +package app import ( - "fmt" + "testing" - "github.com/tendermint/basecoin/app" - "github.com/tendermint/basecoin/tests" + cmn "github.com/tendermint/basecoin/common" "github.com/tendermint/basecoin/types" . "github.com/tendermint/go-common" "github.com/tendermint/go-wire" eyescli "github.com/tendermint/merkleeyes/client" ) -func main() { - testSendTx() - testSequence() -} - -func testSendTx() { +func TestSendTx(t *testing.T) { eyesCli := eyescli.NewLocalClient() chainID := "test_chain_id" - bcApp := app.NewBasecoin(eyesCli) + bcApp := NewBasecoin(eyesCli) bcApp.SetOption("base/chainID", chainID) - fmt.Println(bcApp.Info()) + t.Log(bcApp.Info()) - test1PrivAcc := tests.PrivAccountFromSecret("test1") - test2PrivAcc := tests.PrivAccountFromSecret("test2") + test1PrivAcc := cmn.PrivAccountFromSecret("test1") + test2PrivAcc := cmn.PrivAccountFromSecret("test2") // Seed Basecoin with account test1Acc := test1PrivAcc.Account test1Acc.Balance = types.Coins{{"", 1000}} - fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc)))) + t.Log(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc)))) res := bcApp.Commit() if res.IsErr() { @@ -41,7 +35,7 @@ func testSendTx() { Fee: 0, Gas: 0, Inputs: []types.TxInput{ - tests.MakeInput(test1PrivAcc.Account.PubKey, types.Coins{{"", 1}}, 1), + cmn.MakeInput(test1PrivAcc.Account.PubKey, types.Coins{{"", 1}}, 1), }, Outputs: []types.TxOutput{ types.TxOutput{ @@ -53,42 +47,41 @@ func testSendTx() { // Sign request signBytes := tx.SignBytes(chainID) - fmt.Printf("Sign bytes: %X\n", signBytes) + t.Log("Sign bytes: %X\n", signBytes) sig := test1PrivAcc.PrivKey.Sign(signBytes) tx.Inputs[0].Signature = sig - //fmt.Println("tx:", tx) - fmt.Printf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx})) + t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx})) // Write request txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) res = bcApp.AppendTx(txBytes) - fmt.Println(res) + t.Log(res) if res.IsErr() { - Exit(Fmt("Failed: %v", res.Error())) + t.Errorf(Fmt("Failed: %v", res.Error())) } } -func testSequence() { +func TestSequence(t *testing.T) { eyesCli := eyescli.NewLocalClient() chainID := "test_chain_id" - bcApp := app.NewBasecoin(eyesCli) + bcApp := NewBasecoin(eyesCli) bcApp.SetOption("base/chainID", chainID) - fmt.Println(bcApp.Info()) + t.Log(bcApp.Info()) // Get the test account - test1PrivAcc := tests.PrivAccountFromSecret("test1") + test1PrivAcc := cmn.PrivAccountFromSecret("test1") test1Acc := test1PrivAcc.Account test1Acc.Balance = types.Coins{{"", 1 << 53}} - fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc)))) + t.Log(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc)))) res := bcApp.Commit() if res.IsErr() { - Exit(Fmt("Failed Commit: %v", res.Error())) + t.Errorf(Fmt("Failed Commit: %v", res.Error())) } sequence := int(1) // Make a bunch of PrivAccounts - privAccounts := tests.RandAccounts(1000, 1000000, 0) + privAccounts := cmn.RandAccounts(1000, 1000000, 0) privAccountSequences := make(map[string]int) // Send coins to each account @@ -99,7 +92,7 @@ func testSequence() { Fee: 2, Gas: 2, Inputs: []types.TxInput{ - tests.MakeInput(test1Acc.PubKey, types.Coins{{"", 1000002}}, sequence), + cmn.MakeInput(test1Acc.PubKey, types.Coins{{"", 1000002}}, sequence), }, Outputs: []types.TxOutput{ types.TxOutput{ @@ -114,22 +107,22 @@ func testSequence() { signBytes := tx.SignBytes(chainID) sig := test1PrivAcc.PrivKey.Sign(signBytes) tx.Inputs[0].Signature = sig - // fmt.Printf("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) + // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) res := bcApp.AppendTx(txBytes) if res.IsErr() { - Exit("AppendTx error: " + res.Error()) + t.Errorf("AppendTx error: " + res.Error()) } } - fmt.Println("-------------------- RANDOM SENDS --------------------") + t.Log("-------------------- RANDOM SENDS --------------------") res = bcApp.Commit() if res.IsErr() { - Exit(Fmt("Failed Commit: %v", res.Error())) + t.Errorf(Fmt("Failed Commit: %v", res.Error())) } // Now send coins between these accounts @@ -149,7 +142,7 @@ func testSequence() { Fee: 2, Gas: 2, Inputs: []types.TxInput{ - tests.MakeInput(privAccountA.Account.PubKey, types.Coins{{"", 3}}, privAccountASequence+1), + cmn.MakeInput(privAccountA.Account.PubKey, types.Coins{{"", 3}}, privAccountASequence+1), }, Outputs: []types.TxOutput{ types.TxOutput{ @@ -163,13 +156,13 @@ func testSequence() { signBytes := tx.SignBytes(chainID) sig := privAccountA.PrivKey.Sign(signBytes) tx.Inputs[0].Signature = sig - // fmt.Printf("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) + // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) res := bcApp.AppendTx(txBytes) if res.IsErr() { - Exit("AppendTx error: " + res.Error()) + t.Errorf("AppendTx error: " + res.Error()) } } } diff --git a/tests/common.go b/common/testing.go similarity index 96% rename from tests/common.go rename to common/testing.go index 5e0d4ac32df6..918494e60c9d 100644 --- a/tests/common.go +++ b/common/testing.go @@ -1,4 +1,5 @@ -package tests +//functions used in testing throughout +package common import ( "github.com/tendermint/basecoin/types" diff --git a/plugins/vote/vote_test.go b/plugins/vote/vote_test.go index 1d6181cc801a..c2cce6f3a010 100644 --- a/plugins/vote/vote_test.go +++ b/plugins/vote/vote_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/tendermint/basecoin/app" - "github.com/tendermint/basecoin/tests" + cmn "github.com/tendermint/basecoin/common" "github.com/tendermint/basecoin/types" . "github.com/tendermint/go-common" "github.com/tendermint/go-wire" @@ -21,7 +21,7 @@ func TestVote(t *testing.T) { fmt.Println(bcApp.Info()) //account initialization - test1PrivAcc := tests.PrivAccountFromSecret("test1") + test1PrivAcc := cmn.PrivAccountFromSecret("test1") // Seed Basecoin with account test1Acc := test1PrivAcc.Account @@ -53,7 +53,7 @@ func TestVote(t *testing.T) { Fee: fees, Gas: 0, Type: typeByte, - Input: tests.MakeInput(test1Acc.PubKey, types.Coins{{"", sendCoins}}, seqNum), + Input: cmn.MakeInput(test1Acc.PubKey, types.Coins{{"", sendCoins}}, seqNum), Data: wire.BinaryBytes(struct{ Tx }{Tx{voteYes: true}}), //a vote for human rights } diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index a221d4b000a8..91ed52e7b9a9 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -5,7 +5,7 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/tendermint/basecoin/tests" + cmn "github.com/tendermint/basecoin/common" "github.com/tendermint/basecoin/types" . "github.com/tendermint/go-common" "github.com/tendermint/go-rpc/client" @@ -37,10 +37,10 @@ func main() { }() // Get the root account - root := tests.PrivAccountFromSecret("test") + root := cmn.PrivAccountFromSecret("test") sequence := int(0) // Make a bunch of PrivAccounts - privAccounts := tests.RandAccounts(1000, 1000000, 0) + privAccounts := cmn.RandAccounts(1000, 1000000, 0) privAccountSequences := make(map[string]int) // Send coins to each account