Skip to content

Commit

Permalink
fix+test: packer sizes are exposed differently
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Aug 17, 2024
1 parent 34b6334 commit f8357eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions public/dashjoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ var DashJoin = ('object' === typeof module && exports) || {};

DashJoin.packers = Packers;
DashJoin.parsers = Parsers;
DashJoin.sizes = Sizes;
DashJoin.utils = Utils;

//@ts-ignore
Expand Down
15 changes: 8 additions & 7 deletions tests/dsq.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ let Assert = require('node:assert/strict');
let Fs = require('node:fs/promises');
let Path = require('node:path');

let Parser = require('../parser.js');
let DashP2P = require('../public/dashp2p.js');
let DashJoin = require('../public/dashjoin.js');
// TODO copy .utils.bytesToHex rather than depend on it
let DashKeys = require('dashkeys');

async function test() {
let totalSize = Parser.HEADER_SIZE + Parser.DSQ_SIZE;
let totalSize = DashP2P.sizes.HEADER + DashJoin.sizes.DSQ;
let fixtureDsqBytes = await readFixtureHex('dsq');
let fixtureDsqJson = require('../fixtures/dsq.json');

Expand All @@ -18,21 +19,21 @@ async function test() {
throw new Error(msg);
}

let header = Parser.parseHeader(fixtureDsqBytes);
let header = DashP2P.parsers.header(fixtureDsqBytes);
if (header.command !== 'dsq') {
throw new Error('sanity fail: loaded incorrect fixture');
}

if (header.payloadSize !== Parser.DSQ_SIZE) {
if (header.payloadSize !== DashJoin.sizes.DSQ) {
throw new Error('sanity fail: wrong payload size in header');
}

let payload = fixtureDsqBytes.subarray(Parser.HEADER_SIZE);
if (payload.length !== Parser.DSQ_SIZE) {
let payload = fixtureDsqBytes.subarray(DashP2P.sizes.HEADER);
if (payload.length !== DashJoin.sizes.DSQ) {
throw new Error('sanity fail: payload has trailing bytes');
}

let dsq = Parser.parseDsq(payload);
let dsq = DashJoin.parsers.dsq(payload);

// JSON-ify
dsq.protxhash = DashKeys.utils.bytesToHex(dsq.protxhash_bytes);
Expand Down

0 comments on commit f8357eb

Please sign in to comment.