From b8e0c1826ac1a124c1c428d52722e365b2a6cec1 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Mon, 20 Jun 2022 12:11:56 +0530 Subject: [PATCH] updated tests --- test/arbitrum/dsa-spell/dsa-spell.test.ts | 67 ++++++++----- test/avalanche/dsa-spell/dsa-spell.test.ts | 99 +++++++++---------- test/fantom/dsa-spell/dsa-spell.test.ts | 67 ++++++++----- test/mainnet/dsa-spell/dsa-spell.test.ts | 57 ++++++----- test/optimism/dsa-spell/dsa-spell.test.ts | 67 ++++++++----- test/polygon/dsa-spell/dsa-spell.test.ts | 110 ++++++++++----------- 6 files changed, 266 insertions(+), 201 deletions(-) diff --git a/test/arbitrum/dsa-spell/dsa-spell.test.ts b/test/arbitrum/dsa-spell/dsa-spell.test.ts index 98346369..399e17a3 100644 --- a/test/arbitrum/dsa-spell/dsa-spell.test.ts +++ b/test/arbitrum/dsa-spell/dsa-spell.test.ts @@ -85,28 +85,37 @@ describe("DSA Spell", function () { describe("Main", function () { let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); var abi = [ "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" ]; function getCallData(spell: string, params: any) { var iface = new ethers.utils.Interface(abi); let data = iface.encodeFunctionData(spell, params); - return data; + return ethers.utils.hexlify(data); } it("should cast spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["withdraw", "deposit", "borrow"]; + let params = [ + [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + [ETH, ethers.constants.MaxUint256, 0, 0], + [USDC, ethers.utils.parseUnits("1", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -116,29 +125,36 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); + it("should check balances after cast on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("0")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.gte(ethers.utils.parseUnits("1", 6)); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic, dataWithdraw]; - - let connectors = ["BASIC-A", "BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["deposit", "withdraw", "deposit", "borrow"]; + let params = [ + [ETH, ethers.utils.parseEther("1"), 0, 0], + [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0], + [ETH, ethers.utils.parseEther("10"), 0, 0], + [USDC, ethers.utils.parseUnits("3", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; @@ -146,9 +162,12 @@ describe("DSA Spell", function () { .connect(wallet0) .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("1")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("3", 6)); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("2")); }); }); }); diff --git a/test/avalanche/dsa-spell/dsa-spell.test.ts b/test/avalanche/dsa-spell/dsa-spell.test.ts index aa1668fd..48d45fdd 100644 --- a/test/avalanche/dsa-spell/dsa-spell.test.ts +++ b/test/avalanche/dsa-spell/dsa-spell.test.ts @@ -90,33 +90,37 @@ describe("DSA Spell", function () { describe("Main", function () { let AVAX = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); + var abi = [ + "function withdraw(address,uint256,address,uint256,uint256)", + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" + ]; + function getCallData(spell: string, params: any) { + var iface = new ethers.utils.Interface(abi); + let data = iface.encodeFunctionData(spell, params); + return ethers.utils.hexlify(data); + } + it("should cast spells", async function () { - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [walletB.address] - }); - - walletBsigner = await ethers.getSigner(walletB.address); - async function getArg() { - var abi = [ - "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" - ]; - function getCallData(connector: string, spell: string, params: any) { - var iface = new ethers.utils.Interface(abi); - let data = iface.encodeFunctionData(spell, params); - return data; + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); } - let basicParams = [AVAX, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("BASIC-A", "withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["withdraw", "deposit", "borrow"]; + let params = [ + [AVAX, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + [AVAX, ethers.constants.MaxUint256, 0, 0], + [USDC, ethers.utils.parseUnits("1", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -126,44 +130,36 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); + it("should check balances after cast on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("0")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.gte(ethers.utils.parseUnits("1", 6)); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [walletB.address] - }); - - walletBsigner = await ethers.getSigner(walletB.address); - async function getArg() { - var abi = [ - "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" - ]; - function getCallData(spell: string, params: any) { - var iface = new ethers.utils.Interface(abi); - let data = iface.encodeFunctionData(spell, params); - return data; + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); } - let basicParams = [AVAX, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [AVAX, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic, dataWithdraw]; - - let connectors = ["BASIC-A", "BASIC-A"]; - return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["deposit", "withdraw", "deposit", "borrow"]; + let params = [ + [AVAX, ethers.utils.parseEther("1"), 0, 0], + [AVAX, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0], + [AVAX, ethers.utils.parseEther("10"), 0, 0], + [USDC, ethers.utils.parseUnits("3", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; @@ -171,9 +167,12 @@ describe("DSA Spell", function () { .connect(wallet0) .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("1")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("3", 6)); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("2")); }); }); }); diff --git a/test/fantom/dsa-spell/dsa-spell.test.ts b/test/fantom/dsa-spell/dsa-spell.test.ts index 6dc2850d..e58c3367 100644 --- a/test/fantom/dsa-spell/dsa-spell.test.ts +++ b/test/fantom/dsa-spell/dsa-spell.test.ts @@ -87,28 +87,37 @@ describe("DSA Spell", function () { describe("Main", function () { let FTM = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0x04068DA6C83AFCFA0e13ba15A6696662335D5B75"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); var abi = [ "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" ]; function getCallData(spell: string, params: any) { var iface = new ethers.utils.Interface(abi); let data = iface.encodeFunctionData(spell, params); - return data; + return ethers.utils.hexlify(data); } it("should cast spells", async function () { - async function getArg() { - let basicParams = [FTM, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["withdraw", "deposit", "borrow"]; + let params = [ + [FTM, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + [FTM, ethers.constants.MaxUint256, 0, 0], + [USDC, ethers.utils.parseUnits("1", 5), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -118,29 +127,36 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); + it("should check balances after cast on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("0")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.gte(ethers.utils.parseUnits("1", 5)); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - async function getArg() { - let basicParams = [FTM, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [FTM, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic, dataWithdraw]; - - let connectors = ["BASIC-A", "BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["deposit", "withdraw", "deposit", "borrow"]; + let params = [ + [FTM, ethers.utils.parseEther("1"), 0, 0], + [FTM, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0], + [FTM, ethers.utils.parseEther("10"), 0, 0], + [USDC, ethers.utils.parseUnits("1", 5), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; @@ -148,9 +164,12 @@ describe("DSA Spell", function () { .connect(wallet0) .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("1")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("1", 5)); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("2")); }); }); }); diff --git a/test/mainnet/dsa-spell/dsa-spell.test.ts b/test/mainnet/dsa-spell/dsa-spell.test.ts index 5cf8a7b8..be805d95 100644 --- a/test/mainnet/dsa-spell/dsa-spell.test.ts +++ b/test/mainnet/dsa-spell/dsa-spell.test.ts @@ -85,28 +85,35 @@ describe("DSA Spell", function () { describe("Main", function () { let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); var abi = [ "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" ]; function getCallData(spell: string, params: any) { var iface = new ethers.utils.Interface(abi); let data = iface.encodeFunctionData(spell, params); - return data; + return ethers.utils.hexlify(data); } it("should cast spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A"]; + let methods = ["withdraw"]; + let params = [ + [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -116,29 +123,33 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); + it("should check balances after cast on DSA", async function () { expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic, dataWithdraw]; - - let connectors = ["BASIC-A", "BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A"]; + let methods = ["deposit", "withdraw"]; + let params = [ + [ETH, ethers.utils.parseEther("1"), 0, 0], + [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; @@ -146,8 +157,10 @@ describe("DSA Spell", function () { .connect(wallet0) .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("13")); expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); }); }); diff --git a/test/optimism/dsa-spell/dsa-spell.test.ts b/test/optimism/dsa-spell/dsa-spell.test.ts index 7c0faa61..b4a12e69 100644 --- a/test/optimism/dsa-spell/dsa-spell.test.ts +++ b/test/optimism/dsa-spell/dsa-spell.test.ts @@ -85,28 +85,37 @@ describe("DSA Spell", function () { describe("Main", function () { let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); var abi = [ "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" ]; function getCallData(spell: string, params: any) { var iface = new ethers.utils.Interface(abi); let data = iface.encodeFunctionData(spell, params); - return data; + return ethers.utils.hexlify(data); } it("should cast spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["withdraw", "deposit", "borrow"]; + let params = [ + [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + [ETH, ethers.constants.MaxUint256, 0, 0], + [USDC, ethers.utils.parseUnits("1", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -116,29 +125,36 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); + it("should check balances after cast on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("0")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.gte(ethers.utils.parseUnits("1", 6)); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - async function getArg() { - let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic, dataWithdraw]; - - let connectors = ["BASIC-A", "BASIC-A"]; - + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); + } return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["deposit", "withdraw", "deposit", "borrow"]; + let params = [ + [ETH, ethers.utils.parseEther("1"), 0, 0], + [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0], + [ETH, ethers.utils.parseEther("10"), 0, 0], + [USDC, ethers.utils.parseUnits("3", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; @@ -146,9 +162,12 @@ describe("DSA Spell", function () { .connect(wallet0) .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("1")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("3", 6)); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("2")); }); }); }); diff --git a/test/polygon/dsa-spell/dsa-spell.test.ts b/test/polygon/dsa-spell/dsa-spell.test.ts index 577ad5cd..c06d44d9 100644 --- a/test/polygon/dsa-spell/dsa-spell.test.ts +++ b/test/polygon/dsa-spell/dsa-spell.test.ts @@ -89,36 +89,38 @@ describe("DSA Spell", function () { }); describe("Main", function () { + let MATIC = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + let USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; + let usdc = new ethers.Contract(USDC, abis.basic.erc20); + var abi = [ + "function withdraw(address,uint256,address,uint256,uint256)", + "function deposit(address,uint256,uint256,uint256)", + "function borrow(address,uint256,uint256,uint256,uint256)" + ]; + function getCallData(spell: string, params: any) { + var iface = new ethers.utils.Interface(abi); + let data = iface.encodeFunctionData(spell, params); + return ethers.utils.hexlify(data); + } + it("should cast spells", async function () { - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [walletB.address] - }); - - walletBsigner = await ethers.getSigner(walletB.address); - let buyTokenAmountZeroX: any; - let USDT = "0xc2132d05d31c914a87c6611c10748aeb04b58e8f"; - let MATIC = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; - async function getArg() { - var abi = [ - "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" - ]; - function getCallData(connector: string, spell: string, params: any) { - var iface = new ethers.utils.Interface(abi); - let data = iface.encodeFunctionData(spell, params); - return data; + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); } - let basicParams = [MATIC, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("BASIC-A", "withdraw", basicParams)); - let datas = [dataBasic]; - - let connectors = ["BASIC-A"]; - return [dsaWallet1.address, connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["withdraw", "deposit", "borrow"]; + let params = [ + [MATIC, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0], + [MATIC, ethers.constants.MaxUint256, 0, 0], + [USDC, ethers.utils.parseUnits("1", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); + const spells = [ { connector: connectorName, @@ -128,55 +130,49 @@ describe("DSA Spell", function () { ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8")); + it("should check balances after cast on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("0")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.gte(ethers.utils.parseUnits("1", 6)); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); }); it("should retry spells", async function () { - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [walletB.address] - }); - - walletBsigner = await ethers.getSigner(walletB.address); - let buyTokenAmountZeroX: any; - let USDT = "0xc2132d05d31c914a87c6611c10748aeb04b58e8f"; - let MATIC = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; - async function getArg() { - var abi = [ - "function withdraw(address,uint256,address,uint256,uint256)", - "function deposit(address,uint256,uint256,uint256)" - ]; - function getCallData(spell: string, params: any) { - var iface = new ethers.utils.Interface(abi); - let data = iface.encodeFunctionData(spell, params); - return data; + async function getArg(connectors: any, spells: any, params: any) { + let datas = []; + for (let i = 0; i < connectors.length; i++) { + datas.push(getCallData(spells[i], params[i])); } - let basicParams = [MATIC, ethers.utils.parseEther("1"), 0, 0]; - let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); - let basicWithdraw = [MATIC, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; - let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); - let datas = [dataBasic,dataWithdraw]; - - let connectors = ["BASIC-A","BASIC-A"]; - return [connectors, datas]; } - let arg = await getArg(); + let connectors = ["BASIC-A", "BASIC-A", "AAVE-V3-A", "AAVE-V3-A"]; + let methods = ["deposit", "withdraw", "deposit", "borrow"]; + let params = [ + [MATIC, ethers.utils.parseEther("1"), 0, 0], + [MATIC, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0], + [MATIC, ethers.utils.parseEther("10"), 0, 0], + [USDC, ethers.utils.parseUnits("1", 6), 2, 0, 0] + ]; + let arg = await getArg(connectors, methods, params); const spells = [ { connector: connectorName, - method: "retrySpell", + method: "spellFactory", args: arg } ]; - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress(), {value: ethers.utils.parseEther("1")}); + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); const receipt = await tx.wait(); + }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("11")); - expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); + it("should check balances after spells on DSA", async function () { + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("1")); + expect(await usdc.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseUnits("1", 6)); + expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("2")); }); }); });