This repository was archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathisAlive.spec.ts
More file actions
68 lines (60 loc) · 2.47 KB
/
isAlive.spec.ts
File metadata and controls
68 lines (60 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { VectorChainService } from "@connext/vector-contracts";
import { IVectorChainService, Result } from "@connext/vector-types";
import {
createTestChannelState,
expect,
getRandomChannelSigner,
getTestLoggers,
MemoryMessagingService,
MemoryStoreService,
mkAddress,
mkPublicIdentifier,
} from "@connext/vector-utils";
import Sinon from "sinon";
import { sendIsAlive } from "../isAlive";
import { env } from "./env";
describe("checkIn", () => {
const testName = "checkIn";
const { log } = getTestLoggers(testName, env.logLevel);
const chainId = parseInt(Object.keys(env.chainProviders)[0]);
let storeService: Sinon.SinonStubbedInstance<MemoryStoreService>;
let messagingService: Sinon.SinonStubbedInstance<MemoryMessagingService>;
let chainService: Sinon.SinonStubbedInstance<VectorChainService>;
beforeEach(() => {
storeService = Sinon.createStubInstance(MemoryStoreService);
messagingService = Sinon.createStubInstance(MemoryMessagingService);
chainService = Sinon.createStubInstance(VectorChainService);
chainService.getChainRpcProviders.returns(Result.ok(env.chainProviders));
});
it("should send no checkIn messages if there are no channels", async () => {
const signer = getRandomChannelSigner();
storeService.getChannelStates.resolves([]);
await sendIsAlive(signer, messagingService, storeService, chainService as IVectorChainService, log);
expect(messagingService.sendIsAliveMessage.called).to.be.false;
});
it("should send checkIn messages to all channels", async () => {
const signer = getRandomChannelSigner();
const channel1 = createTestChannelState("create", {
alice: signer.address,
bob: mkAddress("0xbbb"),
aliceIdentifier: signer.publicIdentifier,
bobIdentifier: mkPublicIdentifier("vectorBBB"),
networkContext: {
chainId,
},
}).channel;
const channel2 = createTestChannelState("resolve", {
bob: signer.address,
alice: mkAddress("0xccc"),
bobIdentifier: signer.publicIdentifier,
aliceIdentifier: mkPublicIdentifier("vectorCCC"),
networkContext: {
chainId,
},
}).channel;
messagingService.sendIsAliveMessage.resolves(Result.ok({ channelAddress: channel1.channelAddress }));
storeService.getChannelStates.resolves([channel1, channel2]);
await sendIsAlive(signer, messagingService, storeService, chainService as IVectorChainService, log);
expect(messagingService.sendIsAliveMessage.callCount).to.eq(2);
});
});