Skip to content

Commit

Permalink
Move isKeyringUnlocked option in WithControllerOptions out of con…
Browse files Browse the repository at this point in the history
…troller constructor options
  • Loading branch information
MajorLift committed Feb 9, 2024
1 parent ad3593d commit 95b34ac
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions packages/assets-controllers/src/TokenDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ describe('TokenDetectionController', () => {
it('should not poll and detect tokens on interval while keyring is locked', async () => {
await withController(
{
options: {
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({ controller }) => {
const mockTokens = sinon.stub(controller, 'detectTokens');
Expand All @@ -213,9 +211,7 @@ describe('TokenDetectionController', () => {
it('should detect tokens but not restart polling if locked keyring is unlocked', async () => {
await withController(
{
options: {
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({ controller, triggerKeyringUnlock }) => {
const mockTokens = sinon.stub(controller, 'detectTokens');
Expand All @@ -233,9 +229,7 @@ describe('TokenDetectionController', () => {
it('should stop polling and detect tokens on interval if unlocked keyring is locked', async () => {
await withController(
{
options: {
isKeyringUnlocked: true,
},
isKeyringUnlocked: true,
},
async ({ controller, triggerKeyringLock }) => {
const mockTokens = sinon.stub(controller, 'detectTokens');
Expand Down Expand Up @@ -639,8 +633,8 @@ describe('TokenDetectionController', () => {
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({
mockTokenListGetState,
Expand Down Expand Up @@ -970,8 +964,8 @@ describe('TokenDetectionController', () => {
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({
mockTokenListGetState,
Expand Down Expand Up @@ -1019,8 +1013,8 @@ describe('TokenDetectionController', () => {
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({
mockTokenListGetState,
Expand Down Expand Up @@ -1344,8 +1338,8 @@ describe('TokenDetectionController', () => {
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({
mockTokenListGetState,
Expand Down Expand Up @@ -1541,8 +1535,8 @@ describe('TokenDetectionController', () => {
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
isKeyringUnlocked: false,
},
isKeyringUnlocked: false,
},
async ({
mockTokenListGetState,
Expand Down Expand Up @@ -1937,9 +1931,8 @@ type WithControllerCallback<ReturnValue> = ({
}) => Promise<ReturnValue> | ReturnValue;

type WithControllerOptions = {
options?: Partial<
ConstructorParameters<typeof TokenDetectionController>[0]
> & { isKeyringUnlocked?: boolean };
options?: Partial<ConstructorParameters<typeof TokenDetectionController>[0]>;
isKeyringUnlocked?: boolean;
messenger?: ControllerMessenger<AllowedActions, AllowedEvents>;
};

Expand All @@ -1960,15 +1953,15 @@ async function withController<ReturnValue>(
...args: WithControllerArgs<ReturnValue>
): Promise<ReturnValue> {
const [{ ...rest }, fn] = args.length === 2 ? args : [{}, args[0]];
const { options, messenger } = rest;
const { options, isKeyringUnlocked, messenger } = rest;
const controllerMessenger =
messenger ?? new ControllerMessenger<AllowedActions, AllowedEvents>();

const mockKeyringState = jest.fn<KeyringControllerState, []>();
controllerMessenger.registerActionHandler(
'KeyringController:getState',
mockKeyringState.mockReturnValue({
isUnlocked: options?.isKeyringUnlocked ?? true,
isUnlocked: isKeyringUnlocked ?? true,
} as KeyringControllerState),
);
const mockGetNetworkConfigurationByNetworkClientId = jest.fn<
Expand Down

0 comments on commit 95b34ac

Please sign in to comment.