Browse Source

Make counter app use LittleEndian uint64 encoding

pull/1780/head
Jae Kwon 9 years ago
parent
commit
4a0469d3ec
2 changed files with 10 additions and 11 deletions
  1. +5
    -6
      example/counter.go
  2. +5
    -5
      test.sh

+ 5
- 6
example/counter.go View File

@ -57,11 +57,10 @@ func (appC *CounterAppContext) SetOption(key string, value string) types.RetCode
func (appC *CounterAppContext) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
if appC.serial {
txValue, bz := binary.Varint(tx)
if bz <= 0 {
return nil, types.RetCodeInternalError
}
if txValue != int64(appC.txCount) {
tx8 := make([]byte, 8)
copy(tx8, tx)
txValue := binary.LittleEndian.Uint64(tx8)
if txValue != uint64(appC.txCount) {
return nil, types.RetCodeInternalError
}
}
@ -75,7 +74,7 @@ func (appC *CounterAppContext) GetHash() ([]byte, types.RetCode) {
return nil, 0
} else {
hash := make([]byte, 32)
binary.PutVarint(hash, int64(appC.txCount))
binary.LittleEndian.PutUint64(hash, uint64(appC.txCount))
return hash, 0
}
}


+ 5
- 5
test.sh View File

@ -76,20 +76,20 @@ OUTPUT=`(tmsp batch) <<STDIN
set_option serial on
append_tx 0x00
get_hash
append_tx 0x02
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}" != "02" ]]; then
echo "Expected hash to lead with 02. Got $HASH1"
if [[ "${HASH1:0:2}" != "01" ]]; then
echo "Expected hash to lead with 01. Got $HASH1"
exit 1
fi
if [[ "${HASH2:0:2}" != "04" ]]; then
echo "Expected hash to lead with 04. Got $HASH2"
if [[ "${HASH2:0:2}" != "02" ]]; then
echo "Expected hash to lead with 02. Got $HASH2"
exit 1
fi


Loading…
Cancel
Save