BaseOperationTest.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { web3 } from "hardhat";
  2. import deployer from '../.secret'
  3. import contracts from '../contracts'
  4. import {default as WETH_ABI} from "../abi/WETH_ABI";
  5. describe('Base operation test', () => {
  6. it('Parse ether test', async () => {
  7. console.log(web3.utils.toWei('1', 'gwei'))
  8. })
  9. it('Get block number test', async () => {
  10. console.log(await web3.eth.getBlockNumber())
  11. })
  12. it('Get balance test', async () => {
  13. console.log(await web3.eth.getBalance(deployer.address))
  14. })
  15. it('Transfer test', async () => {
  16. let rawTx = {
  17. from: deployer.address,
  18. nonce: await web3.eth.getTransactionCount(deployer.address),
  19. gasPrice: web3.utils.toWei('2', 'gwei'),
  20. gasLimit: 1_000_000,
  21. to: contracts.ZERO,
  22. value: 1e9
  23. }
  24. await web3.eth.sendTransaction(rawTx).then(console.log)
  25. })
  26. it('Weth withdraw test', async () => {
  27. const WETH_ABI = require('../abi/WETH_ABI').default
  28. const WETH_ADDR = contracts.WETH
  29. let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
  30. // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
  31. let rawTx = {
  32. from: deployer.address,
  33. nonce: await web3.eth.getTransactionCount(deployer.address),
  34. gasPrice: web3.utils.toWei('2', 'gwei'),
  35. gasLimit: 1_000_000
  36. }
  37. await weth_contract.methods.withdraw(1e15).send(rawTx).then(console.log)
  38. })
  39. it ('Weth approve test', async () => {
  40. const WETH_ABI = require('../abi/WETH_ABI').default
  41. const WETH_ADDR = contracts.WETH
  42. let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
  43. // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
  44. let rawTx = {
  45. from: deployer.address,
  46. nonce: await web3.eth.getTransactionCount(deployer.address),
  47. gasPrice: web3.utils.toWei('2', 'gwei'),
  48. gasLimit: 1_000_000
  49. }
  50. await weth_contract.methods.approve(contracts.UNIV3, 1e9).send(rawTx).then(console.log)
  51. })
  52. it('Univ3 swap test', async () => {
  53. const UNIV3_ABI = require('../abi/UNIV3_ABI').default
  54. let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
  55. let rawTx = {
  56. from: deployer.address,
  57. nonce: await web3.eth.getTransactionCount(deployer.address),
  58. gasPrice: web3.utils.toWei('2', 'gwei'),
  59. gasLimit: 1_000_000
  60. }
  61. let amountIn = 1_000_000
  62. let amountOutMin = 1
  63. let path = [contracts.WETH, contracts.HEX]
  64. let to = deployer.address
  65. await univ3_contract.methods
  66. .swapExactTokensForTokens(amountIn, amountOutMin, path, to)
  67. .send(rawTx).then(console.log)
  68. })
  69. })