Skip to content

Commit

Permalink
restructure, tmsp test now using go testing, app/tmsp_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Jan 13, 2017
1 parent f2275c3 commit ba24e69
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand Down
65 changes: 29 additions & 36 deletions tests/tmsp/main.go → app/tmsp_test.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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{
Expand All @@ -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

Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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())
}
}
}
3 changes: 2 additions & 1 deletion tests/common.go → common/testing.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package tests
//functions used in testing throughout
package common

import (
"github.com/tendermint/basecoin/types"
Expand Down
6 changes: 3 additions & 3 deletions plugins/vote/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions tests/tendermint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ba24e69

Please sign in to comment.