BaseOperationTest.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { web3 } from "hardhat"
  2. import { ethers } from "hardhat"
  3. import deployer from '../.secret'
  4. import contracts from '../config/contracts'
  5. import fee from '../config/fee'
  6. describe('Base operation test', () => {
  7. it('Parse ether test', async () => {
  8. console.log(web3.utils.toWei('1', 'gwei'))
  9. })
  10. it('Get block number test', async () => {
  11. console.log(await web3.eth.getBlockNumber())
  12. })
  13. it('Get balance test', async () => {
  14. console.log(await web3.eth.getBalance(deployer.address))
  15. })
  16. it('Transfer test', async () => {
  17. let rawTx = {
  18. from: deployer.address,
  19. nonce: await web3.eth.getTransactionCount(deployer.address),
  20. gasPrice: web3.utils.toWei('2', 'gwei'),
  21. gasLimit: 1_000_000,
  22. to: contracts.ZERO,
  23. value: 1e9
  24. }
  25. await web3.eth.sendTransaction(rawTx).then(console.log)
  26. })
  27. it('Weth withdraw test', async () => {
  28. const WETH_ABI = require('../abi/WETH_ABI.json')
  29. const WETH_ADDR = contracts.WETH
  30. let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
  31. // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
  32. let rawTx = {
  33. from: deployer.address,
  34. nonce: await web3.eth.getTransactionCount(deployer.address),
  35. gasPrice: web3.utils.toWei('2', 'gwei'),
  36. gasLimit: 1_000_000
  37. }
  38. await weth_contract.methods.withdraw(1e15).send(rawTx).then(console.log)
  39. })
  40. it ('Weth approve test', async () => {
  41. const WETH_ABI = require('../abi/WETH_ABI.json')
  42. const WETH_ADDR = contracts.WETH
  43. let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
  44. // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
  45. let rawTx = {
  46. from: deployer.address,
  47. nonce: await web3.eth.getTransactionCount(deployer.address),
  48. gasPrice: web3.utils.toWei('2', 'gwei'),
  49. gasLimit: 1_000_000
  50. }
  51. await weth_contract.methods.approve(contracts.UNIV3, 1e18.toString()).send(rawTx).then(console.log)
  52. })
  53. })