Skip to content

Commit

Permalink
test engine logs
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Dec 21, 2024
1 parent d45b4bb commit 1dd82bd
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions app/core/Engine/utils/test/logger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import Logger from '../../../../util/Logger';
import { logEngineCreation } from '../logger';

jest.mock('../../../../util/Logger');

describe('logEngineCreation', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('logs empty state initialization', () => {
logEngineCreation({}, null);

expect(Logger.log).toHaveBeenCalledWith(
'Engine initialized with empty state',
{
keyringStateFromBackup: false,
},
);
});

it('logs empty state initialization with keyring backup', () => {
logEngineCreation(
{},
{ vault: 'test-vault', keyrings: [], isUnlocked: false },
);

expect(Logger.log).toHaveBeenCalledWith(
'Engine initialized with empty state',
{
keyringStateFromBackup: true,
},
);
});

it('logs non-empty state initialization with accounts', () => {
const initialState = {
AccountsController: {
internalAccounts: {
accounts: {},
selectedAccount: '',
},
},
};

logEngineCreation(initialState, null);

expect(Logger.log).toHaveBeenCalledWith(
'Engine initialized with non-empty state',
{
hasAccountsState: true,
hasKeyringState: false,
keyringStateFromBackup: false,
},
);
});

it('logs non-empty state initialization with keyring state', () => {
const initialState = {
KeyringController: {
vault: 'test-vault',
keyrings: [],
isUnlocked: false,
},
};

logEngineCreation(initialState, null);

expect(Logger.log).toHaveBeenCalledWith(
'Engine initialized with non-empty state',
{
hasAccountsState: false,
hasKeyringState: true,
keyringStateFromBackup: false,
},
);
});

it('logs non-empty state initialization with both accounts and keyring', () => {
const initialState = {
AccountsController: {
internalAccounts: {
accounts: {},
selectedAccount: '',
},
},
KeyringController: {
vault: 'test-vault',
keyrings: [],
isUnlocked: false,
},
};

const keyringBackup = {
vault: 'backup-vault',
keyrings: [],
isUnlocked: false,
};

logEngineCreation(initialState, keyringBackup);

expect(Logger.log).toHaveBeenCalledWith(
'Engine initialized with non-empty state',
{
hasAccountsState: true,
hasKeyringState: true,
keyringStateFromBackup: true,
},
);
});
});

0 comments on commit 1dd82bd

Please sign in to comment.