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

chore: Release Cleanup #17

Merged
merged 1 commit into from
Mar 17, 2022
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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ cd xMPL
forge update
```
#### Running Tests
- To run all tests: `make test` (runs `./test.sh`)
- To run a specific test function: `./test.sh -t <test_name>` (e.g., `./test.sh -t test_deposit`)
- To run tests with a specified number of fuzz runs: `./test.sh -r <runs>` (e.g., `./test.sh -t test_deposit -r 10000`)
- To run all unit/fuzz tests: `make test` (runs `./test.sh`)
- To run all invariant tests: `make invariant` (runs `./invariant.sh`)
- To run all tests (unit/fuzz and invariant tests): `make test-all`
- To run specific unit tests: `./test.sh -t <test_name>` (e.g., `./test.sh -t test_scheduleMigration`)
- To run specific invariant tests: `./invariant-test.sh -t <test_name>` (e.g., `./invariant-test.sh -t invariant_totalSupply`)
- To run specific fuzz tests with a specified number of fuzz runs: `./test.sh -r <runs>` (e.g., `./test.sh -t testFuzz_performMigration -r 10000`)

This project was built using [Foundry](https://github.com/gakonst/Foundry).

Expand Down
28 changes: 14 additions & 14 deletions contracts/test/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ pragma solidity ^0.8.7;

import { TestUtils, InvariantTest } from "../../modules/contract-test-utils/contracts/test.sol";
import { Migrator } from "../../modules/mpl-migration/contracts/Migrator.sol";
import { InvariantStakerManager } from "../../modules/revenue-distribution-token/contracts/test/accounts/Staker.sol";
import { InvariantERC20User } from "../../modules/revenue-distribution-token/contracts/test/accounts/ERC20User.sol";
import { InvariantStakerManager } from "../../modules/revenue-distribution-token/contracts/test/accounts/Staker.sol";
import { Warper } from "../../modules/revenue-distribution-token/contracts/test/accounts/Warper.sol";
import { MockERC20 } from "../../modules/revenue-distribution-token/modules/erc20/contracts/test/mocks/MockERC20.sol";
import { RDTInvariants, MutableRDT } from "../../modules/revenue-distribution-token/contracts/test/Invariants.t.sol";
import { MockERC20 } from "../../modules/revenue-distribution-token/modules/erc20/contracts/test/mocks/MockERC20.sol";

import { xMPLInvariantOwner } from "./accounts/Owner.sol";

import { MutableXMPL } from "./mocks/Mocks.sol";

contract xMPLInvariants is RDTInvariants {

InvariantERC20User _newErc20User;
Migrator _migrator;
MockERC20 _newUnderlying;
xMPLInvariantOwner owner_; // Different from inherited _owner
InvariantERC20User internal _newErc20User;
Migrator internal _migrator;
MockERC20 internal _newUnderlying;
xMPLInvariantOwner internal _invariantOwner; // Different from inherited _owner

bool migrated;

Expand All @@ -27,24 +27,24 @@ contract xMPLInvariants is RDTInvariants {
_newUnderlying = new MockERC20("NewMockToken", "NMT", 18);
_migrator = new Migrator(address(_underlying), address(_newUnderlying));

_rdToken = MutableRDT(address(new MutableXMPL("Revenue Distribution Token", "RDT", address(this), address(_underlying), 1e30)));
_rdToken = MutableRDT(address(new MutableXMPL("Revenue Distribution Token", "RDT", address(this), address(_underlying), 1e30)));

_erc20User = new InvariantERC20User(address(_rdToken), address(_underlying));
_newErc20User = new InvariantERC20User(address(_rdToken), address(_underlying));
_stakerManager = new InvariantStakerManager(address(_rdToken), address(_underlying));
owner_ = new xMPLInvariantOwner(address(_rdToken), address(_underlying), address(_migrator), address(_newUnderlying));
_warper = new Warper();
_erc20User = new InvariantERC20User(address(_rdToken), address(_underlying));
_newErc20User = new InvariantERC20User(address(_rdToken), address(_underlying));
_stakerManager = new InvariantStakerManager(address(_rdToken), address(_underlying));
_invariantOwner = new xMPLInvariantOwner(address(_rdToken), address(_underlying), address(_migrator), address(_newUnderlying));
_warper = new Warper();

// Required to prevent `acceptOwner` from being a target function
_rdToken.setOwner(address(owner_));
_rdToken.setOwner(address(_invariantOwner));

// Performs random transfers of underlying into contract
addTargetContract(address(_erc20User));
addTargetContract(address(_newErc20User));

// Performs random transfers of underlying into contract
// Performs random updateVestingSchedule calls
addTargetContract(address(owner_));
addTargetContract(address(_invariantOwner));

// Performs random instantiations of new staker users
// Performs random deposit calls from a random instantiated staker
Expand Down
171 changes: 157 additions & 14 deletions contracts/test/RDT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@
pragma solidity 0.8.7;

import { RevenueDistributionToken as RDT } from "../../modules/revenue-distribution-token/contracts/RevenueDistributionToken.sol";

import { Staker } from "../../modules/revenue-distribution-token/contracts/test/accounts/Staker.sol";
import { Staker } from "../../modules/revenue-distribution-token/contracts/test/accounts/Staker.sol";
import { MockERC20 } from "../../modules/revenue-distribution-token/modules/erc20/contracts/test/mocks/MockERC20.sol";

import {
AuthTest,
DepositAndMintTest,
DepositAndMintWithPermitTest,
ExitTest,
RevenueStreamingTest
AuthTests,
ConstructorTest,
DepositFailureTests,
DepositTests,
DepositWithPermitFailureTests,
DepositWithPermitTests,
EndToEndRevenueStreamingTests,
MintFailureTests,
MintTests,
MintWithPermitFailureTests,
MintWithPermitTests,
RedeemCallerNotOwnerTests,
RedeemFailureTests,
RedeemRevertOnTransfers,
RedeemTests,
RevenueStreamingTests,
WithdrawCallerNotOwnerTests,
WithdrawFailureTests,
WithdrawRevertOnTransfers,
WithdrawTests
} from "../../modules/revenue-distribution-token/contracts/test/RevenueDistributionToken.t.sol";

import { MockERC20 } from "../../modules/revenue-distribution-token/modules/erc20/contracts/test/mocks/MockERC20.sol";

import { xMPL } from "../xMPL.sol";

contract xMPL_RDT_AuthTest is AuthTest {
contract xMPL_RDT_AuthTests is AuthTests {

function setUp() override public {
super.setUp();
Expand All @@ -26,7 +39,45 @@ contract xMPL_RDT_AuthTest is AuthTest {

}

contract xMPL_RDT_DepositAndMintTest is DepositAndMintTest {
contract xMPL_RDT_ConstructorTest is ConstructorTest { }

contract xMPL_RDT_DepositFailureTests is DepositFailureTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_DepositTests is DepositTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_DepositWithPermitFailureTests is DepositWithPermitFailureTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_DepositWithPermitTests is DepositWithPermitTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_EndToEndRevenueStreamingTests is EndToEndRevenueStreamingTests {

function setUp() override public {
super.setUp();
Expand All @@ -35,7 +86,7 @@ contract xMPL_RDT_DepositAndMintTest is DepositAndMintTest {

}

contract xMPL_RDT_DepositAndMintWithPermitTest is DepositAndMintWithPermitTest {
contract xMPL_RDT_MintFailureTests is MintFailureTests {

function setUp() override public {
super.setUp();
Expand All @@ -44,7 +95,7 @@ contract xMPL_RDT_DepositAndMintWithPermitTest is DepositAndMintWithPermitTest {

}

contract xMPL_RDT_ExitTest is ExitTest {
contract xMPL_RDT_MintTests is MintTests {

function setUp() override public {
super.setUp();
Expand All @@ -53,16 +104,108 @@ contract xMPL_RDT_ExitTest is ExitTest {

}

contract xMPL_RDT_RevenueStreamingTest is RevenueStreamingTest {
contract xMPL_RDT_MintWithPermitFailureTests is MintWithPermitFailureTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_MintWithPermitTests is MintWithPermitTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_RedeemCallerNotOwnerTests is RedeemCallerNotOwnerTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_RedeemFailureTests is RedeemFailureTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_RedeemRevertOnTransfers is RedeemRevertOnTransfers {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(revertingAsset), 1e30)));
}

}

contract xMPL_RDT_RedeemTests is RedeemTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_RevenueStreamingTests is RevenueStreamingTests {

function setUp() override public {
super.setUp();

rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));

// Deposit the minimum amount of the asset to allow the vesting schedule updates to occur.
asset.mint(address(firstStaker), startingAssets);

firstStaker.erc20_approve(address(asset), address(rdToken), startingAssets);
firstStaker.rdToken_deposit(address(rdToken), startingAssets);
}

}

contract xMPL_RDT_WithdrawCallerNotOwnerTests is WithdrawCallerNotOwnerTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_WithdrawFailureTests is WithdrawFailureTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}

contract xMPL_RDT_WithdrawRevertOnTransfers is WithdrawRevertOnTransfers {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(revertingAsset), 1e30)));
}

}

contract xMPL_RDT_WithdrawTests is WithdrawTests {

function setUp() override public {
super.setUp();
rdToken = RDT(address(new xMPL("Token", "TKN", address(this), address(asset), 1e30)));
}

}
4 changes: 2 additions & 2 deletions contracts/test/accounts/Owner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ contract xMPLInvariantOwner is InvariantOwner {

IxMPL xmpl = IxMPL(address(_rdToken));

constructor(address rdToken_, address underlying_, address migrator_, address newUnderlying_) InvariantOwner(rdToken_, underlying_){
_migrator = migrator_;
constructor(address rdToken_, address underlying_, address migrator_, address newUnderlying_) InvariantOwner(rdToken_, underlying_) {
_migrator = migrator_;
newUnderlying = newUnderlying_;
}

Expand Down
Loading