updated tests

This commit is contained in:
Richa-iitr 2022-06-20 12:11:56 +05:30
parent 47475742a2
commit b8e0c1826a
6 changed files with 266 additions and 201 deletions

View File

@ -85,28 +85,37 @@ describe("DSA Spell", function () {
describe("Main", function () { describe("Main", function () {
let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
let USDC = "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8";
let usdc = new ethers.Contract(USDC, abis.basic.erc20);
var abi = [ var abi = [
"function withdraw(address,uint256,address,uint256,uint256)", "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) { function getCallData(spell: string, params: any) {
var iface = new ethers.utils.Interface(abi); var iface = new ethers.utils.Interface(abi);
let data = iface.encodeFunctionData(spell, params); let data = iface.encodeFunctionData(spell, params);
return data; return ethers.utils.hexlify(data);
} }
it("should cast spells", async function () { it("should cast spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); for (let i = 0; i < connectors.length; i++) {
let datas = [dataBasic]; datas.push(getCallData(spells[i], params[i]));
}
let connectors = ["BASIC-A"];
return [dsaWallet1.address, connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -116,29 +125,36 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); for (let i = 0; i < connectors.length; i++) {
let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; datas.push(getCallData(spells[i], params[i]));
let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); }
let datas = [dataBasic, dataWithdraw];
let connectors = ["BASIC-A", "BASIC-A"];
return [connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg args: arg
} }
]; ];
@ -146,9 +162,12 @@ describe("DSA Spell", function () {
.connect(wallet0) .connect(wallet0)
.cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") });
const receipt = await tx.wait(); 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(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); 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"));
}); });
}); });
}); });

View File

@ -90,33 +90,37 @@ describe("DSA Spell", function () {
describe("Main", function () { describe("Main", function () {
let AVAX = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; 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 () { it("should cast spells", async function () {
await hre.network.provider.request({ async function getArg(connectors: any, spells: any, params: any) {
method: "hardhat_impersonateAccount", let datas = [];
params: [walletB.address] for (let i = 0; i < connectors.length; i++) {
}); datas.push(getCallData(spells[i], params[i]));
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;
} }
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]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -126,44 +130,36 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
await hre.network.provider.request({ async function getArg(connectors: any, spells: any, params: any) {
method: "hardhat_impersonateAccount", let datas = [];
params: [walletB.address] for (let i = 0; i < connectors.length; i++) {
}); datas.push(getCallData(spells[i], params[i]));
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;
} }
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]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg args: arg
} }
]; ];
@ -171,9 +167,12 @@ describe("DSA Spell", function () {
.connect(wallet0) .connect(wallet0)
.cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") });
const receipt = await tx.wait(); 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(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); 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"));
}); });
}); });
}); });

View File

@ -87,28 +87,37 @@ describe("DSA Spell", function () {
describe("Main", function () { describe("Main", function () {
let FTM = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; let FTM = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
let USDC = "0x04068DA6C83AFCFA0e13ba15A6696662335D5B75";
let usdc = new ethers.Contract(USDC, abis.basic.erc20);
var abi = [ var abi = [
"function withdraw(address,uint256,address,uint256,uint256)", "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) { function getCallData(spell: string, params: any) {
var iface = new ethers.utils.Interface(abi); var iface = new ethers.utils.Interface(abi);
let data = iface.encodeFunctionData(spell, params); let data = iface.encodeFunctionData(spell, params);
return data; return ethers.utils.hexlify(data);
} }
it("should cast spells", async function () { it("should cast spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [FTM, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); for (let i = 0; i < connectors.length; i++) {
let datas = [dataBasic]; datas.push(getCallData(spells[i], params[i]));
}
let connectors = ["BASIC-A"];
return [dsaWallet1.address, connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -118,29 +127,36 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [FTM, ethers.utils.parseEther("1"), 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); for (let i = 0; i < connectors.length; i++) {
let basicWithdraw = [FTM, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; datas.push(getCallData(spells[i], params[i]));
let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); }
let datas = [dataBasic, dataWithdraw];
let connectors = ["BASIC-A", "BASIC-A"];
return [connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg args: arg
} }
]; ];
@ -148,9 +164,12 @@ describe("DSA Spell", function () {
.connect(wallet0) .connect(wallet0)
.cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") });
const receipt = await tx.wait(); 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(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); 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"));
}); });
}); });
}); });

View File

@ -85,28 +85,35 @@ describe("DSA Spell", function () {
describe("Main", function () { describe("Main", function () {
let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
let USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
let usdc = new ethers.Contract(USDC, abis.basic.erc20);
var abi = [ var abi = [
"function withdraw(address,uint256,address,uint256,uint256)", "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) { function getCallData(spell: string, params: any) {
var iface = new ethers.utils.Interface(abi); var iface = new ethers.utils.Interface(abi);
let data = iface.encodeFunctionData(spell, params); let data = iface.encodeFunctionData(spell, params);
return data; return ethers.utils.hexlify(data);
} }
it("should cast spells", async function () { it("should cast spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); for (let i = 0; i < connectors.length; i++) {
let datas = [dataBasic]; datas.push(getCallData(spells[i], params[i]));
}
let connectors = ["BASIC-A"];
return [dsaWallet1.address, connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -116,29 +123,33 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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(dsaWallet1.address)).to.be.lte(ethers.utils.parseEther("8"));
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); for (let i = 0; i < connectors.length; i++) {
let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; datas.push(getCallData(spells[i], params[i]));
let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); }
let datas = [dataBasic, dataWithdraw];
let connectors = ["BASIC-A", "BASIC-A"];
return [connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg args: arg
} }
]; ];
@ -146,8 +157,10 @@ describe("DSA Spell", function () {
.connect(wallet0) .connect(wallet0)
.cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") });
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10"));
}); });
}); });

View File

@ -85,28 +85,37 @@ describe("DSA Spell", function () {
describe("Main", function () { describe("Main", function () {
let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; let ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
let USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
let usdc = new ethers.Contract(USDC, abis.basic.erc20);
var abi = [ var abi = [
"function withdraw(address,uint256,address,uint256,uint256)", "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) { function getCallData(spell: string, params: any) {
var iface = new ethers.utils.Interface(abi); var iface = new ethers.utils.Interface(abi);
let data = iface.encodeFunctionData(spell, params); let data = iface.encodeFunctionData(spell, params);
return data; return ethers.utils.hexlify(data);
} }
it("should cast spells", async function () { it("should cast spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("2"), dsaWallet0.address, 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("withdraw", basicParams)); for (let i = 0; i < connectors.length; i++) {
let datas = [dataBasic]; datas.push(getCallData(spells[i], params[i]));
}
let connectors = ["BASIC-A"];
return [dsaWallet1.address, connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -116,29 +125,36 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
async function getArg() { async function getArg(connectors: any, spells: any, params: any) {
let basicParams = [ETH, ethers.utils.parseEther("1"), 0, 0]; let datas = [];
let dataBasic = ethers.utils.hexlify(await getCallData("deposit", basicParams)); for (let i = 0; i < connectors.length; i++) {
let basicWithdraw = [ETH, ethers.utils.parseEther("2"), dsaWallet1.address, 0, 0]; datas.push(getCallData(spells[i], params[i]));
let dataWithdraw = ethers.utils.hexlify(await getCallData("withdraw", basicWithdraw)); }
let datas = [dataBasic, dataWithdraw];
let connectors = ["BASIC-A", "BASIC-A"];
return [connectors, datas]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg args: arg
} }
]; ];
@ -146,9 +162,12 @@ describe("DSA Spell", function () {
.connect(wallet0) .connect(wallet0)
.cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") }); .cast(...encodeSpells(spells), await wallet0.getAddress(), { value: ethers.utils.parseEther("1") });
const receipt = await tx.wait(); 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(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); 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"));
}); });
}); });
}); });

View File

@ -89,36 +89,38 @@ describe("DSA Spell", function () {
}); });
describe("Main", 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 () { it("should cast spells", async function () {
await hre.network.provider.request({ async function getArg(connectors: any, spells: any, params: any) {
method: "hardhat_impersonateAccount", let datas = [];
params: [walletB.address] for (let i = 0; i < connectors.length; i++) {
}); datas.push(getCallData(spells[i], params[i]));
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;
} }
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]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -128,55 +130,49 @@ describe("DSA Spell", function () {
]; ];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress()); const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet0.getAddress());
const receipt = await tx.wait(); 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")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("12"));
}); });
it("should retry spells", async function () { it("should retry spells", async function () {
await hre.network.provider.request({ async function getArg(connectors: any, spells: any, params: any) {
method: "hardhat_impersonateAccount", let datas = [];
params: [walletB.address] for (let i = 0; i < connectors.length; i++) {
}); datas.push(getCallData(spells[i], params[i]));
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;
} }
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]; 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 = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "retrySpell", method: "spellFactory",
args: arg 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(); 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(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10")); 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"));
}); });
}); });
}); });