restructure, tmsp test now using go testing, app/tmsp_test.go
This commit is contained in:
parent
f2275c3089
commit
ba24e69e45
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ install:
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test --race `${NOVENDOR}`
|
go test --race `${NOVENDOR}`
|
||||||
go run tests/tmsp/*.go
|
#go run tests/tendermint/*.go
|
||||||
|
|
||||||
get_deps:
|
get_deps:
|
||||||
go get -d github.com/tendermint/basecoin/...
|
go get -d github.com/tendermint/basecoin/...
|
||||||
|
|
|
@ -1,35 +1,29 @@
|
||||||
package main
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"testing"
|
||||||
|
|
||||||
"github.com/tendermint/basecoin/app"
|
cmn "github.com/tendermint/basecoin/common"
|
||||||
"github.com/tendermint/basecoin/tests"
|
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
eyescli "github.com/tendermint/merkleeyes/client"
|
eyescli "github.com/tendermint/merkleeyes/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func TestSendTx(t *testing.T) {
|
||||||
testSendTx()
|
|
||||||
testSequence()
|
|
||||||
}
|
|
||||||
|
|
||||||
func testSendTx() {
|
|
||||||
eyesCli := eyescli.NewLocalClient()
|
eyesCli := eyescli.NewLocalClient()
|
||||||
chainID := "test_chain_id"
|
chainID := "test_chain_id"
|
||||||
bcApp := app.NewBasecoin(eyesCli)
|
bcApp := NewBasecoin(eyesCli)
|
||||||
bcApp.SetOption("base/chainID", chainID)
|
bcApp.SetOption("base/chainID", chainID)
|
||||||
fmt.Println(bcApp.Info())
|
t.Log(bcApp.Info())
|
||||||
|
|
||||||
test1PrivAcc := tests.PrivAccountFromSecret("test1")
|
test1PrivAcc := cmn.PrivAccountFromSecret("test1")
|
||||||
test2PrivAcc := tests.PrivAccountFromSecret("test2")
|
test2PrivAcc := cmn.PrivAccountFromSecret("test2")
|
||||||
|
|
||||||
// Seed Basecoin with account
|
// Seed Basecoin with account
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
test1Acc.Balance = types.Coins{{"", 1000}}
|
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()
|
res := bcApp.Commit()
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
|
@ -41,7 +35,7 @@ func testSendTx() {
|
||||||
Fee: 0,
|
Fee: 0,
|
||||||
Gas: 0,
|
Gas: 0,
|
||||||
Inputs: []types.TxInput{
|
Inputs: []types.TxInput{
|
||||||
tests.MakeInput(test1PrivAcc.Account.PubKey, types.Coins{{"", 1}}, 1),
|
cmn.MakeInput(test1PrivAcc.Account.PubKey, types.Coins{{"", 1}}, 1),
|
||||||
},
|
},
|
||||||
Outputs: []types.TxOutput{
|
Outputs: []types.TxOutput{
|
||||||
types.TxOutput{
|
types.TxOutput{
|
||||||
|
@ -53,42 +47,41 @@ func testSendTx() {
|
||||||
|
|
||||||
// Sign request
|
// Sign request
|
||||||
signBytes := tx.SignBytes(chainID)
|
signBytes := tx.SignBytes(chainID)
|
||||||
fmt.Printf("Sign bytes: %X\n", signBytes)
|
t.Log("Sign bytes: %X\n", signBytes)
|
||||||
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
||||||
tx.Inputs[0].Signature = sig
|
tx.Inputs[0].Signature = sig
|
||||||
//fmt.Println("tx:", tx)
|
t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx}))
|
||||||
fmt.Printf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx}))
|
|
||||||
|
|
||||||
// Write request
|
// Write request
|
||||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||||
res = bcApp.AppendTx(txBytes)
|
res = bcApp.AppendTx(txBytes)
|
||||||
fmt.Println(res)
|
t.Log(res)
|
||||||
if res.IsErr() {
|
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()
|
eyesCli := eyescli.NewLocalClient()
|
||||||
chainID := "test_chain_id"
|
chainID := "test_chain_id"
|
||||||
bcApp := app.NewBasecoin(eyesCli)
|
bcApp := NewBasecoin(eyesCli)
|
||||||
bcApp.SetOption("base/chainID", chainID)
|
bcApp.SetOption("base/chainID", chainID)
|
||||||
fmt.Println(bcApp.Info())
|
t.Log(bcApp.Info())
|
||||||
|
|
||||||
// Get the test account
|
// Get the test account
|
||||||
test1PrivAcc := tests.PrivAccountFromSecret("test1")
|
test1PrivAcc := cmn.PrivAccountFromSecret("test1")
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
test1Acc.Balance = types.Coins{{"", 1 << 53}}
|
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()
|
res := bcApp.Commit()
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
Exit(Fmt("Failed Commit: %v", res.Error()))
|
t.Errorf(Fmt("Failed Commit: %v", res.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
sequence := int(1)
|
sequence := int(1)
|
||||||
// Make a bunch of PrivAccounts
|
// Make a bunch of PrivAccounts
|
||||||
privAccounts := tests.RandAccounts(1000, 1000000, 0)
|
privAccounts := cmn.RandAccounts(1000, 1000000, 0)
|
||||||
privAccountSequences := make(map[string]int)
|
privAccountSequences := make(map[string]int)
|
||||||
// Send coins to each account
|
// Send coins to each account
|
||||||
|
|
||||||
|
@ -99,7 +92,7 @@ func testSequence() {
|
||||||
Fee: 2,
|
Fee: 2,
|
||||||
Gas: 2,
|
Gas: 2,
|
||||||
Inputs: []types.TxInput{
|
Inputs: []types.TxInput{
|
||||||
tests.MakeInput(test1Acc.PubKey, types.Coins{{"", 1000002}}, sequence),
|
cmn.MakeInput(test1Acc.PubKey, types.Coins{{"", 1000002}}, sequence),
|
||||||
},
|
},
|
||||||
Outputs: []types.TxOutput{
|
Outputs: []types.TxOutput{
|
||||||
types.TxOutput{
|
types.TxOutput{
|
||||||
|
@ -114,22 +107,22 @@ func testSequence() {
|
||||||
signBytes := tx.SignBytes(chainID)
|
signBytes := tx.SignBytes(chainID)
|
||||||
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
||||||
tx.Inputs[0].Signature = sig
|
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
|
// Write request
|
||||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||||
res := bcApp.AppendTx(txBytes)
|
res := bcApp.AppendTx(txBytes)
|
||||||
if res.IsErr() {
|
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()
|
res = bcApp.Commit()
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
Exit(Fmt("Failed Commit: %v", res.Error()))
|
t.Errorf(Fmt("Failed Commit: %v", res.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now send coins between these accounts
|
// Now send coins between these accounts
|
||||||
|
@ -149,7 +142,7 @@ func testSequence() {
|
||||||
Fee: 2,
|
Fee: 2,
|
||||||
Gas: 2,
|
Gas: 2,
|
||||||
Inputs: []types.TxInput{
|
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{
|
Outputs: []types.TxOutput{
|
||||||
types.TxOutput{
|
types.TxOutput{
|
||||||
|
@ -163,13 +156,13 @@ func testSequence() {
|
||||||
signBytes := tx.SignBytes(chainID)
|
signBytes := tx.SignBytes(chainID)
|
||||||
sig := privAccountA.PrivKey.Sign(signBytes)
|
sig := privAccountA.PrivKey.Sign(signBytes)
|
||||||
tx.Inputs[0].Signature = sig
|
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
|
// Write request
|
||||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||||
res := bcApp.AppendTx(txBytes)
|
res := bcApp.AppendTx(txBytes)
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
Exit("AppendTx error: " + res.Error())
|
t.Errorf("AppendTx error: " + res.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
package tests
|
//functions used in testing throughout
|
||||||
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/tendermint/basecoin/app"
|
"github.com/tendermint/basecoin/app"
|
||||||
"github.com/tendermint/basecoin/tests"
|
cmn "github.com/tendermint/basecoin/common"
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-wire"
|
"github.com/tendermint/go-wire"
|
||||||
|
@ -21,7 +21,7 @@ func TestVote(t *testing.T) {
|
||||||
fmt.Println(bcApp.Info())
|
fmt.Println(bcApp.Info())
|
||||||
|
|
||||||
//account initialization
|
//account initialization
|
||||||
test1PrivAcc := tests.PrivAccountFromSecret("test1")
|
test1PrivAcc := cmn.PrivAccountFromSecret("test1")
|
||||||
|
|
||||||
// Seed Basecoin with account
|
// Seed Basecoin with account
|
||||||
test1Acc := test1PrivAcc.Account
|
test1Acc := test1PrivAcc.Account
|
||||||
|
@ -53,7 +53,7 @@ func TestVote(t *testing.T) {
|
||||||
Fee: fees,
|
Fee: fees,
|
||||||
Gas: 0,
|
Gas: 0,
|
||||||
Type: typeByte,
|
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
|
Data: wire.BinaryBytes(struct{ Tx }{Tx{voteYes: true}}), //a vote for human rights
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/basecoin/tests"
|
cmn "github.com/tendermint/basecoin/common"
|
||||||
"github.com/tendermint/basecoin/types"
|
"github.com/tendermint/basecoin/types"
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-rpc/client"
|
"github.com/tendermint/go-rpc/client"
|
||||||
|
@ -37,10 +37,10 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Get the root account
|
// Get the root account
|
||||||
root := tests.PrivAccountFromSecret("test")
|
root := cmn.PrivAccountFromSecret("test")
|
||||||
sequence := int(0)
|
sequence := int(0)
|
||||||
// Make a bunch of PrivAccounts
|
// Make a bunch of PrivAccounts
|
||||||
privAccounts := tests.RandAccounts(1000, 1000000, 0)
|
privAccounts := cmn.RandAccounts(1000, 1000000, 0)
|
||||||
privAccountSequences := make(map[string]int)
|
privAccountSequences := make(map[string]int)
|
||||||
|
|
||||||
// Send coins to each account
|
// Send coins to each account
|
||||||
|
|
Loading…
Reference in New Issue