Support encoding and decoding of NegativeUNL pseudo-transactions (#89)

* Support encoding and decoding of NegativeUNL pseudo-transactions
This commit is contained in:
Nathan Nichols
2020-08-13 12:20:12 -05:00
parent 2e6c68ba73
commit 30ff63e653
8 changed files with 161 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
/* eslint-disable func-style */
const { binary } = require('../dist/coretypes')
const { encode } = require('../dist')
const { encode, decode } = require('../dist')
const { makeParser, BytesList, BinarySerializer } = binary
const { coreTypes } = require('../dist/types')
const { UInt8, UInt16, UInt32, UInt64, STObject } = coreTypes
@@ -50,6 +50,8 @@ const PaymentChannel = {
}
}
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 () {
@@ -171,6 +173,15 @@ function PaymentChannelTest () {
})
}
function NegativeUNLTest () {
test('can serialize NegativeUNL', () => {
expect(encode(NegativeUNL.tx)).toEqual(NegativeUNL.binary);
})
test('can deserialize NegativeUNL', () => {
expect(decode(NegativeUNL.binary)).toEqual(NegativeUNL.tx);
})
}
describe('Binary Serialization', function() {
describe('nestedObjectTests', nestedObjectTests);
describe('BytesList', bytesListTest);
@@ -179,4 +190,5 @@ describe('Binary Serialization', function() {
describe('SignerListSet', SignerListSetTest);
describe('Escrow', EscrowTest);
describe('PaymentChannel', PaymentChannelTest);
describe('NegativeUNLTest', NegativeUNLTest);
})