-
Notifications
You must be signed in to change notification settings - Fork 79
/
mockUserAccountSubscriber.ts
53 lines (41 loc) · 1.37 KB
/
mockUserAccountSubscriber.ts
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
import { DataAndSlot, UserAccountEvents, UserAccountSubscriber } from './types';
import { PublicKey } from '@solana/web3.js';
import StrictEventEmitter from 'strict-event-emitter-types';
import { EventEmitter } from 'events';
import { UserAccount } from '../types';
export class MockUserAccountSubscriber implements UserAccountSubscriber {
isSubscribed: boolean;
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
userAccountPublicKey: PublicKey;
callbackId?: string;
errorCallbackId?: string;
user: DataAndSlot<UserAccount>;
public constructor(
userAccountPublicKey: PublicKey,
data: UserAccount,
slot: number
) {
this.isSubscribed = true;
this.eventEmitter = new EventEmitter();
this.userAccountPublicKey = userAccountPublicKey;
this.user = { data, slot };
}
async subscribe(_userAccount?: UserAccount): Promise<boolean> {
return true;
}
async addToAccountLoader(): Promise<void> {}
async fetch(): Promise<void> {}
doesAccountExist(): boolean {
return this.user !== undefined;
}
async unsubscribe(): Promise<void> {}
assertIsSubscribed(): void {}
public getUserAccountAndSlot(): DataAndSlot<UserAccount> {
return this.user;
}
public updateData(userAccount: UserAccount, slot: number): void {
this.user = { data: userAccount, slot };
this.eventEmitter.emit('userAccountUpdate', userAccount);
this.eventEmitter.emit('update');
}
}