From 9ddb6498b0c15ee5be9d4965b649870227c092cd Mon Sep 17 00:00:00 2001 From: wilsonianb Date: Mon, 20 Mar 2017 15:30:48 -0700 Subject: [PATCH] Add escrow support --- .../src/enums/definitions.json | 21 +++++++++---- .../test/binary-serializer-test.js | 30 +++++++++++++++++++ .../test/fixtures/data-driven-tests.json | 21 ++++++++----- .../test/fixtures/escrow-cancel-binary.json | 1 + .../test/fixtures/escrow-cancel-tx.json | 6 ++++ .../test/fixtures/escrow-create-binary.json | 1 + .../test/fixtures/escrow-create-tx.json | 10 +++++++ .../test/fixtures/escrow-finish-binary.json | 1 + .../test/fixtures/escrow-finish-tx.json | 8 +++++ 9 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-cancel-binary.json create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-cancel-tx.json create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-create-binary.json create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-create-tx.json create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-finish-binary.json create mode 100644 packages/ripple-binary-codec/test/fixtures/escrow-finish-tx.json diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 9ea0d152..df014bcd 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -30,10 +30,11 @@ "AccountRoot": 97, "RippleState": 114, "FeeSettings": 115, - "SuspendedPayment": 117, + "Escrow": 117, "DirectoryNode": 100, "GeneratorMap": 103, "Contract": 99, + "PayChannel": 120, "Invalid": -1 }, "FIELDS": [ @@ -988,7 +989,17 @@ } ], [ - "Proof", + "Fulfillment", + { + "nth": 16, + "isVLEncoded": true, + "isSerialized": true, + "isSigningField": true, + "type": "Blob" + } + ], + [ + "Condition", { "nth": 17, "isVLEncoded": true, @@ -1556,9 +1567,9 @@ "OfferCreate": 7, "SignerListSet": 12, "Contract": 9, - "SuspendedPaymentCreate": 1, - "SuspendedPaymentFinish": 2, - "SuspendedPaymentCancel": 4, + "EscrowCreate": 1, + "EscrowFinish": 2, + "EscrowCancel": 4, "PaymentChannelCreate": 13, "PaymentChannelFund": 14, "PaymentChannelClaim": 15, diff --git a/packages/ripple-binary-codec/test/binary-serializer-test.js b/packages/ripple-binary-codec/test/binary-serializer-test.js index c0023b09..7bcc311e 100644 --- a/packages/ripple-binary-codec/test/binary-serializer-test.js +++ b/packages/ripple-binary-codec/test/binary-serializer-test.js @@ -15,6 +15,20 @@ const SignerListSet = { binary: require('./fixtures/signerlistset-tx-binary.json'), meta: require('./fixtures/signerlistset-tx-meta-binary.json') }; +const Escrow = { + create: { + 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') + }, + cancel: { + 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'), @@ -120,6 +134,21 @@ function SignerListSetTest() { }); } +function EscrowTest() { + it('can serialize EscrowCreate', () => { + assert.strictEqual(encode(Escrow.create.tx), + Escrow.create.binary); + }); + it('can serialize EscrowFinish', () => { + assert.strictEqual(encode(Escrow.finish.tx), + Escrow.finish.binary); + }); + it('can serialize EscrowCancel', () => { + assert.strictEqual(encode(Escrow.cancel.tx), + Escrow.cancel.binary); + }); +} + function PaymentChannelTest() { it('can serialize PaymentChannelCreate', () => { assert.strictEqual(encode(PaymentChannel.create.tx), @@ -142,5 +171,6 @@ describe('Binary Serialization', function() { describe('BytesList', bytesListTest); describe('DeliverMin', deliverMinTest); describe('SignerListSet', SignerListSetTest); + describe('Escrow', EscrowTest); describe('PaymentChannel', PaymentChannelTest); }); diff --git a/packages/ripple-binary-codec/test/fixtures/data-driven-tests.json b/packages/ripple-binary-codec/test/fixtures/data-driven-tests.json index 2079f2eb..a5f34405 100644 --- a/packages/ripple-binary-codec/test/fixtures/data-driven-tests.json +++ b/packages/ripple-binary-codec/test/fixtures/data-driven-tests.json @@ -681,7 +681,14 @@ }, { "type_name": "Blob", - "name": "Proof", + "name": "Fulfillment", + "nth_of_type": 16, + "type": 7, + "expected_hex": "7010" + }, + { + "type_name": "Blob", + "name": "Condition", "nth_of_type": 17, "type": 7, "expected_hex": "7011" @@ -2924,7 +2931,7 @@ "expected_hex": "0000" }, { - "test_json": "SuspendedPaymentCreate", + "test_json": "EscrowCreate", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", @@ -2932,14 +2939,14 @@ }, { "test_json": 1, - "canonical_json": "SuspendedPaymentCreate", + "canonical_json": "EscrowCreate", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", "expected_hex": "0001" }, { - "test_json": "SuspendedPaymentFinish", + "test_json": "EscrowFinish", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", @@ -2947,7 +2954,7 @@ }, { "test_json": 2, - "canonical_json": "SuspendedPaymentFinish", + "canonical_json": "EscrowFinish", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", @@ -2969,7 +2976,7 @@ "expected_hex": "0003" }, { - "test_json": "SuspendedPaymentCancel", + "test_json": "EscrowCancel", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", @@ -2977,7 +2984,7 @@ }, { "test_json": 4, - "canonical_json": "SuspendedPaymentCancel", + "canonical_json": "EscrowCancel", "type_id": 1, "type_specialisation_field": "TransactionType", "type": "UInt16", diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-cancel-binary.json b/packages/ripple-binary-codec/test/fixtures/escrow-cancel-binary.json new file mode 100644 index 00000000..f9d13347 --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-cancel-binary.json @@ -0,0 +1 @@ +"1200042019000000198114EE5F7CF61504C7CF7E0C22562EB19CC7ACB0FCBA8214EE5F7CF61504C7CF7E0C22562EB19CC7ACB0FCBA" diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-cancel-tx.json b/packages/ripple-binary-codec/test/fixtures/escrow-cancel-tx.json new file mode 100644 index 00000000..4f51c2d3 --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-cancel-tx.json @@ -0,0 +1,6 @@ +{ + "Account" : "r4jQDHCUvgcBAa5EzcB1D8BHGcjYP9eBC2", + "OfferSequence" : 25, + "Owner" : "r4jQDHCUvgcBAa5EzcB1D8BHGcjYP9eBC2", + "TransactionType" : "EscrowCancel" +} diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-create-binary.json b/packages/ripple-binary-codec/test/fixtures/escrow-create-binary.json new file mode 100644 index 00000000..58fa1ea2 --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-create-binary.json @@ -0,0 +1 @@ +"1200012E00005BB82024258D09812025258D0980614000000000000064701127A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B8558101008114EE5F7CF61504C7CF7E0C22562EB19CC7ACB0FCBA8314B5F762798A53D543A014CAF8B297CFF8F2F937E8" diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-create-tx.json b/packages/ripple-binary-codec/test/fixtures/escrow-create-tx.json new file mode 100644 index 00000000..376efaf6 --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-create-tx.json @@ -0,0 +1,10 @@ +{ + "Account" : "r4jQDHCUvgcBAa5EzcB1D8BHGcjYP9eBC2", + "Amount" : "100", + "CancelAfter" : 630000001, + "Condition" : "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100", + "Destination" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", + "DestinationTag" : 23480, + "FinishAfter" : 630000000, + "TransactionType": "EscrowCreate" +} diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-finish-binary.json b/packages/ripple-binary-codec/test/fixtures/escrow-finish-binary.json new file mode 100644 index 00000000..af74934b --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-finish-binary.json @@ -0,0 +1 @@ +"120002201900000007701004A0028000701127A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B8558101008114EE5F7CF61504C7CF7E0C22562EB19CC7ACB0FCBA8214EE5F7CF61504C7CF7E0C22562EB19CC7ACB0FCBA" diff --git a/packages/ripple-binary-codec/test/fixtures/escrow-finish-tx.json b/packages/ripple-binary-codec/test/fixtures/escrow-finish-tx.json new file mode 100644 index 00000000..24a57bf0 --- /dev/null +++ b/packages/ripple-binary-codec/test/fixtures/escrow-finish-tx.json @@ -0,0 +1,8 @@ +{ + "Account" : "r4jQDHCUvgcBAa5EzcB1D8BHGcjYP9eBC2", + "Condition" : "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100", + "Fulfillment" : "A0028000", + "OfferSequence" : 7, + "Owner" : "r4jQDHCUvgcBAa5EzcB1D8BHGcjYP9eBC2", + "TransactionType" : "EscrowFinish" +}