-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package systemtests | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
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 | ||
|
||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
account2Addr := cli.AddKey("account2") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the err := sut.ModifyGenesisCLI(t, []string{"genesis", "add-genesis-account", account1Addr, "10000000stake"})
assert.NoError(t, err) |
||
|
||
sut.StartChain(t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the 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) | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the 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) | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the rsp1, err := cli.Run("tx", "bank", "send", account1Addr, account2Addr, "5000stake", "--from="+account1Addr, "--fees=1stake")
assert.NoError(t, err)
RequireTxSuccess(t, rsp1) |
||
|
||
// query account2 | ||
|
||
rsp2 := cli.WithRunErrorsIgnored().CustomQuery("q", "auth", "account", account2Addr) | ||
assert.True(t, strings.Contains(rsp2, "not found: key not found")) | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the 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) | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the rsp3, err := cli.Run("tx", "bank", "send", account2Addr, account1Addr, "1000stake", "--from="+account1Addr, "--fees=1stake")
assert.NoError(t, err)
RequireTxSuccess(t, rsp3) |
||
|
||
// query account2 to make sure its created | ||
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) | ||
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the result of Ensure that the 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) |
||
} |
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.