BaseOperationTest.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { web3 } from "hardhat"
  2. import deployer from '../.secret'
  3. import contracts from '../config/contracts'
  4. import logger from "../utils/logger";
  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.json')
  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.json')
  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, 1e18.toString()).send(rawTx).then(console.log)
  51. })
  52. it ('IERC20 name test', async () => {
  53. const IERC20_ABI = require('../abi/IERC20_ABI.json')
  54. const IERC20_ADDRESS = web3.utils.toChecksumAddress('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48')
  55. let ierc20_contract = new web3.eth.Contract(IERC20_ABI, IERC20_ADDRESS)
  56. logger.debug(await ierc20_contract.methods.name().call())
  57. logger.debug(await ierc20_contract.methods.symbol().call())
  58. })
  59. })