mirror of https://github.com/waku-org/js-waku.git
Remove dupe tests
This commit is contained in:
parent
6afecd9989
commit
302fc20243
|
@ -4,7 +4,7 @@ import fc from 'fast-check';
|
||||||
import { WakuMessage } from '../../lib/waku_message';
|
import { WakuMessage } from '../../lib/waku_message';
|
||||||
import { getPublicKey } from '../../lib/waku_message/version_1';
|
import { getPublicKey } from '../../lib/waku_message/version_1';
|
||||||
|
|
||||||
describe('Waku Message', function () {
|
describe('Waku Message: Browser & Node', function () {
|
||||||
it('Waku message round trip binary serialization [clear]', async function () {
|
it('Waku message round trip binary serialization [clear]', async function () {
|
||||||
await fc.assert(
|
await fc.assert(
|
||||||
fc.asyncProperty(fc.string(), async (s) => {
|
fc.asyncProperty(fc.string(), async (s) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import fc from 'fast-check';
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore: No types available
|
// @ts-ignore: No types available
|
||||||
import TCP from 'libp2p-tcp';
|
import TCP from 'libp2p-tcp';
|
||||||
|
@ -21,120 +20,7 @@ import { DefaultContentTopic, WakuMessage } from './index';
|
||||||
|
|
||||||
const dbg = debug('waku:test:message');
|
const dbg = debug('waku:test:message');
|
||||||
|
|
||||||
describe('Waku Message', function () {
|
describe('Waku Message: Node only', function () {
|
||||||
it('Waku message round trip binary serialization [clear]', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(fc.string(), async (s) => {
|
|
||||||
const msg = await WakuMessage.fromUtf8String(s);
|
|
||||||
const binary = msg.encode();
|
|
||||||
const actual = await WakuMessage.decode(binary);
|
|
||||||
|
|
||||||
expect(actual).to.deep.equal(msg);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Payload to utf-8', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(fc.string(), async (s) => {
|
|
||||||
const msg = await WakuMessage.fromUtf8String(s);
|
|
||||||
const utf8 = msg.payloadAsUtf8;
|
|
||||||
|
|
||||||
return utf8 === s;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Waku message round trip binary encryption [asymmetric, no signature]', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(
|
|
||||||
fc.uint8Array({ minLength: 1 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
async (payload, privKey) => {
|
|
||||||
const publicKey = getPublicKey(privKey);
|
|
||||||
|
|
||||||
const msg = await WakuMessage.fromBytes(payload, {
|
|
||||||
encPublicKey: publicKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wireBytes = msg.encode();
|
|
||||||
const actual = await WakuMessage.decode(wireBytes, [privKey]);
|
|
||||||
|
|
||||||
expect(actual?.payload).to.deep.equal(payload);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Waku message round trip binary encryption [asymmetric, signature]', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(
|
|
||||||
fc.uint8Array({ minLength: 1 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
async (payload, sigPrivKey, encPrivKey) => {
|
|
||||||
const sigPubKey = getPublicKey(sigPrivKey);
|
|
||||||
const encPubKey = getPublicKey(encPrivKey);
|
|
||||||
|
|
||||||
const msg = await WakuMessage.fromBytes(payload, {
|
|
||||||
encPublicKey: encPubKey,
|
|
||||||
sigPrivKey: sigPrivKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wireBytes = msg.encode();
|
|
||||||
const actual = await WakuMessage.decode(wireBytes, [encPrivKey]);
|
|
||||||
|
|
||||||
expect(actual?.payload).to.deep.equal(payload);
|
|
||||||
expect(actual?.signaturePublicKey).to.deep.equal(sigPubKey);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Waku message round trip binary encryption [symmetric, no signature]', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(
|
|
||||||
fc.uint8Array({ minLength: 1 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
async (payload, key) => {
|
|
||||||
const msg = await WakuMessage.fromBytes(payload, {
|
|
||||||
symKey: key,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wireBytes = msg.encode();
|
|
||||||
const actual = await WakuMessage.decode(wireBytes, [key]);
|
|
||||||
|
|
||||||
expect(actual?.payload).to.deep.equal(payload);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Waku message round trip binary encryption [symmetric, signature]', async function () {
|
|
||||||
await fc.assert(
|
|
||||||
fc.asyncProperty(
|
|
||||||
fc.uint8Array({ minLength: 1 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
fc.uint8Array({ minLength: 32, maxLength: 32 }),
|
|
||||||
async (payload, sigPrivKey, symKey) => {
|
|
||||||
const sigPubKey = getPublicKey(sigPrivKey);
|
|
||||||
|
|
||||||
const msg = await WakuMessage.fromBytes(payload, {
|
|
||||||
symKey: symKey,
|
|
||||||
sigPrivKey: sigPrivKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wireBytes = msg.encode();
|
|
||||||
const actual = await WakuMessage.decode(wireBytes, [symKey]);
|
|
||||||
|
|
||||||
expect(actual?.payload).to.deep.equal(payload);
|
|
||||||
expect(actual?.signaturePublicKey).to.deep.equal(sigPubKey);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Interop: Nim', function () {
|
describe('Interop: Nim', function () {
|
||||||
let waku: Waku;
|
let waku: Waku;
|
||||||
let nimWaku: NimWaku;
|
let nimWaku: NimWaku;
|
||||||
|
@ -178,9 +64,11 @@ describe('Interop: Nim', function () {
|
||||||
|
|
||||||
waku.relay.addDecryptionPrivateKey(privateKey);
|
waku.relay.addDecryptionPrivateKey(privateKey);
|
||||||
|
|
||||||
const receivedMsgPromise: Promise<WakuMessage> = new Promise((resolve) => {
|
const receivedMsgPromise: Promise<WakuMessage> = new Promise(
|
||||||
|
(resolve) => {
|
||||||
waku.relay.addObserver(resolve);
|
waku.relay.addObserver(resolve);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const publicKey = getPublicKey(privateKey);
|
const publicKey = getPublicKey(privateKey);
|
||||||
dbg('Post message');
|
dbg('Post message');
|
||||||
|
@ -218,3 +106,4 @@ describe('Interop: Nim', function () {
|
||||||
expect(hexToBuf(msgs[0].payload).toString('utf-8')).to.equal(messageText);
|
expect(hexToBuf(msgs[0].payload).toString('utf-8')).to.equal(messageText);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue