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

Adds hardhat for SDK tests #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-cache-2",
"files": {}
}
20 changes: 20 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// import "hardhat-jest-plugin";
// require("hardhat-jest-plugin");
// import { task } from "hardhat/config";
import '@nomiclabs/hardhat-waffle';
// require("@nomiclabs/hardhat-waffle");

/**
* @type import('hardhat/config').HardhatUserConfig
*/

module.exports = {
solidity: '0.7.3',
networks: {
hardhat: {
forking: {
url: 'https://eth-ropsten.alchemyapi.io/v2/is1WqyAFM1nNFFx2aCozhTep7IxHVNGo',
},
},
},
};
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"analyze": "size-limit --why",
"prettier": "prettier --write \"**/*.{ts,tsx,js,json,css,yml,md}\"",
"generate-types": "typechain --out-dir 'src/contracts' --target=ethers-v5 'src/abis/**/*.json'",
"typecheck": "tsc --pretty --noEmit"
"typecheck": "tsc --pretty --noEmit",
"test:unit": "hardhat test test/**/*.unit.ts --tsconfig tsconfig-hardhat.json "
},
"peerDependencies": {},
"husky": {
Expand Down Expand Up @@ -48,13 +49,22 @@
}
],
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@size-limit/preset-small-lib": "7.0.5",
"@typechain/ethers-v5": "^9.0.0",
"@types/chai": "^4.3.0",
"@types/lodash": "^4.14.178",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.15",
"@types/uuid": "^8.3.4",
"chai": "^4.3.6",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.8.3",
"husky": "^7.0.2",
"prettier": "^2.5.1",
"size-limit": "7.0.5",
"ts-node": "^10.4.0",
"tsdx": "^0.14.1",
"tslib": "^2.3.1",
"typechain": "^7.0.0",
Expand All @@ -71,6 +81,7 @@
"date-fns": "^2.28.0",
"ethers": "^5.5.4",
"from-exponential": "^1.1.1",
"hardhat-jest-plugin": "^0.0.6",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"tiny-invariant": "^1.2.0",
Expand Down
18 changes: 18 additions & 0 deletions test/truffle/example.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ethers } from 'hardhat';
import { Signer } from 'ethers';
import { expect } from 'chai';
describe('Token', function () {
let accounts: Signer[];

beforeEach(async function () {
accounts = await ethers.getSigners();
});

it('should do something right', async function () {
// Do something with the accounts
const addy = await accounts[0].getAddress();
expect(addy.toLowerCase()).equal(
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'.toLowerCase()
);
});
});
18 changes: 7 additions & 11 deletions test/v4/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ const nftSwapperMaker = new NftSwapV4(
// const nftSwapperTaker = new NftSwap(TAKER_PROVIDER as any, 4);

const MAKER_ASSET: SwappableAsset = {
type: 'ERC20',
tokenAddress: DAI_TOKEN_ADDRESS_TESTNET,
amount: '420000000000000', // 1 USDC
};

const TAKER_ASSET: SwappableAsset = {
type: 'ERC721',
tokenAddress: TEST_NFT_CONTRACT_ADDRESS,
tokenId: '11045',
};

const TAKER_ASSET: SwappableAsset = {
type: 'ERC20',
tokenAddress: DAI_TOKEN_ADDRESS_TESTNET,
amount: '420000000000000', // 1 USDC
};

describe('NFTSwapV4', () => {
it.only('fees', async () => {
// NOTE(johnrjj) - Assumes USDC and DAI are already approved w/ the ExchangeProxy
const v4Erc721Order = nftSwapperMaker.buildOrder(
TAKER_ASSET,
MAKER_ASSET,
TAKER_ASSET,
MAKER_WALLET_ADDRESS,
{
fees: [
Expand All @@ -63,10 +63,6 @@ describe('NFTSwapV4', () => {
},
],
}
// {
// // Fix dates and salt so we have reproducible tests
// expiration: new Date(3000, 10, 1),
// }
);

// console.log('v4Erc721Order.nonce', v4Erc721Order.nonce.toString());
Expand Down
38 changes: 38 additions & 0 deletions tsconfig-hardhat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["src", "types"],
"files": ["hardhat.config.ts"],
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "esnext"],
"importHelpers": true,
// output .d.ts declaration files for consumers
"declaration": true,
// output .js.map sourcemap files for consumers
"sourceMap": true,
// match output dir to input dir. e.g. dist/index instead of dist/src/index
"rootDir": "./src",
// stricter type-checking for stronger correctness. Recommended by TS
"strict": true,
// linter checks for common issues
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
// noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
"noUnusedLocals": false,
"noUnusedParameters": false,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
// transpile JSX to React.createElement
"jsx": "react",
// interop between ESM and CJS modules. Recommended by TS
"esModuleInterop": true,
// significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
// Enabled for addresses.json
"resolveJsonModule": true
}
}
Loading