Skip to content

Commit

Permalink
Merge pull request #1536 from tgrecojs/tgrecojs-marshal-readme-new-se…
Browse files Browse the repository at this point in the history
…rialization-api

test(marshal): added test cases for new serialization API
  • Loading branch information
michaelfig committed Jan 9, 2024
2 parents 2db12e9 + 552e1a9 commit b89e457
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packages/marshal/test/test-marshal-serialization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { test } from './prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { makeMarshal } from '../src/marshal.js';

test('toCapData', t => {
const m = makeMarshal();
const o = harden({ a: 1 });

// deprecated seralization API
const usingSerializeMethod = m.serialize(o);

const usingToCapDataMethod = m.toCapData(o);

t.deepEqual(
usingSerializeMethod,
usingToCapDataMethod,
'should create a serialized object that is deeply equal to value produced using makeMarshal().serialize',
);

const oo = harden([o, o]);

const ooUsingSerializeMethod = m.serialize(oo);
const ooUsingToCapDataMethod = m.toCapData(oo);
t.deepEqual(
ooUsingSerializeMethod,
ooUsingToCapDataMethod,
'given a previously serialized object, should create a serialized object that is deeply equal to value produced using makeMarshal().serialize',
);
});

test('fromCapData', t => {
const m = makeMarshal();
const o = harden({ a: 1 });

// deprecated seralization API
const usingSerializeMethod = m.serialize(o);

const usingToCapDataMethod = m.toCapData(o);

const usingUnserializeMethod = m.unserialize(usingSerializeMethod);
const usingFromCapDataMethod = m.fromCapData(usingToCapDataMethod);

t.deepEqual(
usingUnserializeMethod,
usingFromCapDataMethod,
'should return an unserialized object that is deeply equal to value unserialized using makeMarshal().unserialize',
);

const oo = harden([o, o]);

const ooUsingSerializeMethod = m.serialize(oo);
const ooUsingToCapDataMethod = m.toCapData(oo);

const uoUsingUnserializeMethod = m.unserialize(ooUsingSerializeMethod);
const uoUsingFromCapDataMethod = m.fromCapData(ooUsingToCapDataMethod);

t.deepEqual(
uoUsingUnserializeMethod,
uoUsingFromCapDataMethod,
'given a previously serialized object, should create a serialized object that is deeply equal to value produced using makeMarshal().serialize',
);
});

0 comments on commit b89e457

Please sign in to comment.