diff --git a/Makefile b/Makefile index ea93496b7c4c..2e9b94f6ffa7 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,6 @@ test: test_unit test_cli test_unit: go test `glide novendor` - #go run tests/tendermint/*.go test_cli: tests/cli/shunit2 # sudo apt-get install jq diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go deleted file mode 100644 index 04a39f9f67ae..000000000000 --- a/tests/tendermint/main.go +++ /dev/null @@ -1,140 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/gorilla/websocket" - "github.com/tendermint/basecoin/types" - wire "github.com/tendermint/go-wire" - _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types - "github.com/tendermint/tendermint/rpc/lib/client" - "github.com/tendermint/tendermint/rpc/lib/types" - cmn "github.com/tendermint/tmlibs/common" -) - -func main() { - // ws := rpcclient.NewWSClient("127.0.0.1:46657", "/websocket") - ws := rpcclient.NewWSClient("192.168.99.100:46657", "/websocket") - chainID := "test_chain_id" - - _, err := ws.Start() - if err != nil { - cmn.Exit(err.Error()) - } - var counter = 0 - - // Read a bunch of responses - go func() { - for { - res, ok := <-ws.ResultsCh - if !ok { - break - } - fmt.Println(counter, "res:", cmn.Blue(string(res))) - } - }() - - // Get the root account - root := types.PrivAccountFromSecret("test") - sequence := int(0) - // Make a bunch of PrivAccounts - privAccounts := types.RandAccounts(1000, 1000000, 0) - privAccountSequences := make(map[string]int) - - // Send coins to each account - for i := 0; i < len(privAccounts); i++ { - privAccount := privAccounts[i] - tx := &types.SendTx{ - Inputs: []types.TxInput{ - types.TxInput{ - Address: root.Account.PubKey.Address(), - PubKey: root.Account.PubKey, // TODO is this needed? - Coins: types.Coins{{"", 1000002}}, - Sequence: sequence, - }, - }, - Outputs: []types.TxOutput{ - types.TxOutput{ - Address: privAccount.Account.PubKey.Address(), - Coins: types.Coins{{"", 1000000}}, - }, - }, - } - sequence += 1 - - // Sign request - signBytes := tx.SignBytes(chainID) - sig := root.Sign(signBytes) - tx.Inputs[0].Signature = sig - //fmt.Println("tx:", tx) - - // Write request - txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) - request, err := rpctypes.MapToRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) - if err != nil { - cmn.Exit("cannot encode request: " + err.Error()) - } - reqBytes := wire.JSONBytes(request) - //fmt.Print(".") - err = ws.WriteMessage(websocket.TextMessage, reqBytes) - if err != nil { - cmn.Exit("writing websocket request: " + err.Error()) - } - } - - // Now send coins between these accounts - for { - counter += 1 - time.Sleep(time.Millisecond * 10) - - randA := cmn.RandInt() % len(privAccounts) - randB := cmn.RandInt() % len(privAccounts) - if randA == randB { - continue - } - - privAccountA := privAccounts[randA] - privAccountASequence := privAccountSequences[privAccountA.Account.PubKey.KeyString()] - privAccountSequences[privAccountA.Account.PubKey.KeyString()] = privAccountASequence + 1 - privAccountB := privAccounts[randB] - - tx := &types.SendTx{ - Inputs: []types.TxInput{ - types.TxInput{ - Address: privAccountA.Account.PubKey.Address(), - PubKey: privAccountA.Account.PubKey, - Coins: types.Coins{{"", 3}}, - Sequence: privAccountASequence + 1, - }, - }, - Outputs: []types.TxOutput{ - types.TxOutput{ - Address: privAccountB.Account.PubKey.Address(), - Coins: types.Coins{{"", 1}}, - }, - }, - } - - // Sign request - signBytes := tx.SignBytes(chainID) - sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = sig - //fmt.Println("tx:", tx) - - // Write request - txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) - request, err := rpctypes.MapToRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) - if err != nil { - cmn.Exit("cannot encode request: " + err.Error()) - } - reqBytes := wire.JSONBytes(request) - //fmt.Print(".") - err = ws.WriteMessage(websocket.TextMessage, reqBytes) - if err != nil { - cmn.Exit("writing websocket request: " + err.Error()) - } - } - - ws.Stop() -} diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go deleted file mode 100644 index 19b32341b7d7..000000000000 --- a/tests/tmsp/tmsp_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package tmsp_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/tendermint/basecoin/app" - "github.com/tendermint/basecoin/types" - wire "github.com/tendermint/go-wire" - eyescli "github.com/tendermint/merkleeyes/client" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/log" -) - -func TestSendTx(t *testing.T) { - eyesCli := eyescli.NewLocalClient("", 0) - chainID := "test_chain_id" - bcApp := app.NewBasecoin(eyesCli) - bcApp.SetLogger(log.TestingLogger().With("module", "app")) - bcApp.SetOption("base/chain_id", chainID) - // t.Log(bcApp.Info()) - - test1PrivAcc := types.PrivAccountFromSecret("test1") - test2PrivAcc := types.PrivAccountFromSecret("test2") - - // Seed Basecoin with account - test1Acc := test1PrivAcc.Account - test1Acc.Balance = types.Coins{{"", 1000}} - accOpt, err := json.Marshal(test1Acc) - require.Nil(t, err) - bcApp.SetOption("base/account", string(accOpt)) - - // Construct a SendTx signature - tx := &types.SendTx{ - Gas: 0, - Fee: types.Coin{"", 0}, - Inputs: []types.TxInput{ - types.NewTxInput(test1PrivAcc.Account.PubKey, types.Coins{{"", 1}}, 1), - }, - Outputs: []types.TxOutput{ - types.TxOutput{ - Address: test2PrivAcc.Account.PubKey.Address(), - Coins: types.Coins{{"", 1}}, - }, - }, - } - - // Sign request - signBytes := tx.SignBytes(chainID) - // t.Log("Sign bytes: %X\n", signBytes) - sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = sig - // t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(types.TxS{tx})) - - // Write request - txBytes := wire.BinaryBytes(types.TxS{tx}) - res := bcApp.DeliverTx(txBytes) - // t.Log(res) - assert.True(t, res.IsOK(), "Failed: %v", res.Error()) -} - -func TestSequence(t *testing.T) { - eyesCli := eyescli.NewLocalClient("", 0) - chainID := "test_chain_id" - bcApp := app.NewBasecoin(eyesCli) - bcApp.SetOption("base/chain_id", chainID) - // t.Log(bcApp.Info()) - - // Get the test account - test1PrivAcc := types.PrivAccountFromSecret("test1") - test1Acc := test1PrivAcc.Account - test1Acc.Balance = types.Coins{{"", 1 << 53}} - accOpt, err := json.Marshal(test1Acc) - require.Nil(t, err) - bcApp.SetOption("base/account", string(accOpt)) - - sequence := int(1) - // Make a bunch of PrivAccounts - privAccounts := types.RandAccounts(1000, 1000000, 0) - privAccountSequences := make(map[string]int) - // Send coins to each account - - for i := 0; i < len(privAccounts); i++ { - privAccount := privAccounts[i] - - tx := &types.SendTx{ - Gas: 2, - Fee: types.Coin{"", 2}, - Inputs: []types.TxInput{ - types.NewTxInput(test1Acc.PubKey, types.Coins{{"", 1000002}}, sequence), - }, - Outputs: []types.TxOutput{ - types.TxOutput{ - Address: privAccount.Account.PubKey.Address(), - Coins: types.Coins{{"", 1000000}}, - }, - }, - } - sequence += 1 - - // Sign request - signBytes := tx.SignBytes(chainID) - sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = sig - // 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.DeliverTx(txBytes) - assert.True(t, res.IsOK(), "DeliverTx error: %v", res.Error()) - } - - res := bcApp.Commit() - assert.True(t, res.IsOK(), "Failed Commit: %v", res.Error()) - - t.Log("-------------------- RANDOM SENDS --------------------") - - // Now send coins between these accounts - for i := 0; i < 10000; i++ { - randA := cmn.RandInt() % len(privAccounts) - randB := cmn.RandInt() % len(privAccounts) - if randA == randB { - continue - } - - privAccountA := privAccounts[randA] - privAccountASequence := privAccountSequences[privAccountA.Account.PubKey.KeyString()] - privAccountSequences[privAccountA.Account.PubKey.KeyString()] = privAccountASequence + 1 - privAccountB := privAccounts[randB] - - tx := &types.SendTx{ - Gas: 2, - Fee: types.Coin{"", 2}, - Inputs: []types.TxInput{ - types.NewTxInput(privAccountA.PubKey, types.Coins{{"", 3}}, privAccountASequence+1), - }, - Outputs: []types.TxOutput{ - types.TxOutput{ - Address: privAccountB.PubKey.Address(), - Coins: types.Coins{{"", 1}}, - }, - }, - } - - // Sign request - signBytes := tx.SignBytes(chainID) - sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = sig - // 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.DeliverTx(txBytes) - assert.True(t, res.IsOK(), "DeliverTx error: %v", res.Error()) - } -}