Skip to content

Commit

Permalink
contracts: migration simulation: Test migration simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Mar 29, 2021
1 parent 3b94746 commit 61309eb
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 150 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ brownie pm install OpenZeppelin/[email protected]

Run, from `packages/contracts/`:
```
brownie test -s
brownie test tests/simulation_test.py -s
brownie test tests/migration_test.py -s
```

### OpenEthereum
Expand All @@ -644,7 +645,8 @@ yarn start-dev-chain:openethereum

Then, again from `packages/contracts/`, run it with:
```
brownie test -s --network openethereum
brownie test tests/simulation_test.py -s --network openethereum
brownie test tests/migration_test.py -s --network openethereum
```

To stop the Openethereum node, you can do it with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.6.11;

import "../TroveManager.sol";


contract TroveManagerNoBootstrap is TroveManager {
function _requireAfterBootstrapPeriod() internal view override {}
}
2 changes: 1 addition & 1 deletion packages/contracts/contracts/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
require(_getTCR(_price) >= MCR, "TroveManager: Cannot redeem when TCR < MCR");
}

function _requireAfterBootstrapPeriod() internal view {
function _requireAfterBootstrapPeriod() internal view virtual {
uint systemDeploymentTime = lqtyToken.getDeploymentStartTime();
require(block.timestamp >= systemDeploymentTime.add(BOOTSTRAP_PERIOD), "TroveManager: Redemptions are not allowed during bootstrap phase");
}
Expand Down
150 changes: 148 additions & 2 deletions packages/contracts/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from brownie import Wei
import pytest

from brownie import *
from accounts import *

ZERO_ADDRESS = '0x' + '0'.zfill(40)
MAX_BYTES_32 = '0x' + 'F' * 64
MAX_FEE = Wei(1e18)

class Contracts: pass

def floatToWei(amount):
return Wei(amount * 1e18)

def logGlobalState(contracts):
def logGlobalState(contracts, message=""):
print('\n ---- Global state ----')
if message != "":
print(message)
print('Num troves ', contracts.sortedTroves.getSize())
activePoolColl = contracts.activePool.getETH()
activePoolDebt = contracts.activePool.getLUSDDebt()
Expand All @@ -32,3 +40,141 @@ def logGlobalState(contracts):
#print('Last trove ', last_trove)
print('Last trove’s ICR', last_ICR.to("ether"))
print(' ----------------------\n')

def setAddresses(contracts):
contracts.sortedTroves.setParams(
MAX_BYTES_32,
contracts.troveManager.address,
contracts.borrowerOperations.address,
{ 'from': accounts[0] }
)

contracts.troveManager.setAddresses(
contracts.borrowerOperations.address,
contracts.activePool.address,
contracts.defaultPool.address,
contracts.stabilityPool.address,
contracts.gasPool.address,
contracts.collSurplusPool.address,
contracts.priceFeedTestnet.address,
contracts.lusdToken.address,
contracts.sortedTroves.address,
contracts.lqtyToken.address,
contracts.lqtyStaking.address,
{ 'from': accounts[0] }
)

contracts.borrowerOperations.setAddresses(
contracts.troveManager.address,
contracts.activePool.address,
contracts.defaultPool.address,
contracts.stabilityPool.address,
contracts.gasPool.address,
contracts.collSurplusPool.address,
contracts.priceFeedTestnet.address,
contracts.sortedTroves.address,
contracts.lusdToken.address,
contracts.lqtyStaking.address,
{ 'from': accounts[0] }
)

contracts.stabilityPool.setAddresses(
contracts.borrowerOperations.address,
contracts.troveManager.address,
contracts.activePool.address,
contracts.lusdToken.address,
contracts.sortedTroves.address,
contracts.priceFeedTestnet.address,
contracts.communityIssuance.address,
{ 'from': accounts[0] }
)

contracts.activePool.setAddresses(
contracts.borrowerOperations.address,
contracts.troveManager.address,
contracts.stabilityPool.address,
contracts.defaultPool.address,
{ 'from': accounts[0] }
)

contracts.defaultPool.setAddresses(
contracts.troveManager.address,
contracts.activePool.address,
{ 'from': accounts[0] }
)

contracts.collSurplusPool.setAddresses(
contracts.borrowerOperations.address,
contracts.troveManager.address,
contracts.activePool.address,
{ 'from': accounts[0] }
)

contracts.hintHelpers.setAddresses(
contracts.sortedTroves.address,
contracts.troveManager.address,
{ 'from': accounts[0] }
)

# LQTY
contracts.lqtyStaking.setAddresses(
contracts.lqtyToken.address,
contracts.lusdToken.address,
contracts.troveManager.address,
contracts.borrowerOperations.address,
contracts.activePool.address,
{ 'from': accounts[0] }
)

contracts.communityIssuance.setAddresses(
contracts.lqtyToken.address,
contracts.stabilityPool.address,
{ 'from': accounts[0] }
)

def deploy_contracts():
contracts = Contracts()

contracts.priceFeedTestnet = PriceFeedTestnet.deploy({ 'from': accounts[0] })
contracts.sortedTroves = SortedTroves.deploy({ 'from': accounts[0] })
#contracts.troveManager = TroveManager.deploy({ 'from': accounts[0] })
contracts.troveManager = TroveManagerNoBootstrap.deploy({ 'from': accounts[0] })
contracts.activePool = ActivePool.deploy({ 'from': accounts[0] })
contracts.stabilityPool = StabilityPool.deploy({ 'from': accounts[0] })
contracts.gasPool = GasPool.deploy({ 'from': accounts[0] })
contracts.defaultPool = DefaultPool.deploy({ 'from': accounts[0] })
contracts.collSurplusPool = CollSurplusPool.deploy({ 'from': accounts[0] })
contracts.borrowerOperations = BorrowerOperations.deploy({ 'from': accounts[0] })
contracts.hintHelpers = HintHelpers.deploy({ 'from': accounts[0] })
contracts.lusdToken = LUSDToken.deploy(
contracts.troveManager.address,
contracts.stabilityPool.address,
contracts.borrowerOperations.address,
{ 'from': accounts[0] }
)
# LQTY
contracts.lqtyStaking = LQTYStaking.deploy({ 'from': accounts[0] })
contracts.communityIssuance = CommunityIssuance.deploy({ 'from': accounts[0] })
contracts.lockupContractFactory = LockupContractFactory.deploy({ 'from': accounts[0] })
contracts.lqtyToken = LQTYToken.deploy(
contracts.communityIssuance.address,
contracts.lqtyStaking.address,
contracts.lockupContractFactory.address,
accounts[1], # bountyAddress
accounts[1], # lpRewardsAddress
{ 'from': accounts[0] }
)

setAddresses(contracts)

return contracts

@pytest.fixture
@pytest.mark.require_network("openethereum")
def add_accounts(scope="module"):
import_accounts(accounts)
"""
if network.show_active() != 'development':
print("Importing accounts...")
import_accounts(accounts)
"""
Loading

0 comments on commit 61309eb

Please sign in to comment.