mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added tests
This commit is contained in:
parent
a2f60470ec
commit
1b021dca18
34
contracts/mocks/tokens/MintableDelegationERC20.sol
Normal file
34
contracts/mocks/tokens/MintableDelegationERC20.sol
Normal file
|
@ -0,0 +1,34 @@
|
|||
// SPDX-License-Identifier: agpl-3.0
|
||||
pragma solidity ^0.6.8;
|
||||
|
||||
import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol';
|
||||
|
||||
/**
|
||||
* @title ERC20Mintable
|
||||
* @dev ERC20 minting logic
|
||||
*/
|
||||
contract MintableDelegationERC20 is ERC20 {
|
||||
address public delegatee;
|
||||
|
||||
constructor(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
uint8 decimals
|
||||
) public ERC20(name, symbol) {
|
||||
_setupDecimals(decimals);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Function to mint tokensp
|
||||
* @param value The amount of tokens to mint.
|
||||
* @return A boolean that indicates if the operation was successful.
|
||||
*/
|
||||
function mint(uint256 value) public returns (bool) {
|
||||
_mint(msg.sender, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function delegate(address delegateeAddress) external {
|
||||
delegatee = delegateeAddress;
|
||||
}
|
||||
}
|
|
@ -163,26 +163,25 @@
|
|||
},
|
||||
"ReserveLogic": {
|
||||
"buidlerevm": {
|
||||
"address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c",
|
||||
"address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
"GenericLogic": {
|
||||
"buidlerevm": {
|
||||
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
|
||||
"address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
"ValidationLogic": {
|
||||
"buidlerevm": {
|
||||
"address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574",
|
||||
"address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
"LendingPool": {
|
||||
"buidlerevm": {
|
||||
"address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
"address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e"
|
||||
}
|
||||
},
|
||||
"LendingPoolConfigurator": {
|
||||
|
@ -198,7 +197,7 @@
|
|||
},
|
||||
"ATokensAndRatesHelper": {
|
||||
"buidlerevm": {
|
||||
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
|
||||
"address": "0x06bA8d8af0dF898D0712DffFb0f862cC51AF45c2",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
|
@ -265,5 +264,17 @@
|
|||
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
"MintableDelegationERC20": {
|
||||
"buidlerevm": {
|
||||
"address": "0x77B0b5636fEA30eA79BB65AeCCdb599997A849A8",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
"AToken": {
|
||||
"buidlerevm": {
|
||||
"address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
LendingPoolFactory,
|
||||
LendingPoolLibraryAddresses,
|
||||
LendingRateOracleFactory,
|
||||
MintableDelegationErc20Factory,
|
||||
MintableErc20Factory,
|
||||
MockAggregatorFactory,
|
||||
MockATokenFactory,
|
||||
|
@ -48,6 +49,7 @@ import {withSaveAndVerify, registerContractInJsonDb, linkBytecode} from './contr
|
|||
import {StableAndVariableTokensHelperFactory} from '../types/StableAndVariableTokensHelperFactory';
|
||||
import {MockStableDebtToken} from '../types/MockStableDebtToken';
|
||||
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
|
||||
import {MintableDelegationErc20} from '../types/MintableDelegationErc20';
|
||||
|
||||
export const deployLendingPoolAddressesProvider = async (verify?: boolean) =>
|
||||
withSaveAndVerify(
|
||||
|
@ -255,6 +257,16 @@ export const deployMintableERC20 = async (
|
|||
verify
|
||||
);
|
||||
|
||||
export const deployMintableDelegationERC20 = async (
|
||||
args: [string, string, string],
|
||||
verify?: boolean
|
||||
): Promise<MintableDelegationErc20> =>
|
||||
withSaveAndVerify(
|
||||
await new MintableDelegationErc20Factory(await getFirstSigner()).deploy(...args),
|
||||
eContractid.MintableDelegationERC20,
|
||||
args,
|
||||
verify
|
||||
);
|
||||
export const deployDefaultReserveInterestRateStrategy = async (
|
||||
args: [tEthereumAddress, string, string, string, string, string],
|
||||
verify: boolean
|
||||
|
|
|
@ -28,6 +28,7 @@ export enum eContractid {
|
|||
Example = 'Example',
|
||||
LendingPoolAddressesProvider = 'LendingPoolAddressesProvider',
|
||||
MintableERC20 = 'MintableERC20',
|
||||
MintableDelegationERC20 = 'MintableDelegationERC20',
|
||||
LendingPoolAddressesProviderRegistry = 'LendingPoolAddressesProviderRegistry',
|
||||
LendingPoolParametersProvider = 'LendingPoolParametersProvider',
|
||||
LendingPoolConfigurator = 'LendingPoolConfigurator',
|
||||
|
@ -73,6 +74,10 @@ export enum eContractid {
|
|||
* - P = Pausable
|
||||
*/
|
||||
export enum ProtocolErrors {
|
||||
//common errors
|
||||
CALLER_NOT_AAVE_ADMIN = '33', // 'The caller must be the aave admin'
|
||||
|
||||
//contract specific errors
|
||||
VL_AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
|
||||
VL_NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
|
||||
VL_RESERVE_FROZEN = '3', // 'Action requires an unfrozen reserve'
|
||||
|
@ -105,7 +110,6 @@ export enum ProtocolErrors {
|
|||
AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
||||
AT_TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
||||
RL_RESERVE_ALREADY_INITIALIZED = '32', // 'Reserve has already been initialized'
|
||||
LPC_CALLER_NOT_AAVE_ADMIN = '33', // 'The caller must be the aave admin'
|
||||
LPC_RESERVE_LIQUIDITY_NOT_0 = '34', // 'The liquidity of the reserve needs to be 0'
|
||||
LPC_INVALID_ATOKEN_POOL_ADDRESS = '35', // 'The liquidity of the reserve needs to be 0'
|
||||
LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36', // 'The liquidity of the reserve needs to be 0'
|
||||
|
|
58
test/delegation-aware-atoken.spec.ts
Normal file
58
test/delegation-aware-atoken.spec.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import {MAX_UINT_AMOUNT, ZERO_ADDRESS} from '../helpers/constants';
|
||||
import {BUIDLEREVM_CHAINID} from '../helpers/buidler-constants';
|
||||
import {buildPermitParams, getSignatureFromTypedData} from '../helpers/contracts-helpers';
|
||||
import {expect} from 'chai';
|
||||
import {ethers} from 'ethers';
|
||||
import {eEthereumNetwork, ProtocolErrors} from '../helpers/types';
|
||||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||
import {BRE} from '../helpers/misc-utils';
|
||||
import {
|
||||
ConfigNames,
|
||||
getATokenDomainSeparatorPerNetwork,
|
||||
loadPoolConfig,
|
||||
} from '../helpers/configuration';
|
||||
import {waitForTx} from '../helpers/misc-utils';
|
||||
import {
|
||||
deployDelegationAwareAToken,
|
||||
deployMintableDelegationERC20,
|
||||
} from '../helpers/contracts-deployments';
|
||||
import {DelegationAwareATokenFactory} from '../types';
|
||||
import {DelegationAwareAToken} from '../types/DelegationAwareAToken';
|
||||
import {MintableDelegationErc20} from '../types/MintableDelegationErc20';
|
||||
|
||||
const {parseEther} = ethers.utils;
|
||||
|
||||
makeSuite('AToken: underlying delegation', (testEnv: TestEnv) => {
|
||||
const poolConfig = loadPoolConfig(ConfigNames.Commons);
|
||||
let delegationAToken = <DelegationAwareAToken>{};
|
||||
let delegationERC20 = <MintableDelegationErc20>{};
|
||||
|
||||
it('Deploys a new MintableDelegationERC20 and a DelegationAwareAToken', async () => {
|
||||
const {pool} = testEnv;
|
||||
|
||||
delegationERC20 = await deployMintableDelegationERC20(['DEL', 'DEL', '18']);
|
||||
|
||||
delegationAToken = await deployDelegationAwareAToken(
|
||||
[pool.address, delegationERC20.address, 'aDEL', 'aDEL', ZERO_ADDRESS],
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it('Tries to delegate with the caller not being the Aave admin', async () => {
|
||||
const {users} = testEnv;
|
||||
|
||||
await expect(
|
||||
delegationAToken.connect(users[1].signer).delegateUnderlyingTo(users[2].address)
|
||||
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_AAVE_ADMIN);
|
||||
});
|
||||
|
||||
it('Tries to delegate to user 2', async () => {
|
||||
const {users} = testEnv;
|
||||
|
||||
await delegationAToken.delegateUnderlyingTo(users[2].address);
|
||||
|
||||
const delegateeAddress = await delegationERC20.delegatee();
|
||||
|
||||
expect(delegateeAddress).to.be.equal(users[2].address);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user