Tickets support (#110)

* feat(tickets): add TicketCount definition

* feat(tickets): add TicketSequence definition

* fix(tests): unit tests
This commit is contained in:
elmurci
2020-11-17 17:33:20 +01:00
parent b43e79a9af
commit 479ade8a76
5 changed files with 59 additions and 0 deletions

View File

@@ -444,6 +444,26 @@
"type": "UInt32" "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", "IndexNext",
{ {

View File

@@ -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 = { let json_undefined = {
TakerPays: "223174650", TakerPays: "223174650",
Account: "rPk2dXr27rMw9G5Ej9ad2Tt7RJzGy8ycBp", 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("Binary Serialization", function () {
describe("nestedObjectTests", () => nestedObjectTests()); describe("nestedObjectTests", () => nestedObjectTests());
describe("BytesList", () => bytesListTest()); describe("BytesList", () => bytesListTest());
@@ -246,4 +259,5 @@ describe("Binary Serialization", function () {
describe("PaymentChannel", () => PaymentChannelTest()); describe("PaymentChannel", () => PaymentChannelTest());
describe("NegativeUNLTest", () => NegativeUNLTest()); describe("NegativeUNLTest", () => NegativeUNLTest());
describe("OmitUndefined", () => omitUndefinedTest()); describe("OmitUndefined", () => omitUndefinedTest());
describe("TicketTest", () => ticketTest());
}); });

View File

@@ -0,0 +1 @@
"12000A240000000E2029000000016840000000000027108114D5024F157225CA9F8F4C73094D61A8FDD746E0DB"

View File

@@ -0,0 +1,7 @@
{
"TransactionType": "TicketCreate",
"TicketCount": 1,
"Account": "rLRH6HciuPv5rQBNFBYH1iPPAuVFERtNXZ",
"Sequence": 14,
"Fee": "10000"
}

View File

@@ -33,6 +33,23 @@ describe("encoding and decoding tx_json", function () {
const decoded = decode(encoded); const decoded = decode(encoded);
expect(my_tx).toEqual(decoded); 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 () { test("throws when Amount is invalid", function () {
const my_tx = Object.assign({}, tx_json, { const my_tx = Object.assign({}, tx_json, {
Amount: "1000.001", Amount: "1000.001",