-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: mint & burn e2e tests for fiattokenfactory #371
Conversation
WalkthroughThe changes introduce new test functions for the Changes
Possibly related PRs
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Co-authored-by: Dan Kanefsky <dan@noble.xyz>
5b04c55
to
c779a9f
Compare
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.
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) | ||
} |
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.
🛠️ 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.
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()) | ||
} |
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.
🛠️ 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.
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.
Includes:
TestFiatTFMint
TestFiatTFBurn