mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
Check field_code and type_code when readFieldOrdinal() is called (#81)
Added verification that nth and type are valid when read from BinaryParser
This commit is contained in:
@@ -50,7 +50,6 @@ function basicApiTests () {
|
||||
expect(parser.readUInt32()).toEqual(0xFFFFFFFF)
|
||||
})
|
||||
}
|
||||
basicApiTests()
|
||||
|
||||
function transactionParsingTests () {
|
||||
const transaction = {
|
||||
@@ -184,7 +183,6 @@ function transactionParsingTests () {
|
||||
expect(_.isPlainObject(jsonFromBinary)).toBe(true)
|
||||
})
|
||||
}
|
||||
transactionParsingTests()
|
||||
|
||||
function amountParsingTests () {
|
||||
_.filter(fixtures.values_tests, { type: 'Amount' }).forEach((f, i) => {
|
||||
@@ -206,7 +204,6 @@ function amountParsingTests () {
|
||||
})
|
||||
})
|
||||
}
|
||||
amountParsingTests()
|
||||
|
||||
function fieldParsingTests () {
|
||||
fixtures.fields_tests.forEach((f, i) => {
|
||||
@@ -217,8 +214,20 @@ function fieldParsingTests () {
|
||||
expect(field.type.name).toEqual(f.type_name)
|
||||
})
|
||||
})
|
||||
test("Field throws when type code out of range", () => {
|
||||
const parser = makeParser("0101");
|
||||
expect(() => parser.readField()).toThrow(new Error("Cannot read FieldOrdinal, type_code out of range"));
|
||||
})
|
||||
test("Field throws when field code out of range", () => {
|
||||
const parser = makeParser("1001");
|
||||
expect(() => parser.readFieldOrdinal()).toThrowError(new Error("Cannot read FieldOrdinal, field_code out of range"))
|
||||
})
|
||||
test("Field throws when both type and field code out of range", () => {
|
||||
const parser = makeParser("000101");
|
||||
expect(() => parser.readFieldOrdinal()).toThrowError(new Error("Cannot read FieldOrdinal, type_code out of range"))
|
||||
})
|
||||
}
|
||||
fieldParsingTests()
|
||||
|
||||
|
||||
function assertRecyclable (json, forField) {
|
||||
const Type = forField.associatedType
|
||||
@@ -366,9 +375,12 @@ function pathSetBinaryTests () {
|
||||
)
|
||||
})
|
||||
}
|
||||
pathSetBinaryTests()
|
||||
|
||||
describe('Binary Parser', function() {
|
||||
describe('pathSetBinaryTests', pathSetBinaryTests);
|
||||
describe('nestedObjectTests', nestedObjectTests);
|
||||
describe('fieldParsingTests', fieldParsingTests);
|
||||
describe('amountParsingTests', amountParsingTests);
|
||||
describe('transactionParsingTests', transactionParsingTests);
|
||||
describe('basicApiTests', basicApiTests);
|
||||
});
|
||||
Reference in New Issue
Block a user