You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
996 B

  1. package localclient_test
  2. import (
  3. "math/rand"
  4. meapp "github.com/tendermint/merkleeyes/app"
  5. wire "github.com/tendermint/go-wire"
  6. )
  7. // MakeTxKV returns a text transaction, allong with expected key, value pair
  8. func MakeTxKV() ([]byte, []byte, []byte) {
  9. k := RandAsciiBytes(8)
  10. v := RandAsciiBytes(8)
  11. return k, v, makeSet(k, v)
  12. }
  13. // blatently copied from merkleeyes/app/app_test.go
  14. // constructs a "set" transaction
  15. func makeSet(key, value []byte) []byte {
  16. tx := make([]byte, 1+wire.ByteSliceSize(key)+wire.ByteSliceSize(value))
  17. buf := tx
  18. buf[0] = meapp.WriteSet // Set TypeByte
  19. buf = buf[1:]
  20. n, err := wire.PutByteSlice(buf, key)
  21. if err != nil {
  22. panic(err)
  23. }
  24. buf = buf[n:]
  25. n, err = wire.PutByteSlice(buf, value)
  26. if err != nil {
  27. panic(err)
  28. }
  29. return tx
  30. }
  31. const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  32. func RandAsciiBytes(n int) []byte {
  33. b := make([]byte, n)
  34. for i := range b {
  35. b[i] = letterBytes[rand.Intn(len(letterBytes))]
  36. }
  37. return b
  38. }