-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding tests for core dapp-kit (#81)
* chore: adding tests for core dapp-kit * chore: revert eslint config * chore: revert eslint config * chore: update GH actions
- Loading branch information
1 parent
f329e51
commit d41f892
Showing
24 changed files
with
1,146 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,8 @@ jobs: | |
- name: Lint | ||
run: yarn run lint | ||
|
||
- name: Test | ||
run: yarn run test | ||
|
||
- name: Build | ||
run: yarn run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import type { Connex1 } from '@vechain/connex/esm/signer'; | ||
import { createWallet } from '../src/create-wallet'; | ||
import type { ConnexOptions, WalletConnectOptions, WalletSource } from '../src'; | ||
|
||
type ICreateWallet = ConnexOptions & { | ||
source: WalletSource; | ||
onDisconnected: () => void; | ||
}; | ||
const createOptions = ( | ||
source: WalletSource, | ||
wcOptions?: WalletConnectOptions, | ||
): ICreateWallet => { | ||
return { | ||
nodeUrl: 'https://testnet.veblocks.net/', | ||
source, | ||
walletConnectOptions: wcOptions, | ||
genesis: 'main', | ||
customWcModal: undefined, | ||
onDisconnected: () => {}, | ||
}; | ||
}; | ||
|
||
vi.mock('@walletconnect/modal'); | ||
|
||
describe('createWallet', () => { | ||
describe('sync', () => { | ||
it('is NOT in sync browser', () => { | ||
window.connex = undefined; | ||
|
||
expect(() => { | ||
createWallet(createOptions('sync')); | ||
}).toThrowError('User is not in a Sync wallet'); | ||
}); | ||
|
||
it('is in sync2 browser', () => { | ||
window.connex = {} as Connex1; | ||
|
||
const wallet = createWallet(createOptions('sync2')); | ||
|
||
expect(wallet).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('veworld-extension', () => { | ||
it('is not installed', () => { | ||
window.vechain = undefined; | ||
|
||
expect(() => { | ||
createWallet(createOptions('veworld-extension')); | ||
}).toThrowError('VeWorld Extension is not installed'); | ||
}); | ||
|
||
it('is installed', () => { | ||
window.vechain = { | ||
newConnexSigner: () => ({} as Connex.Signer), | ||
}; | ||
|
||
const wallet = createWallet(createOptions('veworld-extension')); | ||
|
||
expect(wallet).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('wallet-connect', () => { | ||
it('no options provided', () => { | ||
expect(() => { | ||
createWallet(createOptions('wallet-connect')); | ||
}).toThrowError('WalletConnect options are not provided'); | ||
}); | ||
|
||
it('options provided', () => { | ||
const wallet = createWallet( | ||
createOptions('wallet-connect', { | ||
projectId: '123', | ||
metadata: { | ||
name: 'test', | ||
description: 'test', | ||
url: 'test', | ||
icons: ['test'], | ||
}, | ||
}), | ||
); | ||
|
||
expect(wallet).toBeDefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { genesisBlocks } from '@vechain/connex/esm/config'; | ||
import { normalizeGenesisBlock, normalizeGenesisId } from '../src/genesis'; | ||
|
||
const customBlock = { | ||
number: 0, | ||
id: '0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6', | ||
size: 170, | ||
parentID: | ||
'0xffffffff00000000000000000000000000000000000000000000000000000000', | ||
timestamp: 1526400000, | ||
gasLimit: 10000000, | ||
beneficiary: '0x0000000000000000000000000000000000000000', | ||
gasUsed: 0, | ||
totalScore: 0, | ||
txsRoot: | ||
'0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', | ||
txsFeatures: 0, | ||
stateRoot: | ||
'0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550', | ||
receiptsRoot: | ||
'0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', | ||
signer: '0x0000000000000000000000000000000000000000', | ||
isTrunk: true, | ||
transactions: [], | ||
}; | ||
|
||
describe('genesis', () => { | ||
describe('normalizeGenesisId', () => { | ||
it('normalizes `main`', () => { | ||
expect(normalizeGenesisId('main')).toBe(genesisBlocks.main.id); | ||
}); | ||
|
||
it('normalizes `test`', () => { | ||
expect(normalizeGenesisId('test')).toBe(genesisBlocks.test.id); | ||
}); | ||
|
||
it('normalizes a block', () => { | ||
expect(normalizeGenesisId(customBlock)).toBe(customBlock.id); | ||
}); | ||
}); | ||
|
||
describe('normalizeGenesisBlock', () => { | ||
it('normalizes `main`', () => { | ||
expect(normalizeGenesisBlock('main')).toBe(genesisBlocks.main); | ||
}); | ||
|
||
it('normalizes `test`', () => { | ||
expect(normalizeGenesisBlock('test')).toBe(genesisBlocks.test); | ||
}); | ||
|
||
it('normalizes a block', () => { | ||
expect(normalizeGenesisBlock(customBlock)).toBe(customBlock); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { vi } from 'vitest'; | ||
import type { WalletConnectOptions } from '../../src'; | ||
import { MultiWalletConnex } from '../../src'; | ||
|
||
export const createUnitTestConnex = ( | ||
walletConnectOptions?: WalletConnectOptions, | ||
): MultiWalletConnex => { | ||
return new MultiWalletConnex({ | ||
nodeUrl: 'https://mainnet.vechain.org/', | ||
walletConnectOptions, | ||
customWcModal: { | ||
openModal: vi.fn(), | ||
closeModal: vi.fn(), | ||
subscribeModal: () => { | ||
return vi.fn(); | ||
}, | ||
}, | ||
}); | ||
}; |
Oops, something went wrong.