forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3428971
commit b5d7e81
Showing
8 changed files
with
171 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package sanitycheck | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/0xPolygon/polygon-edge/command/loadtest" | ||
) | ||
|
||
const ( | ||
epochSizeFlag = "epoch-size" | ||
validatorKeysFlag = "validator-keys" | ||
) | ||
|
||
var ( | ||
errInvalidEpochSize = errors.New("epoch size must be greater than 0") | ||
) | ||
|
||
// sanityCheckParams holds the parameters for the sanity check command | ||
type sanityCheckParams struct { | ||
mnemonic string | ||
jsonRPCAddress string | ||
|
||
receiptsTimeout time.Duration | ||
|
||
epochSize uint64 | ||
toJSON bool | ||
|
||
validatorKeys []string | ||
} | ||
|
||
// validateFlags checks if the provided flags are valid | ||
func (scp *sanityCheckParams) validateFlags() error { | ||
if scp.mnemonic == "" { | ||
return loadtest.ErrNoMnemonicProvided | ||
} | ||
|
||
if scp.epochSize == 0 { | ||
return errInvalidEpochSize | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package sanitycheck | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/0xPolygon/polygon-edge/command" | ||
"github.com/0xPolygon/polygon-edge/command/helper" | ||
"github.com/0xPolygon/polygon-edge/command/loadtest" | ||
"github.com/0xPolygon/polygon-edge/loadtest/sanitycheck" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
params sanityCheckParams | ||
) | ||
|
||
func GetCommand() *cobra.Command { | ||
loadTestCmd := &cobra.Command{ | ||
Use: "sanity-check", | ||
Short: "Runs a sanity check tests on a specified network", | ||
PreRunE: preRunCommand, | ||
Run: runCommand, | ||
} | ||
|
||
helper.RegisterJSONRPCFlag(loadTestCmd) | ||
|
||
setFlags(loadTestCmd) | ||
|
||
return loadTestCmd | ||
} | ||
|
||
func preRunCommand(cmd *cobra.Command, _ []string) error { | ||
params.jsonRPCAddress = helper.GetJSONRPCAddress(cmd) | ||
|
||
return params.validateFlags() | ||
} | ||
|
||
func setFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVar( | ||
¶ms.mnemonic, | ||
loadtest.MnemonicFlag, | ||
"", | ||
"the mnemonic used to fund accounts if needed for the sanity check", | ||
) | ||
|
||
cmd.Flags().Uint64Var( | ||
¶ms.epochSize, | ||
epochSizeFlag, | ||
10, | ||
"epoch size on the network for which the sanity check is run", | ||
) | ||
|
||
cmd.Flags().DurationVar( | ||
¶ms.receiptsTimeout, | ||
loadtest.ReceiptsTimeoutFlag, | ||
30*time.Second, | ||
"the timeout for waiting for transaction receipts", | ||
) | ||
|
||
cmd.Flags().BoolVar( | ||
¶ms.toJSON, | ||
loadtest.SaveToJSONFlag, | ||
false, | ||
"saves results to JSON file", | ||
) | ||
|
||
cmd.Flags().StringSliceVar( | ||
¶ms.validatorKeys, | ||
validatorKeysFlag, | ||
nil, | ||
"private keys of validators on the network for which the sanity check is run", | ||
) | ||
|
||
_ = cmd.MarkFlagRequired(loadtest.MnemonicFlag) | ||
} | ||
|
||
func runCommand(cmd *cobra.Command, _ []string) { | ||
outputter := command.InitializeOutputter(cmd) | ||
defer outputter.WriteOutput() | ||
|
||
sanityCheckRunner, err := sanitycheck.NewSanityCheckTestRunner( | ||
&sanitycheck.SanityCheckTestConfig{ | ||
Mnemonic: params.mnemonic, | ||
JSONRPCUrl: params.jsonRPCAddress, | ||
ReceiptsTimeout: params.receiptsTimeout, | ||
EpochSize: params.epochSize, | ||
ValidatorKeys: params.validatorKeys, | ||
ResultsToJSON: params.toJSON, | ||
}, | ||
) | ||
|
||
if err != nil { | ||
outputter.SetError(err) | ||
|
||
return | ||
} | ||
|
||
sanityCheckRunner.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters