From 86741c7afdff7c48165c81faa4fc8e21330cd4c8 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Fri, 12 May 2023 05:55:37 -0400 Subject: [PATCH] update test script --- test/mainnet/spark/spark.test.ts | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/mainnet/spark/spark.test.ts b/test/mainnet/spark/spark.test.ts index 9511219e..908cf18b 100644 --- a/test/mainnet/spark/spark.test.ts +++ b/test/mainnet/spark/spark.test.ts @@ -22,6 +22,18 @@ describe("Sparklend", function () { let dsaWallet0: any; let instaConnectorsV2: Contract; let masterSigner: Signer; + const account = "0x72a53cdbbcc1b9efa39c834a540550e23463aacb"; + let signer: any; + + const ABI = [ + "function balanceOf(address account) public view returns (uint256)", + "function approve(address spender, uint256 amount) external returns(bool)", + "function transfer(address recipient, uint256 amount) external returns (bool)" + ]; + + const wethContract = new ethers.Contract(tokens.weth.address, ABI); + const daiContract = new ethers.Contract(tokens.dai.address, ABI); + before(async () => { await hre.network.provider.request({ method: "hardhat_reset", @@ -48,6 +60,12 @@ describe("Sparklend", function () { connectors: instaConnectorsV2, }); console.log("Connector address", connector.address); + + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [account] + }); + signer = await ethers.getSigner(account); }); it("should have contracts deployed", async () => { @@ -222,5 +240,62 @@ describe("Sparklend", function () { ethers.utils.parseEther("10") ); }); + + it("should deposit without collateral and withdraw", async () => { + const amt = parseEther("1"); // 1 eth + const setId = "834782373"; + const spells = [ + { + connector: connectorName, + method: "depositWithoutCollateral", + args: [tokens.eth.address, amt, 0, setId], + }, + { + connector: connectorName, + method: "withdraw", + args: [tokens.eth.address, amt, setId, 0], + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.getAddress()); + await tx.wait(); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + ethers.utils.parseEther("10") + ); + }); + + // it("should deposit ETH in Sparklend", async function () { + // const amt = parseEther("1"); + // const spells = [ + // { + // connector: connectorName, + // method: "deposit", + // args: [tokens.eth.address, amt, 0, 0], + // }, + // { + // connector: connectorName, + // method: "borrow", + // args: [tokens.dai.address, amt.mul(300), 2, 0, 0], + // }, + // { + // connector: connectorName, + // method: "paybackWithATokens", + // args: [tokens.dai.address, amt.mul(300), 2, 0, 0], + // }, + // ]; + + // const tx = await dsaWallet0 + // .connect(wallet0) + // .cast(...encodeSpells(spells), wallet1.getAddress()); + + // await tx.wait(); + + // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq( + // parseEther("9") + // ); + // }); + }); });