Skip to content

Commit

Permalink
test(account-validator): test fix to isSmartContract
Browse files Browse the repository at this point in the history
  • Loading branch information
envin3 committed Feb 25, 2024
1 parent 823016e commit 138373f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/utils/__tests__/account-validator.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { validators } from 'ptokens-helpers'
import { test, describe, expect, vi } from 'vitest'

import { isValidAccountByBlockchain } from '../account-validator'
import { isValidAccountByBlockchain, isSmartContract } from '../account-validator'

const mockGetCode = vi.fn()
const mockWeb3Instance = {
eth: {
getCode: mockGetCode,
},
}

const getCodeMock = (expectedCode) => vi.fn().mockResolvedValue(expectedCode)

describe('isValidAccountByBlockchain', () => {
beforeAll(() => {
Expand All @@ -18,6 +27,22 @@ describe('isValidAccountByBlockchain', () => {
vi.resetAllMocks()
})

test('Should return true if address is a smart contract', async () => {
const expectedCode = '0x1234'
mockGetCode.mockResolvedValue(expectedCode)

const passed = await isSmartContract('0xb794f5ea0ba39494ce839613fffba74279579268', mockWeb3Instance)
expect(passed).toBeTruthy()
})

test('Should return false if address is a not smart contract', async () => {
const expectedCode = '0x'
mockGetCode.mockResolvedValue(expectedCode)

const passed = await isSmartContract('0xb794f5ea0ba39494ce839613fffba74279579268', mockWeb3Instance)
expect(passed).toBeFalsy()
})

test.each`
account | blockchain | expectedChainId | expectedAccount
${`account`} | ${'ETH'} | ${'0x005fe7f9'} | ${'0xaccount'}
Expand Down

0 comments on commit 138373f

Please sign in to comment.