diff --git a/Makefile b/Makefile index 9cb7475ac..2974e951a 100644 --- a/Makefile +++ b/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/... diff --git a/app/app.go b/app/app.go index 95c9ba10f..a086cf9dc 100644 --- a/app/app.go +++ b/app/app.go @@ -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] diff --git a/state/state.go b/state/state.go index 4a9c1167f..2f29184ce 100644 --- a/state/state.go +++ b/state/state.go @@ -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...) +} diff --git a/tests/tmsp/main.go b/tests/tmsp/main.go index f6495fcc6..1bbfd07f6 100644 --- a/tests/tmsp/main.go +++ b/tests/tmsp/main.go @@ -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 {