Governmint testing
This commit is contained in:
parent
d6f75370a1
commit
bc78a2d272
1
Makefile
1
Makefile
|
@ -7,6 +7,7 @@ install: get_deps
|
|||
|
||||
test:
|
||||
go test github.com/tendermint/basecoin/...
|
||||
go run tests/tmsp/*.go
|
||||
|
||||
get_deps:
|
||||
go get -d github.com/tendermint/basecoin/...
|
||||
|
|
|
@ -174,9 +174,9 @@ func (app *Basecoin) EndBlock(height uint64) []*tmsp.Validator {
|
|||
|
||||
//----------------------------------------
|
||||
|
||||
// Splits the string at the first :.
|
||||
// Splits the string at the first '/'.
|
||||
// if there are none, the second string is nil.
|
||||
func splitKey(key string) (prefix string, sufix string) {
|
||||
func splitKey(key string) (prefix string, suffix string) {
|
||||
if strings.Contains(key, "/") {
|
||||
keyParts := strings.SplitN(key, "/", 2)
|
||||
return keyParts[0], keyParts[1]
|
||||
|
|
|
@ -38,7 +38,7 @@ func (s *State) GetChainID() string {
|
|||
}
|
||||
|
||||
func (s *State) GetAccount(addr []byte) *types.Account {
|
||||
res := s.eyesCli.GetSync(addr)
|
||||
res := s.eyesCli.GetSync(AccountKey(addr))
|
||||
if res.IsErr() {
|
||||
panic(Fmt("Error loading account addr %X error: %v", addr, res.Error()))
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ func (s *State) GetAccount(addr []byte) *types.Account {
|
|||
return acc
|
||||
}
|
||||
|
||||
func (s *State) SetAccount(address []byte, acc *types.Account) {
|
||||
func (s *State) SetAccount(addr []byte, acc *types.Account) {
|
||||
accBytes := wire.BinaryBytes(acc)
|
||||
res := s.eyesCli.SetSync(address, accBytes)
|
||||
res := s.eyesCli.SetSync(AccountKey(addr), accBytes)
|
||||
if res.IsErr() {
|
||||
panic(Fmt("Error storing account addr %X error: %v", address, res.Error()))
|
||||
panic(Fmt("Error storing account addr %X error: %v", addr, res.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,3 +68,9 @@ func (s *State) GetCheckCache() *types.AccountCache {
|
|||
func (s *State) ResetCacheState() {
|
||||
s.checkCache = types.NewAccountCache(s)
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
func AccountKey(addr []byte) []byte {
|
||||
return append([]byte("base/a/"), addr...)
|
||||
}
|
||||
|
|
|
@ -7,14 +7,17 @@ import (
|
|||
"github.com/tendermint/basecoin/tests"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire"
|
||||
"github.com/tendermint/go-wire/expr"
|
||||
govtypes "github.com/tendermint/governmint/types"
|
||||
eyescli "github.com/tendermint/merkleeyes/client"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//testSendTx()
|
||||
//testGov()
|
||||
testSendTx()
|
||||
testGov()
|
||||
testSequence()
|
||||
}
|
||||
|
||||
|
@ -75,11 +78,14 @@ func testGov() {
|
|||
fmt.Println(bcApp.Info())
|
||||
|
||||
tPriv := tests.PrivAccountFromSecret("test")
|
||||
valPrivKey0 := crypto.GenPrivKeyEd25519FromSecret([]byte("val0"))
|
||||
valPrivKey1 := crypto.GenPrivKeyEd25519FromSecret([]byte("val1"))
|
||||
valPrivKey2 := crypto.GenPrivKeyEd25519FromSecret([]byte("val2"))
|
||||
|
||||
// Seed Basecoin with admin using PrivAccount
|
||||
tAcc := tPriv.Account
|
||||
adminEntity := govtypes.Entity{
|
||||
ID: "",
|
||||
Addr: tAcc.PubKey.Address(),
|
||||
PubKey: tAcc.PubKey,
|
||||
}
|
||||
log := bcApp.SetOption("gov/admin", string(wire.JSONBytes(adminEntity)))
|
||||
|
@ -88,6 +94,24 @@ func testGov() {
|
|||
}
|
||||
|
||||
// Call InitChain to initialize the validator set
|
||||
bcApp.InitChain([]*tmsp.Validator{
|
||||
{PubKey: valPrivKey0.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: valPrivKey1.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: valPrivKey2.PubKey().Bytes(), Power: 1},
|
||||
})
|
||||
|
||||
// Query for validator set
|
||||
res := bcApp.Query(expr.MustCompile(`x02 x01 "gov/g/validators"`))
|
||||
if res.IsErr() {
|
||||
Exit(Fmt("Failed: %v", res.Error()))
|
||||
}
|
||||
group := govtypes.Group{}
|
||||
err := wire.ReadBinaryBytes(res.Data, &group)
|
||||
if err != nil {
|
||||
Exit(Fmt("Unexpected query response bytes: %X error: %v",
|
||||
res.Data, err))
|
||||
}
|
||||
fmt.Println(">>", group)
|
||||
|
||||
// TODO more tests...
|
||||
}
|
||||
|
@ -149,7 +173,7 @@ func testSequence() {
|
|||
fmt.Println("-------------------- RANDOM SENDS --------------------")
|
||||
|
||||
// Now send coins between these accounts
|
||||
for {
|
||||
for i := 0; i < 10000; i++ {
|
||||
randA := RandInt() % len(privAccounts)
|
||||
randB := RandInt() % len(privAccounts)
|
||||
if randA == randB {
|
||||
|
|
Loading…
Reference in New Issue