Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contracts/FlashloanLender.sol: add transferOwnership #146

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/FlashloanLender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ contract FlashloanLender is ERC3156FlashLenderInterface {
return CCollateralCapErc20(cToken).flashLoan(receiver, msg.sender, amount, data);
}

function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "new owner cannot be zero address");
owner = newOwner;
}

function updateUnderlyingMapping(CToken[] calldata cTokens) external onlyOwner returns (bool) {
uint256 cTokenLength = cTokens.length;
for (uint256 i = 0; i < cTokenLength; i++) {
Expand Down
21 changes: 14 additions & 7 deletions tests/Tokens/flashloanTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
etherUnsigned,
etherMantissa,
mergeInterface,
unlockedAccount
address,
} = require('../Utils/Ethereum');

const {
Expand All @@ -25,6 +25,7 @@ describe('Flashloan test', function () {
beforeEach(async () => {
admin = saddle.accounts[0];
nonAdmin = saddle.accounts[1];
other = saddle.accounts[2];
cToken = await makeCToken({kind: 'ccollateralcap', supportMarket: true});
flashloanReceiver = await makeFlashloanReceiver()
flashloanLender = await deploy('FlashloanLender', [cToken.comptroller._address, admin]);
Expand All @@ -40,7 +41,7 @@ describe('Flashloan test', function () {

await send(cToken.underlying, 'harnessSetBalance', [flashloanReceiver._address, receiverBalance]);
});

describe('test FlashLoanLender interface', ()=>{
let unsupportedCToken;
beforeEach(async () => {
Expand All @@ -60,25 +61,31 @@ describe('Flashloan test', function () {
await expect(call(flashloanLender, 'flashFee', [unsupportedCToken.underlying._address, borrowAmount])).rejects.toRevert('revert cannot find cToken of this underlying in the mapping');
expect(await call(flashloanLender, 'flashFee', [cToken.underlying._address, borrowAmount])).toEqualNumber(totalFee);
});
it("test updateUnderlyingMapping", async () =>
it("test updateUnderlyingMapping", async () =>
{
const borrowAmount = 10_000;
const totalFee = 3
await send(flashloanLender, 'updateUnderlyingMapping', [[unsupportedCToken._address]]);
expect(await call(flashloanLender, 'flashFee', [cToken.underlying._address, borrowAmount])).toEqualNumber(totalFee);
});
it("test removeUnderlyingMapping", async () =>
it("test removeUnderlyingMapping", async () =>
{
const borrowAmount = 10_000;
await send(flashloanLender, 'removeUnderlyingMapping', [[cToken._address]]);
await expect(call(flashloanLender, 'flashFee', [cToken.underlying._address, borrowAmount])).rejects.toRevert('revert cannot find cToken of this underlying in the mapping');
});
it("test onlyOwner", async () =>
it("test onlyOwner", async () =>
{
await expect(send(flashloanLender, 'updateUnderlyingMapping', [[unsupportedCToken._address]], {from:nonAdmin})).rejects.toRevert("revert not owner");
});


it("test transferOwnership", async () =>
{
await expect(send(flashloanLender, 'transferOwnership', [other], {from:nonAdmin})).rejects.toRevert("revert not owner");
});
it("test transferOwnership with zero address", async () =>
{
await expect(send(flashloanLender, 'transferOwnership', [address(0)], {from:admin})).rejects.toRevert("revert new owner cannot be zero address");
});
})

describe('internal cash equal underlying balance', () => {
Expand Down