mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
Tickets support (#110)
* feat(tickets): add TicketCount definition * feat(tickets): add TicketSequence definition * fix(tests): unit tests
This commit is contained in:
@@ -444,6 +444,26 @@
|
||||
"type": "UInt32"
|
||||
}
|
||||
],
|
||||
[
|
||||
"TicketCount",
|
||||
{
|
||||
"nth": 41,
|
||||
"isVLEncoded": false,
|
||||
"isSerialized": true,
|
||||
"isSigningField": true,
|
||||
"type": "UInt32"
|
||||
}
|
||||
],
|
||||
[
|
||||
"TicketSequence",
|
||||
{
|
||||
"nth": 42,
|
||||
"isVLEncoded": false,
|
||||
"isSerialized": true,
|
||||
"isSigningField": true,
|
||||
"type": "UInt32"
|
||||
}
|
||||
],
|
||||
[
|
||||
"IndexNext",
|
||||
{
|
||||
|
||||
@@ -51,6 +51,13 @@ const PaymentChannel = {
|
||||
},
|
||||
};
|
||||
|
||||
const Ticket = {
|
||||
create: {
|
||||
tx: require("./fixtures/ticket-create-tx.json"),
|
||||
binary: require("./fixtures/ticket-create-binary.json"),
|
||||
},
|
||||
};
|
||||
|
||||
let json_undefined = {
|
||||
TakerPays: "223174650",
|
||||
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp",
|
||||
@@ -236,6 +243,12 @@ function omitUndefinedTest() {
|
||||
});
|
||||
}
|
||||
|
||||
function ticketTest() {
|
||||
test("can serialize TicketCreate", () => {
|
||||
expect(encode(Ticket.create.tx)).toEqual(Ticket.create.binary);
|
||||
});
|
||||
}
|
||||
|
||||
describe("Binary Serialization", function () {
|
||||
describe("nestedObjectTests", () => nestedObjectTests());
|
||||
describe("BytesList", () => bytesListTest());
|
||||
@@ -246,4 +259,5 @@ describe("Binary Serialization", function () {
|
||||
describe("PaymentChannel", () => PaymentChannelTest());
|
||||
describe("NegativeUNLTest", () => NegativeUNLTest());
|
||||
describe("OmitUndefined", () => omitUndefinedTest());
|
||||
describe("TicketTest", () => ticketTest());
|
||||
});
|
||||
|
||||
1
packages/ripple-binary-codec/test/fixtures/ticket-create-binary.json
vendored
Normal file
1
packages/ripple-binary-codec/test/fixtures/ticket-create-binary.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"12000A240000000E2029000000016840000000000027108114D5024F157225CA9F8F4C73094D61A8FDD746E0DB"
|
||||
7
packages/ripple-binary-codec/test/fixtures/ticket-create-tx.json
vendored
Normal file
7
packages/ripple-binary-codec/test/fixtures/ticket-create-tx.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"TransactionType": "TicketCreate",
|
||||
"TicketCount": 1,
|
||||
"Account": "rLRH6HciuPv5rQBNFBYH1iPPAuVFERtNXZ",
|
||||
"Sequence": 14,
|
||||
"Fee": "10000"
|
||||
}
|
||||
@@ -33,6 +33,23 @@ describe("encoding and decoding tx_json", function () {
|
||||
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 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 my_tx = Object.assign({}, tx_json, {
|
||||
Amount: "1000.001",
|
||||
|
||||
Reference in New Issue
Block a user