Fix binary parsing of Vector256

This commit is contained in:
Nicholas Dudfield
2014-02-01 10:46:04 +07:00
parent 430dfef23d
commit 23528293e0
2 changed files with 17 additions and 1 deletions

View File

@@ -570,7 +570,8 @@ var STVector256 = exports.Vector256 = new SerializedType({
parse: function (so) {
var length = this.parse_varint(so);
var output = [];
for (var i=0; i<length; i++) {
// length is number of bytes not number of Hash256
for (var i=0; i<length / 32; i++) {
output.push(STHash256.parse(so));
}
return output;

View File

@@ -793,6 +793,21 @@ describe('Serialized types', function() {
});
describe('Object', function() {
it('Can parse objects with VL encoded Vector256', function() {
var hex = '110064220000000058000360186E008422E06B72D5B275E29EE3BE9D87A370F424E0E7BF613C4659098214289D19799C892637306AAAF03805EDFCDF6C28B8011320081342A0AB45459A54D8E4FA1842339A102680216CF9A152BCE4F4CE467D8246';
var so = new SerializedObject(hex);
var as_json = so.to_json();
var expected_json = {
"LedgerEntryType": "DirectoryNode",
"Owner": "rh6kN9s7spSb3vdv6H8ZGYzsddSLeEUGmc",
"Flags": 0,
"Indexes": [
"081342A0AB45459A54D8E4FA1842339A102680216CF9A152BCE4F4CE467D8246"
],
"RootIndex": "000360186E008422E06B72D5B275E29EE3BE9D87A370F424E0E7BF613C465909"
}
assert.deepEqual(as_json, expected_json);
});
it('Serialize empty object {}', function () {
var so = new SerializedObject();
types.Object.serialize(so, {});