mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 01:11:32 +00:00
python fixes, tests
This commit is contained in:
@ -121,6 +121,8 @@ func cmdBatch(app *cli.App, c *cli.Context) {
|
||||
Exit("input line is too long")
|
||||
} else if err == io.EOF {
|
||||
break
|
||||
} else if len(line) == 0 {
|
||||
continue
|
||||
} else if err != nil {
|
||||
Exit(err.Error())
|
||||
}
|
||||
|
@ -38,9 +38,12 @@ class CounterAppContext():
|
||||
|
||||
def append_tx(self, txBytes):
|
||||
if self.serial:
|
||||
txValue = decode_big_endian(BytesReader(txBytes), len(txBytes))
|
||||
txByteArray = bytearray(txBytes)
|
||||
if len(txBytes) >= 2 and txBytes[:2] == "0x":
|
||||
txByteArray = hex2bytes(txBytes[2:])
|
||||
txValue = decode_big_endian(BytesReader(txByteArray), len(txBytes))
|
||||
if txValue != self.txCount:
|
||||
return [], 1
|
||||
return None, 1
|
||||
self.txCount += 1
|
||||
return None, 0
|
||||
|
||||
@ -48,7 +51,9 @@ class CounterAppContext():
|
||||
self.hashCount += 1
|
||||
if self.txCount == 0:
|
||||
return "", 0
|
||||
return str(encode_big_endian(self.txCount, 8)), 0
|
||||
h = encode_big_endian(self.txCount, 8)
|
||||
h.reverse()
|
||||
return str(h), 0
|
||||
|
||||
def commit(self):
|
||||
return 0
|
||||
|
@ -6,6 +6,7 @@ class BytesReader():
|
||||
|
||||
def read(self, n):
|
||||
if len(self.buf) < n:
|
||||
print "reader err: buf less than n"
|
||||
# TODO: exception
|
||||
return
|
||||
r = self.buf[:n]
|
||||
|
@ -77,9 +77,9 @@ class TMSPServer():
|
||||
ret_code = res
|
||||
res = None
|
||||
|
||||
print "called", req_type, "ret code:", ret_code
|
||||
if ret_code != 0:
|
||||
print "non-zero retcode:", ret_code
|
||||
return
|
||||
|
||||
if req_type in ("echo", "info"): # these dont return a ret code
|
||||
response += bytearray([resTypeByte]) + encode(res)
|
||||
|
@ -2,6 +2,9 @@
|
||||
# the decoder works off a reader
|
||||
# the encoder returns bytearray
|
||||
|
||||
def hex2bytes(h):
|
||||
return bytearray(h.decode('hex'))
|
||||
|
||||
def bytes2hex(b):
|
||||
if type(b) in (str, unicode):
|
||||
return "".join([hex(ord(c))[2:].zfill(2) for c in b])
|
||||
|
13
tests/test.sh
Normal file
13
tests/test.sh
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
ROOT=$GOPATH/src/github.com/tendermint/tmsp
|
||||
cd $ROOT
|
||||
|
||||
# test golang dummy
|
||||
bash tests/test_dummy.sh
|
||||
|
||||
# test golang counter
|
||||
bash tests/test_counter.sh
|
||||
|
||||
# test python counter
|
||||
cd example/python
|
||||
COUNTER_APP="python app.py" bash $ROOT/tests/test_counter.sh
|
75
tests/test_counter.sh
Normal file
75
tests/test_counter.sh
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
# so we can test other languages
|
||||
if [[ "$COUNTER_APP" == "" ]]; then
|
||||
COUNTER_APP="counter"
|
||||
fi
|
||||
|
||||
echo "Testing counter app for: $COUNTER_APP"
|
||||
|
||||
# run the counter app
|
||||
$COUNTER_APP &> /dev/null &
|
||||
PID=`echo $!`
|
||||
|
||||
if [[ "$?" != 0 ]]; then
|
||||
echo "Error running tmsp command"
|
||||
echo $OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
OUTPUT=`(tmsp batch) <<STDIN
|
||||
set_option serial on
|
||||
get_hash
|
||||
append_tx abc
|
||||
STDIN`
|
||||
|
||||
if [[ "$?" != 0 ]]; then
|
||||
echo "Error running tmsp command"
|
||||
echo $OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# why can't we pick up the non-zero exit code here?
|
||||
# echo $?
|
||||
|
||||
HASH1=`echo "$OUTPUT" | tail -n +2 | head -n 1`
|
||||
if [[ "${HASH1}" != "" ]]; then
|
||||
echo "Expected opening hash to be empty. Got $HASH1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUTPUT=`(tmsp batch) <<STDIN
|
||||
set_option serial on
|
||||
append_tx 0x00
|
||||
get_hash
|
||||
append_tx 0x01
|
||||
get_hash
|
||||
STDIN`
|
||||
|
||||
if [[ "$?" != 0 ]]; then
|
||||
echo "Error running tmsp command"
|
||||
echo $OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HASH1=`echo "$OUTPUT" | tail -n +3 | head -n 1`
|
||||
HASH2=`echo "$OUTPUT" | tail -n +5 | head -n 1`
|
||||
|
||||
if [[ "${HASH1:0:2}" != "01" ]]; then
|
||||
echo "Expected hash to lead with 01. Got $HASH1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${HASH2:0:2}" != "02" ]]; then
|
||||
echo "Expected hash to lead with 02. Got $HASH2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "... Pass!"
|
||||
echo ""
|
||||
|
||||
ps -p $PID > /dev/null
|
||||
if [[ "$?" == "0" ]]; then
|
||||
kill -9 $PID
|
||||
fi
|
||||
|
@ -51,50 +51,3 @@ echo ""
|
||||
|
||||
kill $PID
|
||||
sleep 1
|
||||
|
||||
# test the counter app
|
||||
echo "Counter test ..."
|
||||
counter &> /dev/null &
|
||||
PID=`echo $!`
|
||||
sleep 1
|
||||
OUTPUT=`(tmsp batch) <<STDIN
|
||||
set_option serial on
|
||||
get_hash
|
||||
append_tx abc
|
||||
STDIN`
|
||||
|
||||
# why can't we pick up the non-zero exit code here?
|
||||
# echo $?
|
||||
|
||||
HASH1=`echo "$OUTPUT" | tail -n +2 | head -n 1`
|
||||
if [[ "$HASH1" != "" ]]; then
|
||||
echo "Expected opening hash to be empty. Got $HASH1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUTPUT=`(tmsp batch) <<STDIN
|
||||
set_option serial on
|
||||
append_tx 0x00
|
||||
get_hash
|
||||
append_tx 0x01
|
||||
get_hash
|
||||
STDIN`
|
||||
|
||||
HASH1=`echo "$OUTPUT" | tail -n +3 | head -n 1`
|
||||
HASH2=`echo "$OUTPUT" | tail -n +5 | head -n 1`
|
||||
|
||||
if [[ "${HASH1:0:2}" != "01" ]]; then
|
||||
echo "Expected hash to lead with 01. Got $HASH1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${HASH2:0:2}" != "02" ]]; then
|
||||
echo "Expected hash to lead with 02. Got $HASH2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "... Pass!"
|
||||
echo ""
|
||||
|
||||
kill $PID
|
||||
|
Reference in New Issue
Block a user