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: pause e2e tests for fiattokenfactory #369

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Conversation

boojamya
Copy link
Member

Includes:

  • TestFiatTFUpdatePauser
  • TestFiatTFPause
  • TestFiatTFUnpause

Copy link

coderabbitai bot commented May 27, 2024

Walkthrough

The changes introduce new test functions in the e2e/fiat_tf_test.go file to enhance testing coverage for pauser functionalities and pause/unpause mechanisms in the token factory. The modifications also include renaming several private functions in e2e/utils.go to public functions, improving their visibility without altering their internal logic.

Changes

File Change Summary
e2e/fiat_tf_test.go - Added TestFiatTFUpdatePauser, TestFiatTFPause, and TestFiatTFUnpause test functions.
e2e/utils.go - Renamed functions: showPauser to ShowPauser, showBlacklister to ShowBlacklister, showBlacklisted to ShowBlacklisted, and showPaused to ShowPaused.

Possibly related PRs

  • feat: owner e2e tests for fiattokenfactory #367: The changes in this PR also involve the e2e/fiat_tf_test.go file and include tests related to the Fiat Token Factory, specifically focusing on ownership functionalities, which may interact with the pauser functionality introduced in the main PR.

Suggested reviewers

  • kaliweh-circle

Poem

In the meadow where bunnies play,
New tests hop in, brightening the day.
With pausers and unpausers, all in a row,
Our code now dances, ready to show!
So let’s leap with joy, for changes are here,
A warren of functions, let’s give a cheer! 🐇✨


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.

},
}
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)
}
Copy link

Choose a reason for hiding this comment

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

Could we add the happy path case as well? (i.e. a normal request — nothing is paused or blacklisted)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in: 9a77cc4 (#369)

}
require.Equal(t, expectedPaused, showPausedRes)

// ACTION: Pause TF from a blacklisted Pauser account
Copy link

Choose a reason for hiding this comment

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

Seems that assertions of the expected result are missing from this case and the one below?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do an assertion inside the pauseFiatTF function:

noble/e2e/utils.go

Lines 421 to 433 in 149a7f6

res, _, err := val.ExecQuery(ctx, "fiat-tokenfactory", "show-paused")
require.NoError(t, err, "error querying for paused state")
var showPausedResponse fiattokenfactorytypes.QueryGetPausedResponse
err = json.Unmarshal(res, &showPausedResponse)
require.NoError(t, err)
expectedPaused := fiattokenfactorytypes.QueryGetPausedResponse{
Paused: fiattokenfactorytypes.Paused{
Paused: true,
},
}
require.Equal(t, expectedPaused, showPausedResponse)

// Paused: true

pauseFiatTF(t, ctx, val, nw.fiatTfRoles.Pauser)
}
Copy link

Choose a reason for hiding this comment

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

Can we add a happy path test here? (precondition: valid pause request while nothing is paused or blacklisted)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in: 9a77cc4 (#369)


unblacklistAccount(t, ctx, val, nw.fiatTfRoles.Blacklister, nw.fiatTfRoles.Pauser)

// ACTION: Unpause TF while TF is already paused
Copy link

@xngln xngln Jun 25, 2024

Choose a reason for hiding this comment

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

I think you might have mixed up this case—we want the precondition to be that TF is unpaused, and unpausing it in this state results in the module remaining unpaused.

The EXPECTED comment implies you were intending on testing this, and the ACTION comment might have a typo? But the actual test implementation is testing unpausing of an already paused TF.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated! 2910fdb (#369)

}
require.Equal(t, expectedPaused, showPausedRes)

// ACTION: Unpause TF from a blacklisted Pauser account
Copy link

Choose a reason for hiding this comment

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

Missing assertions of expected result for this test and the one below

Copy link
Member Author

Choose a reason for hiding this comment

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

We do this assertion in the unpauseFiatTF function:

noble/e2e/utils.go

Lines 445 to 454 in 149a7f6

var showPausedResponse fiattokenfactorytypes.QueryGetPausedResponse
err = json.Unmarshal(res, &showPausedResponse)
require.NoError(t, err, "failed to unmarshal show-paused response")
expectedUnpaused := fiattokenfactorytypes.QueryGetPausedResponse{
Paused: fiattokenfactorytypes.Paused{
Paused: false,
},
}
require.Equal(t, expectedUnpaused, showPausedResponse)


unpauseFiatTF(t, ctx, val, nw.fiatTfRoles.Pauser)

unpauseFiatTF(t, ctx, val, nw.fiatTfRoles.Pauser)
Copy link

Choose a reason for hiding this comment

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

Duplicate unpause?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated! 2910fdb (#369)

unpauseFiatTF(t, ctx, val, nw.fiatTfRoles.Pauser)

unpauseFiatTF(t, ctx, val, nw.fiatTfRoles.Pauser)
}
Copy link

Choose a reason for hiding this comment

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

Can we get a happy path test here as well? So unpausing a paused TF with an unblacklisted pauser.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in: 9a77cc4 (#369)

@johnletey johnletey changed the base branch from feat/sdk-eden to main October 17, 2024 08:56
@johnletey johnletey requested a review from a team as a code owner October 17, 2024 08:56
@johnletey johnletey changed the title chore: pause E2E tests for fiat token factory feat: pause 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: 1

🧹 Outside diff range and nitpick comments (1)
e2e/utils.go (1)

Line range hint 664-726: Consider adopting a consistent approach to function visibility.

The changes in this file have made some functions public (ShowPauser and ShowPaused) while leaving others private (showBlacklister and showBlacklisted). To improve code consistency and maintainability, consider adopting a uniform approach to function visibility in this utility file. If there are specific reasons for keeping certain functions private, it might be helpful to add comments explaining these decisions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7c0fce0 and 5d526ac.

📒 Files selected for processing (2)
  • e2e/fiat_tf_test.go (1 hunks)
  • e2e/utils.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (6)
e2e/utils.go (4)

664-665: LGTM: Function renamed and made public.

The showPauser function has been renamed to ShowPauser, making it public. This change increases the function's visibility, which is likely intentional for testing purposes. The implementation remains correct and follows good practices.

Also applies to: 666-677


Line range hint 679-692: Verify: Inconsistent visibility for showBlacklister.

The showBlacklister function remains private, while similar functions like ShowPauser have been made public. Is this intentional? If not, consider renaming it to ShowBlacklister for consistency with the other utility functions.


Line range hint 694-708: Verify: Inconsistent visibility for showBlacklisted.

The showBlacklisted function remains private, while similar functions like ShowPauser have been made public. Is this intentional? If not, consider renaming it to ShowBlacklisted for consistency with the other utility functions.


713-714: LGTM: Function renamed and made public.

The showPaused function has been renamed to ShowPaused, making it public. This change increases the function's visibility and is consistent with the ShowPauser function. The implementation remains correct and follows good practices.

Also applies to: 715-726

e2e/fiat_tf_test.go (2)

891-947: Tests Effectively Cover Pausing Scenarios

The TestFiatTFPause function thoroughly tests the pausing functionality of the Token Factory (TF). It includes cases for:

  • Successful pausing by the authorized pauser.
  • Attempted pausing by an unauthorized account.
  • Pausing by a blacklisted pauser account.
  • Attempting to pause when the TF is already paused.

These tests ensure that the TF behaves correctly under various conditions.


949-1005: Comprehensive Testing of Unpausing Functionality

The TestFiatTFUnpause function effectively verifies the unpausing behavior of the TF. It includes:

  • Successful unpausing by the authorized pauser.
  • Attempted unpausing by an unauthorized account.
  • Unpausing by a blacklisted pauser account.
  • Attempting to unpause when the TF is already unpaused.

The tests cover key scenarios to validate that the unpausing mechanism operates as expected.

Comment on lines +776 to +889
// EXPECTED: Success; pauser updated

w := interchaintest.GetAndFundTestUsers(t, ctx, "new-pauser-1", math.OneInt(), noble)
newPauser1 := w[0]

_, err := val.ExecTx(ctx, nw.FiatTfRoles.Owner.KeyName(), "fiat-tokenfactory", "update-pauser", newPauser1.FormattedAddress())
require.NoError(t, err, "failed to broadcast update-pauser message")

showPauserRes, err := e2e.ShowPauser(ctx, val)
require.NoError(t, err, "failed to query show-pauser")
expectedGetPauserResponse := fiattokenfactorytypes.QueryGetPauserResponse{
Pauser: fiattokenfactorytypes.Pauser{
Address: newPauser1.FormattedAddress(),
},
}
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)

// ACTION: Update Pauser while TF is paused
// EXPECTED: Success; pauser updated
// Status:
// Pauser: newPauser1

e2e.PauseFiatTF(t, ctx, val, newPauser1)

w = interchaintest.GetAndFundTestUsers(t, ctx, "new-pauser-2", math.OneInt(), noble)
newPauser2 := w[0]

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Owner.KeyName(), "fiat-tokenfactory", "update-pauser", newPauser2.FormattedAddress())
require.NoError(t, err, "failed to broadcast update-pauser message")

showPauserRes, err = e2e.ShowPauser(ctx, val)
require.NoError(t, err, "failed to query show-pauser")
expectedGetPauserResponse = fiattokenfactorytypes.QueryGetPauserResponse{
Pauser: fiattokenfactorytypes.Pauser{
Address: newPauser2.FormattedAddress(),
},
}
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)

e2e.UnpauseFiatTF(t, ctx, val, newPauser2)

// ACTION: Update Pauser from non owner account
// EXPECTED: Request fails; pauser not updated
// Status:
// Pauser: newPauser2

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

_, err = val.ExecTx(ctx, alice.KeyName(), "fiat-tokenfactory", "update-pauser", newPauser3.FormattedAddress())
require.ErrorContains(t, err, "you are not the owner: unauthorized")

showPauserRes, err = e2e.ShowPauser(ctx, val)
require.NoError(t, err, "failed to query show-pauser")
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)

// ACTION: Update Pauser from blacklisted owner account
// EXPECTED: Success; pauser updated
// Status:
// Pauser: newPauser2

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

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Owner.KeyName(), "fiat-tokenfactory", "update-pauser", newPauser3.FormattedAddress())
require.NoError(t, err, "failed to broadcast update-pauser message")

showPauserRes, err = e2e.ShowPauser(ctx, val)
require.NoError(t, err, "failed to query show-pauser")
expectedGetPauserResponse = fiattokenfactorytypes.QueryGetPauserResponse{
Pauser: fiattokenfactorytypes.Pauser{
Address: newPauser3.FormattedAddress(),
},
}
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)

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

// ACTION: Update Pauser to blacklisted Pauser account
// EXPECTED: Success; pauser updated
// Status:
// Pauser: newPauser3

w = interchaintest.GetAndFundTestUsers(t, ctx, "new-pauser-4", math.OneInt(), noble)
newPauser4 := w[0]

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

_, err = val.ExecTx(ctx, nw.FiatTfRoles.Owner.KeyName(), "fiat-tokenfactory", "update-pauser", newPauser4.FormattedAddress())
require.NoError(t, err, "failed to broadcast update-pauser message")

showPauserRes, err = e2e.ShowPauser(ctx, val)
require.NoError(t, err, "failed to query show-pauser")
expectedGetPauserResponse = fiattokenfactorytypes.QueryGetPauserResponse{
Pauser: fiattokenfactorytypes.Pauser{
Address: newPauser4.FormattedAddress(),
},
}
require.Equal(t, expectedGetPauserResponse.Pauser, showPauserRes.Pauser)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider Refactoring Test Setup to Reduce Code Duplication

The TestFiatTFUpdatePauser function contains multiple sections where new users are created and funded in a similar manner. Refactoring this repetitive code into a helper function can improve readability and maintainability.

You could create a helper function to handle user creation and funding:

 func TestFiatTFUpdatePauser(t *testing.T) {
     // ...
-    w := interchaintest.GetAndFundTestUsers(t, ctx, "new-pauser-1", math.OneInt(), noble)
-    newPauser1 := w[0]
+    newPauser1 := createAndFundUser(t, ctx, noble, "new-pauser-1")

     // ...

-    w = interchaintest.GetAndFundTestUsers(t, ctx, "new-pauser-2", math.OneInt(), noble)
-    newPauser2 := w[0]
+    newPauser2 := createAndFundUser(t, ctx, noble, "new-pauser-2")

     // ...

+func createAndFundUser(t *testing.T, ctx context.Context, chain *e2e.Chain, username string) *interchaintest.User {
+    users := interchaintest.GetAndFundTestUsers(t, ctx, username, math.OneInt(), chain)
+    return users[0]
+}

Committable suggestion was skipped due to low confidence.

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 TestFiatTFUpdatePauser (link)
  • ✅ Green CI for TestFiatTFPause (link)
  • ✅ Green CI for TestFiatTFUnpause (link)

@johnletey johnletey merged commit 1f89643 into main Oct 17, 2024
23 checks passed
@johnletey johnletey deleted the dan/fiat-tf-pause branch October 17, 2024 09:10
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.

4 participants