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

feat: mint & burn e2e tests for fiattokenfactory #371

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

boojamya
Copy link
Member

Includes:

  • TestFiatTFMint
  • TestFiatTFBurn

Copy link

coderabbitai bot commented May 27, 2024

Walkthrough

The changes introduce new test functions for the fiat-tokenfactory module, specifically targeting the minting and burning functionalities. The tests, TestFiatTFMint and TestFiatTFBurn, cover various scenarios to ensure that minting and burning operations comply with required conditions, such as authorization and state checks. The enhancements aim to improve the test coverage of the module.

Changes

File Change Summary
e2e/fiat_tf_test.go Added new test functions: TestFiatTFMint and TestFiatTFBurn, covering multiple scenarios for minting and burning tokens.

Possibly related PRs

  • feat: owner e2e tests for fiattokenfactory #367: The tests in this PR focus on ownership functionalities in the fiat-tokenfactory, which may interact with the minting and burning operations tested in the main PR, particularly regarding authorization checks.
  • feat: pause e2e tests for fiattokenfactory #369: This PR introduces tests for pausing and unpausing the token factory, which is relevant to the minting and burning tests in the main PR, as these operations are expected to fail when the factory is paused.

Suggested reviewers

  • kaliweh-circle

Poem

In the garden of tokens, we frolic and play,
Minting and burning, in a secure ballet.
With tests all around, we hop without fear,
Ensuring our factory's safe, oh so clear!
So here's to the changes, let's give them a cheer,
For a bountiful harvest, the future is near! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@johnletey johnletey changed the base branch from feat/sdk-eden to main October 17, 2024 09:24
@johnletey johnletey requested a review from a team as a code owner October 17, 2024 09:24
@johnletey johnletey changed the title chore: mint + burn E2E tests for fiat token factory feat: mint & burn e2e tests for fiattokenfactory Oct 17, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8664bcf and c779a9f.

📒 Files selected for processing (1)
  • e2e/fiat_tf_test.go (1 hunks)
🧰 Additional context used

Comment on lines +1292 to +1429
Allowance: sdk.Coin{
Denom: "uusdc",
Amount: preMintAllowance,
},
},
}

require.Equal(t, expectedShowMinters.Minters, showMinterPostMint.Minters)

e2e.UnpauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

// ACTION: Mint from non minter
// EXPECTED: Request fails; amount not minted

w = interchaintest.GetAndFundTestUsers(t, ctx, "alice", math.OneInt(), noble)
alice := w[0]

_, err = val.ExecTx(ctx, alice.KeyName(), "fiat-tokenfactory", "mint", receiver1.FormattedAddress(), "1uusdc")
require.ErrorContains(t, err, "you are not a minter")

bal, err = noble.GetBalance(ctx, receiver1.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.IsZero())

// ACTION: Mint from blacklisted minter
// EXPECTED: Request fails; amount not minted

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nw.FiatTfRoles.Minter)

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", receiver1.FormattedAddress(), "1uusdc")
require.ErrorContains(t, err, "minter address is blacklisted")

bal, err = noble.GetBalance(ctx, receiver1.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.IsZero())

// allowance should not have changed
showMintersRes, err := e2e.ShowMinters(ctx, val, nw.FiatTfRoles.Minter)
require.NoError(t, err, "failed to query show-minter")

require.Equal(t, expectedShowMinters.Minters, showMintersRes.Minters)

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nw.FiatTfRoles.Minter)

// ACTION: Mint to blacklisted account
// EXPECTED: Request fails; amount not minted

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, receiver1)

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", receiver1.FormattedAddress(), "1uusdc")
require.ErrorContains(t, err, "receiver address is blacklisted")

bal, err = noble.GetBalance(ctx, receiver1.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.IsZero())

// allowance should not have changed
showMintersRes, err = e2e.ShowMinters(ctx, val, nw.FiatTfRoles.Minter)
require.NoError(t, err, "failed to query show-minter")

require.Equal(t, expectedShowMinters.Minters, showMintersRes.Minters)

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, receiver1)

// ACTION: Mint an amount that exceeds the minters allowance
// EXPECTED: Request fails; amount not minted

exceedAllowance := preMintAllowance.Add(math.NewInt(99))
_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", receiver1.FormattedAddress(), fmt.Sprintf("%duusdc", exceedAllowance.Int64()))
require.ErrorContains(t, err, "minting amount is greater than the allowance")

bal, err = noble.GetBalance(ctx, receiver1.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.IsZero())

// allowance should not have changed
showMintersRes, err = e2e.ShowMinters(ctx, val, nw.FiatTfRoles.Minter)
require.NoError(t, err, "failed to query show-minter")
require.Equal(t, expectedShowMinters.Minters, showMintersRes.Minters)

// ACTION: Successfully mint into an account
// EXPECTED: Success

mintAmount := int64(3)
_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", receiver1.FormattedAddress(), fmt.Sprintf("%duusdc", mintAmount))
require.NoError(t, err, "error minting")

bal, err = noble.GetBalance(ctx, receiver1.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.Equal(math.NewInt(mintAmount)))

showMintersRes, err = e2e.ShowMinters(ctx, val, nw.FiatTfRoles.Minter)
require.NoError(t, err, "failed to query show-minter")
expectedShowMinters.Minters.Allowance = sdk.Coin{
Denom: "uusdc",
Amount: preMintAllowance.Sub(math.NewInt(mintAmount)),
}

require.Equal(t, expectedShowMinters.Minters, showMintersRes.Minters)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Organize TestFiatTFMint using sub-tests for clarity

The TestFiatTFMint function contains multiple test scenarios within a single function. Consider using t.Run to create sub-tests for each scenario. This approach enhances readability, allows for better isolation of test cases, and provides more detailed test output.

Comment on lines +1431 to +1523
func TestFiatTFBurn(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Parallel()

ctx := context.Background()

nw := e2e.NobleSpinUp(t, ctx, true)
noble := nw.Chain
val := noble.Validators[0]

// setup - mint into minter's wallet
mintAmount := int64(5)
_, err := val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", nw.FiatTfRoles.Minter.FormattedAddress(), fmt.Sprintf("%duusdc", mintAmount))
require.NoError(t, err, "error minting")

bal, err := noble.GetBalance(ctx, nw.FiatTfRoles.Minter.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.EqualValues(t, mintAmount, bal.Int64())

// ACTION: Burn while TF is paused
// EXPECTED: Request fails; amount not burned

e2e.PauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

burnAmount := int64(1)
_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "burn", fmt.Sprintf("%duusdc", burnAmount))
require.ErrorContains(t, err, "burning is paused")

bal, err = noble.GetBalance(ctx, nw.FiatTfRoles.Minter.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.EqualValues(t, mintAmount, bal.Int64(), "minters balance should not have decreased")

e2e.UnpauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

// ACTION: Burn from non minter account
// EXPECTED: Request fails; amount not burned

w := interchaintest.GetAndFundTestUsers(t, ctx, "alice", math.NewInt(burnAmount), noble)
alice := w[0]

// mint into Alice's account to give her a balance to burn
_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", alice.FormattedAddress(), fmt.Sprintf("%duusdc", mintAmount))
require.NoError(t, err, "error minting")

bal, err = noble.GetBalance(ctx, alice.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.True(t, bal.Equal(math.NewInt(mintAmount)))

_, err = val.ExecTx(ctx, alice.KeyName(), "fiat-tokenfactory", "burn", fmt.Sprintf("%duusdc", burnAmount))
require.ErrorContains(t, err, "you are not a minter")

bal, err = noble.GetBalance(ctx, alice.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.EqualValues(t, mintAmount, bal.Int64(), "minters balance should not have decreased")

// ACTION: Burn from a blacklisted minter account
// EXPECTED: Request fails; amount not burned

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nw.FiatTfRoles.Minter)

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "burn", fmt.Sprintf("%duusdc", burnAmount))
require.ErrorContains(t, err, "minter address is blacklisted")

bal, err = noble.GetBalance(ctx, nw.FiatTfRoles.Minter.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.EqualValues(t, mintAmount, bal.Int64(), "minters balance should not have decreased")

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nw.FiatTfRoles.Minter)

// ACTION: Burn amount greater than the minters balance
// EXPECTED: Request fails; amount not burned

exceedAllowance := bal.Add(math.NewInt(99))
_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "burn", fmt.Sprintf("%duusdc", exceedAllowance.Int64()))
require.ErrorContains(t, err, "insufficient funds")

bal, err = noble.GetBalance(ctx, nw.FiatTfRoles.Minter.FormattedAddress(), "uusdc")
require.NoError(t, err, "error getting balance")
require.EqualValues(t, mintAmount, bal.Int64(), "minters balance should not have decreased")

// ACTION: Successfully burn tokens
// EXPECTED: Success; amount burned and Minters balance is decreased

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "burn", fmt.Sprintf("%duusdc", burnAmount))
require.NoError(t, err, "error broadcasting burn")

bal, err = noble.GetBalance(ctx, nw.FiatTfRoles.Minter.FormattedAddress(), "uusdc")
expectedAmount := mintAmount - burnAmount
require.NoError(t, err, "error getting balance")
require.EqualValues(t, expectedAmount, bal.Int64())
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Organize TestFiatTFBurn using sub-tests for clarity

Similarly, the TestFiatTFBurn function includes multiple test scenarios. Utilizing t.Run to structure these as sub-tests can improve test organization and maintainability.

Copy link
Member

@johnletey johnletey left a comment

Choose a reason for hiding this comment

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

LGTM! Passing on Cosmos SDK v0.50 ⚡

  • ✅ Green CI for TestFiatTFMint (link)
  • ✅ Green CI for TestFiatTFBurn (link)

@johnletey johnletey merged commit 8cb4c9f into main Oct 17, 2024
28 checks passed
@johnletey johnletey deleted the dan/fiat-tf-actions branch October 17, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants