mirror of
https://github.com/logos-messaging/js-noise.git
synced 2026-01-02 05:33:09 +00:00
update mock
This commit is contained in:
parent
3e27606edc
commit
ba201fb560
@ -1,6 +1,6 @@
|
||||
import { HMACDRBG } from "@stablelib/hmac-drbg";
|
||||
import { randomBytes } from "@stablelib/random";
|
||||
import type { IDecoder, IEncoder, IMessage, IProtoMessage, ISender } from "@waku/interfaces";
|
||||
import type { IDecoder, IEncoder, IMessage, IProtoMessage, IReceiver, ISender } from "@waku/interfaces";
|
||||
import { expect } from "chai";
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import { pEvent } from "p-event";
|
||||
@ -43,24 +43,23 @@ describe("js-noise: pairing object", () => {
|
||||
};
|
||||
},
|
||||
};
|
||||
const decoderMap: { [key: string]: IDecoder<NoiseHandshakeMessage> } = {};
|
||||
const responder = {
|
||||
subscribe(decoder: IDecoder<NoiseHandshakeMessage>): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
decoderMap[decoder.contentTopic] = decoder;
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
async nextMessage(contentTopic: string): Promise<NoiseHandshakeMessage> {
|
||||
const msg = await pEvent(msgEmitter, contentTopic);
|
||||
const decodedMessage = await decoderMap[contentTopic].fromProtoObj(PUBSUB_TOPIC, msg);
|
||||
return decodedMessage!;
|
||||
},
|
||||
async stop(contentTopic: string): Promise<void> {
|
||||
// Do nothing. This is just a simulation
|
||||
console.debug("stopping subscription to", contentTopic);
|
||||
},
|
||||
};
|
||||
toSubscriptionIterator(decoder: IDecoder<NoiseHandshakeMessage>) {
|
||||
async function* iterator() {
|
||||
const msg = await pEvent(msgEmitter, decoder.contentTopic);
|
||||
const decodedMessage = await decoder.fromProtoObj(PUBSUB_TOPIC, msg);
|
||||
yield decodedMessage!;
|
||||
}
|
||||
|
||||
return {
|
||||
iterator: iterator(),
|
||||
stop() {
|
||||
// Do nothing. This is just a simulation
|
||||
console.debug("stopping subscription to", decoder.contentTopic);
|
||||
},
|
||||
}
|
||||
}
|
||||
} as any as IReceiver;
|
||||
// =================
|
||||
|
||||
it("should pair", async function () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user