BaseOperationTest.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { web3 } from "hardhat";
  2. import deployer from '../.secret'
  3. describe('Base operation test', () => {
  4. it('Parse ether test', async () => {
  5. console.log(web3.utils.toWei('1', 'gwei'))
  6. })
  7. it('Get block number test', async () => {
  8. console.log(await web3.eth.getBlockNumber())
  9. })
  10. it('Get balance test', async () => {
  11. console.log(await web3.eth.getBalance(deployer.address))
  12. })
  13. it('Transfer test', async () => {
  14. let rawTx = {
  15. from: deployer.address,
  16. nonce: await web3.eth.getTransactionCount(deployer.address),
  17. gasPrice: web3.utils.toWei('2', 'gwei'),
  18. gasLimit: 1_000_000,
  19. to: '0x0000000000000000000000000000000000000000',
  20. value: 1e9
  21. }
  22. await web3.eth.sendTransaction(rawTx).then(console.log)
  23. })
  24. it('Weth test', async () => {
  25. const WETH_ABI = require('../abi/WETH_ABI').default
  26. const WETH_ADDR = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
  27. let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
  28. // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
  29. let rawTx = {
  30. from: deployer.address,
  31. nonce: await web3.eth.getTransactionCount(deployer.address),
  32. gasPrice: web3.utils.toWei('2', 'gwei'),
  33. gasLimit: 1_000_000
  34. }
  35. await weth_contract.methods.withdraw(1e15).send(rawTx).then(console.log)
  36. })
  37. })