mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-15 10:05:48 +00:00
run prettier on all packages
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
const { loadFixture } = require("./utils");
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { Amount } = coreTypes;
|
||||
const fixtures = loadFixture("data-driven-tests.json");
|
||||
const { loadFixture } = require('./utils')
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { Amount } = coreTypes
|
||||
const fixtures = loadFixture('data-driven-tests.json')
|
||||
|
||||
function amountErrorTests() {
|
||||
fixtures.values_tests
|
||||
.filter((obj) => obj.type === "Amount")
|
||||
.filter((obj) => obj.type === 'Amount')
|
||||
.forEach((f) => {
|
||||
// We only want these with errors
|
||||
if (!f.error) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const testName =
|
||||
`${JSON.stringify(f.test_json)}\n\tis invalid ` + `because: ${f.error}`;
|
||||
`${JSON.stringify(f.test_json)}\n\tis invalid ` + `because: ${f.error}`
|
||||
it(testName, () => {
|
||||
expect(() => {
|
||||
Amount.from(f.test_json);
|
||||
JSON.stringify(f.test_json);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
Amount.from(f.test_json)
|
||||
JSON.stringify(f.test_json)
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe("Amount", function () {
|
||||
it("can be parsed from", function () {
|
||||
expect(Amount.from("1000000") instanceof Amount).toBe(true);
|
||||
expect(Amount.from("1000000").toJSON()).toEqual("1000000");
|
||||
describe('Amount', function () {
|
||||
it('can be parsed from', function () {
|
||||
expect(Amount.from('1000000') instanceof Amount).toBe(true)
|
||||
expect(Amount.from('1000000').toJSON()).toEqual('1000000')
|
||||
const fixture = {
|
||||
value: "1",
|
||||
issuer: "0000000000000000000000000000000000000000",
|
||||
currency: "USD",
|
||||
};
|
||||
const amt = Amount.from(fixture);
|
||||
value: '1',
|
||||
issuer: '0000000000000000000000000000000000000000',
|
||||
currency: 'USD',
|
||||
}
|
||||
const amt = Amount.from(fixture)
|
||||
const rewritten = {
|
||||
value: "1",
|
||||
issuer: "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||
currency: "USD",
|
||||
};
|
||||
expect(amt.toJSON()).toEqual(rewritten);
|
||||
});
|
||||
amountErrorTests();
|
||||
});
|
||||
value: '1',
|
||||
issuer: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
|
||||
currency: 'USD',
|
||||
}
|
||||
expect(amt.toJSON()).toEqual(rewritten)
|
||||
})
|
||||
amountErrorTests()
|
||||
})
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
const fixtures = require("./fixtures/codec-fixtures.json");
|
||||
const { decode, encode, decodeLedgerData } = require("../dist");
|
||||
const fixtures = require('./fixtures/codec-fixtures.json')
|
||||
const { decode, encode, decodeLedgerData } = require('../dist')
|
||||
|
||||
function json(object) {
|
||||
return JSON.stringify(object);
|
||||
return JSON.stringify(object)
|
||||
}
|
||||
|
||||
function truncateForDisplay(longStr) {
|
||||
return `${longStr.slice(0, 10)} ... ${longStr.slice(-10)}`;
|
||||
return `${longStr.slice(0, 10)} ... ${longStr.slice(-10)}`
|
||||
}
|
||||
|
||||
describe("ripple-binary-codec", function () {
|
||||
describe('ripple-binary-codec', function () {
|
||||
function makeSuite(name, entries) {
|
||||
describe(name, function () {
|
||||
entries.forEach((t, testN) => {
|
||||
test(`${name}[${testN}] can encode ${truncateForDisplay(
|
||||
json(t.json)
|
||||
json(t.json),
|
||||
)} to ${truncateForDisplay(t.binary)}`, () => {
|
||||
expect(encode(t.json)).toEqual(t.binary);
|
||||
});
|
||||
expect(encode(t.json)).toEqual(t.binary)
|
||||
})
|
||||
test(`${name}[${testN}] can decode ${truncateForDisplay(
|
||||
t.binary
|
||||
t.binary,
|
||||
)} to ${truncateForDisplay(json(t.json))}`, () => {
|
||||
const decoded = decode(t.binary);
|
||||
expect(decoded).toEqual(t.json);
|
||||
});
|
||||
});
|
||||
});
|
||||
const decoded = decode(t.binary)
|
||||
expect(decoded).toEqual(t.json)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
makeSuite("transactions", fixtures.transactions);
|
||||
makeSuite("accountState", fixtures.accountState);
|
||||
makeSuite('transactions', fixtures.transactions)
|
||||
makeSuite('accountState', fixtures.accountState)
|
||||
|
||||
describe("ledgerData", function () {
|
||||
describe('ledgerData', function () {
|
||||
if (fixtures.ledgerData) {
|
||||
fixtures.ledgerData.forEach((t, testN) => {
|
||||
test(`ledgerData[${testN}] can decode ${t.binary} to ${json(
|
||||
t.json
|
||||
t.json,
|
||||
)}`, () => {
|
||||
const decoded = decodeLedgerData(t.binary);
|
||||
expect(t.json).toEqual(decoded);
|
||||
});
|
||||
});
|
||||
const decoded = decodeLedgerData(t.binary)
|
||||
expect(t.json).toEqual(decoded)
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const Decimal = require("decimal.js");
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const Decimal = require('decimal.js')
|
||||
|
||||
const { encodeAccountID } = require("ripple-address-codec");
|
||||
const { binary } = require("../dist/coretypes");
|
||||
const { Amount, Hash160 } = coreTypes;
|
||||
const { makeParser, readJSON } = binary;
|
||||
const { Field, TransactionType } = require("./../dist/enums");
|
||||
const { parseHexOnly, hexOnly, loadFixture } = require("./utils");
|
||||
const fixtures = loadFixture("data-driven-tests.json");
|
||||
const { BytesList } = require("../dist/serdes/binary-serializer");
|
||||
const { Buffer } = require("buffer/");
|
||||
const { encodeAccountID } = require('ripple-address-codec')
|
||||
const { binary } = require('../dist/coretypes')
|
||||
const { Amount, Hash160 } = coreTypes
|
||||
const { makeParser, readJSON } = binary
|
||||
const { Field, TransactionType } = require('./../dist/enums')
|
||||
const { parseHexOnly, hexOnly, loadFixture } = require('./utils')
|
||||
const fixtures = loadFixture('data-driven-tests.json')
|
||||
const { BytesList } = require('../dist/serdes/binary-serializer')
|
||||
const { Buffer } = require('buffer/')
|
||||
|
||||
const __ = hexOnly;
|
||||
const __ = hexOnly
|
||||
function toJSON(v) {
|
||||
return v.toJSON ? v.toJSON() : v;
|
||||
return v.toJSON ? v.toJSON() : v
|
||||
}
|
||||
|
||||
function assertEqualAmountJSON(actual, expected) {
|
||||
expect(typeof actual === typeof expected).toBe(true);
|
||||
if (typeof actual === "string") {
|
||||
expect(actual).toEqual(expected);
|
||||
return;
|
||||
expect(typeof actual === typeof expected).toBe(true)
|
||||
if (typeof actual === 'string') {
|
||||
expect(actual).toEqual(expected)
|
||||
return
|
||||
}
|
||||
expect(actual.currency).toEqual(expected.currency);
|
||||
expect(actual.issuer).toEqual(expected.issuer);
|
||||
expect(actual.currency).toEqual(expected.currency)
|
||||
expect(actual.issuer).toEqual(expected.issuer)
|
||||
expect(
|
||||
actual.value === expected.value ||
|
||||
new Decimal(actual.value).equals(new Decimal(expected.value))
|
||||
).toBe(true);
|
||||
new Decimal(actual.value).equals(new Decimal(expected.value)),
|
||||
).toBe(true)
|
||||
}
|
||||
|
||||
function basicApiTests() {
|
||||
const bytes = parseHexOnly("00,01020304,0506", Uint8Array);
|
||||
test("can read slices of bytes", () => {
|
||||
const parser = makeParser(bytes);
|
||||
expect(parser.bytes instanceof Buffer).toBe(true);
|
||||
const read1 = parser.read(1);
|
||||
expect(read1 instanceof Buffer).toBe(true);
|
||||
expect(read1).toEqual(Buffer.from([0]));
|
||||
expect(parser.read(4)).toEqual(Buffer.from([1, 2, 3, 4]));
|
||||
expect(parser.read(2)).toEqual(Buffer.from([5, 6]));
|
||||
expect(() => parser.read(1)).toThrow();
|
||||
});
|
||||
test("can read a Uint32 at full", () => {
|
||||
const parser = makeParser("FFFFFFFF");
|
||||
expect(parser.readUInt32()).toEqual(0xffffffff);
|
||||
});
|
||||
const bytes = parseHexOnly('00,01020304,0506', Uint8Array)
|
||||
test('can read slices of bytes', () => {
|
||||
const parser = makeParser(bytes)
|
||||
expect(parser.bytes instanceof Buffer).toBe(true)
|
||||
const read1 = parser.read(1)
|
||||
expect(read1 instanceof Buffer).toBe(true)
|
||||
expect(read1).toEqual(Buffer.from([0]))
|
||||
expect(parser.read(4)).toEqual(Buffer.from([1, 2, 3, 4]))
|
||||
expect(parser.read(2)).toEqual(Buffer.from([5, 6]))
|
||||
expect(() => parser.read(1)).toThrow()
|
||||
})
|
||||
test('can read a Uint32 at full', () => {
|
||||
const parser = makeParser('FFFFFFFF')
|
||||
expect(parser.readUInt32()).toEqual(0xffffffff)
|
||||
})
|
||||
}
|
||||
|
||||
function transactionParsingTests() {
|
||||
const transaction = {
|
||||
json: {
|
||||
Account: "raD5qJMAShLeHZXf9wjUmo6vRK4arj9cF3",
|
||||
Fee: "10",
|
||||
Account: 'raD5qJMAShLeHZXf9wjUmo6vRK4arj9cF3',
|
||||
Fee: '10',
|
||||
Flags: 0,
|
||||
Sequence: 103929,
|
||||
SigningPubKey:
|
||||
"028472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F418D6A7166",
|
||||
'028472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F418D6A7166',
|
||||
TakerGets: {
|
||||
currency: "ILS",
|
||||
issuer: "rNPRNzBB92BVpAhhZr4iXDTveCgV5Pofm9",
|
||||
value: "1694.768",
|
||||
currency: 'ILS',
|
||||
issuer: 'rNPRNzBB92BVpAhhZr4iXDTveCgV5Pofm9',
|
||||
value: '1694.768',
|
||||
},
|
||||
TakerPays: "98957503520",
|
||||
TransactionType: "OfferCreate",
|
||||
TakerPays: '98957503520',
|
||||
TransactionType: 'OfferCreate',
|
||||
TxnSignature: __(`
|
||||
304502202ABE08D5E78D1E74A4C18F2714F64E87B8BD57444AF
|
||||
A5733109EB3C077077520022100DB335EE97386E4C0591CAC02
|
||||
@@ -78,208 +78,208 @@ function transactionParsingTests() {
|
||||
8BD57444AFA5733109EB3C077077520022100DB335EE97386E4C059
|
||||
1CAC024D50E9230D8F171EEB901B5E5E4BD6D1E0AEF98C811439408
|
||||
A69F0895E62149CFCC006FB89FA7D1E6E5D`),
|
||||
};
|
||||
}
|
||||
|
||||
const tx_json = transaction.json;
|
||||
const tx_json = transaction.json
|
||||
// These tests are basically development logs
|
||||
|
||||
test("can be done with low level apis", () => {
|
||||
const parser = makeParser(transaction.binary);
|
||||
test('can be done with low level apis', () => {
|
||||
const parser = makeParser(transaction.binary)
|
||||
|
||||
expect(parser.readField()).toEqual(Field.TransactionType);
|
||||
expect(parser.readUInt16()).toEqual(7);
|
||||
expect(parser.readField()).toEqual(Field.Flags);
|
||||
expect(parser.readUInt32()).toEqual(0);
|
||||
expect(parser.readField()).toEqual(Field.Sequence);
|
||||
expect(parser.readUInt32()).toEqual(103929);
|
||||
expect(parser.readField()).toEqual(Field.TakerPays);
|
||||
parser.read(8);
|
||||
expect(parser.readField()).toEqual(Field.TakerGets);
|
||||
expect(parser.readField()).toEqual(Field.TransactionType)
|
||||
expect(parser.readUInt16()).toEqual(7)
|
||||
expect(parser.readField()).toEqual(Field.Flags)
|
||||
expect(parser.readUInt32()).toEqual(0)
|
||||
expect(parser.readField()).toEqual(Field.Sequence)
|
||||
expect(parser.readUInt32()).toEqual(103929)
|
||||
expect(parser.readField()).toEqual(Field.TakerPays)
|
||||
parser.read(8)
|
||||
expect(parser.readField()).toEqual(Field.TakerGets)
|
||||
// amount value
|
||||
expect(parser.read(8)).not.toBe([]);
|
||||
expect(parser.read(8)).not.toBe([])
|
||||
// amount currency
|
||||
expect(Hash160.fromParser(parser)).not.toBe([]);
|
||||
expect(encodeAccountID(parser.read(20))).toEqual(tx_json.TakerGets.issuer);
|
||||
expect(parser.readField()).toEqual(Field.Fee);
|
||||
expect(parser.read(8)).not.toEqual([]);
|
||||
expect(parser.readField()).toEqual(Field.SigningPubKey);
|
||||
expect(parser.readVariableLengthLength()).toBe(33);
|
||||
expect(parser.read(33).toString("hex").toUpperCase()).toEqual(
|
||||
tx_json.SigningPubKey
|
||||
);
|
||||
expect(parser.readField()).toEqual(Field.TxnSignature);
|
||||
expect(parser.readVariableLength().toString("hex").toUpperCase()).toEqual(
|
||||
tx_json.TxnSignature
|
||||
);
|
||||
expect(parser.readField()).toEqual(Field.Account);
|
||||
expect(Hash160.fromParser(parser)).not.toBe([])
|
||||
expect(encodeAccountID(parser.read(20))).toEqual(tx_json.TakerGets.issuer)
|
||||
expect(parser.readField()).toEqual(Field.Fee)
|
||||
expect(parser.read(8)).not.toEqual([])
|
||||
expect(parser.readField()).toEqual(Field.SigningPubKey)
|
||||
expect(parser.readVariableLengthLength()).toBe(33)
|
||||
expect(parser.read(33).toString('hex').toUpperCase()).toEqual(
|
||||
tx_json.SigningPubKey,
|
||||
)
|
||||
expect(parser.readField()).toEqual(Field.TxnSignature)
|
||||
expect(parser.readVariableLength().toString('hex').toUpperCase()).toEqual(
|
||||
tx_json.TxnSignature,
|
||||
)
|
||||
expect(parser.readField()).toEqual(Field.Account)
|
||||
expect(encodeAccountID(parser.readVariableLength())).toEqual(
|
||||
tx_json.Account
|
||||
);
|
||||
expect(parser.end()).toBe(true);
|
||||
});
|
||||
tx_json.Account,
|
||||
)
|
||||
expect(parser.end()).toBe(true)
|
||||
})
|
||||
|
||||
test("can be done with high level apis", () => {
|
||||
const parser = makeParser(transaction.binary);
|
||||
test('can be done with high level apis', () => {
|
||||
const parser = makeParser(transaction.binary)
|
||||
function readField() {
|
||||
return parser.readFieldAndValue();
|
||||
return parser.readFieldAndValue()
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.TransactionType);
|
||||
expect(value).toEqual(TransactionType.OfferCreate);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.TransactionType)
|
||||
expect(value).toEqual(TransactionType.OfferCreate)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.Flags);
|
||||
expect(value.valueOf()).toEqual(0);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.Flags)
|
||||
expect(value.valueOf()).toEqual(0)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.Sequence);
|
||||
expect(value.valueOf()).toEqual(103929);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.Sequence)
|
||||
expect(value.valueOf()).toEqual(103929)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.TakerPays);
|
||||
expect(value.isNative()).toEqual(true);
|
||||
expect(value.toJSON()).toEqual("98957503520");
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.TakerPays)
|
||||
expect(value.isNative()).toEqual(true)
|
||||
expect(value.toJSON()).toEqual('98957503520')
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.TakerGets);
|
||||
expect(value.isNative()).toEqual(false);
|
||||
expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.TakerGets)
|
||||
expect(value.isNative()).toEqual(false)
|
||||
expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.Fee);
|
||||
expect(value.isNative()).toEqual(true);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.Fee)
|
||||
expect(value.isNative()).toEqual(true)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.SigningPubKey);
|
||||
expect(value.toJSON()).toEqual(tx_json.SigningPubKey);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.SigningPubKey)
|
||||
expect(value.toJSON()).toEqual(tx_json.SigningPubKey)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.TxnSignature);
|
||||
expect(value.toJSON()).toEqual(tx_json.TxnSignature);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.TxnSignature)
|
||||
expect(value.toJSON()).toEqual(tx_json.TxnSignature)
|
||||
}
|
||||
{
|
||||
const [field, value] = readField();
|
||||
expect(field).toEqual(Field.Account);
|
||||
expect(value.toJSON()).toEqual(tx_json.Account);
|
||||
const [field, value] = readField()
|
||||
expect(field).toEqual(Field.Account)
|
||||
expect(value.toJSON()).toEqual(tx_json.Account)
|
||||
}
|
||||
expect(parser.end()).toBe(true);
|
||||
});
|
||||
expect(parser.end()).toBe(true)
|
||||
})
|
||||
|
||||
test("can be done with higher level apis", () => {
|
||||
const parser = makeParser(transaction.binary);
|
||||
const jsonFromBinary = readJSON(parser);
|
||||
expect(jsonFromBinary).toEqual(tx_json);
|
||||
});
|
||||
test('can be done with higher level apis', () => {
|
||||
const parser = makeParser(transaction.binary)
|
||||
const jsonFromBinary = readJSON(parser)
|
||||
expect(jsonFromBinary).toEqual(tx_json)
|
||||
})
|
||||
|
||||
test("readJSON (binary.decode) does not return STObject ", () => {
|
||||
const parser = makeParser(transaction.binary);
|
||||
const jsonFromBinary = readJSON(parser);
|
||||
expect(jsonFromBinary instanceof coreTypes.STObject).toBe(false);
|
||||
expect(jsonFromBinary instanceof Object).toBe(true);
|
||||
expect(jsonFromBinary.prototype).toBe(undefined);
|
||||
});
|
||||
test('readJSON (binary.decode) does not return STObject ', () => {
|
||||
const parser = makeParser(transaction.binary)
|
||||
const jsonFromBinary = readJSON(parser)
|
||||
expect(jsonFromBinary instanceof coreTypes.STObject).toBe(false)
|
||||
expect(jsonFromBinary instanceof Object).toBe(true)
|
||||
expect(jsonFromBinary.prototype).toBe(undefined)
|
||||
})
|
||||
}
|
||||
|
||||
function amountParsingTests() {
|
||||
fixtures.values_tests
|
||||
.filter((obj) => obj.type === "Amount")
|
||||
.filter((obj) => obj.type === 'Amount')
|
||||
.forEach((f, i) => {
|
||||
if (f.error) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const parser = makeParser(f.expected_hex);
|
||||
const parser = makeParser(f.expected_hex)
|
||||
const testName = `values_tests[${i}] parses ${f.expected_hex.slice(
|
||||
0,
|
||||
16
|
||||
16,
|
||||
)}...
|
||||
as ${JSON.stringify(f.test_json)}`;
|
||||
as ${JSON.stringify(f.test_json)}`
|
||||
test(testName, () => {
|
||||
const value = parser.readType(Amount);
|
||||
const value = parser.readType(Amount)
|
||||
// May not actually be in canonical form. The fixtures are to be used
|
||||
// also for json -> binary;
|
||||
const json = toJSON(value);
|
||||
assertEqualAmountJSON(json, f.test_json);
|
||||
const json = toJSON(value)
|
||||
assertEqualAmountJSON(json, f.test_json)
|
||||
if (f.exponent) {
|
||||
const exponent = new Decimal(json.value);
|
||||
expect(exponent.e - 15).toEqual(f.exponent);
|
||||
const exponent = new Decimal(json.value)
|
||||
expect(exponent.e - 15).toEqual(f.exponent)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fieldParsingTests() {
|
||||
fixtures.fields_tests.forEach((f, i) => {
|
||||
const parser = makeParser(f.expected_hex);
|
||||
const parser = makeParser(f.expected_hex)
|
||||
test(`fields[${i}]: parses ${f.expected_hex} as ${f.name}`, () => {
|
||||
const field = parser.readField();
|
||||
expect(field.name).toEqual(f.name);
|
||||
expect(field.type.name).toEqual(f.type_name);
|
||||
});
|
||||
});
|
||||
test("Field throws when type code out of range", () => {
|
||||
const parser = makeParser("0101");
|
||||
const field = parser.readField()
|
||||
expect(field.name).toEqual(f.name)
|
||||
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");
|
||||
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");
|
||||
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")
|
||||
);
|
||||
});
|
||||
new Error('Cannot read FieldOrdinal, type_code out of range'),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function assertRecyclable(json, forField) {
|
||||
const Type = forField.associatedType;
|
||||
const recycled = Type.from(json).toJSON();
|
||||
expect(recycled).toEqual(json);
|
||||
const sink = new BytesList();
|
||||
Type.from(recycled).toBytesSink(sink);
|
||||
const recycledAgain = makeParser(sink.toHex()).readType(Type).toJSON();
|
||||
expect(recycledAgain).toEqual(json);
|
||||
const Type = forField.associatedType
|
||||
const recycled = Type.from(json).toJSON()
|
||||
expect(recycled).toEqual(json)
|
||||
const sink = new BytesList()
|
||||
Type.from(recycled).toBytesSink(sink)
|
||||
const recycledAgain = makeParser(sink.toHex()).readType(Type).toJSON()
|
||||
expect(recycledAgain).toEqual(json)
|
||||
}
|
||||
|
||||
function nestedObjectTests() {
|
||||
fixtures.whole_objects.forEach((f, i) => {
|
||||
test(`whole_objects[${i}]: can parse blob into
|
||||
${JSON.stringify(
|
||||
f.tx_json
|
||||
f.tx_json,
|
||||
)}`, /* */ () => {
|
||||
const parser = makeParser(f.blob_with_no_signing);
|
||||
let ix = 0;
|
||||
const parser = makeParser(f.blob_with_no_signing)
|
||||
let ix = 0
|
||||
while (!parser.end()) {
|
||||
const [field, value] = parser.readFieldAndValue();
|
||||
const expected = f.fields[ix];
|
||||
const expectedJSON = expected[1].json;
|
||||
const expectedField = expected[0];
|
||||
const actual = toJSON(value);
|
||||
const [field, value] = parser.readFieldAndValue()
|
||||
const expected = f.fields[ix]
|
||||
const expectedJSON = expected[1].json
|
||||
const expectedField = expected[0]
|
||||
const actual = toJSON(value)
|
||||
|
||||
try {
|
||||
expect(actual).toEqual(expectedJSON);
|
||||
expect(actual).toEqual(expectedJSON)
|
||||
} catch (e) {
|
||||
throw new Error(`${e} ${field} a: ${actual} e: ${expectedJSON}`);
|
||||
throw new Error(`${e} ${field} a: ${actual} e: ${expectedJSON}`)
|
||||
}
|
||||
expect(field.name).toEqual(expectedField);
|
||||
assertRecyclable(actual, field);
|
||||
ix++;
|
||||
expect(field.name).toEqual(expectedField)
|
||||
assertRecyclable(actual, field)
|
||||
ix++
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function pathSetBinaryTests() {
|
||||
@@ -312,85 +312,85 @@ function pathSetBinaryTests() {
|
||||
69E6DCC940CA48D82337AD000000000000000000000000425443000000000057
|
||||
180C769B66D942EE69E6DCC940CA48D82337AD10000000000000000000000000
|
||||
00000000000000003000000000000000000000000055534400000000000A20B3
|
||||
C85F482532A9578DBB3950B85CA06594D100`
|
||||
);
|
||||
C85F482532A9578DBB3950B85CA06594D100`,
|
||||
)
|
||||
|
||||
const expectedJSON = [
|
||||
[
|
||||
{
|
||||
account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
currency: "BTC",
|
||||
issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
currency: 'BTC',
|
||||
issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
},
|
||||
{
|
||||
account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
|
||||
currency: "BTC",
|
||||
issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
|
||||
account: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
|
||||
currency: 'BTC',
|
||||
issuer: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
|
||||
},
|
||||
{
|
||||
account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
currency: "BTC",
|
||||
issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
currency: 'BTC',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
},
|
||||
{
|
||||
currency: "USD",
|
||||
issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
currency: 'USD',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
currency: "BTC",
|
||||
issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
currency: 'BTC',
|
||||
issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
},
|
||||
{
|
||||
account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
|
||||
currency: "BTC",
|
||||
issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
|
||||
account: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
|
||||
currency: 'BTC',
|
||||
issuer: 'rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo',
|
||||
},
|
||||
{
|
||||
account: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
|
||||
currency: "BTC",
|
||||
issuer: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
|
||||
account: 'rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi',
|
||||
currency: 'BTC',
|
||||
issuer: 'rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi',
|
||||
},
|
||||
{
|
||||
currency: "USD",
|
||||
issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
currency: 'USD',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
currency: "BTC",
|
||||
issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
|
||||
account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
currency: 'BTC',
|
||||
issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||
},
|
||||
{
|
||||
account: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
|
||||
currency: "BTC",
|
||||
issuer: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
|
||||
account: 'r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn',
|
||||
currency: 'BTC',
|
||||
issuer: 'r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn',
|
||||
},
|
||||
{ currency: "XRP" },
|
||||
{ currency: 'XRP' },
|
||||
{
|
||||
currency: "USD",
|
||||
issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
currency: 'USD',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
},
|
||||
],
|
||||
];
|
||||
]
|
||||
|
||||
test("works with long paths", () => {
|
||||
const parser = makeParser(bytes);
|
||||
const txn = readJSON(parser);
|
||||
expect(txn.Paths).toEqual(expectedJSON);
|
||||
test('works with long paths', () => {
|
||||
const parser = makeParser(bytes)
|
||||
const txn = readJSON(parser)
|
||||
expect(txn.Paths).toEqual(expectedJSON)
|
||||
// TODO: this should go elsewhere
|
||||
expect(coreTypes.PathSet.from(txn.Paths).toJSON()).toEqual(expectedJSON);
|
||||
});
|
||||
expect(coreTypes.PathSet.from(txn.Paths).toJSON()).toEqual(expectedJSON)
|
||||
})
|
||||
}
|
||||
|
||||
describe("Binary Parser", function () {
|
||||
describe("pathSetBinaryTests", () => pathSetBinaryTests());
|
||||
describe("nestedObjectTests", () => nestedObjectTests());
|
||||
describe("fieldParsingTests", () => fieldParsingTests());
|
||||
describe("amountParsingTests", () => amountParsingTests());
|
||||
describe("transactionParsingTests", () => transactionParsingTests());
|
||||
describe("basicApiTests", () => basicApiTests());
|
||||
});
|
||||
describe('Binary Parser', function () {
|
||||
describe('pathSetBinaryTests', () => pathSetBinaryTests())
|
||||
describe('nestedObjectTests', () => nestedObjectTests())
|
||||
describe('fieldParsingTests', () => fieldParsingTests())
|
||||
describe('amountParsingTests', () => amountParsingTests())
|
||||
describe('transactionParsingTests', () => transactionParsingTests())
|
||||
describe('basicApiTests', () => basicApiTests())
|
||||
})
|
||||
|
||||
@@ -1,260 +1,258 @@
|
||||
const { binary } = require("../dist/coretypes");
|
||||
const { encode, decode } = require("../dist");
|
||||
const { makeParser, BytesList, BinarySerializer } = binary;
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes;
|
||||
const bigInt = require("big-integer");
|
||||
const { Buffer } = require("buffer/");
|
||||
const { binary } = require('../dist/coretypes')
|
||||
const { encode, decode } = require('../dist')
|
||||
const { makeParser, BytesList, BinarySerializer } = binary
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes
|
||||
const bigInt = require('big-integer')
|
||||
const { Buffer } = require('buffer/')
|
||||
|
||||
const { loadFixture } = require("./utils");
|
||||
const fixtures = loadFixture("data-driven-tests.json");
|
||||
const deliverMinTx = require("./fixtures/delivermin-tx.json");
|
||||
const deliverMinTxBinary = require("./fixtures/delivermin-tx-binary.json");
|
||||
const { loadFixture } = require('./utils')
|
||||
const fixtures = loadFixture('data-driven-tests.json')
|
||||
const deliverMinTx = require('./fixtures/delivermin-tx.json')
|
||||
const deliverMinTxBinary = require('./fixtures/delivermin-tx-binary.json')
|
||||
const SignerListSet = {
|
||||
tx: require("./fixtures/signerlistset-tx.json"),
|
||||
binary: require("./fixtures/signerlistset-tx-binary.json"),
|
||||
meta: require("./fixtures/signerlistset-tx-meta-binary.json"),
|
||||
};
|
||||
tx: require('./fixtures/signerlistset-tx.json'),
|
||||
binary: require('./fixtures/signerlistset-tx-binary.json'),
|
||||
meta: require('./fixtures/signerlistset-tx-meta-binary.json'),
|
||||
}
|
||||
const DepositPreauth = {
|
||||
tx: require("./fixtures/deposit-preauth-tx.json"),
|
||||
binary: require("./fixtures/deposit-preauth-tx-binary.json"),
|
||||
meta: require("./fixtures/deposit-preauth-tx-meta-binary.json"),
|
||||
};
|
||||
tx: require('./fixtures/deposit-preauth-tx.json'),
|
||||
binary: require('./fixtures/deposit-preauth-tx-binary.json'),
|
||||
meta: require('./fixtures/deposit-preauth-tx-meta-binary.json'),
|
||||
}
|
||||
const Escrow = {
|
||||
create: {
|
||||
tx: require("./fixtures/escrow-create-tx.json"),
|
||||
binary: require("./fixtures/escrow-create-binary.json"),
|
||||
tx: require('./fixtures/escrow-create-tx.json'),
|
||||
binary: require('./fixtures/escrow-create-binary.json'),
|
||||
},
|
||||
finish: {
|
||||
tx: require("./fixtures/escrow-finish-tx.json"),
|
||||
binary: require("./fixtures/escrow-finish-binary.json"),
|
||||
meta: require("./fixtures/escrow-finish-meta-binary.json"),
|
||||
tx: require('./fixtures/escrow-finish-tx.json'),
|
||||
binary: require('./fixtures/escrow-finish-binary.json'),
|
||||
meta: require('./fixtures/escrow-finish-meta-binary.json'),
|
||||
},
|
||||
cancel: {
|
||||
tx: require("./fixtures/escrow-cancel-tx.json"),
|
||||
binary: require("./fixtures/escrow-cancel-binary.json"),
|
||||
tx: require('./fixtures/escrow-cancel-tx.json'),
|
||||
binary: require('./fixtures/escrow-cancel-binary.json'),
|
||||
},
|
||||
};
|
||||
}
|
||||
const PaymentChannel = {
|
||||
create: {
|
||||
tx: require("./fixtures/payment-channel-create-tx.json"),
|
||||
binary: require("./fixtures/payment-channel-create-binary.json"),
|
||||
tx: require('./fixtures/payment-channel-create-tx.json'),
|
||||
binary: require('./fixtures/payment-channel-create-binary.json'),
|
||||
},
|
||||
fund: {
|
||||
tx: require("./fixtures/payment-channel-fund-tx.json"),
|
||||
binary: require("./fixtures/payment-channel-fund-binary.json"),
|
||||
tx: require('./fixtures/payment-channel-fund-tx.json'),
|
||||
binary: require('./fixtures/payment-channel-fund-binary.json'),
|
||||
},
|
||||
claim: {
|
||||
tx: require("./fixtures/payment-channel-claim-tx.json"),
|
||||
binary: require("./fixtures/payment-channel-claim-binary.json"),
|
||||
tx: require('./fixtures/payment-channel-claim-tx.json'),
|
||||
binary: require('./fixtures/payment-channel-claim-binary.json'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const Ticket = {
|
||||
create: {
|
||||
tx: require("./fixtures/ticket-create-tx.json"),
|
||||
binary: require("./fixtures/ticket-create-binary.json"),
|
||||
tx: require('./fixtures/ticket-create-tx.json'),
|
||||
binary: require('./fixtures/ticket-create-binary.json'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let json_undefined = {
|
||||
TakerPays: "223174650",
|
||||
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp",
|
||||
TransactionType: "OfferCreate",
|
||||
TakerPays: '223174650',
|
||||
Account: 'rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp',
|
||||
TransactionType: 'OfferCreate',
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoType: "584D4D2076616C7565",
|
||||
MemoData: "322E3230393635",
|
||||
MemoType: '584D4D2076616C7565',
|
||||
MemoData: '322E3230393635',
|
||||
MemoFormat: undefined,
|
||||
},
|
||||
},
|
||||
],
|
||||
Fee: "15",
|
||||
Fee: '15',
|
||||
OfferSequence: undefined,
|
||||
TakerGets: {
|
||||
currency: "XMM",
|
||||
value: "100",
|
||||
issuer: "rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8",
|
||||
currency: 'XMM',
|
||||
value: '100',
|
||||
issuer: 'rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8',
|
||||
},
|
||||
Flags: 524288,
|
||||
Sequence: undefined,
|
||||
LastLedgerSequence: 6220135,
|
||||
};
|
||||
}
|
||||
|
||||
let json_omitted = {
|
||||
TakerPays: "223174650",
|
||||
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp",
|
||||
TransactionType: "OfferCreate",
|
||||
TakerPays: '223174650',
|
||||
Account: 'rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp',
|
||||
TransactionType: 'OfferCreate',
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoType: "584D4D2076616C7565",
|
||||
MemoData: "322E3230393635",
|
||||
MemoType: '584D4D2076616C7565',
|
||||
MemoData: '322E3230393635',
|
||||
},
|
||||
},
|
||||
],
|
||||
Fee: "15",
|
||||
Fee: '15',
|
||||
TakerGets: {
|
||||
currency: "XMM",
|
||||
value: "100",
|
||||
issuer: "rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8",
|
||||
currency: 'XMM',
|
||||
value: '100',
|
||||
issuer: 'rExAPEZvbkZqYPuNcZ7XEBLENEshsWDQc8',
|
||||
},
|
||||
Flags: 524288,
|
||||
LastLedgerSequence: 6220135,
|
||||
};
|
||||
}
|
||||
|
||||
const NegativeUNL = require("./fixtures/negative-unl.json");
|
||||
const NegativeUNL = require('./fixtures/negative-unl.json')
|
||||
|
||||
function bytesListTest() {
|
||||
const list = new BytesList()
|
||||
.put(Buffer.from([0]))
|
||||
.put(Buffer.from([2, 3]))
|
||||
.put(Buffer.from([4, 5]));
|
||||
test("is an Array<Buffer>", function () {
|
||||
expect(Array.isArray(list.bytesArray)).toBe(true);
|
||||
expect(list.bytesArray[0] instanceof Buffer).toBe(true);
|
||||
});
|
||||
test("keeps track of the length itself", function () {
|
||||
expect(list.getLength()).toBe(5);
|
||||
});
|
||||
test("can join all arrays into one via toBytes", function () {
|
||||
const joined = list.toBytes();
|
||||
expect(joined).toHaveLength(5);
|
||||
expect(joined).toEqual(Buffer.from([0, 2, 3, 4, 5]));
|
||||
});
|
||||
.put(Buffer.from([4, 5]))
|
||||
test('is an Array<Buffer>', function () {
|
||||
expect(Array.isArray(list.bytesArray)).toBe(true)
|
||||
expect(list.bytesArray[0] instanceof Buffer).toBe(true)
|
||||
})
|
||||
test('keeps track of the length itself', function () {
|
||||
expect(list.getLength()).toBe(5)
|
||||
})
|
||||
test('can join all arrays into one via toBytes', function () {
|
||||
const joined = list.toBytes()
|
||||
expect(joined).toHaveLength(5)
|
||||
expect(joined).toEqual(Buffer.from([0, 2, 3, 4, 5]))
|
||||
})
|
||||
}
|
||||
|
||||
function assertRecycles(blob) {
|
||||
const parser = makeParser(blob);
|
||||
const so = parser.readType(STObject);
|
||||
const out = new BytesList();
|
||||
so.toBytesSink(out);
|
||||
const hex = out.toHex();
|
||||
expect(hex).toEqual(blob);
|
||||
expect(hex + ":").not.toEqual(blob);
|
||||
const parser = makeParser(blob)
|
||||
const so = parser.readType(STObject)
|
||||
const out = new BytesList()
|
||||
so.toBytesSink(out)
|
||||
const hex = out.toHex()
|
||||
expect(hex).toEqual(blob)
|
||||
expect(hex + ':').not.toEqual(blob)
|
||||
}
|
||||
|
||||
function nestedObjectTests() {
|
||||
fixtures.whole_objects.forEach((f, i) => {
|
||||
test(`whole_objects[${i}]: can parse blob and dump out same blob`, () => {
|
||||
assertRecycles(f.blob_with_no_signing);
|
||||
});
|
||||
});
|
||||
assertRecycles(f.blob_with_no_signing)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function check(type, n, expected) {
|
||||
test(`Uint${type.width * 8} serializes ${n} as ${expected}`, function () {
|
||||
const bl = new BytesList();
|
||||
const serializer = new BinarySerializer(bl);
|
||||
if (expected === "throws") {
|
||||
expect(() => serializer.writeType(type, n)).toThrow();
|
||||
return;
|
||||
const bl = new BytesList()
|
||||
const serializer = new BinarySerializer(bl)
|
||||
if (expected === 'throws') {
|
||||
expect(() => serializer.writeType(type, n)).toThrow()
|
||||
return
|
||||
}
|
||||
serializer.writeType(type, n);
|
||||
expect(bl.toBytes()).toEqual(Buffer.from(expected));
|
||||
});
|
||||
serializer.writeType(type, n)
|
||||
expect(bl.toBytes()).toEqual(Buffer.from(expected))
|
||||
})
|
||||
}
|
||||
|
||||
check(UInt8, 5, [5]);
|
||||
check(UInt16, 5, [0, 5]);
|
||||
check(UInt32, 5, [0, 0, 0, 5]);
|
||||
check(UInt32, 0xffffffff, [255, 255, 255, 255]);
|
||||
check(UInt8, 0xfeffffff, "throws");
|
||||
check(UInt16, 0xfeffffff, "throws");
|
||||
check(UInt16, 0xfeffffff, "throws");
|
||||
check(UInt64, 0xfeffffff, [0, 0, 0, 0, 254, 255, 255, 255]);
|
||||
check(UInt64, -1, "throws");
|
||||
check(UInt64, 0, [0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
check(UInt64, 1, [0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
check(UInt64, bigInt(1), [0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
check(UInt8, 5, [5])
|
||||
check(UInt16, 5, [0, 5])
|
||||
check(UInt32, 5, [0, 0, 0, 5])
|
||||
check(UInt32, 0xffffffff, [255, 255, 255, 255])
|
||||
check(UInt8, 0xfeffffff, 'throws')
|
||||
check(UInt16, 0xfeffffff, 'throws')
|
||||
check(UInt16, 0xfeffffff, 'throws')
|
||||
check(UInt64, 0xfeffffff, [0, 0, 0, 0, 254, 255, 255, 255])
|
||||
check(UInt64, -1, 'throws')
|
||||
check(UInt64, 0, [0, 0, 0, 0, 0, 0, 0, 0])
|
||||
check(UInt64, 1, [0, 0, 0, 0, 0, 0, 0, 1])
|
||||
check(UInt64, bigInt(1), [0, 0, 0, 0, 0, 0, 0, 1])
|
||||
|
||||
function deliverMinTest() {
|
||||
test("can serialize DeliverMin", () => {
|
||||
expect(encode(deliverMinTx)).toEqual(deliverMinTxBinary);
|
||||
});
|
||||
test('can serialize DeliverMin', () => {
|
||||
expect(encode(deliverMinTx)).toEqual(deliverMinTxBinary)
|
||||
})
|
||||
}
|
||||
|
||||
function SignerListSetTest() {
|
||||
test("can serialize SignerListSet", () => {
|
||||
expect(encode(SignerListSet.tx)).toEqual(SignerListSet.binary);
|
||||
});
|
||||
test("can serialize SignerListSet metadata", () => {
|
||||
expect(encode(SignerListSet.tx.meta)).toEqual(SignerListSet.meta);
|
||||
});
|
||||
test('can serialize SignerListSet', () => {
|
||||
expect(encode(SignerListSet.tx)).toEqual(SignerListSet.binary)
|
||||
})
|
||||
test('can serialize SignerListSet metadata', () => {
|
||||
expect(encode(SignerListSet.tx.meta)).toEqual(SignerListSet.meta)
|
||||
})
|
||||
}
|
||||
|
||||
function DepositPreauthTest() {
|
||||
test("can serialize DepositPreauth", () => {
|
||||
expect(encode(DepositPreauth.tx)).toEqual(DepositPreauth.binary);
|
||||
});
|
||||
test("can serialize DepositPreauth metadata", () => {
|
||||
expect(encode(DepositPreauth.tx.meta)).toEqual(DepositPreauth.meta);
|
||||
});
|
||||
test('can serialize DepositPreauth', () => {
|
||||
expect(encode(DepositPreauth.tx)).toEqual(DepositPreauth.binary)
|
||||
})
|
||||
test('can serialize DepositPreauth metadata', () => {
|
||||
expect(encode(DepositPreauth.tx.meta)).toEqual(DepositPreauth.meta)
|
||||
})
|
||||
}
|
||||
|
||||
function EscrowTest() {
|
||||
test("can serialize EscrowCreate", () => {
|
||||
expect(encode(Escrow.create.tx)).toEqual(Escrow.create.binary);
|
||||
});
|
||||
test("can serialize EscrowFinish", () => {
|
||||
expect(encode(Escrow.finish.tx)).toEqual(Escrow.finish.binary);
|
||||
expect(encode(Escrow.finish.tx.meta)).toEqual(Escrow.finish.meta);
|
||||
});
|
||||
test("can serialize EscrowCancel", () => {
|
||||
expect(encode(Escrow.cancel.tx)).toEqual(Escrow.cancel.binary);
|
||||
});
|
||||
test('can serialize EscrowCreate', () => {
|
||||
expect(encode(Escrow.create.tx)).toEqual(Escrow.create.binary)
|
||||
})
|
||||
test('can serialize EscrowFinish', () => {
|
||||
expect(encode(Escrow.finish.tx)).toEqual(Escrow.finish.binary)
|
||||
expect(encode(Escrow.finish.tx.meta)).toEqual(Escrow.finish.meta)
|
||||
})
|
||||
test('can serialize EscrowCancel', () => {
|
||||
expect(encode(Escrow.cancel.tx)).toEqual(Escrow.cancel.binary)
|
||||
})
|
||||
}
|
||||
|
||||
function PaymentChannelTest() {
|
||||
test("can serialize PaymentChannelCreate", () => {
|
||||
test('can serialize PaymentChannelCreate', () => {
|
||||
expect(encode(PaymentChannel.create.tx)).toEqual(
|
||||
PaymentChannel.create.binary
|
||||
);
|
||||
});
|
||||
test("can serialize PaymentChannelFund", () => {
|
||||
expect(encode(PaymentChannel.fund.tx)).toEqual(PaymentChannel.fund.binary);
|
||||
});
|
||||
test("can serialize PaymentChannelClaim", () => {
|
||||
expect(encode(PaymentChannel.claim.tx)).toEqual(
|
||||
PaymentChannel.claim.binary
|
||||
);
|
||||
});
|
||||
PaymentChannel.create.binary,
|
||||
)
|
||||
})
|
||||
test('can serialize PaymentChannelFund', () => {
|
||||
expect(encode(PaymentChannel.fund.tx)).toEqual(PaymentChannel.fund.binary)
|
||||
})
|
||||
test('can serialize PaymentChannelClaim', () => {
|
||||
expect(encode(PaymentChannel.claim.tx)).toEqual(PaymentChannel.claim.binary)
|
||||
})
|
||||
}
|
||||
|
||||
function NegativeUNLTest() {
|
||||
test("can serialize NegativeUNL", () => {
|
||||
expect(encode(NegativeUNL.tx)).toEqual(NegativeUNL.binary);
|
||||
});
|
||||
test("can deserialize NegativeUNL", () => {
|
||||
expect(decode(NegativeUNL.binary)).toEqual(NegativeUNL.tx);
|
||||
});
|
||||
test('can serialize NegativeUNL', () => {
|
||||
expect(encode(NegativeUNL.tx)).toEqual(NegativeUNL.binary)
|
||||
})
|
||||
test('can deserialize NegativeUNL', () => {
|
||||
expect(decode(NegativeUNL.binary)).toEqual(NegativeUNL.tx)
|
||||
})
|
||||
}
|
||||
|
||||
function omitUndefinedTest() {
|
||||
test("omits fields with undefined value", () => {
|
||||
let encodedOmitted = encode(json_omitted);
|
||||
let encodedUndefined = encode(json_undefined);
|
||||
expect(encodedOmitted).toEqual(encodedUndefined);
|
||||
expect(decode(encodedOmitted)).toEqual(decode(encodedUndefined));
|
||||
});
|
||||
test('omits fields with undefined value', () => {
|
||||
let encodedOmitted = encode(json_omitted)
|
||||
let encodedUndefined = encode(json_undefined)
|
||||
expect(encodedOmitted).toEqual(encodedUndefined)
|
||||
expect(decode(encodedOmitted)).toEqual(decode(encodedUndefined))
|
||||
})
|
||||
}
|
||||
|
||||
function ticketTest() {
|
||||
test("can serialize TicketCreate", () => {
|
||||
expect(encode(Ticket.create.tx)).toEqual(Ticket.create.binary);
|
||||
});
|
||||
test('can serialize TicketCreate', () => {
|
||||
expect(encode(Ticket.create.tx)).toEqual(Ticket.create.binary)
|
||||
})
|
||||
}
|
||||
|
||||
describe("Binary Serialization", function () {
|
||||
describe("nestedObjectTests", () => nestedObjectTests());
|
||||
describe("BytesList", () => bytesListTest());
|
||||
describe("DeliverMin", () => deliverMinTest());
|
||||
describe("DepositPreauth", () => DepositPreauthTest());
|
||||
describe("SignerListSet", () => SignerListSetTest());
|
||||
describe("Escrow", () => EscrowTest());
|
||||
describe("PaymentChannel", () => PaymentChannelTest());
|
||||
describe("NegativeUNLTest", () => NegativeUNLTest());
|
||||
describe("OmitUndefined", () => omitUndefinedTest());
|
||||
describe("TicketTest", () => ticketTest());
|
||||
});
|
||||
describe('Binary Serialization', function () {
|
||||
describe('nestedObjectTests', () => nestedObjectTests())
|
||||
describe('BytesList', () => bytesListTest())
|
||||
describe('DeliverMin', () => deliverMinTest())
|
||||
describe('DepositPreauth', () => DepositPreauthTest())
|
||||
describe('SignerListSet', () => SignerListSetTest())
|
||||
describe('Escrow', () => EscrowTest())
|
||||
describe('PaymentChannel', () => PaymentChannelTest())
|
||||
describe('NegativeUNLTest', () => NegativeUNLTest())
|
||||
describe('OmitUndefined', () => omitUndefinedTest())
|
||||
describe('TicketTest', () => ticketTest())
|
||||
})
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { Hash160, Hash256, AccountID, Currency } = coreTypes;
|
||||
const { Buffer } = require("buffer/");
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { Hash160, Hash256, AccountID, Currency } = coreTypes
|
||||
const { Buffer } = require('buffer/')
|
||||
|
||||
describe("Hash160", function () {
|
||||
test("has a static width member", function () {
|
||||
expect(Hash160.width).toBe(20);
|
||||
});
|
||||
test("inherited by subclasses", function () {
|
||||
expect(AccountID.width).toBe(20);
|
||||
expect(Currency.width).toBe(20);
|
||||
});
|
||||
test("can be compared against another", function () {
|
||||
const h1 = Hash160.from("1000000000000000000000000000000000000000");
|
||||
const h2 = Hash160.from("2000000000000000000000000000000000000000");
|
||||
const h3 = Hash160.from("0000000000000000000000000000000000000003");
|
||||
expect(h1.lt(h2)).toBe(true);
|
||||
expect(h3.lt(h2)).toBe(true);
|
||||
});
|
||||
test("throws when constructed from invalid hash length", () => {
|
||||
describe('Hash160', function () {
|
||||
test('has a static width member', function () {
|
||||
expect(Hash160.width).toBe(20)
|
||||
})
|
||||
test('inherited by subclasses', function () {
|
||||
expect(AccountID.width).toBe(20)
|
||||
expect(Currency.width).toBe(20)
|
||||
})
|
||||
test('can be compared against another', function () {
|
||||
const h1 = Hash160.from('1000000000000000000000000000000000000000')
|
||||
const h2 = Hash160.from('2000000000000000000000000000000000000000')
|
||||
const h3 = Hash160.from('0000000000000000000000000000000000000003')
|
||||
expect(h1.lt(h2)).toBe(true)
|
||||
expect(h3.lt(h2)).toBe(true)
|
||||
})
|
||||
test('throws when constructed from invalid hash length', () => {
|
||||
expect(() =>
|
||||
Hash160.from("10000000000000000000000000000000000000")
|
||||
).toThrow("Invalid Hash length 19");
|
||||
Hash160.from('10000000000000000000000000000000000000'),
|
||||
).toThrow('Invalid Hash length 19')
|
||||
expect(() =>
|
||||
Hash160.from("100000000000000000000000000000000000000000")
|
||||
).toThrow("Invalid Hash length 21");
|
||||
});
|
||||
});
|
||||
Hash160.from('100000000000000000000000000000000000000000'),
|
||||
).toThrow('Invalid Hash length 21')
|
||||
})
|
||||
})
|
||||
|
||||
describe("Hash256", function () {
|
||||
test("has a static width member", function () {
|
||||
expect(Hash256.width).toBe(32);
|
||||
});
|
||||
test("has a ZERO_256 member", function () {
|
||||
describe('Hash256', function () {
|
||||
test('has a static width member', function () {
|
||||
expect(Hash256.width).toBe(32)
|
||||
})
|
||||
test('has a ZERO_256 member', function () {
|
||||
expect(Hash256.ZERO_256.toJSON()).toBe(
|
||||
"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
);
|
||||
});
|
||||
test("supports getting the nibblet values at given positions", function () {
|
||||
'0000000000000000000000000000000000000000000000000000000000000000',
|
||||
)
|
||||
})
|
||||
test('supports getting the nibblet values at given positions', function () {
|
||||
const h = Hash256.from(
|
||||
"1359BD0000000000000000000000000000000000000000000000000000000000"
|
||||
);
|
||||
expect(h.nibblet(0)).toBe(0x1);
|
||||
expect(h.nibblet(1)).toBe(0x3);
|
||||
expect(h.nibblet(2)).toBe(0x5);
|
||||
expect(h.nibblet(3)).toBe(0x9);
|
||||
expect(h.nibblet(4)).toBe(0x0b);
|
||||
expect(h.nibblet(5)).toBe(0xd);
|
||||
});
|
||||
});
|
||||
'1359BD0000000000000000000000000000000000000000000000000000000000',
|
||||
)
|
||||
expect(h.nibblet(0)).toBe(0x1)
|
||||
expect(h.nibblet(1)).toBe(0x3)
|
||||
expect(h.nibblet(2)).toBe(0x5)
|
||||
expect(h.nibblet(3)).toBe(0x9)
|
||||
expect(h.nibblet(4)).toBe(0x0b)
|
||||
expect(h.nibblet(5)).toBe(0xd)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Currency", function () {
|
||||
test("Will throw an error for dodgy XRP ", function () {
|
||||
describe('Currency', function () {
|
||||
test('Will throw an error for dodgy XRP ', function () {
|
||||
expect(() =>
|
||||
Currency.from("0000000000000000000000005852500000000000")
|
||||
).toThrow();
|
||||
});
|
||||
test("Currency with lowercase letters decode to hex", () => {
|
||||
expect(Currency.from("xRp").toJSON()).toBe(
|
||||
"0000000000000000000000007852700000000000"
|
||||
);
|
||||
});
|
||||
test("Currency codes with symbols decode to hex", () => {
|
||||
expect(Currency.from("x|p").toJSON()).toBe(
|
||||
"000000000000000000000000787C700000000000"
|
||||
);
|
||||
});
|
||||
test("Currency codes with uppercase and 0-9 decode to ISO codes", () => {
|
||||
expect(Currency.from("X8P").toJSON()).toBe("X8P");
|
||||
expect(Currency.from("USD").toJSON()).toBe("USD");
|
||||
});
|
||||
test("can be constructed from a Buffer", function () {
|
||||
const xrp = new Currency(Buffer.alloc(20));
|
||||
expect(xrp.iso()).toBe("XRP");
|
||||
});
|
||||
test("Can handle non-standard currency codes", () => {
|
||||
const currency = "015841551A748AD2C1F76FF6ECB0CCCD00000000";
|
||||
expect(Currency.from(currency).toJSON()).toBe(currency);
|
||||
});
|
||||
test("throws on invalid reprs", function () {
|
||||
expect(() => Currency.from(Buffer.alloc(19))).toThrow();
|
||||
expect(() => Currency.from(1)).toThrow();
|
||||
Currency.from('0000000000000000000000005852500000000000'),
|
||||
).toThrow()
|
||||
})
|
||||
test('Currency with lowercase letters decode to hex', () => {
|
||||
expect(Currency.from('xRp').toJSON()).toBe(
|
||||
'0000000000000000000000007852700000000000',
|
||||
)
|
||||
})
|
||||
test('Currency codes with symbols decode to hex', () => {
|
||||
expect(Currency.from('x|p').toJSON()).toBe(
|
||||
'000000000000000000000000787C700000000000',
|
||||
)
|
||||
})
|
||||
test('Currency codes with uppercase and 0-9 decode to ISO codes', () => {
|
||||
expect(Currency.from('X8P').toJSON()).toBe('X8P')
|
||||
expect(Currency.from('USD').toJSON()).toBe('USD')
|
||||
})
|
||||
test('can be constructed from a Buffer', function () {
|
||||
const xrp = new Currency(Buffer.alloc(20))
|
||||
expect(xrp.iso()).toBe('XRP')
|
||||
})
|
||||
test('Can handle non-standard currency codes', () => {
|
||||
const currency = '015841551A748AD2C1F76FF6ECB0CCCD00000000'
|
||||
expect(Currency.from(currency).toJSON()).toBe(currency)
|
||||
})
|
||||
test('throws on invalid reprs', function () {
|
||||
expect(() => Currency.from(Buffer.alloc(19))).toThrow()
|
||||
expect(() => Currency.from(1)).toThrow()
|
||||
expect(() =>
|
||||
Currency.from("00000000000000000000000000000000000000m")
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
Currency.from('00000000000000000000000000000000000000m'),
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
const { loadFixture } = require("./utils");
|
||||
const { loadFixture } = require('./utils')
|
||||
const {
|
||||
transactionTreeHash,
|
||||
ledgerHash,
|
||||
accountStateHash,
|
||||
} = require("../dist/ledger-hashes");
|
||||
} = require('../dist/ledger-hashes')
|
||||
|
||||
describe("Ledger Hashes", function () {
|
||||
describe('Ledger Hashes', function () {
|
||||
function testFactory(ledgerFixture) {
|
||||
describe(`can calculate hashes for ${ledgerFixture}`, function () {
|
||||
const ledger = loadFixture(ledgerFixture);
|
||||
test("computes correct account state hash", function () {
|
||||
const ledger = loadFixture(ledgerFixture)
|
||||
test('computes correct account state hash', function () {
|
||||
expect(accountStateHash(ledger.accountState).toHex()).toBe(
|
||||
ledger.account_hash
|
||||
);
|
||||
});
|
||||
test("computes correct transaction tree hash", function () {
|
||||
ledger.account_hash,
|
||||
)
|
||||
})
|
||||
test('computes correct transaction tree hash', function () {
|
||||
expect(transactionTreeHash(ledger.transactions).toHex()).toBe(
|
||||
ledger.transaction_hash
|
||||
);
|
||||
});
|
||||
test("computes correct ledger header hash", function () {
|
||||
expect(ledgerHash(ledger).toHex()).toBe(ledger.hash);
|
||||
});
|
||||
});
|
||||
ledger.transaction_hash,
|
||||
)
|
||||
})
|
||||
test('computes correct ledger header hash', function () {
|
||||
expect(ledgerHash(ledger).toHex()).toBe(ledger.hash)
|
||||
})
|
||||
})
|
||||
}
|
||||
testFactory("ledger-full-40000.json");
|
||||
testFactory("ledger-full-38129.json");
|
||||
});
|
||||
testFactory('ledger-full-40000.json')
|
||||
testFactory('ledger-full-38129.json')
|
||||
})
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
const { encode, decode } = require("../dist");
|
||||
const { encode, decode } = require('../dist')
|
||||
|
||||
let str =
|
||||
"1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC";
|
||||
let lower = str.toLowerCase();
|
||||
'1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'
|
||||
let lower = str.toLowerCase()
|
||||
|
||||
let bin =
|
||||
"1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0";
|
||||
'1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0'
|
||||
let json = {
|
||||
OwnerCount: 0,
|
||||
Account: "rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK",
|
||||
Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
|
||||
PreviousTxnLgrSeq: 8,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5".toLowerCase(),
|
||||
'0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5'.toLowerCase(),
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let jsonUpper = {
|
||||
OwnerCount: 0,
|
||||
Account: "rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK",
|
||||
Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
|
||||
PreviousTxnLgrSeq: 8,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5",
|
||||
'0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
describe("Lowercase hex test", () => {
|
||||
test("Correctly decodes", () => {
|
||||
expect(decode(lower)).toEqual(decode(str));
|
||||
});
|
||||
test("Re-encodes to uppercase hex", () => {
|
||||
expect(encode(decode(lower))).toEqual(str);
|
||||
});
|
||||
test("Encode when hex field lowercase", () => {
|
||||
expect(encode(json)).toBe(bin);
|
||||
});
|
||||
test("Re-decodes to uppercase hex", () => {
|
||||
expect(decode(encode(json))).toEqual(jsonUpper);
|
||||
});
|
||||
});
|
||||
describe('Lowercase hex test', () => {
|
||||
test('Correctly decodes', () => {
|
||||
expect(decode(lower)).toEqual(decode(str))
|
||||
})
|
||||
test('Re-encodes to uppercase hex', () => {
|
||||
expect(encode(decode(lower))).toEqual(str)
|
||||
})
|
||||
test('Encode when hex field lowercase', () => {
|
||||
expect(encode(json)).toBe(bin)
|
||||
})
|
||||
test('Re-decodes to uppercase hex', () => {
|
||||
expect(decode(encode(json))).toEqual(jsonUpper)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
const { encode, decode } = require("../dist");
|
||||
const { encode, decode } = require('../dist')
|
||||
|
||||
let json = {
|
||||
Account: "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||
Account: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
|
||||
Sequence: 0,
|
||||
Fee: "0",
|
||||
SigningPubKey: "",
|
||||
Signature: "",
|
||||
};
|
||||
Fee: '0',
|
||||
SigningPubKey: '',
|
||||
Signature: '',
|
||||
}
|
||||
|
||||
let json_blank_acct = {
|
||||
Account: "",
|
||||
Account: '',
|
||||
Sequence: 0,
|
||||
Fee: "0",
|
||||
SigningPubKey: "",
|
||||
Signature: "",
|
||||
};
|
||||
Fee: '0',
|
||||
SigningPubKey: '',
|
||||
Signature: '',
|
||||
}
|
||||
|
||||
let binary =
|
||||
"24000000006840000000000000007300760081140000000000000000000000000000000000000000";
|
||||
'24000000006840000000000000007300760081140000000000000000000000000000000000000000'
|
||||
|
||||
describe("Can encode Pseudo Transactions", () => {
|
||||
test("Correctly encodes Pseudo Transaciton", () => {
|
||||
expect(encode(json)).toEqual(binary);
|
||||
});
|
||||
describe('Can encode Pseudo Transactions', () => {
|
||||
test('Correctly encodes Pseudo Transaciton', () => {
|
||||
expect(encode(json)).toEqual(binary)
|
||||
})
|
||||
|
||||
test("Can decode account objects", () => {
|
||||
expect(decode(encode(json))).toEqual(json);
|
||||
});
|
||||
test('Can decode account objects', () => {
|
||||
expect(decode(encode(json))).toEqual(json)
|
||||
})
|
||||
|
||||
test("Blank AccountID is ACCOUNT_ZERO", () => {
|
||||
expect(encode(json_blank_acct)).toEqual(binary);
|
||||
});
|
||||
test('Blank AccountID is ACCOUNT_ZERO', () => {
|
||||
expect(encode(json_blank_acct)).toEqual(binary)
|
||||
})
|
||||
|
||||
test("Decodes Blank AccountID", () => {
|
||||
expect(decode(encode(json_blank_acct))).toEqual(json);
|
||||
});
|
||||
});
|
||||
test('Decodes Blank AccountID', () => {
|
||||
expect(decode(encode(json_blank_acct))).toEqual(json)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const { quality } = require("../dist/coretypes");
|
||||
const { quality } = require('../dist/coretypes')
|
||||
|
||||
describe("Quality encode/decode", function () {
|
||||
describe('Quality encode/decode', function () {
|
||||
const bookDirectory =
|
||||
"4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0";
|
||||
const expectedQuality = "195796912.5171664";
|
||||
test("can decode", function () {
|
||||
const decimal = quality.decode(bookDirectory);
|
||||
expect(decimal.toString()).toBe(expectedQuality);
|
||||
});
|
||||
test("can encode", function () {
|
||||
const bytes = quality.encode(expectedQuality);
|
||||
expect(bytes.toString("hex").toUpperCase()).toBe(bookDirectory.slice(-16));
|
||||
});
|
||||
});
|
||||
'4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0'
|
||||
const expectedQuality = '195796912.5171664'
|
||||
test('can decode', function () {
|
||||
const decimal = quality.decode(bookDirectory)
|
||||
expect(decimal.toString()).toBe(expectedQuality)
|
||||
})
|
||||
test('can encode', function () {
|
||||
const bytes = quality.encode(expectedQuality)
|
||||
expect(bytes.toString('hex').toUpperCase()).toBe(bookDirectory.slice(-16))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
const { ShaMap } = require("../dist/shamap.js");
|
||||
const { binary, HashPrefix } = require("../dist/coretypes");
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { loadFixture } = require("./utils");
|
||||
const { Buffer } = require("buffer/");
|
||||
const { ShaMap } = require('../dist/shamap.js')
|
||||
const { binary, HashPrefix } = require('../dist/coretypes')
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { loadFixture } = require('./utils')
|
||||
const { Buffer } = require('buffer/')
|
||||
|
||||
function now() {
|
||||
return Number(Date.now()) / 1000;
|
||||
return Number(Date.now()) / 1000
|
||||
}
|
||||
|
||||
const ZERO = "0000000000000000000000000000000000000000000000000000000000000000";
|
||||
const ZERO = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
|
||||
function makeItem(indexArg) {
|
||||
let str = indexArg;
|
||||
let str = indexArg
|
||||
while (str.length < 64) {
|
||||
str += "0";
|
||||
str += '0'
|
||||
}
|
||||
const index = coreTypes.Hash256.from(str);
|
||||
const index = coreTypes.Hash256.from(str)
|
||||
const item = {
|
||||
toBytesSink(sink) {
|
||||
index.toBytesSink(sink);
|
||||
index.toBytesSink(sink)
|
||||
},
|
||||
hashPrefix() {
|
||||
return Buffer.from([1, 3, 3, 7]);
|
||||
return Buffer.from([1, 3, 3, 7])
|
||||
},
|
||||
};
|
||||
return [index, item];
|
||||
}
|
||||
return [index, item]
|
||||
}
|
||||
|
||||
describe("ShaMap", () => {
|
||||
now();
|
||||
describe('ShaMap', () => {
|
||||
now()
|
||||
|
||||
test("hashes to zero when empty", () => {
|
||||
const map = new ShaMap();
|
||||
expect(map.hash().toHex()).toBe(ZERO);
|
||||
});
|
||||
test("creates the same hash no matter which order items are added", () => {
|
||||
let map = new ShaMap();
|
||||
test('hashes to zero when empty', () => {
|
||||
const map = new ShaMap()
|
||||
expect(map.hash().toHex()).toBe(ZERO)
|
||||
})
|
||||
test('creates the same hash no matter which order items are added', () => {
|
||||
let map = new ShaMap()
|
||||
const items = [
|
||||
"0",
|
||||
"1",
|
||||
"11",
|
||||
"7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000",
|
||||
"7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000",
|
||||
"7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000",
|
||||
"7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000",
|
||||
"12",
|
||||
"122",
|
||||
];
|
||||
items.forEach((i) => map.addItem(...makeItem(i)));
|
||||
const h1 = map.hash();
|
||||
expect(h1.eq(h1)).toBe(true);
|
||||
map = new ShaMap();
|
||||
items.reverse().forEach((i) => map.addItem(...makeItem(i)));
|
||||
expect(map.hash()).toStrictEqual(h1);
|
||||
});
|
||||
'0',
|
||||
'1',
|
||||
'11',
|
||||
'7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000',
|
||||
'7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000',
|
||||
'7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000',
|
||||
'7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000',
|
||||
'12',
|
||||
'122',
|
||||
]
|
||||
items.forEach((i) => map.addItem(...makeItem(i)))
|
||||
const h1 = map.hash()
|
||||
expect(h1.eq(h1)).toBe(true)
|
||||
map = new ShaMap()
|
||||
items.reverse().forEach((i) => map.addItem(...makeItem(i)))
|
||||
expect(map.hash()).toStrictEqual(h1)
|
||||
})
|
||||
function factory(fixture) {
|
||||
test(`recreate account state hash from ${fixture}`, () => {
|
||||
const map = new ShaMap();
|
||||
const ledger = loadFixture(fixture);
|
||||
const map = new ShaMap()
|
||||
const ledger = loadFixture(fixture)
|
||||
// const t = now();
|
||||
const leafNodePrefix = HashPrefix.accountStateEntry;
|
||||
const leafNodePrefix = HashPrefix.accountStateEntry
|
||||
ledger.accountState
|
||||
.map((e, i) => {
|
||||
if ((i > 1000) & (i % 1000 === 0)) {
|
||||
console.log(e.index);
|
||||
console.log(i);
|
||||
console.log(e.index)
|
||||
console.log(i)
|
||||
}
|
||||
const bytes = binary.serializeObject(e);
|
||||
const bytes = binary.serializeObject(e)
|
||||
return {
|
||||
index: coreTypes.Hash256.from(e.index),
|
||||
hashPrefix() {
|
||||
return leafNodePrefix;
|
||||
return leafNodePrefix
|
||||
},
|
||||
toBytesSink(sink) {
|
||||
sink.put(bytes);
|
||||
sink.put(bytes)
|
||||
},
|
||||
};
|
||||
}
|
||||
})
|
||||
.forEach((so) => map.addItem(so.index, so));
|
||||
expect(map.hash().toHex()).toBe(ledger.account_hash);
|
||||
.forEach((so) => map.addItem(so.index, so))
|
||||
expect(map.hash().toHex()).toBe(ledger.account_hash)
|
||||
// console.log('took seconds: ', (now() - t));
|
||||
});
|
||||
})
|
||||
}
|
||||
factory("ledger-full-38129.json");
|
||||
factory("ledger-full-40000.json");
|
||||
factory('ledger-full-38129.json')
|
||||
factory('ledger-full-40000.json')
|
||||
// factory('ledger-4320277.json');
|
||||
// factory('14280680.json');
|
||||
});
|
||||
})
|
||||
|
||||
@@ -2,128 +2,128 @@ const {
|
||||
encodeForSigning,
|
||||
encodeForSigningClaim,
|
||||
encodeForMultisigning,
|
||||
} = require("../dist");
|
||||
} = require('../dist')
|
||||
|
||||
const tx_json = {
|
||||
Account: "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ",
|
||||
Amount: "1000",
|
||||
Destination: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
Fee: "10",
|
||||
Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
|
||||
Amount: '1000',
|
||||
Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
||||
Fee: '10',
|
||||
Flags: 2147483648,
|
||||
Sequence: 1,
|
||||
TransactionType: "Payment",
|
||||
TransactionType: 'Payment',
|
||||
TxnSignature:
|
||||
"30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1" +
|
||||
"E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80" +
|
||||
"ECA3CD7B9B",
|
||||
'30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1' +
|
||||
'E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80' +
|
||||
'ECA3CD7B9B',
|
||||
Signature:
|
||||
"30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E72" +
|
||||
"1B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA" +
|
||||
"3CD7B9B",
|
||||
'30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E72' +
|
||||
'1B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA' +
|
||||
'3CD7B9B',
|
||||
SigningPubKey:
|
||||
"ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A",
|
||||
};
|
||||
'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
|
||||
}
|
||||
|
||||
describe("Signing data", function () {
|
||||
test("can create single signing blobs", function () {
|
||||
const actual = encodeForSigning(tx_json);
|
||||
describe('Signing data', function () {
|
||||
test('can create single signing blobs', function () {
|
||||
const actual = encodeForSigning(tx_json)
|
||||
expect(actual).toBe(
|
||||
[
|
||||
"53545800", // signingPrefix
|
||||
'53545800', // signingPrefix
|
||||
// TransactionType
|
||||
"12",
|
||||
"0000",
|
||||
'12',
|
||||
'0000',
|
||||
// Flags
|
||||
"22",
|
||||
"80000000",
|
||||
'22',
|
||||
'80000000',
|
||||
// Sequence
|
||||
"24",
|
||||
"00000001",
|
||||
'24',
|
||||
'00000001',
|
||||
// Amount
|
||||
"61",
|
||||
'61',
|
||||
// native amount
|
||||
"40000000000003E8",
|
||||
'40000000000003E8',
|
||||
// Fee
|
||||
"68",
|
||||
'68',
|
||||
// native amount
|
||||
"400000000000000A",
|
||||
'400000000000000A',
|
||||
// SigningPubKey
|
||||
"73",
|
||||
'73',
|
||||
// VLLength
|
||||
"21",
|
||||
"ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A",
|
||||
'21',
|
||||
'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
|
||||
// Account
|
||||
"81",
|
||||
'81',
|
||||
// VLLength
|
||||
"14",
|
||||
"5B812C9D57731E27A2DA8B1830195F88EF32A3B6",
|
||||
'14',
|
||||
'5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
|
||||
// Destination
|
||||
"83",
|
||||
'83',
|
||||
// VLLength
|
||||
"14",
|
||||
"B5F762798A53D543A014CAF8B297CFF8F2F937E8",
|
||||
].join("")
|
||||
);
|
||||
});
|
||||
test("can create multi signing blobs", function () {
|
||||
const signingAccount = "rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN";
|
||||
const signingJson = Object.assign({}, tx_json, { SigningPubKey: "" });
|
||||
const actual = encodeForMultisigning(signingJson, signingAccount);
|
||||
'14',
|
||||
'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
test('can create multi signing blobs', function () {
|
||||
const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN'
|
||||
const signingJson = Object.assign({}, tx_json, { SigningPubKey: '' })
|
||||
const actual = encodeForMultisigning(signingJson, signingAccount)
|
||||
expect(actual).toBe(
|
||||
[
|
||||
"534D5400", // signingPrefix
|
||||
'534D5400', // signingPrefix
|
||||
// TransactionType
|
||||
"12",
|
||||
"0000",
|
||||
'12',
|
||||
'0000',
|
||||
// Flags
|
||||
"22",
|
||||
"80000000",
|
||||
'22',
|
||||
'80000000',
|
||||
// Sequence
|
||||
"24",
|
||||
"00000001",
|
||||
'24',
|
||||
'00000001',
|
||||
// Amount
|
||||
"61",
|
||||
'61',
|
||||
// native amount
|
||||
"40000000000003E8",
|
||||
'40000000000003E8',
|
||||
// Fee
|
||||
"68",
|
||||
'68',
|
||||
// native amount
|
||||
"400000000000000A",
|
||||
'400000000000000A',
|
||||
// SigningPubKey
|
||||
"73",
|
||||
'73',
|
||||
// VLLength
|
||||
"00",
|
||||
'00',
|
||||
// '',
|
||||
// Account
|
||||
"81",
|
||||
'81',
|
||||
// VLLength
|
||||
"14",
|
||||
"5B812C9D57731E27A2DA8B1830195F88EF32A3B6",
|
||||
'14',
|
||||
'5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
|
||||
// Destination
|
||||
"83",
|
||||
'83',
|
||||
// VLLength
|
||||
"14",
|
||||
"B5F762798A53D543A014CAF8B297CFF8F2F937E8",
|
||||
'14',
|
||||
'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
|
||||
// signingAccount suffix
|
||||
"C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1",
|
||||
].join("")
|
||||
);
|
||||
});
|
||||
test("can create claim blob", function () {
|
||||
'C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1',
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
test('can create claim blob', function () {
|
||||
const channel =
|
||||
"43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1";
|
||||
const amount = "1000";
|
||||
const json = { channel, amount };
|
||||
const actual = encodeForSigningClaim(json);
|
||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
||||
const amount = '1000'
|
||||
const json = { channel, amount }
|
||||
const actual = encodeForSigningClaim(json)
|
||||
expect(actual).toBe(
|
||||
[
|
||||
// hash prefix
|
||||
"434C4D00",
|
||||
'434C4D00',
|
||||
// channel ID
|
||||
"43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1",
|
||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1',
|
||||
// amount as a uint64
|
||||
"00000000000003E8",
|
||||
].join("")
|
||||
);
|
||||
});
|
||||
});
|
||||
'00000000000003E8',
|
||||
].join(''),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { encode, decode } = require("../dist");
|
||||
const { encode, decode } = require('../dist')
|
||||
|
||||
// Notice: no Amount or Fee
|
||||
const tx_json = {
|
||||
Account: "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ",
|
||||
Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
|
||||
// Amount: '1000',
|
||||
Destination: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
||||
// Fee: '10',
|
||||
|
||||
// JavaScript converts operands to 32-bit signed ints after doing bitwise
|
||||
@@ -12,86 +12,86 @@ const tx_json = {
|
||||
Flags: (1 << 31) >>> 0, // tfFullyCanonicalSig
|
||||
|
||||
Sequence: 1,
|
||||
TransactionType: "Payment",
|
||||
TransactionType: 'Payment',
|
||||
// TxnSignature,
|
||||
// Signature,
|
||||
// SigningPubKey
|
||||
};
|
||||
}
|
||||
|
||||
describe("encoding and decoding tx_json", function () {
|
||||
test("can encode tx_json without Amount or Fee", function () {
|
||||
const encoded = encode(tx_json);
|
||||
const decoded = decode(encoded);
|
||||
expect(tx_json).toEqual(decoded);
|
||||
});
|
||||
test("can encode tx_json with Amount and Fee", function () {
|
||||
describe('encoding and decoding tx_json', function () {
|
||||
test('can encode tx_json without Amount or Fee', function () {
|
||||
const encoded = encode(tx_json)
|
||||
const decoded = decode(encoded)
|
||||
expect(tx_json).toEqual(decoded)
|
||||
})
|
||||
test('can encode tx_json with Amount and Fee', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: "1000",
|
||||
Fee: "10",
|
||||
});
|
||||
const encoded = encode(my_tx);
|
||||
const decoded = decode(encoded);
|
||||
expect(my_tx).toEqual(decoded);
|
||||
});
|
||||
test("can encode tx_json with TicketCount", function () {
|
||||
Amount: '1000',
|
||||
Fee: '10',
|
||||
})
|
||||
const encoded = encode(my_tx)
|
||||
const decoded = decode(encoded)
|
||||
expect(my_tx).toEqual(decoded)
|
||||
})
|
||||
test('can encode tx_json with TicketCount', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
TicketCount: 2,
|
||||
});
|
||||
const encoded = encode(my_tx);
|
||||
const decoded = decode(encoded);
|
||||
expect(my_tx).toEqual(decoded);
|
||||
});
|
||||
test("can encode tx_json with TicketSequence", function () {
|
||||
})
|
||||
const encoded = encode(my_tx)
|
||||
const decoded = decode(encoded)
|
||||
expect(my_tx).toEqual(decoded)
|
||||
})
|
||||
test('can encode tx_json with TicketSequence', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Sequence: 0,
|
||||
TicketSequence: 2,
|
||||
});
|
||||
const encoded = encode(my_tx);
|
||||
const decoded = decode(encoded);
|
||||
expect(my_tx).toEqual(decoded);
|
||||
});
|
||||
test("throws when Amount is invalid", function () {
|
||||
})
|
||||
const encoded = encode(my_tx)
|
||||
const decoded = decode(encoded)
|
||||
expect(my_tx).toEqual(decoded)
|
||||
})
|
||||
test('throws when Amount is invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: "1000.001",
|
||||
Fee: "10",
|
||||
});
|
||||
Amount: '1000.001',
|
||||
Fee: '10',
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx);
|
||||
}).toThrow();
|
||||
});
|
||||
test("throws when Fee is invalid", function () {
|
||||
encode(my_tx)
|
||||
}).toThrow()
|
||||
})
|
||||
test('throws when Fee is invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: "1000",
|
||||
Fee: "10.123",
|
||||
});
|
||||
Amount: '1000',
|
||||
Fee: '10.123',
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx);
|
||||
}).toThrow();
|
||||
});
|
||||
test("throws when Amount and Fee are invalid", function () {
|
||||
encode(my_tx)
|
||||
}).toThrow()
|
||||
})
|
||||
test('throws when Amount and Fee are invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: "1000.789",
|
||||
Fee: "10.123",
|
||||
});
|
||||
Amount: '1000.789',
|
||||
Fee: '10.123',
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx);
|
||||
}).toThrow();
|
||||
});
|
||||
test("throws when Amount is a number instead of a string-encoded integer", function () {
|
||||
encode(my_tx)
|
||||
}).toThrow()
|
||||
})
|
||||
test('throws when Amount is a number instead of a string-encoded integer', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: 1000.789,
|
||||
});
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx);
|
||||
}).toThrow();
|
||||
});
|
||||
encode(my_tx)
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
test("throws when Fee is a number instead of a string-encoded integer", function () {
|
||||
test('throws when Fee is a number instead of a string-encoded integer', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: 1234.56,
|
||||
});
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
encode(my_tx)
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { SerializedType } = require("../dist/types/serialized-type");
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { SerializedType } = require('../dist/types/serialized-type')
|
||||
|
||||
describe("SerializedType interfaces", () => {
|
||||
describe('SerializedType interfaces', () => {
|
||||
Object.entries(coreTypes).forEach(([name, Value]) => {
|
||||
test(`${name} has a \`from\` static constructor`, () => {
|
||||
expect(Value.from && Value.from !== Array.from).toBe(true);
|
||||
});
|
||||
expect(Value.from && Value.from !== Array.from).toBe(true)
|
||||
})
|
||||
test(`${name} has a default constructor`, () => {
|
||||
expect(new Value()).not.toBe(undefined);
|
||||
});
|
||||
expect(new Value()).not.toBe(undefined)
|
||||
})
|
||||
test(`${name}.from will return the same object`, () => {
|
||||
const instance = new Value();
|
||||
expect(Value.from(instance) === instance).toBe(true);
|
||||
});
|
||||
const instance = new Value()
|
||||
expect(Value.from(instance) === instance).toBe(true)
|
||||
})
|
||||
test(`${name} instances have toBytesSink`, () => {
|
||||
expect(new Value().toBytesSink).not.toBe(undefined);
|
||||
});
|
||||
expect(new Value().toBytesSink).not.toBe(undefined)
|
||||
})
|
||||
test(`${name} instances have toJSON`, () => {
|
||||
expect(new Value().toJSON).not.toBe(undefined);
|
||||
});
|
||||
expect(new Value().toJSON).not.toBe(undefined)
|
||||
})
|
||||
test(`${name}.from(json).toJSON() == json`, () => {
|
||||
const newJSON = new Value().toJSON();
|
||||
expect(Value.from(newJSON).toJSON()).toEqual(newJSON);
|
||||
});
|
||||
const newJSON = new Value().toJSON()
|
||||
expect(Value.from(newJSON).toJSON()).toEqual(newJSON)
|
||||
})
|
||||
describe(`${name} supports all methods of the SerializedType mixin`, () => {
|
||||
Object.keys(SerializedType.prototype).forEach((k) => {
|
||||
test(`new ${name}.prototype.${k} !== undefined`, () => {
|
||||
expect(Value.prototype[k]).not.toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(Value.prototype[k]).not.toBe(undefined)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,148 +1,148 @@
|
||||
const { coreTypes } = require("../dist/types");
|
||||
const { UInt8, UInt64 } = coreTypes;
|
||||
const { coreTypes } = require('../dist/types')
|
||||
const { UInt8, UInt64 } = coreTypes
|
||||
|
||||
const { encode } = require("../dist");
|
||||
const { encode } = require('../dist')
|
||||
|
||||
const binary =
|
||||
"11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F";
|
||||
'11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'
|
||||
const json = {
|
||||
Balance: {
|
||||
currency: "USD",
|
||||
issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
|
||||
value: "0",
|
||||
currency: 'USD',
|
||||
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
||||
value: '0',
|
||||
},
|
||||
Flags: 196608,
|
||||
HighLimit: {
|
||||
currency: "USD",
|
||||
issuer: "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
|
||||
value: "1000",
|
||||
currency: 'USD',
|
||||
issuer: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
|
||||
value: '1000',
|
||||
},
|
||||
HighNode: "0",
|
||||
LedgerEntryType: "RippleState",
|
||||
HighNode: '0',
|
||||
LedgerEntryType: 'RippleState',
|
||||
LowLimit: {
|
||||
currency: "USD",
|
||||
issuer: "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
|
||||
value: "1000",
|
||||
currency: 'USD',
|
||||
issuer: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
|
||||
value: '1000',
|
||||
},
|
||||
LowNode: "0",
|
||||
};
|
||||
LowNode: '0',
|
||||
}
|
||||
|
||||
const binaryEntry0 =
|
||||
"11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098";
|
||||
'11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098'
|
||||
const jsonEntry0 = {
|
||||
Balance: {
|
||||
currency: "JPY",
|
||||
issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
|
||||
value: "0.3369568318",
|
||||
currency: 'JPY',
|
||||
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
||||
value: '0.3369568318',
|
||||
},
|
||||
Flags: 1114112,
|
||||
HighLimit: {
|
||||
currency: "JPY",
|
||||
issuer: "r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN",
|
||||
value: "0",
|
||||
currency: 'JPY',
|
||||
issuer: 'r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN',
|
||||
value: '0',
|
||||
},
|
||||
HighNode: "a3",
|
||||
LedgerEntryType: "RippleState",
|
||||
HighNode: 'a3',
|
||||
LedgerEntryType: 'RippleState',
|
||||
LowLimit: {
|
||||
currency: "JPY",
|
||||
issuer: "rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY",
|
||||
value: "1000000000",
|
||||
currency: 'JPY',
|
||||
issuer: 'rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY',
|
||||
value: '1000000000',
|
||||
},
|
||||
LowNode: "0",
|
||||
LowNode: '0',
|
||||
PreviousTxnID:
|
||||
"06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA",
|
||||
'06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA',
|
||||
PreviousTxnLgrSeq: 32253063,
|
||||
index: "000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840",
|
||||
};
|
||||
index: '000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840',
|
||||
}
|
||||
|
||||
const binaryEntry1 =
|
||||
"1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F";
|
||||
'1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F'
|
||||
const jsonEntry1 = {
|
||||
Flags: 0,
|
||||
IndexPrevious: "2",
|
||||
IndexPrevious: '2',
|
||||
Indexes: [
|
||||
"A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A",
|
||||
"E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F",
|
||||
'A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A',
|
||||
'E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F',
|
||||
],
|
||||
LedgerEntryType: "DirectoryNode",
|
||||
Owner: "rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP",
|
||||
RootIndex: "0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752",
|
||||
index: "0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167",
|
||||
};
|
||||
LedgerEntryType: 'DirectoryNode',
|
||||
Owner: 'rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP',
|
||||
RootIndex: '0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752',
|
||||
index: '0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167',
|
||||
}
|
||||
|
||||
const binaryEntry2 =
|
||||
"1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E";
|
||||
'1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E'
|
||||
const jsonEntry2 = {
|
||||
Balance: {
|
||||
currency: "GCB",
|
||||
issuer: "rrrrrrrrrrrrrrrrrrrrBZbvji",
|
||||
value: "0",
|
||||
currency: 'GCB',
|
||||
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
||||
value: '0',
|
||||
},
|
||||
Flags: 2162688,
|
||||
HighLimit: {
|
||||
currency: "GCB",
|
||||
issuer: "rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n",
|
||||
value: "0",
|
||||
currency: 'GCB',
|
||||
issuer: 'rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n',
|
||||
value: '0',
|
||||
},
|
||||
HighNode: "283",
|
||||
LedgerEntryType: "RippleState",
|
||||
HighNode: '283',
|
||||
LedgerEntryType: 'RippleState',
|
||||
LowLimit: {
|
||||
currency: "GCB",
|
||||
issuer: "rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj",
|
||||
value: "2000000",
|
||||
currency: 'GCB',
|
||||
issuer: 'rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj',
|
||||
value: '2000000',
|
||||
},
|
||||
LowNode: "0",
|
||||
LowNode: '0',
|
||||
PreviousTxnID:
|
||||
"C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694",
|
||||
'C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694',
|
||||
PreviousTxnLgrSeq: 24695242,
|
||||
index: "0000041EFD027808D3F78C8352F97E324CB816318E00B977C74ECDDC7CD975B2",
|
||||
};
|
||||
index: '0000041EFD027808D3F78C8352F97E324CB816318E00B977C74ECDDC7CD975B2',
|
||||
}
|
||||
|
||||
test("compareToTests[0]", () => {
|
||||
expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0);
|
||||
});
|
||||
test('compareToTests[0]', () => {
|
||||
expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0)
|
||||
})
|
||||
|
||||
test("compareToTest[1]", () => {
|
||||
expect(UInt64.from(124).compareTo(UInt8.from(124))).toBe(0);
|
||||
});
|
||||
test('compareToTest[1]', () => {
|
||||
expect(UInt64.from(124).compareTo(UInt8.from(124))).toBe(0)
|
||||
})
|
||||
|
||||
test("compareToTest[2]", () => {
|
||||
expect(UInt64.from(124).compareTo(UInt8.from(123))).toBe(1);
|
||||
});
|
||||
test('compareToTest[2]', () => {
|
||||
expect(UInt64.from(124).compareTo(UInt8.from(123))).toBe(1)
|
||||
})
|
||||
|
||||
test("compareToTest[3]", () => {
|
||||
expect(UInt8.from(124).compareTo(UInt8.from(13))).toBe(1);
|
||||
});
|
||||
test('compareToTest[3]', () => {
|
||||
expect(UInt8.from(124).compareTo(UInt8.from(13))).toBe(1)
|
||||
})
|
||||
|
||||
test("compareToTest[4]", () => {
|
||||
expect(UInt8.from(124).compareTo(124)).toBe(0);
|
||||
});
|
||||
test('compareToTest[4]', () => {
|
||||
expect(UInt8.from(124).compareTo(124)).toBe(0)
|
||||
})
|
||||
|
||||
test("compareToTest[5]", () => {
|
||||
expect(UInt64.from(124).compareTo(124)).toBe(0);
|
||||
});
|
||||
test('compareToTest[5]', () => {
|
||||
expect(UInt64.from(124).compareTo(124)).toBe(0)
|
||||
})
|
||||
|
||||
test("compareToTest[6]", () => {
|
||||
expect(UInt64.from(124).compareTo(123)).toBe(1);
|
||||
});
|
||||
test('compareToTest[6]', () => {
|
||||
expect(UInt64.from(124).compareTo(123)).toBe(1)
|
||||
})
|
||||
|
||||
test("compareToTest[7]", () => {
|
||||
expect(UInt8.from(124).compareTo(13)).toBe(1);
|
||||
});
|
||||
test('compareToTest[7]', () => {
|
||||
expect(UInt8.from(124).compareTo(13)).toBe(1)
|
||||
})
|
||||
|
||||
test("UInt64 from string zero", () => {
|
||||
expect(UInt64.from("0")).toEqual(UInt64.from(0));
|
||||
expect(encode(json)).toEqual(binary);
|
||||
});
|
||||
test('UInt64 from string zero', () => {
|
||||
expect(UInt64.from('0')).toEqual(UInt64.from(0))
|
||||
expect(encode(json)).toEqual(binary)
|
||||
})
|
||||
|
||||
test("UInt64 from non 16 length hex", () => {
|
||||
expect(encode(jsonEntry0)).toEqual(binaryEntry0);
|
||||
expect(encode(jsonEntry1)).toEqual(binaryEntry1);
|
||||
expect(encode(jsonEntry2)).toEqual(binaryEntry2);
|
||||
});
|
||||
test('UInt64 from non 16 length hex', () => {
|
||||
expect(encode(jsonEntry0)).toEqual(binaryEntry0)
|
||||
expect(encode(jsonEntry1)).toEqual(binaryEntry1)
|
||||
expect(encode(jsonEntry2)).toEqual(binaryEntry2)
|
||||
})
|
||||
|
||||
test("valueOfTests", () => {
|
||||
let val = UInt8.from(1);
|
||||
val |= 0x2;
|
||||
expect(val).toBe(3);
|
||||
});
|
||||
test('valueOfTests', () => {
|
||||
let val = UInt8.from(1)
|
||||
val |= 0x2
|
||||
expect(val).toBe(3)
|
||||
})
|
||||
|
||||
@@ -1,181 +1,181 @@
|
||||
const { encode, decode } = require("./../dist/index");
|
||||
const fixtures = require("./fixtures/x-codec-fixtures.json");
|
||||
const { encode, decode } = require('./../dist/index')
|
||||
const fixtures = require('./fixtures/x-codec-fixtures.json')
|
||||
|
||||
let json_x1 = {
|
||||
OwnerCount: 0,
|
||||
Account: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
|
||||
Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let json_r1 = {
|
||||
OwnerCount: 0,
|
||||
Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
Balance: '10000000000',
|
||||
SourceTag: 12345,
|
||||
};
|
||||
}
|
||||
|
||||
let json_null_x = {
|
||||
OwnerCount: 0,
|
||||
Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Issuer: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71",
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let json_invalid_x = {
|
||||
OwnerCount: 0,
|
||||
Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Issuer: "XVXdn5wEVm5g4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71",
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Issuer: 'XVXdn5wEVm5g4UhEHWDPqjvdeH361P4GETfNyyXGaoqBj71',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let json_null_r = {
|
||||
OwnerCount: 0,
|
||||
Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Issuer: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Issuer: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let invalid_json_issuer_tagged = {
|
||||
OwnerCount: 0,
|
||||
Account: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Destination: "rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv",
|
||||
Issuer: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Destination: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv',
|
||||
Issuer: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
};
|
||||
Balance: '10000000000',
|
||||
}
|
||||
|
||||
let invalid_json_x_and_tagged = {
|
||||
OwnerCount: 0,
|
||||
Account: "XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT",
|
||||
Account: 'XVXdn5wEVm5G4UhEHWDPqjvdeH361P7BsapL4m2D2XnPSwT',
|
||||
PreviousTxnLgrSeq: 7,
|
||||
LedgerEntryType: "AccountRoot",
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
PreviousTxnID:
|
||||
"DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF",
|
||||
'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
Balance: "10000000000",
|
||||
Balance: '10000000000',
|
||||
SourceTag: 12345,
|
||||
};
|
||||
}
|
||||
|
||||
let json_issued_x = {
|
||||
TakerPays: {
|
||||
currency: "USD",
|
||||
issuer: "X7WZKEeNVS2p9Tire9DtNFkzWBZbFtJHWxDjN9fCrBGqVA4",
|
||||
value: "7072.8",
|
||||
currency: 'USD',
|
||||
issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtJHWxDjN9fCrBGqVA4',
|
||||
value: '7072.8',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let json_issued_r = {
|
||||
TakerPays: {
|
||||
currency: "USD",
|
||||
issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
|
||||
value: "7072.8",
|
||||
currency: 'USD',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
value: '7072.8',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let json_issued_with_tag = {
|
||||
TakerPays: {
|
||||
currency: "USD",
|
||||
issuer: "X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2",
|
||||
value: "7072.8",
|
||||
currency: 'USD',
|
||||
issuer: 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2',
|
||||
value: '7072.8',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("X-Address Account is equivalent to a classic address w/ SourceTag", () => {
|
||||
let encoded_x = encode(json_x1);
|
||||
let encoded_r = encode(json_r1);
|
||||
test("Can encode with x-Address", () => {
|
||||
expect(encoded_x).toEqual(encoded_r);
|
||||
});
|
||||
describe('X-Address Account is equivalent to a classic address w/ SourceTag', () => {
|
||||
let encoded_x = encode(json_x1)
|
||||
let encoded_r = encode(json_r1)
|
||||
test('Can encode with x-Address', () => {
|
||||
expect(encoded_x).toEqual(encoded_r)
|
||||
})
|
||||
|
||||
test("decoded X-address is object w/ source and tag", () => {
|
||||
let decoded_x = decode(encoded_x);
|
||||
expect(decoded_x).toEqual(json_r1);
|
||||
});
|
||||
test('decoded X-address is object w/ source and tag', () => {
|
||||
let decoded_x = decode(encoded_x)
|
||||
expect(decoded_x).toEqual(json_r1)
|
||||
})
|
||||
|
||||
test("Encoding issuer X-Address w/ undefined destination tag", () => {
|
||||
expect(encode(json_null_x)).toEqual(encode(json_null_r));
|
||||
});
|
||||
test('Encoding issuer X-Address w/ undefined destination tag', () => {
|
||||
expect(encode(json_null_x)).toEqual(encode(json_null_r))
|
||||
})
|
||||
|
||||
test("Throws when X-Address is invalid", () => {
|
||||
expect(() => encode(json_invalid_x)).toThrow("checksum_invalid");
|
||||
});
|
||||
test('Throws when X-Address is invalid', () => {
|
||||
expect(() => encode(json_invalid_x)).toThrow('checksum_invalid')
|
||||
})
|
||||
|
||||
test("Encodes issued currency w/ x-address", () => {
|
||||
expect(encode(json_issued_x)).toEqual(encode(json_issued_r));
|
||||
});
|
||||
});
|
||||
test('Encodes issued currency w/ x-address', () => {
|
||||
expect(encode(json_issued_x)).toEqual(encode(json_issued_r))
|
||||
})
|
||||
})
|
||||
|
||||
describe("Invalid X-Address behavior", () => {
|
||||
test("X-Address with tag throws value for invalid field", () => {
|
||||
describe('Invalid X-Address behavior', () => {
|
||||
test('X-Address with tag throws value for invalid field', () => {
|
||||
expect(() => encode(invalid_json_issuer_tagged)).toThrow(
|
||||
new Error("Issuer cannot have an associated tag")
|
||||
);
|
||||
});
|
||||
new Error('Issuer cannot have an associated tag'),
|
||||
)
|
||||
})
|
||||
|
||||
test("Throws when Account has both X-Addr and Destination Tag", () => {
|
||||
test('Throws when Account has both X-Addr and Destination Tag', () => {
|
||||
expect(() => encode(invalid_json_x_and_tagged)).toThrow(
|
||||
new Error("Cannot have Account X-Address and SourceTag")
|
||||
);
|
||||
});
|
||||
new Error('Cannot have Account X-Address and SourceTag'),
|
||||
)
|
||||
})
|
||||
|
||||
test("Throws when issued currency has tag", () => {
|
||||
test('Throws when issued currency has tag', () => {
|
||||
expect(() => encode(json_issued_with_tag)).toThrow(
|
||||
"Only allowed to have tag on Account or Destination"
|
||||
);
|
||||
});
|
||||
});
|
||||
'Only allowed to have tag on Account or Destination',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("ripple-binary-codec x-address test", function () {
|
||||
describe('ripple-binary-codec x-address test', function () {
|
||||
function makeSuite(name, entries) {
|
||||
describe(name, function () {
|
||||
entries.forEach((t, testN) => {
|
||||
test(`${name}[${testN}] encodes X-address json equivalent to classic address json`, () => {
|
||||
expect(encode(t.rjson)).toEqual(encode(t.xjson));
|
||||
});
|
||||
expect(encode(t.rjson)).toEqual(encode(t.xjson))
|
||||
})
|
||||
test(`${name}[${testN}] decodes X-address json equivalent to classic address json`, () => {
|
||||
expect(decode(encode(t.xjson))).toEqual(t.rjson);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(decode(encode(t.xjson))).toEqual(t.rjson)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
makeSuite("transactions", fixtures.transactions);
|
||||
});
|
||||
makeSuite('transactions', fixtures.transactions)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user