mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-02 14:11:37 +00:00
Begin implementation of local client
This commit is contained in:
45
rpc/client/local/app_test.go
Normal file
45
rpc/client/local/app_test.go
Normal file
@ -0,0 +1,45 @@
|
||||
package localclient_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
meapp "github.com/tendermint/merkleeyes/app"
|
||||
|
||||
wire "github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
// MakeTxKV returns a text transaction, allong with expected key, value pair
|
||||
func MakeTxKV() ([]byte, []byte, []byte) {
|
||||
k := RandAsciiBytes(8)
|
||||
v := RandAsciiBytes(8)
|
||||
return k, v, makeSet(k, v)
|
||||
}
|
||||
|
||||
// blatently copied from merkleeyes/app/app_test.go
|
||||
// constructs a "set" transaction
|
||||
func makeSet(key, value []byte) []byte {
|
||||
tx := make([]byte, 1+wire.ByteSliceSize(key)+wire.ByteSliceSize(value))
|
||||
buf := tx
|
||||
buf[0] = meapp.WriteSet // Set TypeByte
|
||||
buf = buf[1:]
|
||||
n, err := wire.PutByteSlice(buf, key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
buf = buf[n:]
|
||||
n, err = wire.PutByteSlice(buf, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
func RandAsciiBytes(n int) []byte {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return b
|
||||
}
|
Reference in New Issue
Block a user