|
| 1 | +import { |
| 2 | + ContractReceipt, |
| 3 | + ContractTransaction, |
| 4 | +} from "@ethersproject/contracts/src.ts/index"; |
| 5 | +import { Network } from "@ethersproject/networks"; |
| 6 | +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; |
| 7 | +import { expect } from "chai"; |
| 8 | +import { BigNumber } from "ethers"; |
| 9 | +import { ethers } from "hardhat"; |
| 10 | +import { IguToken, IguWallet, Iguverse } from "../typechain-types"; |
| 11 | +import { deployContract, txExec } from "./helpers/utils"; |
| 12 | + |
| 13 | +describe("Iguverse", function () { |
| 14 | + let owner: SignerWithAddress; |
| 15 | + let signer: SignerWithAddress; |
| 16 | + let bob: SignerWithAddress; |
| 17 | + let alice: SignerWithAddress; |
| 18 | + |
| 19 | + let iguToken: IguToken; |
| 20 | + let iguWallet: IguWallet; |
| 21 | + |
| 22 | + let network: Network; |
| 23 | + |
| 24 | + beforeEach(async () => { |
| 25 | + [owner, signer, bob, alice] = await ethers.getSigners(); |
| 26 | + network = await ethers.provider.getNetwork(); |
| 27 | + |
| 28 | + iguToken = await deployContract("IguToken"); |
| 29 | + iguWallet = await deployContract( |
| 30 | + "IguWallet", |
| 31 | + iguToken.address, |
| 32 | + owner.address, |
| 33 | + owner.address |
| 34 | + ); |
| 35 | + |
| 36 | + await iguToken |
| 37 | + .connect(owner) |
| 38 | + .approve(iguWallet.address, ethers.utils.parseEther("100")); |
| 39 | + |
| 40 | + await iguWallet.deposit(ethers.utils.parseEther("100")); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("Signatures", () => { |
| 44 | + let tx: ContractTransaction; |
| 45 | + let recipt: ContractReceipt; |
| 46 | + let balanceBefore: BigNumber; |
| 47 | + |
| 48 | + beforeEach(async () => { |
| 49 | + const domainData = { |
| 50 | + name: "Iguverse", |
| 51 | + version: "1", |
| 52 | + chainId: network.chainId, |
| 53 | + verifyingContract: iguWallet.address, |
| 54 | + }; |
| 55 | + |
| 56 | + const types = { |
| 57 | + WithdrawData: [ |
| 58 | + { name: "walletAddress", type: "address" }, |
| 59 | + { name: "amount", type: "uint256" }, |
| 60 | + { name: "fee", type: "uint256" }, |
| 61 | + { name: "nonce", type: "uint256" }, |
| 62 | + { name: "deadline", type: "uint256" }, |
| 63 | + ], |
| 64 | + }; |
| 65 | + |
| 66 | + const value = { |
| 67 | + walletAddress: owner.address, |
| 68 | + amount: ethers.utils.parseEther("50"), |
| 69 | + fee: ethers.utils.parseEther("10"), |
| 70 | + nonce: "123", |
| 71 | + deadline: "1000000000000" |
| 72 | + }; |
| 73 | + |
| 74 | + balanceBefore = await ethers.provider.getBalance(alice.address); |
| 75 | + |
| 76 | + const signature = await owner._signTypedData(domainData, types, value); |
| 77 | + |
| 78 | + [tx, recipt] = await txExec( |
| 79 | + iguWallet.connect(owner) |
| 80 | + .withdraw( |
| 81 | + value.walletAddress, |
| 82 | + value.amount, |
| 83 | + value.fee, |
| 84 | + value.nonce, |
| 85 | + value.deadline, |
| 86 | + signature |
| 87 | + ) |
| 88 | + ); |
| 89 | + }); |
| 90 | + |
| 91 | + it("Should emit IguToken Transfer event", async () => { |
| 92 | + await expect(tx) |
| 93 | + .to.emit(iguToken, "Transfer") |
| 94 | + .withArgs(iguWallet.address, owner.address, ethers.utils.parseEther("50")); |
| 95 | + await expect(tx) |
| 96 | + .to.emit(iguToken, "Transfer") |
| 97 | + .withArgs(iguWallet.address, owner.address, ethers.utils.parseEther("10")); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments