mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
Updated test-cases
This commit is contained in:
parent
bc531a7aa7
commit
3d2c4dce1b
46
contracts/logicProxy/basicCon.sol
Normal file
46
contracts/logicProxy/basicCon.sol
Normal file
|
@ -0,0 +1,46 @@
|
|||
pragma solidity ^0.6.0;
|
||||
|
||||
interface TokenInterface {
|
||||
function approve(address, uint) external;
|
||||
function transfer(address, uint) external;
|
||||
function transferFrom(address, address, uint) external;
|
||||
function deposit() external payable;
|
||||
function withdraw(uint) external;
|
||||
function balanceOf(address) external view returns (uint);
|
||||
}
|
||||
|
||||
interface TokenPool {
|
||||
function deposit(uint amount) external payable returns (uint);
|
||||
function withdraw(uint amount, address to) external returns (uint);
|
||||
}
|
||||
|
||||
interface Registry {
|
||||
function poolToken(address) external view returns (address);
|
||||
}
|
||||
|
||||
contract BasicProxy {
|
||||
function getRegistryAddr() internal pure returns (address) {
|
||||
return 0x53A664d8F4FF1201eA9415825a746D1652345110;
|
||||
}
|
||||
|
||||
function getEthAddr() internal pure returns (address) {
|
||||
return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
}
|
||||
|
||||
function deposit(address token, uint amount) external payable {
|
||||
Registry registry = Registry(getRegistryAddr());
|
||||
address tokenPoolAddr = registry.poolToken(token);
|
||||
require(tokenPoolAddr != address(0), "Token-pool-not-found");
|
||||
uint bal = getEthAddr() == token ? address(this).balance : TokenInterface(token).balanceOf(address(this));
|
||||
uint _amt = amount >= bal ? bal : amount;
|
||||
uint ethAmt = getEthAddr() == token ? _amt : 0;
|
||||
TokenPool(tokenPoolAddr).deposit.value(ethAmt)(amount);
|
||||
}
|
||||
|
||||
function withdraw(address token, uint amount, address to) external {
|
||||
Registry registry = Registry(getRegistryAddr());
|
||||
address tokenPoolAddr = registry.poolToken(token);
|
||||
require(tokenPoolAddr != address(0), "Token-pool-not-found");
|
||||
TokenPool(tokenPoolAddr).withdraw(amount, to);
|
||||
}
|
||||
}
|
7
contracts/tests/FlusherLogic.sol
Normal file
7
contracts/tests/FlusherLogic.sol
Normal file
|
@ -0,0 +1,7 @@
|
|||
pragma solidity ^0.6.0;
|
||||
|
||||
contract FlusherLogic {
|
||||
function isFlusher(address addres) external returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
10
contracts/tests/settleLogic.sol
Normal file
10
contracts/tests/settleLogic.sol
Normal file
|
@ -0,0 +1,10 @@
|
|||
pragma solidity ^0.6.0;
|
||||
|
||||
interface PoolInterface {
|
||||
function setExchangeRate() external;
|
||||
}
|
||||
contract SettleLogic {
|
||||
function calculateExchangeRate(address pool) external {
|
||||
PoolInterface(pool).setExchangeRate();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
const Registry = artifacts.require("Registry");
|
||||
const FlusherLogic = artifacts.require("FlusherLogic");
|
||||
const SettleLogic = artifacts.require("SettleLogic");
|
||||
module.exports = async function(deployer, networks, accounts) {
|
||||
await deployer.deploy(Registry, accounts[0]); //deploy registry.sol contract
|
||||
await deployer.deploy(FlusherLogic, accounts[0]); //deploy flusherLogic.sol contract
|
||||
await deployer.deploy(SettleLogic, accounts[0]); //deploy settleLogic.sol contract
|
||||
};
|
|
@ -48,40 +48,24 @@ contract('Registry.sol', async accounts => {
|
|||
await addPool(registryInstance, ethPoolInstance.address, ethAddr);
|
||||
});
|
||||
|
||||
it('should enable ETH pool in registry', async () => {
|
||||
await enablePool(registryInstance, ethPoolInstance.address);
|
||||
});
|
||||
|
||||
it('should remove ETH pool in registry', async () => {
|
||||
await removePool(registryInstance, ethAddr);
|
||||
});
|
||||
|
||||
it('should disable ETH pool in registry', async () => {
|
||||
await disablePool(registryInstance, ethPoolInstance.address);
|
||||
});
|
||||
|
||||
it('should add ETH pool in registry', async () => {
|
||||
await addPool(registryInstance, ethPoolInstance.address, ethAddr);
|
||||
});
|
||||
|
||||
it('should enable ETH pool in registry', async () => {
|
||||
await enablePool(registryInstance, ethPoolInstance.address);
|
||||
});
|
||||
|
||||
it('should add DAI pool in registry', async () => {
|
||||
await addPool(registryInstance, daiPoolInstance.address, daiAddr);
|
||||
});
|
||||
|
||||
it('should enable DAI pool in registry', async () => {
|
||||
await enablePool(registryInstance, daiPoolInstance.address);
|
||||
});
|
||||
|
||||
it('should update ETH Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, ethPoolInstance.address, ethRateLogicInstance.address);
|
||||
await updateRateLogic(registryInstance, ethPoolInstance.address, ethAddr, ethRateLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update DAI Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, daiPoolInstance.address, daiRateLogicInstance.address);
|
||||
await updateRateLogic(registryInstance, daiPoolInstance.address, daiAddr, daiRateLogicInstance.address);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -100,22 +84,8 @@ async function removePool(registryInstance, tokenAddr) {
|
|||
}
|
||||
|
||||
|
||||
async function enablePool(registryInstance, poolAddr) {
|
||||
await registryInstance.updatePool(poolAddr, {from: masterAddr});
|
||||
|
||||
var _isPool = await registryInstance.isPool(poolAddr);
|
||||
expect(_isPool).to.equal(true);
|
||||
}
|
||||
|
||||
async function disablePool(registryInstance, poolAddr) {
|
||||
await registryInstance.updatePool(poolAddr, {from: masterAddr});
|
||||
|
||||
var _isPool = await registryInstance.isPool(poolAddr);
|
||||
expect(_isPool).to.equal(false);
|
||||
}
|
||||
|
||||
async function updateRateLogic(registryInstance, poolAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(poolAddr, logicAddr, {from: masterAddr});
|
||||
async function updateRateLogic(registryInstance, poolAddr, tokenAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(tokenAddr, logicAddr, {from: masterAddr});
|
||||
|
||||
var _logicAddr = await registryInstance.poolLogic(poolAddr);
|
||||
expect(_logicAddr).to.equal(logicAddr);
|
||||
|
|
|
@ -7,6 +7,8 @@ const PoolETHContract = artifacts.require("PoolETH");
|
|||
|
||||
const DaiRateLogic = artifacts.require("DaiRateLogic");
|
||||
const EthRateLogic = artifacts.require("EthRateLogic");
|
||||
const FlusherLogic = artifacts.require("FlusherLogic");
|
||||
const SettleLogic = artifacts.require("SettleLogic");
|
||||
|
||||
|
||||
const masterAddr = "0xfCD22438AD6eD564a1C26151Df73F6B33B817B56"
|
||||
|
@ -31,6 +33,8 @@ contract('DAI Pool', async accounts => {
|
|||
|
||||
let ethRateLogicInstance;
|
||||
let daiRateLogicInstance;
|
||||
let flusherLogicInstance;
|
||||
let settleLogicInstance;
|
||||
before(async() => {
|
||||
registryInstance = await RegistryContract.deployed();
|
||||
ethPoolInstance = await PoolETHContract.deployed();
|
||||
|
@ -38,6 +42,8 @@ contract('DAI Pool', async accounts => {
|
|||
|
||||
ethRateLogicInstance = await EthRateLogic.deployed();
|
||||
daiRateLogicInstance = await DaiRateLogic.deployed();
|
||||
flusherLogicInstance = await FlusherLogic.deployed();
|
||||
settleLogicInstance = await SettleLogic.deployed();
|
||||
})
|
||||
|
||||
it('should send ether to the user address', async () => {
|
||||
|
@ -74,12 +80,21 @@ contract('DAI Pool', async accounts => {
|
|||
await addPool(registryInstance, daiPoolInstance.address, daiAddr);
|
||||
});
|
||||
|
||||
it('should enable DAI pool in registry', async () => {
|
||||
await enablePool(registryInstance, daiPoolInstance.address);
|
||||
it('should update DAI Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, daiPoolInstance.address, daiAddr, daiRateLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update DAI Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, daiPoolInstance.address, daiRateLogicInstance.address);
|
||||
it('should update Flusher Logic contract in registry for DAI POOL', async () => {
|
||||
await updateFlusherLogic(registryInstance, daiPoolInstance.address, daiAddr, flusherLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update Settle Logic contract in registry for DAI POOL', async () => {
|
||||
await updateSettleLogic(registryInstance, daiPoolInstance.address, daiAddr, settleLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update Pool Cap in registry for DAI POOL', async () => {
|
||||
var amountInWei = (ether("100000000")).toString()
|
||||
await updatePoolCap(registryInstance, daiPoolInstance.address, daiAddr, amountInWei);
|
||||
});
|
||||
|
||||
it('should give DAI allowance for DAI pool', async () => {
|
||||
|
@ -105,7 +120,7 @@ contract('DAI Pool', async accounts => {
|
|||
.transfer(daiRateLogicInstance.address, amountInWei)
|
||||
.send({ from: userAddress});
|
||||
var exchangeRateInit = await daiPoolInstance.exchangeRate()
|
||||
await daiPoolInstance.setExchangeRate({from: masterAddr});
|
||||
await updateExchangeLogic(daiPoolInstance, settleLogicInstance.address);
|
||||
var exchangeRateFinal = await daiPoolInstance.exchangeRate()
|
||||
expect(exchangeRateInit).to.not.equal(exchangeRateFinal);
|
||||
});
|
||||
|
@ -149,16 +164,48 @@ async function addPool(registryInstance, poolAddr, tokenAddr) {
|
|||
expect(_poolAddr).to.equal(poolAddr);
|
||||
}
|
||||
|
||||
async function enablePool(registryInstance, poolAddr) {
|
||||
await registryInstance.updatePool(poolAddr, {from: masterAddr});
|
||||
|
||||
var _isPool = await registryInstance.isPool(poolAddr);
|
||||
expect(_isPool).to.equal(true);
|
||||
async function updatePoolCap(registryInstance, poolAddr, tokenAddr, capAmt) {
|
||||
await registryInstance.updateCap(tokenAddr, capAmt, {from: masterAddr});
|
||||
|
||||
var _capAmt = await registryInstance.poolCap(poolAddr);
|
||||
expect(new BN(_capAmt)).to.bignumber.equal(capAmt);
|
||||
}
|
||||
|
||||
async function updateRateLogic(registryInstance, poolAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(poolAddr, logicAddr, {from: masterAddr});
|
||||
async function updateRateLogic(registryInstance, poolAddr, tokenAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(tokenAddr, logicAddr, {from: masterAddr});
|
||||
|
||||
var _logicAddr = await registryInstance.poolLogic(poolAddr);
|
||||
expect(_logicAddr).to.equal(logicAddr);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateFlusherLogic(registryInstance, poolAddr, tokenAddr, flusherLogic) {
|
||||
await registryInstance.updateFlusherLogic(tokenAddr, flusherLogic, {from: masterAddr});
|
||||
|
||||
var _logicAddr = await registryInstance.flusherLogic(poolAddr);
|
||||
expect(_logicAddr).to.equal(flusherLogic);
|
||||
}
|
||||
|
||||
async function updateSettleLogic(registryInstance, poolAddr, tokenAddr, settleLogic) {
|
||||
await registryInstance.addSettleLogic(tokenAddr, settleLogic, {from: masterAddr});
|
||||
|
||||
var _isSettleLogic = await registryInstance.settleLogic(poolAddr, settleLogic);
|
||||
expect(_isSettleLogic).to.equal(true);
|
||||
}
|
||||
|
||||
async function updateExchangeLogic(daiPoolInstance, settleLogic) {
|
||||
var abi = {
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "pool",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "calculateExchangeRate",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
var encodeCalldata = web3.eth.abi.encodeFunctionCall(abi, [daiPoolInstance.address]);
|
||||
await daiPoolInstance.settle([settleLogic], [encodeCalldata], {from: masterAddr});
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ const { expect } = require('chai');
|
|||
const RegistryContract = artifacts.require("Registry");
|
||||
const PoolETHContract = artifacts.require("PoolETH");
|
||||
|
||||
const FlusherLogic = artifacts.require("FlusherLogic");
|
||||
const SettleLogic = artifacts.require("SettleLogic");
|
||||
const EthRateLogic = artifacts.require("EthRateLogic");
|
||||
|
||||
|
||||
|
@ -21,11 +23,15 @@ contract('ETH Pool', async accounts => {
|
|||
let registryInstance;
|
||||
|
||||
let ethRateLogicInstance;
|
||||
let flusherLogicInstance;
|
||||
let settleLogicInstance;
|
||||
before(async() => {
|
||||
registryInstance = await RegistryContract.deployed();
|
||||
ethPoolInstance = await PoolETHContract.deployed();
|
||||
|
||||
ethRateLogicInstance = await EthRateLogic.deployed();
|
||||
flusherLogicInstance = await FlusherLogic.deployed();
|
||||
settleLogicInstance = await SettleLogic.deployed();
|
||||
})
|
||||
|
||||
it('should send ether to the master address', async () => {
|
||||
|
@ -43,12 +49,21 @@ contract('ETH Pool', async accounts => {
|
|||
await addPool(registryInstance, ethPoolInstance.address, ethAddr);
|
||||
});
|
||||
|
||||
it('should enable ETH pool in registry', async () => {
|
||||
await enablePool(registryInstance, ethPoolInstance.address);
|
||||
it('should update ETH Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, ethPoolInstance.address, ethAddr, ethRateLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update ETH Logic contract in registry', async () => {
|
||||
await updateRateLogic(registryInstance, ethPoolInstance.address, ethRateLogicInstance.address);
|
||||
it('should update Flusher Logic contract in registry for ETH POOL', async () => {
|
||||
await updateFlusherLogic(registryInstance, ethPoolInstance.address, ethAddr, flusherLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update Settle Logic contract in registry for ETH POOL', async () => {
|
||||
await updateSettleLogic(registryInstance, ethPoolInstance.address, ethAddr, settleLogicInstance.address);
|
||||
});
|
||||
|
||||
it('should update Pool Cap in registry for ETH POOL', async () => {
|
||||
var amountInWei = (ether("100000000")).toString()
|
||||
await updatePoolCap(registryInstance, ethPoolInstance.address, ethAddr, amountInWei);
|
||||
});
|
||||
|
||||
it('should deposit 5 ETH in ETH pool', async () => {
|
||||
|
@ -68,7 +83,7 @@ contract('ETH Pool', async accounts => {
|
|||
value: amountInWei
|
||||
});
|
||||
var exchangeRateInit = await ethPoolInstance.exchangeRate()
|
||||
await ethPoolInstance.setExchangeRate({from: masterAddr});
|
||||
await updateExchangeLogic(ethPoolInstance, settleLogicInstance.address);
|
||||
var exchangeRateFinal = await ethPoolInstance.exchangeRate()
|
||||
expect(exchangeRateInit).to.not.equal(exchangeRateFinal);
|
||||
});
|
||||
|
@ -111,9 +126,48 @@ async function enablePool(registryInstance, poolAddr) {
|
|||
expect(_isPool).to.equal(true);
|
||||
}
|
||||
|
||||
async function updateRateLogic(registryInstance, poolAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(poolAddr, logicAddr, {from: masterAddr});
|
||||
async function updateRateLogic(registryInstance, poolAddr, tokenAddr, logicAddr) {
|
||||
await registryInstance.updatePoolLogic(tokenAddr, logicAddr, {from: masterAddr});
|
||||
|
||||
var _logicAddr = await registryInstance.poolLogic(poolAddr);
|
||||
expect(_logicAddr).to.equal(logicAddr);
|
||||
}
|
||||
|
||||
async function updatePoolCap(registryInstance, poolAddr, tokenAddr, capAmt) {
|
||||
await registryInstance.updateCap(tokenAddr, capAmt, {from: masterAddr});
|
||||
|
||||
var _capAmt = await registryInstance.poolCap(poolAddr);
|
||||
expect(new BN(_capAmt)).to.bignumber.equal(capAmt);
|
||||
}
|
||||
|
||||
async function updateFlusherLogic(registryInstance, poolAddr, tokenAddr, flusherLogic) {
|
||||
await registryInstance.updateFlusherLogic(tokenAddr, flusherLogic, {from: masterAddr});
|
||||
|
||||
var _logicAddr = await registryInstance.flusherLogic(poolAddr);
|
||||
expect(_logicAddr).to.equal(flusherLogic);
|
||||
}
|
||||
|
||||
async function updateSettleLogic(registryInstance, poolAddr, tokenAddr, settleLogic) {
|
||||
await registryInstance.addSettleLogic(tokenAddr, settleLogic, {from: masterAddr});
|
||||
|
||||
var _isSettleLogic = await registryInstance.settleLogic(poolAddr, settleLogic);
|
||||
expect(_isSettleLogic).to.equal(true);
|
||||
}
|
||||
|
||||
async function updateExchangeLogic(ethPoolInstance, settleLogic) {
|
||||
var abi = {
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "pool",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "calculateExchangeRate",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
var encodeCalldata = web3.eth.abi.encodeFunctionCall(abi, [ethPoolInstance.address]);
|
||||
await ethPoolInstance.settle([settleLogic], [encodeCalldata], {from: masterAddr});
|
||||
}
|
Loading…
Reference in New Issue
Block a user