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

26 use runtime managed erc20 tokens in tests #27

Conversation

gianfra-t
Copy link
Contributor

@gianfra-t gianfra-t commented Sep 29, 2023

Issue: #26.

Replaced the dependency on MockERC20 for TestableERC20 contract that interacts with the standalone chain during tests.

The tests were modified accordingly to work in this manner. Specifically cleaning token balances before execution of the tests and modifying time delay for swapExecution. Also added a test specific to the TestableERC20Wrapper.

The corresponding modifications for foucococo-standalone and pendulum-wrappers for this to work were made here and here respectively.

@gianfra-t gianfra-t linked an issue Sep 29, 2023 that may be closed by this pull request
@gianfra-t gianfra-t changed the base branch from main to 22-add-experimental-test-command September 29, 2023 16:16
@gianfra-t gianfra-t force-pushed the 26-use-runtime-managed-erc20-tokens-in-tests branch from 3a8f809 to bdd03de Compare October 4, 2023 15:09
@gianfra-t gianfra-t force-pushed the 26-use-runtime-managed-erc20-tokens-in-tests branch from 51d35f6 to fe01d54 Compare October 6, 2023 16:16
@gianfra-t gianfra-t marked this pull request as ready for review October 6, 2023 16:17
Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

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

Looks good to me overall but left some comments.

nabla/test/TestableERC20Tests.ts Outdated Show resolved Hide resolved
nabla/test/TestableERC20Tests.ts Outdated Show resolved Hide resolved
nabla/test/backstop.ts Outdated Show resolved Hide resolved
nabla/test/swaps.ts Show resolved Hide resolved
@@ -118,17 +120,30 @@ export default async function (environment: TestSuiteEnvironment) {
await backstop.addSwapPool(address(swapPool1), 0);
await backstop.addSwapPool(address(swapPool2), 0);


await asset1.burn(tester, await asset1.balanceOf(tester));
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to burn before we mint?

Copy link
Member

Choose a reason for hiding this comment

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

If this is related to

Specifically cleaning token balances before execution of the tests and modifying time delay for swapExecution.

Maybe we should find a clearer way to do this? How about a teardown function, or we add cleanup-related code to the end of each test? Otherwise we should maybe at least add a comment that explains why we burn before we mint.

Copy link
Contributor Author

@gianfra-t gianfra-t Oct 9, 2023

Choose a reason for hiding this comment

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

Indeed this is just to ensure that the balance of the tokens for the relevant accounts is 0 before the mint and at the end of this setUp() function we have only the expected minted amount.

I will add some comments to clarify this, but I don't think we should add another function since we are already in the setUp() function and this is the cleanup for a test that came before (if any), let me know it makes sense @ebma.

BTW, it is true that perhaps a teardown at the end also makes sense, but given that the tests stops if there is an error, as of now I don't think there is a way to actually make sure that the teardown actually runs. That's why I think for now cleaning just in case in the setUp makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I see your point. Although we don't support 'teardown' functions yet, we could just try to execute them (if any) in a new finally {} block at the end of the try-catch here. This way it will be executed in any case.

I'm also fine with your existing implementation actually, the only thing that bothers me a bit is that the comment reasoning why we need to burn before minting is only included in one file. And I see why since copy-pasting it into any file is annoying. But with a teardown function for each test, it might be self-explanatory enough that we don't even need a comment in the first place. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree that would be the better approach. Could we perhaps open a separate issue and wait for this one? Since it would be touching a separate part of the code logic not just the tests but also how they run.
In the meantime if you are okay with it I can just copy the comment to all the setups so we don't forget what is going on.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good 👍 could you create that follow-up ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

src/actions/compileContract.ts Outdated Show resolved Hide resolved
nabla/test/TestableERC20Tests.ts Outdated Show resolved Hide resolved
@@ -118,17 +120,30 @@ export default async function (environment: TestSuiteEnvironment) {
await backstop.addSwapPool(address(swapPool1), 0);
await backstop.addSwapPool(address(swapPool2), 0);


await asset1.burn(tester, await asset1.balanceOf(tester));
Copy link
Member

Choose a reason for hiding this comment

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

Right, I see your point. Although we don't support 'teardown' functions yet, we could just try to execute them (if any) in a new finally {} block at the end of the try-catch here. This way it will be executed in any case.

I'm also fine with your existing implementation actually, the only thing that bothers me a bit is that the comment reasoning why we need to burn before minting is only included in one file. And I see why since copy-pasting it into any file is annoying. But with a teardown function for each test, it might be self-explanatory enough that we don't even need a comment in the first place. WDYT?

Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

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

LGTM

@ebma
Copy link
Member

ebma commented Oct 20, 2023

@gianfra-t you can merge this now if you don't want to add anything. Usually, the author of the PR merges it once approved, because sometimes it might be that the author still wants to add something after it got approved by someone else which would be missed if the reviewer merges it.

@gianfra-t gianfra-t merged commit ba1123b into 22-add-experimental-test-command Oct 20, 2023
@ebma ebma deleted the 26-use-runtime-managed-erc20-tokens-in-tests branch December 15, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use runtime managed ERC20 tokens in tests
3 participants