BaseOperationTest.ts 1.9 KB

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