Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
fix(test): fix flags related tests (#409)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
RogerLamTd and davidtaikocha authored Sep 26, 2023
1 parent 22014b2 commit 4f0a602
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 107 deletions.
29 changes: 17 additions & 12 deletions driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,42 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() {
s.Equal(rpcTimeout, *c.RPCTimeout)
s.NotEmpty(c.JwtSecret)
s.Nil(new(Driver).InitFromCli(context.Background(), ctx))
s.True(c.P2PSyncVerifiedBlocks)
s.Equal("http://localhost:8545", c.L2CheckPoint)

return err
}

s.Nil(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1Endpoint,
"-" + flags.L2WSEndpoint.Name, l2Endpoint,
"-" + flags.L2AuthEndpoint.Name, l2EngineEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"-" + flags.P2PSyncTimeout.Name, "120",
"-" + flags.RPCTimeout.Name, "5",
"--" + flags.L1WSEndpoint.Name, l1Endpoint,
"--" + flags.L2WSEndpoint.Name, l2Endpoint,
"--" + flags.L2AuthEndpoint.Name, l2EngineEndpoint,
"--" + flags.TaikoL1Address.Name, taikoL1,
"--" + flags.TaikoL2Address.Name, taikoL2,
"--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"--" + flags.P2PSyncTimeout.Name, "120",
"--" + flags.RPCTimeout.Name, "5",
"--" + flags.P2PSyncVerifiedBlocks.Name,
"--" + flags.CheckPointSyncUrl.Name, "http://localhost:8545",
}))
}

func (s *DriverTestSuite) TestNewConfigFromCliContextJWTError() {
app := s.SetupApp()
s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.JWTSecret.Name, "wrongsecretfile.txt",
"--" + flags.JWTSecret.Name, "wrongsecretfile.txt",
}), "invalid JWT secret file")
}

func (s *DriverTestSuite) TestNewConfigFromCliContextEmptyL2CheckPoint() {
app := s.SetupApp()
s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"-" + flags.P2PSyncVerifiedBlocks.Name, "true",
"-" + flags.L2WSEndpoint.Name, "",
"--" + flags.JWTSecret.Name, os.Getenv("JWT_SECRET"),
"--" + flags.P2PSyncVerifiedBlocks.Name,
"--" + flags.L2WSEndpoint.Name, "",
}), "empty L2 check point URL")
}

Expand All @@ -80,6 +84,7 @@ func (s *DriverTestSuite) SetupApp() *cli.App {
&cli.BoolFlag{Name: flags.P2PSyncVerifiedBlocks.Name},
&cli.UintFlag{Name: flags.P2PSyncTimeout.Name},
&cli.UintFlag{Name: flags.RPCTimeout.Name},
&cli.StringFlag{Name: flags.CheckPointSyncUrl.Name},
}
app.Action = func(ctx *cli.Context) error {
_, err := NewConfigFromCliContext(ctx)
Expand Down
78 changes: 39 additions & 39 deletions proposer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContext() {

s.Nil(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1Endpoint,
"-" + flags.L2HTTPEndpoint.Name, l2Endpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.TaikoTokenAddress.Name, taikoToken,
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"-" + flags.ProposeInterval.Name, proposeInterval,
"-" + flags.TxPoolLocals.Name, goldenTouchAddress.Hex(),
"-" + flags.ProposeBlockTxReplacementMultiplier.Name, "5",
"-" + flags.RPCTimeout.Name, "5",
"-" + flags.WaitReceiptTimeout.Name, "10",
"-" + flags.ProposeBlockTxGasTipCap.Name, "100000",
"-" + flags.ProposeBlockTxGasLimit.Name, "100000",
"-" + flags.ProverEndpoints.Name, proverEndpoints,
"-" + flags.BlockProposalFee.Name, blockProposalFee,
"-" + flags.BlockProposalFeeIncreasePercentage.Name, "15",
"-" + flags.BlockProposalFeeIterations.Name, "5",
"--" + flags.L1WSEndpoint.Name, l1Endpoint,
"--" + flags.L2HTTPEndpoint.Name, l2Endpoint,
"--" + flags.TaikoL1Address.Name, taikoL1,
"--" + flags.TaikoL2Address.Name, taikoL2,
"--" + flags.TaikoTokenAddress.Name, taikoToken,
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.TxPoolLocals.Name, goldenTouchAddress.Hex(),
"--" + flags.ProposeBlockTxReplacementMultiplier.Name, "5",
"--" + flags.RPCTimeout.Name, "5",
"--" + flags.WaitReceiptTimeout.Name, "10",
"--" + flags.ProposeBlockTxGasTipCap.Name, "100000",
"--" + flags.ProposeBlockTxGasLimit.Name, "100000",
"--" + flags.ProverEndpoints.Name, proverEndpoints,
"--" + flags.BlockProposalFee.Name, blockProposalFee,
"--" + flags.BlockProposalFeeIncreasePercentage.Name, "15",
"--" + flags.BlockProposalFeeIterations.Name, "5",
}))
}

Expand All @@ -92,7 +92,7 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextPrivKeyErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextPrivKeyErr",
"-" + flags.L1ProposerPrivKey.Name, string(common.FromHex("0x")),
"--" + flags.L1ProposerPrivKey.Name, string(common.FromHex("0x")),
}), "invalid L1 proposer private key")
}

Expand All @@ -104,8 +104,8 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextPropIntervalErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextProposeIntervalErr",
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.ProposeInterval.Name, "",
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.ProposeInterval.Name, "",
}), "invalid proposing interval")
}

Expand All @@ -117,9 +117,9 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextEmptyPropoIntervalErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextEmptyProposalIntervalErr",
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.ProposeInterval.Name, proposeInterval,
"-" + flags.ProposeEmptyBlocksInterval.Name, "",
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.ProposeEmptyBlocksInterval.Name, "",
}), "invalid proposing empty blocks interval")
}

Expand All @@ -131,10 +131,10 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextL2RecipErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextL2RecipErr",
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.ProposeInterval.Name, proposeInterval,
"-" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"-" + flags.L2SuggestedFeeRecipient.Name, "notAnAddress",
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"--" + flags.L2SuggestedFeeRecipient.Name, "notAnAddress",
}), "invalid L2 suggested fee recipient address")
}

Expand All @@ -149,11 +149,11 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextTxPoolLocalsErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextTxPoolLocalsErr",
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.ProposeInterval.Name, proposeInterval,
"-" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"-" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"-" + flags.TxPoolLocals.Name, "notAnAddress",
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"--" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"--" + flags.TxPoolLocals.Name, "notAnAddress",
}), "invalid account in --txpool.locals")
}

Expand All @@ -168,12 +168,12 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextReplMultErr() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContextReplMultErr",
"-" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"-" + flags.ProposeInterval.Name, proposeInterval,
"-" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"-" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"-" + flags.TxPoolLocals.Name, goldenTouchAddress.Hex(),
"-" + flags.ProposeBlockTxReplacementMultiplier.Name, "0",
"--" + flags.L1ProposerPrivKey.Name, common.Bytes2Hex(goldenTouchPrivKey.Bytes()),
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.ProposeEmptyBlocksInterval.Name, proposeInterval,
"--" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"--" + flags.TxPoolLocals.Name, goldenTouchAddress.Hex(),
"--" + flags.ProposeBlockTxReplacementMultiplier.Name, "0",
}), "invalid --proposeBlockTxReplacementMultiplier value")
}

Expand Down
113 changes: 57 additions & 56 deletions prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,32 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProver() {
s.Equal(uint64(8), c.Capacity)
s.Equal(minProofFee, c.MinProofFee.String())
s.Nil(new(Prover).InitFromCli(context.Background(), ctx))
s.True(c.ProveUnassignedBlocks)

return err
}

s.Nil(app.Run([]string{
"TestNewConfigFromCliContext_OracleProver",
"-" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"-" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"-" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"-" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.StartingBlockID.Name, "0",
"-" + flags.RPCTimeout.Name, "5",
"-" + flags.ProveBlockTxGasLimit.Name, "100000",
"-" + flags.Dummy.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1h",
"-" + flags.MinProofFee.Name, minProofFee,
"-" + flags.ProverCapacity.Name, "8",
"-" + flags.OracleProver.Name,
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Graffiti.Name, "",
"-" + flags.CheckProofWindowExpiredInterval.Name, "30",
"-" + flags.ProveUnassignedBlocks.Name, "true",
"--" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"--" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"--" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"--" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"--" + flags.TaikoL1Address.Name, taikoL1,
"--" + flags.TaikoL2Address.Name, taikoL2,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.StartingBlockID.Name, "0",
"--" + flags.RPCTimeout.Name, "5",
"--" + flags.ProveBlockTxGasLimit.Name, "100000",
"--" + flags.Dummy.Name,
"--" + flags.RandomDummyProofDelay.Name, "30m-1h",
"--" + flags.MinProofFee.Name, minProofFee,
"--" + flags.ProverCapacity.Name, "8",
"--" + flags.OracleProver.Name,
"--" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.Graffiti.Name, "",
"--" + flags.CheckProofWindowExpiredInterval.Name, "30",
"--" + flags.ProveUnassignedBlocks.Name,
}))
}

Expand All @@ -84,19 +85,19 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverError() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"-" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"-" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"-" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"-" + flags.TaikoL1Address.Name, taikoL1,
"-" + flags.TaikoL2Address.Name, taikoL2,
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.Dummy.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1h",
"-" + flags.OracleProver.Name,
"-" + flags.Graffiti.Name, "",
"-" + flags.RPCTimeout.Name, "5",
"-" + flags.MinProofFee.Name, minProofFee,
"--" + flags.L1WSEndpoint.Name, l1WsEndpoint,
"--" + flags.L1HTTPEndpoint.Name, l1HttpEndpoint,
"--" + flags.L2WSEndpoint.Name, l2WsEndpoint,
"--" + flags.L2HTTPEndpoint.Name, l2HttpEndpoint,
"--" + flags.TaikoL1Address.Name, taikoL1,
"--" + flags.TaikoL2Address.Name, taikoL2,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.Dummy.Name,
"--" + flags.RandomDummyProofDelay.Name, "30m-1h",
"--" + flags.OracleProver.Name,
"--" + flags.Graffiti.Name, "",
"--" + flags.RPCTimeout.Name, "5",
"--" + flags.MinProofFee.Name, minProofFee,
}), "oracleProver flag set without oracleProverPrivateKey set")
}

Expand All @@ -105,7 +106,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_ProverKeyError() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, "0x",
"--" + flags.L1ProverPrivKey.Name, "0x",
}), "invalid L1 prover private key")
}

Expand All @@ -114,9 +115,9 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_OracleProverKeyError() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProver.Name,
"-" + flags.OracleProverPrivateKey.Name, "",
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProver.Name,
"--" + flags.OracleProverPrivateKey.Name, "",
}), "invalid oracle private key")
}

Expand All @@ -125,11 +126,11 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_RandomDelayError() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProver.Name,
"-" + flags.RandomDummyProofDelay.Name, "130m",
"-" + flags.MinProofFee.Name, minProofFee,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProver.Name,
"--" + flags.RandomDummyProofDelay.Name, "130m",
"--" + flags.MinProofFee.Name, minProofFee,
}), "invalid random dummy proof delay value")
}

Expand All @@ -138,11 +139,11 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_RandomDelayErrorLower() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProver.Name,
"-" + flags.RandomDummyProofDelay.Name, "30x-1h",
"-" + flags.MinProofFee.Name, minProofFee,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProver.Name,
"--" + flags.RandomDummyProofDelay.Name, "30x-1h",
"--" + flags.MinProofFee.Name, minProofFee,
}), "invalid random dummy proof delay value")
}

Expand All @@ -151,11 +152,11 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_RandomDelayErrorUpper() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProver.Name,
"-" + flags.RandomDummyProofDelay.Name, "30m-1x",
"-" + flags.MinProofFee.Name, minProofFee,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProver.Name,
"--" + flags.RandomDummyProofDelay.Name, "30m-1x",
"--" + flags.MinProofFee.Name, minProofFee,
}), "invalid random dummy proof delay value")
}

Expand All @@ -164,11 +165,11 @@ func (s *ProverTestSuite) TestNewConfigFromCliContext_RandomDelayErrorOrder() {

s.ErrorContains(app.Run([]string{
"TestNewConfigFromCliContext",
"-" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"-" + flags.OracleProver.Name,
"-" + flags.RandomDummyProofDelay.Name, "1h-30m",
"-" + flags.MinProofFee.Name, minProofFee,
"--" + flags.L1ProverPrivKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProverPrivateKey.Name, os.Getenv("L1_PROVER_PRIVATE_KEY"),
"--" + flags.OracleProver.Name,
"--" + flags.RandomDummyProofDelay.Name, "1h-30m",
"--" + flags.MinProofFee.Name, minProofFee,
}), "invalid random dummy proof delay value (lower > upper)")
}

Expand Down

0 comments on commit 4f0a602

Please sign in to comment.