Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
#116 fixed test for useBalance #117 modified wrapper for ContractContext
Browse files Browse the repository at this point in the history
- removed old json way sof doing things, will be adding local contracts for testing
- updating hardhat mocks
  • Loading branch information
ShravanSunder committed Jan 7, 2022
1 parent 23cae02 commit 0bbb407
Show file tree
Hide file tree
Showing 21 changed files with 304 additions and 686 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
"**/build/**/*": true,
"**/debug/": true,
"**/dist/": true,
"**/node_modules/": true,
"**/obj": true,
"node_modules": true,
"node_modules/*/**": true,
"lib": true
},
"explorerExclude.backup": null,
Expand Down
14 changes: 14 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'tsconfig-paths/register';
import 'global-jsdom/register';

import '@typechain/hardhat';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-ethers';
import 'hardhat-deploy';
import { HardhatUserConfig } from 'hardhat/types';

/**
* this is used for hook tests
*/
const config: HardhatUserConfig = {
solidity: '0.8.6',
defaultNetwork: 'hardhat',
Expand All @@ -27,6 +31,16 @@ const config: HardhatUserConfig = {
toConsole: true,
},
},
paths: {
cache: './test-files/__mocks__/generated/cache',
artifacts: './test-files/__mocks__/generated/artifacts',
deployments: './test-files/__mocks__/generated/deployments',
sources: './test-files/__mocks__/contracts',
deploy: '_./test-files/__mocks_/deploy',
},
typechain: {
outDir: './test-files/__mocks__/generated/contract-types',
},
};

module.exports = config;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "^13.5.0",
"@typechain/ethers-v5": "^8.0.5",
"@typechain/hardhat": "^3.1.0",
"@types/chai": "^4.3.0",
"@types/lodash.isequal": "^4.5.5",
"@types/mocha": "^9.0.0",
Expand Down Expand Up @@ -135,6 +137,7 @@
"ts-patch": "^1.4.5",
"ts-sinon": "^2.0.2",
"tsconfig-paths": "^3.12.0",
"typechain": "^6.1.0",
"typedoc": "^0.22.10",
"typedoc-plugin-markdown": "^3.11.8",
"typescript": "^4.5.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { FC, useEffect } from 'react';
import React, { createElement, FC, useEffect } from 'react';

import { EthersAppContext, useEthersContext } from '~~/context';
import { TCreateEthersModalConnector } from '~~/models/ethersAppContextTypes';

interface IMockProps {
createMockConnector: TCreateEthersModalConnector;
contractContext?: FC;
}

const TestConnectorWrapper: FC<IMockProps> = (props) => {
Expand All @@ -28,10 +29,23 @@ const TestConnectorWrapper: FC<IMockProps> = (props) => {
return <>{props.children}</>;
};

export const MockAppWrapper: FC<IMockProps> = (props) => {
return (
/**
* This is a wrapper for tests
* @param props
* @returns
*/
export const TestAppWrapper: FC<IMockProps> = (props) => {
const element = (
<EthersAppContext>
<TestConnectorWrapper {...props}>{props.children}</TestConnectorWrapper>
<TestConnectorWrapper createMockConnector={props.createMockConnector}>{props.children}</TestConnectorWrapper>
</EthersAppContext>
);

// wrap in contract context if provided
if (props.contractContext != null) {
const wrappedElement = createElement(props.contractContext, {}, element);
return wrappedElement;
}

return element;
};
4 changes: 2 additions & 2 deletions src/helpers/test-utils/wrapper/hookTestWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { FC } from 'react';
import { waitForActivation, isActive } from './wrapperHelpers';

import { getMockProvider } from '~~/helpers/test-utils/wrapper/getMockProvider';
import { MockAppWrapper } from '~~/helpers/test-utils/wrapper/MockAppWrapper';
import { MockConnector } from '~~/helpers/test-utils/wrapper/MockConnector';
import { TestAppWrapper } from '~~/helpers/test-utils/wrapper/TestAppWrapper';
import { TCreateEthersModalConnector } from '~~/models/ethersAppContextTypes';

export type TTestHookResult<PropsT, TResult> = RenderHookResult<PropsT, TResult, Renderer<PropsT>> & {
Expand All @@ -30,7 +30,7 @@ export const hookTestWrapper = async <PropsT, ResultT>(
};

const wrapper: FC = (props) => (
<MockAppWrapper createMockConnector={createMockConnector}>{props.children}</MockAppWrapper>
<TestAppWrapper createMockConnector={createMockConnector}>{props.children}</TestAppWrapper>
);

const result = renderHook(callbackToHook, { wrapper: wrapper });
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/test-utils/wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './MockAppWrapper';
export * from './TestAppWrapper';
export * from './MockConnector';
export * from './getMockProvider';
export * from './hardhatTestHelpers';
Expand Down
5 changes: 0 additions & 5 deletions test-files/__mocks__/contracts/.gitignore

This file was deleted.

124 changes: 0 additions & 124 deletions test-files/__mocks__/contracts/Greeter.d.ts

This file was deleted.

139 changes: 0 additions & 139 deletions test-files/__mocks__/contracts/YourContract.d.ts

This file was deleted.

Loading

0 comments on commit 0bbb407

Please sign in to comment.