-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
test: migrate e2e/genutil to systemtest #22325
Changes from all commits
5b8f187
fdd414d
0423a83
2cffb17
243f9c0
c0dc7b3
035dd78
e6f82dc
cf3e1dc
47c47fa
0e28e7b
20a7690
c7a2c77
fe5f43e
9471780
ca0e086
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//go:build system_test | ||
|
||
package systemtests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
func TestExportCmd_WithHeight(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
|
||
sut.StartChain(t) | ||
|
||
// Wait 10s for producing blocks | ||
time.Sleep(10 * time.Second) | ||
Comment on lines
+22
to
+23
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. Replace hard-coded sleep with deterministic block height check Using Example implementation: -// Wait 10s for producing blocks
-time.Sleep(10 * time.Second)
+// Wait for chain to produce some blocks
+require.Eventually(t, func() bool {
+ height, err := sut.QueryCurrentHeight()
+ return err == nil && height >= 5
+}, 30*time.Second, 100*time.Millisecond)
|
||
|
||
sut.StopChain() | ||
|
||
testCases := []struct { | ||
name string | ||
args []string | ||
expZeroHeight bool | ||
}{ | ||
{"should export correct height", []string{"genesis", "export", "--home", sut.nodePath(0)}, false}, | ||
{"should export correct height with --height", []string{"genesis", "export", "--height=5", "--home", sut.nodePath(0), "--log_level=disabled"}, false}, | ||
{"should export height 0 with --for-zero-height", []string{"genesis", "export", "--for-zero-height=true", "--home", sut.nodePath(0)}, true}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
res := cli.RunCommandWithArgs(tc.args...) | ||
height := gjson.Get(res, "initial_height").Int() | ||
if tc.expZeroHeight { | ||
require.Equal(t, height, int64(0)) | ||
} else { | ||
require.Greater(t, height, int64(0)) | ||
} | ||
|
||
// Check consensus params of exported state | ||
maxGas := gjson.Get(res, "consensus.params.block.max_gas").Int() | ||
require.Equal(t, maxGas, int64(MaxGas)) | ||
} | ||
} | ||
|
||
func TestExportCmd_WithFileFlag(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
exportFile := "foobar.json" | ||
|
||
sut.StartChain(t) | ||
|
||
// Wait 10s for producing blocks | ||
time.Sleep(10 * time.Second) | ||
|
||
sut.StopChain() | ||
|
||
testCases := []struct { | ||
name string | ||
args []string | ||
expErr bool | ||
errMsg string | ||
}{ | ||
{"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, "no such file or directory"}, | ||
{"should export state to the specified file", []string{"genesis", "export", fmt.Sprintf("--output-document=%s", exportFile), "--home", sut.nodePath(0)}, false, ""}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if tc.expErr { | ||
assertOutput := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool { | ||
require.Contains(t, gotOutputs[0], tc.errMsg) | ||
return false | ||
} | ||
cli.WithRunErrorMatcher(assertOutput).RunCommandWithArgs(tc.args...) | ||
} else { | ||
cli.RunCommandWithArgs(tc.args...) | ||
require.FileExists(t, exportFile) | ||
err := os.Remove(exportFile) | ||
require.NoError(t, err) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ var ( | |
|
||
// ExecBinaryUnversionedRegExp regular expression to extract the unversioned binary name | ||
ExecBinaryUnversionedRegExp = regexp.MustCompile(`^(\w+)-?.*$`) | ||
|
||
MaxGas = 10_000_000 | ||
) | ||
|
||
type TestnetInitializer interface { | ||
|
@@ -130,7 +132,7 @@ func (s *SystemUnderTest) SetupChain() { | |
panic(fmt.Sprintf("failed to load genesis: %s", err)) | ||
} | ||
|
||
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, 10_000_000))) | ||
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, MaxGas))) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to set block max gas: %s", err)) | ||
} | ||
Comment on lines
+135
to
138
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. 💡 Codebase verification Inconsistent Usage of Gas Limits Detected Several hardcoded gas limits found alongside
🔗 Analysis chainUsage of The However, to ensure this change doesn't have unintended consequences, we should verify its usage across the codebase. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for other occurrences of hardcoded gas limits that might need updating
# Search for potential hardcoded gas limits
rg -n '(?i)gas.*limit.*=.*\d{7,}' --type go
# Search for other uses of MaxGas to ensure consistent usage
rg -n 'MaxGas' --type go
Length of output: 5558 |
||
|
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.
💡 Codebase verification
Direct usage of
github.com/spf13/cobra
detectedThe
github.com/spf13/cobra
dependency is still directly used in the codebase. Please review the dependency status to ensure it is correctly marked as indirect.🔗 Analysis chain
Verify the indirect status of github.com/spf13/cobra
The
github.com/spf13/cobra
dependency is now marked as indirect. This suggests that it's no longer directly used in the code but is still required by other dependencies. Please verify that this change is intentional and doesn't affect any functionality.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 55686