|
| 1 | +import { BigNumber, Signer, constants, utils } from "ethers"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { impersonateAccount, setBlockNumber } from "@utils/test/testingUtils"; |
| 4 | +import { WithdrawTokens__factory } from "../../../typechain"; |
| 5 | + |
| 6 | +if (process.env.INTEGRATIONTEST) { |
| 7 | + describe.only("WithdrawTokens", function () { |
| 8 | + const deployerAddress = "0x37e6365d4f6aE378467b0e24c9065Ce5f06D70bF"; |
| 9 | + let deployerSigner: Signer; |
| 10 | + |
| 11 | + setBlockNumber(236525000); |
| 12 | + before(async function () { |
| 13 | + deployerSigner = await impersonateAccount(deployerAddress); |
| 14 | + }); |
| 15 | + |
| 16 | + it("deploys to correct address", async function () { |
| 17 | + const nonce = 1556; |
| 18 | + const currentAccountNonce = await deployerSigner.getTransactionCount(); |
| 19 | + |
| 20 | + // Unfortunately we will have to spam a bunch of no-op transactions to get to the desired nonce |
| 21 | + // Costs should be negligible though 21000 gas per tx. (at 0.01 gwei gas price on arbitrum -> 210 gwei) |
| 22 | + for (let i = currentAccountNonce; i < nonce; i++) { |
| 23 | + await deployerSigner.sendTransaction({ |
| 24 | + to: deployerAddress, |
| 25 | + value: BigNumber.from(0), |
| 26 | + nonce: i, |
| 27 | + }); |
| 28 | + } |
| 29 | + const expectedAddress = "0x940ecb16416fe52856e8653b2958bfd556aa6a7e"; |
| 30 | + const factory = await new WithdrawTokens__factory(deployerSigner); |
| 31 | + const contract = await factory.deploy({ nonce }); |
| 32 | + await contract.deployed(); |
| 33 | + expect(contract.address.toLowerCase()).to.equal(expectedAddress); |
| 34 | + |
| 35 | + const contractEthBalance = await deployerSigner.provider.getBalance(contract.address); |
| 36 | + expect(contractEthBalance).to.gt(0); |
| 37 | + console.log(`Contract eth balance: ${utils.formatEther(contractEthBalance)}`); |
| 38 | + |
| 39 | + const deployerBalanceBefore = await deployerSigner.getBalance(); |
| 40 | + const tx = await contract.withdraw(constants.AddressZero, contractEthBalance); |
| 41 | + const receipt = await tx.wait(); |
| 42 | + const deployerBalanceAfter = await deployerSigner.getBalance(); |
| 43 | + const txCost = tx.gasPrice.mul(receipt.gasUsed); |
| 44 | + expect(deployerBalanceAfter).to.eq(deployerBalanceBefore.add(contractEthBalance).sub(txCost)); |
| 45 | + }); |
| 46 | + }); |
| 47 | +} |
0 commit comments