Skip to content

Commit

Permalink
Pluralize controller name
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jul 9, 2024
1 parent 4ca7500 commit ead561b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
getRestrictedSnapInsightControllerMessenger,
getRootSnapInsightControllerMessenger,
getRestrictedSnapInsightsControllerMessenger,
getRootSnapInsightsControllerMessenger,
MOCK_INSIGHTS_PERMISSIONS,
TRANSACTION_META_MOCK,
PERSONAL_SIGNATURE_MOCK,
TYPED_SIGNATURE_MOCK,
} from '../test-utils';
import { SnapInsightController } from './SnapInsightController';
import { SnapInsightsController } from './SnapInsightsController';
import {
getTruncatedSnap,
MOCK_LOCAL_SNAP_ID,
Expand All @@ -15,9 +15,9 @@ import {
import { nanoid } from 'nanoid';
import { HandlerType } from '@metamask/snaps-utils';

describe('SnapInsightController', () => {
describe('SnapInsightsController', () => {
it('adds insight for transactions', async () => {
const rootMessenger = getRootSnapInsightControllerMessenger();
const rootMessenger = getRootSnapInsightsControllerMessenger();

rootMessenger.registerActionHandler('SnapController:getAll', () => {
return [getTruncatedSnap(), getTruncatedSnap({ id: MOCK_LOCAL_SNAP_ID })];
Expand All @@ -38,9 +38,9 @@ describe('SnapInsightController', () => {
);

const controllerMessenger =
getRestrictedSnapInsightControllerMessenger(rootMessenger);
getRestrictedSnapInsightsControllerMessenger(rootMessenger);

const controller = new SnapInsightController({
const controller = new SnapInsightsController({
messenger: controllerMessenger,
});

Expand Down Expand Up @@ -98,11 +98,11 @@ describe('SnapInsightController', () => {
});

it('adds insight for personal sign', async () => {
const rootMessenger = getRootSnapInsightControllerMessenger();
const rootMessenger = getRootSnapInsightsControllerMessenger();
const controllerMessenger =
getRestrictedSnapInsightControllerMessenger(rootMessenger);
getRestrictedSnapInsightsControllerMessenger(rootMessenger);

const controller = new SnapInsightController({
const controller = new SnapInsightsController({
messenger: controllerMessenger,
});

Expand Down Expand Up @@ -192,11 +192,11 @@ describe('SnapInsightController', () => {
});

it('adds insight for typed signatures', async () => {
const rootMessenger = getRootSnapInsightControllerMessenger();
const rootMessenger = getRootSnapInsightsControllerMessenger();
const controllerMessenger =
getRestrictedSnapInsightControllerMessenger(rootMessenger);
getRestrictedSnapInsightsControllerMessenger(rootMessenger);

const controller = new SnapInsightController({
const controller = new SnapInsightsController({
messenger: controllerMessenger,
});

Expand Down Expand Up @@ -284,11 +284,11 @@ describe('SnapInsightController', () => {
});

it('does not fetch signature insights if they are already fetched for a given signature', async () => {
const rootMessenger = getRootSnapInsightControllerMessenger();
const rootMessenger = getRootSnapInsightsControllerMessenger();
const controllerMessenger =
getRestrictedSnapInsightControllerMessenger(rootMessenger);
getRestrictedSnapInsightsControllerMessenger(rootMessenger);

const controller = new SnapInsightController({
const controller = new SnapInsightsController({
messenger: controllerMessenger,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import {
ValidPermission,
} from '@metamask/permission-controller';

const controllerName = 'SnapInsightController';
const controllerName = 'SnapInsightsController';

export type SnapInsightControllerAllowedActions =
export type SnapInsightsControllerAllowedActions =
| HandleSnapRequest
| GetAllSnaps
| GetPermissions;

export type SnapInsightControllerActions = never;
export type SnapInsightsControllerActions = never;

export type SnapInsightControllerAllowedEvents =
export type SnapInsightsControllerAllowedEvents =
| TransactionControllerUnapprovedTransactionAddedEvent
| SignatureStateChange;

export type SnapInsightControllerMessenger = RestrictedControllerMessenger<
export type SnapInsightsControllerMessenger = RestrictedControllerMessenger<
typeof controllerName,
SnapInsightControllerActions | SnapInsightControllerAllowedActions,
SnapInsightControllerAllowedEvents,
SnapInsightControllerAllowedActions['type'],
SnapInsightControllerAllowedEvents['type']
SnapInsightsControllerActions | SnapInsightsControllerAllowedActions,
SnapInsightsControllerAllowedEvents,
SnapInsightsControllerAllowedActions['type'],
SnapInsightsControllerAllowedEvents['type']
>;

export type SnapInsight = {
Expand All @@ -55,13 +55,13 @@ export type SnapInsights = {
results: SnapInsight[];
};

export type SnapInsightControllerState = {
export type SnapInsightsControllerState = {
insights: Record<string, SnapInsights>;
};

export type SnapInsightControllerArgs = {
messenger: SnapInsightControllerMessenger;
state?: SnapInsightControllerState;
export type SnapInsightsControllerArgs = {
messenger: SnapInsightsControllerMessenger;
state?: SnapInsightsControllerState;
};

// The controller doesn't currently export this, so we grab it this way.
Expand All @@ -80,12 +80,12 @@ type SnapWithPermission = {
/**
* Controller for monitoring for new transactions and signatures to provide insight for.
*/
export class SnapInsightController extends BaseController<
export class SnapInsightsController extends BaseController<
typeof controllerName,
SnapInsightControllerState,
SnapInsightControllerMessenger
SnapInsightsControllerState,
SnapInsightsControllerMessenger
> {
constructor({ messenger, state }: SnapInsightControllerArgs) {
constructor({ messenger, state }: SnapInsightsControllerArgs) {
super({
messenger,
metadata: {
Expand Down
24 changes: 12 additions & 12 deletions packages/snaps-controllers/src/test-utils/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import { MOCK_CRONJOB_PERMISSION } from './cronjob';
import { getNodeEES, getNodeEESMessenger } from './execution-environment';
import { MockSnapsRegistry } from './registry';
import {
SnapInsightControllerAllowedActions,
SnapInsightControllerAllowedEvents,
SnapInsightsControllerAllowedActions,
SnapInsightsControllerAllowedEvents,
} from '../insights';

const asyncNoOp = async () => Promise.resolve();
Expand Down Expand Up @@ -751,28 +751,28 @@ export const getRestrictedSnapInterfaceControllerMessenger = (
};

// Mock controller messenger for Insight Controller
export const getRootSnapInsightControllerMessenger = () => {
export const getRootSnapInsightsControllerMessenger = () => {
const messenger = new MockControllerMessenger<
SnapInsightControllerAllowedActions,
SnapInsightControllerAllowedEvents
SnapInsightsControllerAllowedActions,
SnapInsightsControllerAllowedEvents
>();

jest.spyOn(messenger, 'call');

return messenger;
};

export const getRestrictedSnapInsightControllerMessenger = (
export const getRestrictedSnapInsightsControllerMessenger = (
messenger: ReturnType<
typeof getRootSnapInsightControllerMessenger
> = getRootSnapInsightControllerMessenger(),
typeof getRootSnapInsightsControllerMessenger
> = getRootSnapInsightsControllerMessenger(),
) => {
const controllerMessenger = messenger.getRestricted<
'SnapInsightController',
SnapInsightControllerAllowedActions['type'],
SnapInsightControllerAllowedEvents['type']
'SnapInsightsController',
SnapInsightsControllerAllowedActions['type'],
SnapInsightsControllerAllowedEvents['type']
>({
name: 'SnapInsightController',
name: 'SnapInsightsController',
allowedEvents: [
'TransactionController:unapprovedTransactionAdded',
'SignatureController:stateChange',
Expand Down

0 comments on commit ead561b

Please sign in to comment.