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

[P1-N08] Converge upon single source of time for all contracts in testing environments #1236

Merged
merged 24 commits into from
Apr 15, 2020

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Apr 14, 2020

Resolves #1047

This PR separates the time storage in Testable.sol from the external methods. This contract requires a lot of down stream changes to tests and scripts because it rejects our previous assumption that each Testable contract maintains its own sense of time.

The major change is that the input bool isTest into Testable.sol is replaced with an address timerAddress. If the address is anything besides the zero address, then the contract is set to a testing environment and Testable.setCurrentTime() can be called on the Timer contract at the input address. If the address passed in is the zero address, then the contract is considered to be in production, and Testable will always return now as the currentTime.

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@nicholaspai nicholaspai added the audit-fix-phase1 Fixes for Phase 1 (DVM) of the OZ audit label Apr 14, 2020
@mrice32 mrice32 changed the title [P0-N08] Converge upon single source of time for all contracts in testing environments [P1-N08] Converge upon single source of time for all contracts in testing environments Apr 14, 2020
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@@ -90,7 +90,7 @@ const initializeSystem = async function(callback) {
};
await tokenizedDerivativeCreator.createTokenizedDerivative(defaultConstructorParams, { from: sponsor });

const derivatives = await deployedRegistry.getRegisteredDerivatives(sponsor);
const derivatives = await deployedRegistry.getRegisteredContracts(sponsor);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this PR but this contract method has since been renamed.

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@nicholaspai nicholaspai marked this pull request as ready for review April 14, 2020 19:58
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A few minor comments.

@@ -63,9 +63,9 @@ abstract contract FeePayer is Testable {
* @notice Constructs the FeePayer contract. Called by child contracts.
* @param collateralAddress ERC20 token that is used as the underlying collateral for the synthetic.
* @param finderAddress UMA protocol Finder used to discover other protocol contracts.
* @param isTest whether this contract is being constructed for the purpose of running tests.
* @param timerAddress Universal store of time for contracts in test environment.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would add that this parameter should be set to 0x0 for production environments, so they will fall back to block time. Here and elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Changed to:

     * @param _timerAddress Contract that stores the current time in a testing environment. Should be set to 0x0 for production environments that use live time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One very tiny nit. I would change should to must.

core/migrations/3_deploy_timer.js Outdated Show resolved Hide resolved
@@ -0,0 +1,8 @@
const Timer = artifacts.require("Timer");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this here because I can't comment on a moved file.

Why move support identifiers from step 10 to step 20 rather than preserve the ordering? The only reason I suggest that we keep the ordering is that they were previously separated into DVM-related migrations (1-10), TD-related migrations (11-16), and EMP-related migrations (17-19). This was to make selective deployments a little easier, specifically, deploying the DVM without any contract creators.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this was a fat finger on my part. I needed to move the Timer migration earlier because its an upstream dependency for a lot of contracts, but accidentally bumped support identifiers to last. Will fix.

Copy link
Member Author

@nicholaspai nicholaspai Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited order:

Screen Shot 2020-04-14 at 18 57 12

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM outside of a tiny nit on the @param comment.

@@ -63,9 +63,9 @@ abstract contract FeePayer is Testable {
* @notice Constructs the FeePayer contract. Called by child contracts.
* @param collateralAddress ERC20 token that is used as the underlying collateral for the synthetic.
* @param finderAddress UMA protocol Finder used to discover other protocol contracts.
* @param isTest whether this contract is being constructed for the purpose of running tests.
* @param timerAddress Contract that stores the current time in a testing environment. Should be set to 0x0 for production environments that use live time.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param timerAddress Contract that stores the current time in a testing environment. Should be set to 0x0 for production environments that use live time.
* @param timerAddress Contract that stores the current time in a testing environment.
* Should be set to 0x0 for production environments that use live time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string is way too long. Can we split them and try keep it below the 120 char limit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I'll make this change throughout the PR

Copy link
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks @nicholaspai, this will really make testing easier into the future. I'm happy except for a few nits on commenting. Please add the natspec to the new Testable files and ensure that the comments you've added to the other contracts are less than 120 chars in length.

mr_bean

Co-Authored-By: Chris Maree <christopher.maree@gmail.com>
nicholaspai and others added 8 commits April 15, 2020 08:35
Co-Authored-By: Chris Maree <christopher.maree@gmail.com>
Co-Authored-By: Chris Maree <christopher.maree@gmail.com>
Co-Authored-By: Chris Maree <christopher.maree@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@nicholaspai
Copy link
Member Author

@mrice32 @chrismaree @ptare Have responde to all comments, any outstanding issues before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-fix-phase1 Fixes for Phase 1 (DVM) of the OZ audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor testable.sol to report one constant time from all contracts that use it
4 participants