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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 230 additions & 0 deletions e2e/fiat_tf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,233 @@ func TestFiatTFRemoveMinter(t *testing.T) {
_, err = e2e.ShowMinters(ctx, val, nw.FiatTfRoles.Minter)
require.Error(t, err, "minter found; not successfully removed")
}

func TestFiatTFUpdatePauser(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]

// ACTION: Happy path: Update Pauser
// 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.

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)

Comment on lines +776 to +889
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.


func TestFiatTFPause(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]

// ACTION: Happy path: Pause TF
// EXPECTED: Success; TF is paused

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

// ACTION: Pause TF from an account that is not the Pauser
// EXPECTED: Request fails; TF not paused
// Status:
// Paused: true

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

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

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

showPausedRes, err := e2e.ShowPaused(ctx, val)
require.NoError(t, err, "error querying for paused state")
expectedPaused := fiattokenfactorytypes.QueryGetPausedResponse{
Paused: fiattokenfactorytypes.Paused{
Paused: false,
},
}
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)

// EXPECTED: Success; TF is paused
// Status:
// Paused: false

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

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

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

// ACTION: Pause TF while TF is already paused
// EXPECTED: Success; TF remains paused
// Status:
// Paused: true

e2e.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)


func TestFiatTFUnpause(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]

// ACTION: Happy path: Unpause TF
// EXPECTED: Success; TF is unpaused

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

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

// ACTION: Unpause TF from an account that is not a Pauser
// EXPECTED: Request fails; TF remains paused

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

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

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

showPausedRes, err := e2e.ShowPaused(ctx, val)
require.NoError(t, err, "error querying for paused state")
expectedPaused := fiattokenfactorytypes.QueryGetPausedResponse{
Paused: fiattokenfactorytypes.Paused{
Paused: true,
},
}
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)

// EXPECTED: Success; TF is unpaused
// Status:
// Paused: true

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

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

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

// ACTION: Unpause TF while TF is already unpaused
// EXPECTED: Success; TF remains unpaused
// Status:
// Paused: false

e2e.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)

8 changes: 4 additions & 4 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ func ShowMasterMinter(ctx context.Context, val *cosmos.ChainNode) (fiattokenfact
return showMMResponse, nil
}

// showPauser queries for the token factory Pauser by running: `query fiat-tokenfactory show-pauser`.
func showPauser(ctx context.Context, val *cosmos.ChainNode) (fiattokenfactorytypes.QueryGetPauserResponse, error) {
// ShowPauser queries for the token factory Pauser by running: `query fiat-tokenfactory show-pauser`.
func ShowPauser(ctx context.Context, val *cosmos.ChainNode) (fiattokenfactorytypes.QueryGetPauserResponse, error) {
res, _, err := val.ExecQuery(ctx, "fiat-tokenfactory", "show-pauser")
if err != nil {
return fiattokenfactorytypes.QueryGetPauserResponse{}, err
Expand Down Expand Up @@ -710,8 +710,8 @@ func showBlacklisted(ctx context.Context, val *cosmos.ChainNode, blacklistedWall
return showBlacklistedRes, nil
}

// showPaused queries the paused state of the token factory by running: `query fiat-tokenfactory show-paused`.
func showPaused(ctx context.Context, val *cosmos.ChainNode) (fiattokenfactorytypes.QueryGetPausedResponse, error) {
// ShowPaused queries the paused state of the token factory by running: `query fiat-tokenfactory show-paused`.
func ShowPaused(ctx context.Context, val *cosmos.ChainNode) (fiattokenfactorytypes.QueryGetPausedResponse, error) {
res, _, err := val.ExecQuery(ctx, "fiat-tokenfactory", "show-paused")
if err != nil {
return fiattokenfactorytypes.QueryGetPausedResponse{}, err
Expand Down
Loading