Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): 17% coverage for PhantomManager #4447

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions libraries/Phantom/PhantonManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { web3 } from '@project-serum/anchor'
import PhantomManager from '~/libraries/Phantom/PhantomManager'
import { AccountsError } from '~/store/accounts/types'

describe('Test PhantomManager after Solana mock', () => {
it('should throws on mnemonic not present', async () => {
try {
const result = new PhantomManager()
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
AccountsError.MNEMONIC_NOT_PRESENT,
)
}
})
})

describe('Test PhantomManager after Solana mock', () => {
beforeAll(() => {
Object.defineProperty(window, 'solana', {
stavares843 marked this conversation as resolved.
Show resolved Hide resolved
configurable: true,
value: true,
})
})

afterAll(() => {
Object.defineProperty(window, 'solana', {
configurable: true,
value: {},
})
})

it('should fail to initialize wallet', async () => {
// Reason for failing: value should have (isPhantom: true) rather than just true in window.solana
try {
const result = new PhantomManager()
result.initWallet()
expect(result).toBe(123)
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
AccountsError.MNEMONIC_NOT_PRESENT,
)
}
})

it('should fail to initialize wallet', async () => {
// Reason for failing: related to non-existence of isPhantom on window.solana
try {
const constructor = new PhantomManager()
const keypair = web3.Keypair.generate()
const result = constructor.getAccountBalance(keypair.publicKey)
expect(result).toBe(123)
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
AccountsError.MNEMONIC_NOT_PRESENT,
)
}
})
})