-
Notifications
You must be signed in to change notification settings - Fork 10
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
- Loading branch information
1 parent
9d95160
commit 4d8476b
Showing
25 changed files
with
1,151 additions
and
108 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
const Config = require('@vechain/repo-config'); | ||
|
||
module.exports = Config.EslintLibrary; | ||
module.exports = { | ||
...Config.EslintLibrary, | ||
ignorePatterns: ['**/test/**', 'vite.config.ts'], | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
const Config = require('@vechain/repo-config'); | ||
|
||
module.exports = Config.EslintLibrary; | ||
module.exports = { | ||
...Config.EslintLibrary, | ||
ignorePatterns: ['test/**', 'vite.config.ts'], | ||
}; |
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.