Skip to content

Commit

Permalink
cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinse12 committed Oct 30, 2024
1 parent 0a8a468 commit 15f30f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/publications/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class Publication extends TypedEmitter<PublicationEvents> {
.map(([provider]) => provider);
providers.forEach((provider) => this._clientsManager.updatePubsubState("waiting-challenge-verification", provider));

log(`Responded to challenge (${this._challengeAnswer.challengeRequestId}) with answers`, challengeAnswers);
log(`Responded to challenge with answers`, challengeAnswers);
this.emit("challengeanswer", this._challengeAnswer);
}

Expand Down
3 changes: 3 additions & 0 deletions src/rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class PlebbitWsServer extends EventEmitter {
this.subscriptionCleanups[ws._id] = {};
//@ts-expect-error
this._onSettingsChange[ws._id] = {};
//@ts-expect-error
log("Established connection with new RPC client", ws._id);
});

// cleanup on disconnect
Expand All @@ -153,6 +155,7 @@ class PlebbitWsServer extends EventEmitter {
delete this.subscriptionCleanups[ws._id];
delete this.connections[ws._id];
delete this._onSettingsChange[ws._id];
log("Disconnected from RPC client", ws._id);
});

// register all JSON RPC methods
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/subplebbit/local-subplebbit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ export class LocalSubplebbit extends RpcLocalSubplebbit implements CreateNewLoca
this._clientsManager.updatePubsubState("publishing-challenge", undefined);

await this._clientsManager.pubsubPublish(this.pubsubTopicWithfallback(), challengeMessage);
log.trace(
`Published ${challengeMessage.type} over pubsub: `,
log(
`Subplebbit ${this.address} published ${challengeMessage.type} over pubsub: `,
remeda.pick(toSignChallenge, ["timestamp"]),
toEncryptChallenge.challenges.map((challenge) => challenge.type)
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/mock-ipfs-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io, { Socket } from "socket.io-client";
import { IpfsClient, PubsubSubscriptionHandler } from "../types.js";
import type { IpfsClient, PubsubSubscriptionHandler } from "../types.js";

const port = 25963;

Expand Down
14 changes: 9 additions & 5 deletions src/test/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ export async function loadAllPages(pageCid: string, pagesInstance: BasePages) {
}

async function _mockSubplebbitPlebbit(signers: SignerType[], plebbitOptions: InputPlebbitOptions) {
const plebbit = await mockPlebbit({ ...plebbitOptions, pubsubHttpClientsOptions: ["http://localhost:15002/api/v0"] });

for (const pubsubUrl of remeda.keys.strict(plebbit.clients.pubsubClients))
plebbit.clients.pubsubClients[pubsubUrl]._client = createMockIpfsClient();
const plebbit = await mockPlebbit({ ...plebbitOptions, pubsubHttpClientsOptions: ["http://localhost:15002/api/v0"] }, true);

return plebbit;
}
Expand Down Expand Up @@ -404,7 +401,7 @@ export async function createOnlinePlebbit(plebbitOptions?: InputPlebbitOptions)
}

export async function mockRemotePlebbitIpfsOnly(plebbitOptions?: InputPlebbitOptions) {
const plebbit = await mockRemotePlebbit({
const plebbit = await mockPlebbit({
ipfsHttpClientsOptions: ["http://localhost:15001/api/v0"],
plebbitRpcClientsOptions: undefined,
dataPath: undefined,
Expand Down Expand Up @@ -512,6 +509,13 @@ export async function publishWithExpectedResult(publication: Publication, expect
});
});

publication.once("challenge", (challenge) =>
console.log(
"Received challenges in publishWithExpectedResult. Are you sure you're publishing to a sub with no challenges?",
challenge
)
);

await publication.publish();
await validateResponsePromise;
}
Expand Down

0 comments on commit 15f30f7

Please sign in to comment.