-
Notifications
You must be signed in to change notification settings - Fork 1
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
Merged
gianfra-t
merged 5 commits into
22-add-experimental-test-command
from
26-use-runtime-managed-erc20-tokens-in-tests
Oct 20, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27a8096
WIP replacing MockERC20 with Runtime connected wrapper erc20
gianfra-t 480962f
fix deadline issue in swap.ts test
gianfra-t fe01d54
point to master for pendulumWrapper contracts
gianfra-t ec682a0
review comment fix
gianfra-t b1e2938
comments and solang path reset
gianfra-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ Alternatively you can use the parameter `local` instead of `foucoco`. This expec | |
``` | ||
brew install binaryen | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
|
||
import { TestContract, TestSuiteEnvironment } from "../../src/index"; | ||
import { assertApproxEqAbs, assertApproxEqRel, assertEq, assertGt, assertLt, e } from "../../src/index"; | ||
|
||
const MAX_UINT256 = 2n ** 256n - 1n; | ||
|
||
const BOB = "6k6gXPB9idebCxqSJuqpjPaqfYLQbdLHhvsANH8Dg8GQN3tT"; | ||
|
||
export default async function (environment: TestSuiteEnvironment) { | ||
const { | ||
address, | ||
unit, | ||
milliUnit, | ||
microUnit, | ||
getContractByAddress, | ||
vm, | ||
tester, | ||
constructors: { | ||
newTestableERC20Wrapper, | ||
}, | ||
} = environment; | ||
|
||
let router: TestContract; | ||
let backstop: TestContract; | ||
let swapPool1: TestContract; | ||
let swapPool2: TestContract; | ||
|
||
const assetNative = await newTestableERC20Wrapper("TestNative", "TEST1", 12, [0], [0], [], []); | ||
const token1 = await newTestableERC20Wrapper("TestNonNative", "TEST2", 12, [1], [1], [], []); | ||
|
||
const MINT_AMOUNT = unit(10000); | ||
const BURN_AMOUNT = unit(10); | ||
|
||
return { | ||
async setUp() { | ||
|
||
}, | ||
async testMintsNative() { | ||
let totalSupplyBef = await assetNative.totalSupply(); | ||
await assetNative.mint(BOB, MINT_AMOUNT); | ||
let totalSupplyAft = await assetNative.totalSupply(); | ||
|
||
assertEq(totalSupplyAft - totalSupplyBef, MINT_AMOUNT); | ||
}, | ||
|
||
async testMintsTokensPallet() { | ||
let totalSupplyBef = await token1.totalSupply(); | ||
let balanceBobBef = await token1.balanceOf(BOB); | ||
|
||
await token1.mint(BOB, MINT_AMOUNT); | ||
|
||
let totalSupplyAft = await token1.totalSupply(); | ||
let balanceBob = await token1.balanceOf(BOB); | ||
|
||
assertEq(totalSupplyAft - totalSupplyBef, MINT_AMOUNT); | ||
assertEq(balanceBob - balanceBobBef, MINT_AMOUNT); | ||
}, | ||
|
||
async testBurnsNative() { | ||
let totalSupplyBef = await assetNative.totalSupply(); | ||
await assetNative.burn(BOB, BURN_AMOUNT); | ||
let totalSupplyAft = await assetNative.totalSupply(); | ||
|
||
assertEq(totalSupplyBef - totalSupplyAft, BURN_AMOUNT); | ||
}, | ||
|
||
async testBurnsToken() { | ||
let totalSupplyBef = await token1.totalSupply(); | ||
await token1.burn(BOB, BURN_AMOUNT); | ||
let totalSupplyAft = await token1.totalSupply(); | ||
|
||
assertEq(totalSupplyBef - totalSupplyAft, BURN_AMOUNT); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 wemint
?There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!