mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
fixed tests
This commit is contained in:
parent
d48da206da
commit
be922547a9
|
@ -33,8 +33,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@dev helper function for three withdraw or borrow cases:
|
*@dev helper function for following withdraw or borrow cases:
|
||||||
*withdraw - for `withdraw` withdraws the collateral or base from DSA's position to account.
|
|
||||||
*withdrawFrom - for `withdrawFromUsingManager` withdraws from src to dest using DSA as manager
|
*withdrawFrom - for `withdrawFromUsingManager` withdraws from src to dest using DSA as manager
|
||||||
*withdrawTo - for `withdrawTo` withdraws from DSA to dest address.
|
*withdrawTo - for `withdrawTo` withdraws from DSA to dest address.
|
||||||
*/
|
*/
|
||||||
|
@ -45,9 +44,9 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
address to,
|
address to,
|
||||||
uint256 amt
|
uint256 amt
|
||||||
) internal {
|
) internal {
|
||||||
if (from == address(0)) {
|
if (from == address(this)) {
|
||||||
CometInterface(market).withdrawTo(to, token, amt);
|
CometInterface(market).withdrawTo(to, token, amt);
|
||||||
} else if (from != address(0) && to != address(0)) {
|
} else {
|
||||||
CometInterface(market).withdrawFrom(from, to, token, amt);
|
CometInterface(market).withdrawFrom(from, to, token, amt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,8 +71,10 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
params.from
|
params.from
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 balance = TokenInterface(params.market).balanceOf(params.from);
|
require(
|
||||||
require(balance == 0, "borrow-disabled-when-supplied-base");
|
TokenInterface(params.market).balanceOf(params.from) == 0,
|
||||||
|
"borrow-disabled-when-supplied-base"
|
||||||
|
);
|
||||||
|
|
||||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
amt_ = sub(finalBal, initialBal);
|
amt_ = sub(finalBal, initialBal);
|
||||||
|
|
||||||
if (params.from == address(0) || params.to == address(this))
|
if (params.to == address(this))
|
||||||
convertWethToEth(isEth, tokenContract, amt_);
|
convertWethToEth(isEth, tokenContract, amt_);
|
||||||
|
|
||||||
setUint(params.setId, amt_);
|
setUint(params.setId, amt_);
|
||||||
|
@ -133,7 +134,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
amt_ = sub(initialBal, finalBal);
|
amt_ = sub(initialBal, finalBal);
|
||||||
|
|
||||||
if (params.from == address(0) || params.to == address(this))
|
if (params.to == address(this))
|
||||||
convertWethToEth(isEth, tokenContract, amt_);
|
convertWethToEth(isEth, tokenContract, amt_);
|
||||||
|
|
||||||
setUint(params.setId, amt_);
|
setUint(params.setId, amt_);
|
||||||
|
|
|
@ -142,6 +142,7 @@ describe("Compound III", function () {
|
||||||
let dsaWallet0: any;
|
let dsaWallet0: any;
|
||||||
let dsaWallet1: any;
|
let dsaWallet1: any;
|
||||||
let dsaWallet2: any;
|
let dsaWallet2: any;
|
||||||
|
let dsaWallet3: any;
|
||||||
let wallet: any;
|
let wallet: any;
|
||||||
let dsa0Signer: any;
|
let dsa0Signer: any;
|
||||||
let masterSigner: Signer;
|
let masterSigner: Signer;
|
||||||
|
@ -208,6 +209,8 @@ describe("Compound III", function () {
|
||||||
expect(!!dsaWallet1.address).to.be.true;
|
expect(!!dsaWallet1.address).to.be.true;
|
||||||
dsaWallet2 = await buildDSAv2(wallet0.address);
|
dsaWallet2 = await buildDSAv2(wallet0.address);
|
||||||
expect(!!dsaWallet2.address).to.be.true;
|
expect(!!dsaWallet2.address).to.be.true;
|
||||||
|
dsaWallet3 = await buildDSAv2(wallet0.address);
|
||||||
|
expect(!!dsaWallet3.address).to.be.true;
|
||||||
wallet = await ethers.getSigner(dsaWallet0.address);
|
wallet = await ethers.getSigner(dsaWallet0.address);
|
||||||
expect(!!dsaWallet1.address).to.be.true;
|
expect(!!dsaWallet1.address).to.be.true;
|
||||||
});
|
});
|
||||||
|
@ -229,6 +232,11 @@ describe("Compound III", function () {
|
||||||
value: ethers.utils.parseEther("10")
|
value: ethers.utils.parseEther("10")
|
||||||
});
|
});
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
||||||
|
await wallet0.sendTransaction({
|
||||||
|
to: dsaWallet3.address,
|
||||||
|
value: ethers.utils.parseEther("10")
|
||||||
|
});
|
||||||
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -496,7 +504,7 @@ describe("Compound III", function () {
|
||||||
];
|
];
|
||||||
const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
let initialBal= (await baseContract.connect(signer).balanceOf(dsaWallet1.address));
|
let initialBal = await baseContract.connect(signer).balanceOf(dsaWallet1.address);
|
||||||
console.log(initialBal.toString());
|
console.log(initialBal.toString());
|
||||||
let spells1 = [
|
let spells1 = [
|
||||||
{
|
{
|
||||||
|
@ -520,7 +528,7 @@ describe("Compound III", function () {
|
||||||
args: [market, base, dsaWallet0.address, dsaWallet1.address, ethers.constants.MaxUint256, 0, 0]
|
args: [market, base, dsaWallet0.address, dsaWallet1.address, ethers.constants.MaxUint256, 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
let initialBal= (await baseContract.connect(signer).balanceOf(dsaWallet0.address));
|
let initialBal = await baseContract.connect(signer).balanceOf(dsaWallet0.address);
|
||||||
console.log(initialBal.toString());
|
console.log(initialBal.toString());
|
||||||
|
|
||||||
const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
||||||
|
@ -572,37 +580,47 @@ describe("Compound III", function () {
|
||||||
);
|
);
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(initialBal.sub(amount));
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(initialBal.sub(amount));
|
||||||
});
|
});
|
||||||
|
it("should allow manager for dsaWallet0's collateral", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "toggleAccountManager",
|
||||||
|
args: [market, dsaWallet2.address, true]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet3.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
});
|
||||||
it("should borrow using manager", async function () {
|
it("should borrow using manager", async function () {
|
||||||
|
let initialBal = await baseContract.connect(wallet0).balanceOf(dsaWallet0.address);
|
||||||
await wallet0.sendTransaction({
|
await wallet0.sendTransaction({
|
||||||
to: dsaWallet0.address,
|
to: dsaWallet3.address,
|
||||||
value: ethers.utils.parseEther("5")
|
value: ethers.utils.parseEther("15")
|
||||||
});
|
});
|
||||||
const spells1 = [
|
const spells1 = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "deposit",
|
method: "deposit",
|
||||||
args: [market, tokens.eth.address, ethers.utils.parseEther("3"), 0, 0]
|
args: [market, tokens.eth.address, ethers.utils.parseEther("15"), 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const tx1 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells1), wallet1.address);
|
const tx1 = await dsaWallet3.connect(wallet0).cast(...encodeSpells(spells1), wallet1.address);
|
||||||
const amount = ethers.utils.parseUnits("10", 6);
|
const amount = ethers.utils.parseUnits("500", 6);
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "borrowOnBehalf",
|
method: "borrowOnBehalf",
|
||||||
args: [market, base, dsaWallet0.address, dsaWallet1.address, amount, 0, 0]
|
args: [market, base, dsaWallet3.address, dsaWallet0.address, amount, 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
expect(new BigNumber(await comet.connect(signer).borrowBalanceOf(dsaWallet0.address)).toFixed()).to.be.equal(
|
expect(new BigNumber(await comet.connect(signer).borrowBalanceOf(dsaWallet3.address)).toFixed()).to.be.equal(
|
||||||
ethers.utils.parseUnits("10", 6)
|
ethers.utils.parseUnits("500", 6)
|
||||||
);
|
|
||||||
expect(await baseContract.connect(wallet0).balanceOf(dsaWallet1.address)).to.be.equal(
|
|
||||||
ethers.utils.parseUnits("10", 6)
|
|
||||||
);
|
);
|
||||||
|
expect(await baseContract.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.equal(initialBal.add(amount));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should transferAsset collateral using manager", async function () {
|
it("should transferAsset collateral using manager", async function () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user