From 552e1a952dd4ee831eb847ea9993f6882ba01dc7 Mon Sep 17 00:00:00 2001 From: Thomas Greco <6646552+tgrecojs@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:20:31 -0400 Subject: [PATCH] test(marshal): added test cases for new serialization API --- .../test/test-marshal-serialization.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 packages/marshal/test/test-marshal-serialization.js diff --git a/packages/marshal/test/test-marshal-serialization.js b/packages/marshal/test/test-marshal-serialization.js new file mode 100644 index 0000000000..4f2f95440a --- /dev/null +++ b/packages/marshal/test/test-marshal-serialization.js @@ -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', + ); +});