Skip to content

Commit

Permalink
add breaking toJSON test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Aug 13, 2019
1 parent ee7970b commit f93de4c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/toJSON-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var fs = require('fs');
var path = require('path');
var assert = require('assert');
var elliptic = require('../lib/elliptic');
var curves = elliptic.curves;
var compare = assert.deepStrictEqual || assert.deepEqual;

function exportPoint (p) {
return JSON.parse(JSON.stringify(p.toJSON()));
}

describe('toJSON <-> pointFromJSON symmetry', function() {
it('toJSON matches pointFromJSON', function () {
for (var key in curves) {
if (key === 'PresetCurve') continue;

var curve = curves[key];
if (!curve.g.toJSON) continue;

var exported = exportPoint(curve.g);
var reimported = curve.curve.pointFromJSON(exported);
var reexported = exportPoint(reimported);
compare(exported, reexported, 'toJSON is the inverse of pointFromJSON');
}
});
});

0 comments on commit f93de4c

Please sign in to comment.