-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
chore: add test for account creation #21053
Conversation
WalkthroughWalkthroughThe recent changes involve enhancing the documentation and introducing a new test suite for blockchain account creation. The README file for system tests has been improved for readability through better formatting and organization. Additionally, the new test suite in Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
LGTM, also added a similar integration test here: #21048
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.
Actionable comments posted: 8
Outside diff range, codebase verification and nitpick comments (3)
tests/systemtests/account_test.go (3)
1-2
: Ensure package comment is included.Consider adding a package-level comment to describe the purpose of the
systemtests
package.// Package systemtests contains end-to-end system tests for the blockchain. package systemtests
3-9
: Optimize imports.The imports are correctly grouped, but consider adding a blank line between standard library and third-party imports for better readability.
import ( "strings" "testing" "github.com/stretchr/testify/assert" "github.com/tidwall/gjson" )
11-18
: Add a comment to describe the test case.While the inline comments are helpful, consider adding a function-level comment to describe the entire test case.
// TestAccountCreation tests the account creation logic in the blockchain. // It ensures that an account is not created when funds are sent to it, // but is created when it sends funds. func TestAccountCreation(t *testing.T) { // scenario: test account creation // given a running chain // when accountA is sending funds to accountB, // AccountB should not be created // when accountB is sending funds to accountA, // AccountB should be created
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- tests/systemtests/README.md (3 hunks)
- tests/systemtests/account_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
- tests/systemtests/README.md
Additional context used
Path-based instructions (1)
tests/systemtests/account_test.go (3)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
account2Addr := cli.AddKey("account2") |
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.
Add error handling for key addition.
Consider adding error handling for the AddKey
function to ensure that the keys are added successfully.
account1Addr, err := cli.AddKey("account1")
assert.NoError(t, err)
account2Addr, err := cli.AddKey("account2")
assert.NoError(t, err)
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) |
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.
Check the result of ModifyGenesisCLI
.
Ensure that the ModifyGenesisCLI
function call is successful by adding error handling.
err := sut.ModifyGenesisCLI(t, []string{"genesis", "add-genesis-account", account1Addr, "10000000stake"})
assert.NoError(t, err)
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
|
||
sut.StartChain(t) |
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.
Check the result of StartChain
.
Ensure that the StartChain
function call is successful by adding error handling.
err := sut.StartChain(t)
assert.NoError(t, err)
// query account1 | ||
rsp := cli.CustomQuery("q", "auth", "account", account1Addr) | ||
assert.Equal(t, account1Addr, gjson.Get(rsp, "account.value.address").String(), rsp) |
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.
Check the result of CustomQuery
.
Ensure that the CustomQuery
function call is successful by adding error handling.
rsp, err := cli.CustomQuery("q", "auth", "account", account1Addr)
assert.NoError(t, err)
assert.Equal(t, account1Addr, gjson.Get(rsp, "account.value.address").String(), rsp)
rsp1 := cli.Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake") | ||
RequireTxSuccess(t, rsp1) |
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.
Check the result of Run
.
Ensure that the Run
function call is successful by adding error handling.
rsp1, err := cli.Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake")
assert.NoError(t, err)
RequireTxSuccess(t, rsp1)
rsp2 := cli.WithRunErrorsIgnored().CustomQuery("q", "auth", "account", account2Addr) | ||
assert.True(t, strings.Contains(rsp2, "not found: key not found")) |
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.
Check the result of WithRunErrorsIgnored().CustomQuery
.
Ensure that the CustomQuery
function call is successful by adding error handling.
rsp2, err := cli.WithRunErrorsIgnored().CustomQuery("q", "auth", "account", account2Addr)
assert.NoError(t, err)
assert.True(t, strings.Contains(rsp2, "not found: key not found"))
rsp3 := cli.Run("tx", "bank", "send", account2Addr, account1Addr, "1000stake", "--from="+account1Addr, "--fees=1stake") | ||
RequireTxSuccess(t, rsp3) |
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.
Check the result of Run
.
Ensure that the Run
function call is successful by adding error handling.
rsp3, err := cli.Run("tx", "bank", "send", account2Addr, account1Addr, "1000stake", "--from="+account1Addr, "--fees=1stake")
assert.NoError(t, err)
RequireTxSuccess(t, rsp3)
rsp4 := cli.CustomQuery("q", "auth", "account", account2Addr) | ||
assert.Equal(t, "1", gjson.Get(rsp4, "account.value.sequence").String(), rsp4) | ||
rsp5 := cli.CustomQuery("q", "auth", "account", account1Addr) | ||
assert.Equal(t, "1", gjson.Get(rsp5, "account.value.sequence").String(), rsp5) |
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.
Check the result of CustomQuery
.
Ensure that the CustomQuery
function calls are successful by adding error handling.
rsp4, err := cli.CustomQuery("q", "auth", "account", account2Addr)
assert.NoError(t, err)
assert.Equal(t, "1", gjson.Get(rsp4, "account.value.sequence").String(), rsp4)
rsp5, err := cli.CustomQuery("q", "auth", "account", account1Addr)
assert.NoError(t, err)
assert.Equal(t, "1", gjson.Get(rsp5, "account.value.sequence").String(), rsp5)
(cherry picked from commit d514f33)
Description
this pr adds a test case for making sure an account is not created when sending funds to it, only after the account sends funds or does an action does it create the account
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit