github.com/klaytn/klaytn@v1.12.1/cmd/utils/nodecmd/flags_test.go (about) 1 // Modifications Copyright 2019 The klaytn Authors 2 // Copyright 2016 The go-ethereum Authors 3 // This file is part of go-ethereum. 4 // 5 // go-ethereum is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // go-ethereum is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from cmd/geth/genesis_test.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package nodecmd 22 23 import ( 24 "os" 25 "path/filepath" 26 "testing" 27 ) 28 29 var genesis = `{"config":{"chainId":2019,"istanbul":{"epoch":30,"policy":2,"sub":13},"unitPrice":25000000000,"deriveShaImpl":2,"governance":{"governingNode":"0xdddfb991127b43e209c2f8ed08b8b3d0b5843d36","governanceMode":"single","reward":{"mintingAmount":9600000000000000000,"ratio":"34/54/12","useGiniCoeff":false,"deferredTxFee":true,"stakingUpdateInterval":60,"proposerUpdateInterval":30,"minimumStake":5000000}}},"timestamp":"0x5ce33d6e","extraData":"0x0000000000000000000000000000000000000000000000000000000000000000f89af85494dddfb991127b43e209c2f8ed08b8b3d0b5843d3694195ba9cc787b00796a7ae6356e5b656d4360353794777fd033b5e3bcaad6006bc9f481ffed6b83cf5a94d473284239f704adccd24647c7ca132992a28973b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0","governanceData":null,"blockScore":"0x1","alloc":{"195ba9cc787b00796a7ae6356e5b656d43603537":{"balance":"0x446c3b15f9926687d2c40534fdb564000000000000"},"777fd033b5e3bcaad6006bc9f481ffed6b83cf5a":{"balance":"0x446c3b15f9926687d2c40534fdb564000000000000"},"d473284239f704adccd24647c7ca132992a28973":{"balance":"0x446c3b15f9926687d2c40534fdb564000000000000"},"dddfb991127b43e209c2f8ed08b8b3d0b5843d36":{"balance":"0x446c3b15f9926687d2c40534fdb564000000000000"},"f4316f69d9522667c0674afcd8638288489f0333":{"balance":"0x446c3b15f9926687d2c40534fdb564000000000000"}},"number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}` 30 31 const ( 32 FlagTypeBoolean = iota 33 FlagTypeArgument 34 ) 35 36 const ( 37 ErrorIncorrectUsage = iota 38 ErrorInvalidValue 39 ErrorFatal 40 // TODO-Klaytn-Node fix the configuration to filter wrong input flags before the klay server is launched 41 NonError // This error case expects an error, but currently it does not filter the wrong value. 42 ) 43 44 var ( 45 commonThreeErrors = []string{"abcdefg", "1234567", "!@#$%^&"} 46 commonTwoErrors = []string{"abcdefg", "!@#$%^&"} 47 ) 48 49 var flagsWithValues = []struct { 50 flag string 51 flagType uint16 52 values []string 53 wrongValues []string 54 errors []int 55 }{ 56 // TODO-Klaytn-Node the flag is not defined on any klay binaries 57 //{ 58 // flag: "--networktype", 59 // flagType: FlagTypeArgument, 60 // // values: []string{"mn", "scn"}, 61 // values: []string{}, 62 // wrongValues: []string{"baobab", "abcdefg", "1234567", "!@#$%^&"}, 63 // errors: []string{}, 64 //}, 65 { 66 flag: "--dbtype", 67 flagType: FlagTypeArgument, 68 values: []string{"LevelDB", "BadgerDB", "MemoryDB", "DynamoDBS3"}, 69 wrongValues: append(commonThreeErrors, "oracle"), 70 errors: []int{NonError, NonError, NonError, NonError}, 71 }, 72 { 73 flag: "--srvtype", 74 flagType: FlagTypeArgument, 75 values: []string{"http", "fasthttp"}, 76 wrongValues: commonThreeErrors, 77 errors: []int{NonError, NonError, NonError}, 78 }, 79 { 80 flag: "--keystore", 81 flagType: FlagTypeArgument, 82 values: []string{""}, 83 wrongValues: []string{}, 84 errors: []int{}, 85 }, 86 { 87 flag: "--networkid", 88 flagType: FlagTypeArgument, 89 values: []string{"1", "1000", "1001", "12312"}, 90 wrongValues: commonTwoErrors, 91 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 92 }, 93 { 94 flag: "--identity", 95 flagType: FlagTypeArgument, 96 values: []string{"abc", "abde-", "oai121"}, 97 wrongValues: []string{}, 98 errors: []int{}, 99 }, 100 //TODO-Klaytn-Node the flag is not defined on any klay binaries 101 //{ 102 // flag: "--docroot", 103 // flagType: FlagTypeBoolean, 104 // values: []string{}, 105 //}, 106 { 107 flag: "--syncmode", 108 flagType: FlagTypeArgument, 109 values: []string{"full"}, //[]string{"fast", "full"}, 110 wrongValues: commonThreeErrors, 111 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 112 }, 113 { 114 flag: "--gcmode", 115 flagType: FlagTypeArgument, 116 values: []string{"full", "archive"}, 117 wrongValues: commonThreeErrors, 118 errors: []int{ErrorFatal, ErrorFatal, ErrorFatal}, 119 }, 120 { 121 flag: "--lightkdf", 122 flagType: FlagTypeBoolean, 123 }, 124 { 125 flag: "--txpool.nolocals", 126 flagType: FlagTypeBoolean, 127 }, 128 { 129 flag: "--txpool.journal", 130 flagType: FlagTypeArgument, 131 values: []string{"transactions.rlp"}, 132 wrongValues: []string{}, 133 errors: []int{}, 134 }, 135 { 136 flag: "--txpool.journal-interval", 137 flagType: FlagTypeArgument, 138 values: []string{"1h0m0s", "0h0m0s", "0h0m1s", "0h1m0s", "0.5h0.5m0.5s"}, 139 wrongValues: commonThreeErrors, 140 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 141 }, 142 { 143 flag: "--txpool.pricelimit", 144 flagType: FlagTypeArgument, 145 values: []string{"1"}, 146 wrongValues: commonTwoErrors, 147 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 148 }, 149 { 150 flag: "--txpool.pricebump", 151 flagType: FlagTypeArgument, 152 values: []string{"10"}, 153 wrongValues: commonTwoErrors, 154 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 155 }, 156 { 157 flag: "--txpool.exec-slots.account", 158 flagType: FlagTypeArgument, 159 values: []string{"16"}, 160 wrongValues: commonTwoErrors, 161 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 162 }, 163 { 164 flag: "--txpool.exec-slots.all", 165 flagType: FlagTypeArgument, 166 values: []string{"4096"}, 167 wrongValues: commonTwoErrors, 168 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 169 }, 170 { 171 flag: "--txpool.nonexec-slots.account", 172 flagType: FlagTypeArgument, 173 values: []string{"64"}, 174 wrongValues: commonTwoErrors, 175 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 176 }, 177 { 178 flag: "--txpool.nonexec-slots.all", 179 flagType: FlagTypeArgument, 180 values: []string{"1024"}, 181 wrongValues: commonTwoErrors, 182 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 183 }, 184 //TODO-Klaytn-Node the flag is not defined on any klay binaries 185 //{ 186 // flag: "--txpool.keeplocals", 187 // flagType: FlagTypeBoolean, 188 // values: []string{}, 189 //}, 190 { 191 flag: "--txpool.lifetime", 192 flagType: FlagTypeArgument, 193 values: []string{"0h20m0s"}, 194 wrongValues: commonThreeErrors, 195 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 196 }, 197 { 198 flag: "--db.single", 199 flagType: FlagTypeBoolean, 200 }, 201 { 202 flag: "--db.num-statetrie-shards", 203 flagType: FlagTypeArgument, 204 // values: []string{"1", "2"}, 205 values: []string{"1"}, 206 wrongValues: commonTwoErrors, 207 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 208 }, 209 { 210 flag: "--db.leveldb.cache-size", 211 flagType: FlagTypeArgument, 212 values: []string{"768"}, 213 wrongValues: commonTwoErrors, 214 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 215 }, 216 { 217 flag: "--db.leveldb.compression", 218 flagType: FlagTypeArgument, 219 values: []string{"0", "1", "2", "3"}, 220 wrongValues: commonTwoErrors, 221 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 222 }, 223 { 224 flag: "--db.leveldb.no-buffer-pool", 225 flagType: FlagTypeBoolean, 226 }, 227 { 228 flag: "--db.no-parallel-write", 229 flagType: FlagTypeBoolean, 230 }, 231 { 232 flag: "--state.cache-size", 233 flagType: FlagTypeArgument, 234 values: []string{"64", "128", "256", "512"}, 235 wrongValues: commonTwoErrors, 236 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 237 }, 238 { 239 flag: "--state.block-interval", 240 flagType: FlagTypeArgument, 241 values: []string{"64", "128", "256"}, 242 wrongValues: commonTwoErrors, 243 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 244 }, 245 { 246 flag: "--cache.type", 247 flagType: FlagTypeArgument, 248 values: []string{"0", "1", "2"}, 249 wrongValues: commonTwoErrors, 250 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 251 }, 252 { 253 flag: "--cache.scale", 254 flagType: FlagTypeArgument, 255 values: []string{"100"}, 256 wrongValues: commonTwoErrors, 257 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 258 }, 259 { 260 flag: "--cache.level", 261 flagType: FlagTypeBoolean, 262 values: []string{"saving", "normal", "extreme"}, 263 wrongValues: commonThreeErrors, 264 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 265 }, 266 { 267 flag: "--cache.memory", 268 flagType: FlagTypeArgument, 269 values: []string{"16"}, 270 wrongValues: commonTwoErrors, 271 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 272 }, 273 { 274 flag: "--state.trie-cache-limit", 275 flagType: FlagTypeArgument, 276 values: []string{"512", "1024", "2048", "4096"}, 277 wrongValues: commonTwoErrors, 278 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 279 }, 280 { 281 flag: "--sendertxhashindexing", 282 flagType: FlagTypeBoolean, 283 }, 284 { 285 flag: "--childchainindexing", 286 flagType: FlagTypeBoolean, 287 }, 288 { 289 flag: "--targetgaslimit", 290 flagType: FlagTypeArgument, 291 values: []string{"4712388"}, 292 wrongValues: commonTwoErrors, 293 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 294 }, 295 { 296 flag: "--scsigner", 297 flagType: FlagTypeArgument, 298 values: []string{"0x777fd033b5e3bcaad6006bc9f481ffed6b83cf5a"}, 299 wrongValues: commonThreeErrors, 300 errors: []int{ErrorFatal, ErrorFatal, ErrorFatal}, 301 }, 302 { 303 flag: "--rewardbase", 304 flagType: FlagTypeArgument, 305 values: []string{"0x777fd033b5e3bcaad6006bc9f481ffed6b83cf5a"}, 306 wrongValues: commonThreeErrors, 307 errors: []int{ErrorFatal, ErrorFatal, ErrorFatal}, 308 }, 309 { 310 flag: "--extradata", 311 flagType: FlagTypeArgument, 312 values: []string{"0x0000000000000000000000000000000000000000000000000000000000000000f89af85494dddfb991127b43e209c2f8ed08b8b3d0b5843d3694195ba9cc787b00796a7ae6356e5b656d4360353794777fd033b5e3bcaad6006bc9f481ffed6b83cf5a94d473284239f704adccd24647c7ca132992a28973b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0"}, 313 wrongValues: []string{}, 314 errors: []int{}, 315 }, 316 { 317 flag: "--txresend.interval", 318 flagType: FlagTypeArgument, 319 values: []string{"3", "5", "7"}, 320 wrongValues: commonTwoErrors, 321 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 322 }, 323 { 324 flag: "--txresend.max-count", 325 flagType: FlagTypeArgument, 326 values: []string{"1000", "2000"}, 327 wrongValues: commonTwoErrors, 328 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 329 }, 330 { 331 flag: "--txresend.use-legacy", 332 flagType: FlagTypeBoolean, 333 }, 334 { 335 flag: "--unlock", 336 flagType: FlagTypeArgument, 337 values: []string{"", "0x0", "0x777fd033b5e3bcaad6006bc9f481ffed6b83cf5a"}, 338 wrongValues: []string{"abcdefg", "!@#$%^&", "0x921jfinowaae333"}, 339 errors: []int{NonError, NonError, NonError}, 340 }, 341 { 342 flag: "--password", 343 flagType: FlagTypeArgument, 344 values: []string{"abcd", "aoije091"}, 345 wrongValues: []string{}, 346 errors: []int{}, 347 }, 348 { 349 flag: "--vmdebug", 350 flagType: FlagTypeBoolean, 351 }, 352 { 353 flag: "--vmlog", 354 flagType: FlagTypeArgument, 355 values: []string{"0", "1", "2", "3"}, 356 wrongValues: append(commonThreeErrors, "4"), 357 errors: []int{NonError, NonError, NonError, NonError}, 358 }, 359 { 360 flag: "--metrics", 361 flagType: FlagTypeBoolean, 362 }, 363 { 364 flag: "--prometheus", 365 flagType: FlagTypeBoolean, 366 }, 367 { 368 flag: "--prometheusport", 369 flagType: FlagTypeArgument, 370 values: []string{"61001"}, 371 wrongValues: commonThreeErrors, 372 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 373 }, 374 { 375 flag: "--rpc", 376 flagType: FlagTypeBoolean, 377 }, 378 { 379 flag: "--rpcaddr", 380 flagType: FlagTypeArgument, 381 values: []string{"localhost", "123.123.123.123"}, 382 wrongValues: append(commonThreeErrors, "123.123.123.256"), 383 errors: []int{NonError, NonError, NonError, NonError}, 384 }, 385 { 386 flag: "--rpcport", 387 flagType: FlagTypeArgument, 388 values: []string{"8551"}, 389 wrongValues: commonThreeErrors, 390 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 391 }, 392 { 393 flag: "--rpccorsdomain", 394 flagType: FlagTypeArgument, 395 values: []string{"", "localhost", "123.123.123.123"}, 396 wrongValues: append(commonThreeErrors, "123.123.123.256"), 397 errors: []int{NonError, NonError, NonError, NonError}, 398 }, 399 { 400 flag: "--rpcvhosts", 401 flagType: FlagTypeArgument, 402 values: []string{"*"}, 403 wrongValues: commonThreeErrors, 404 errors: []int{NonError, NonError, NonError}, 405 }, 406 { 407 flag: "--rpcapi", 408 flagType: FlagTypeArgument, 409 values: []string{"", "klay", "klay,personal,istanbul,debug,miner"}, 410 wrongValues: commonThreeErrors, 411 errors: []int{NonError, NonError, NonError}, 412 }, 413 { 414 flag: "--ipcdisable", 415 flagType: FlagTypeBoolean, 416 }, 417 { 418 flag: "--ipcpath", 419 flagType: FlagTypeBoolean, 420 }, 421 { 422 flag: "--ws", 423 flagType: FlagTypeBoolean, 424 }, 425 { 426 flag: "--wsaddr", 427 flagType: FlagTypeArgument, 428 values: []string{"localhost"}, 429 wrongValues: commonThreeErrors, 430 errors: []int{NonError, NonError, NonError}, 431 }, 432 { 433 flag: "--wsport", 434 flagType: FlagTypeArgument, 435 values: []string{"8552"}, 436 wrongValues: commonThreeErrors, 437 errors: []int{NonError, NonError, NonError}, 438 }, 439 { 440 flag: "--grpc", 441 flagType: FlagTypeBoolean, 442 }, 443 { 444 flag: "--grpcaddr", 445 flagType: FlagTypeArgument, 446 values: []string{"localhost", "123.123.123.123"}, 447 wrongValues: commonThreeErrors, 448 errors: []int{NonError, NonError, NonError}, 449 }, 450 { 451 flag: "--grpcport", 452 flagType: FlagTypeArgument, 453 values: []string{"8553"}, 454 wrongValues: commonThreeErrors, 455 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 456 }, 457 { 458 flag: "--wsapi", 459 flagType: FlagTypeArgument, 460 values: []string{"", "klay", "klay,personal,istanbul,debug,miner"}, 461 wrongValues: commonThreeErrors, 462 errors: []int{NonError, NonError, NonError}, 463 }, 464 { 465 flag: "--wsorigins", 466 flagType: FlagTypeArgument, 467 values: []string{""}, 468 wrongValues: []string{}, 469 errors: []int{}, 470 }, 471 { 472 flag: "--exec", 473 flagType: FlagTypeArgument, 474 values: []string{"klay.blockNumber", "klat.getBlock(0)", "governance.getParams()[\"reward.proposerupdateinterval\"]"}, 475 wrongValues: commonThreeErrors, 476 errors: []int{NonError, NonError, NonError}, 477 }, 478 { 479 flag: "--preload", 480 flagType: FlagTypeArgument, 481 values: []string{"abc.js", "tmp.js", "tmp"}, 482 wrongValues: []string{}, 483 errors: []int{}, 484 }, 485 //TODO-Klaytn-Node the flag is not defined on any klay binaries 486 //{ 487 // flag: "--nodetype", 488 // flagType: FlagTypeArgument, 489 // values: []string{"cn", "pn", "en"}, 490 // wrongValues: []string{}, 491 // errors: []int{}, 492 //}, 493 { 494 flag: "--maxconnections", 495 flagType: FlagTypeArgument, 496 values: []string{"0", "30", "25000"}, 497 wrongValues: commonTwoErrors, 498 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 499 }, 500 { 501 flag: "--maxpendpeers", 502 flagType: FlagTypeArgument, 503 values: []string{"0", "30", "50"}, 504 wrongValues: commonTwoErrors, 505 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 506 }, 507 { 508 flag: "--port", 509 flagType: FlagTypeArgument, 510 values: []string{"32323", "30303"}, 511 wrongValues: commonThreeErrors, 512 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 513 }, 514 { 515 flag: "--subport", 516 flagType: FlagTypeArgument, 517 values: []string{"32324", "32325", "32327"}, 518 wrongValues: commonThreeErrors, 519 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 520 }, 521 { 522 flag: "--multichannel", 523 flagType: FlagTypeBoolean, 524 }, 525 { 526 flag: "--bootnodes", 527 flagType: FlagTypeArgument, 528 values: []string{"0xf4316f69d9522667c0674afcd8638288489f0333", "", "0xf4316f69d9522667c0674afcd8638288489f0333, d473284239f704adccd24647c7ca132992a28973"}, 529 wrongValues: []string{}, 530 errors: []int{}, 531 }, 532 { 533 flag: "--nodekey", 534 flagType: FlagTypeArgument, 535 values: []string{""}, 536 wrongValues: []string{}, 537 errors: []int{}, 538 }, 539 { 540 flag: "--nodekeyhex", 541 flagType: FlagTypeArgument, 542 values: []string{"8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f"}, 543 wrongValues: commonThreeErrors, 544 errors: []int{ErrorFatal, ErrorFatal, ErrorFatal}, 545 }, 546 { 547 flag: "--nat", 548 flagType: FlagTypeArgument, 549 values: []string{"any", "none", "upnp", "pmp", "extip:127.0.0.1"}, 550 wrongValues: []string{}, 551 errors: []int{}, 552 }, 553 { 554 flag: "--nodiscover", 555 flagType: FlagTypeBoolean, 556 }, 557 { 558 flag: "--netrestrict", 559 flagType: FlagTypeArgument, 560 values: []string{}, 561 wrongValues: []string{}, 562 errors: []int{}, 563 }, 564 { 565 flag: "--chaintxperiod", 566 flagType: FlagTypeArgument, 567 values: []string{"1", "5", "100"}, 568 wrongValues: commonTwoErrors, 569 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 570 }, 571 { 572 flag: "--chaintxlimit", 573 flagType: FlagTypeArgument, 574 values: []string{"100", "200"}, 575 wrongValues: commonTwoErrors, 576 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 577 }, 578 { 579 flag: "--jspath", 580 flagType: FlagTypeArgument, 581 values: []string{".", "root/abc/efg"}, 582 wrongValues: commonThreeErrors, 583 errors: []int{NonError, NonError, NonError}, 584 }, 585 { 586 flag: "--baobab", 587 flagType: FlagTypeBoolean, 588 }, 589 //TODO-Klaytn-Node the flag is not defined on any klay binaries 590 //{ 591 // flag: "--bnaddr", 592 // flagType: FlagTypeArgument, 593 // values: []string{}, 594 // wrongValues: []string{}, 595 // errors: []int{}, 596 //}, 597 //TODO-Klaytn-Node the flag is not defined on any klay binaries 598 //{ 599 // flag: "--genkey", 600 // flagType: FlagTypeArgument, 601 // values: []string{}, 602 // wrongValues: []string{}, 603 // errors: []int{}, 604 //}, 605 //TODO-Klaytn-Node the flag is not defined on any klay binaries 606 //{ 607 // flag: "--writeaddress", 608 // flagType: FlagTypeBoolean, 609 //}, 610 { 611 flag: "--mainbridge", 612 flagType: FlagTypeBoolean, 613 }, 614 { 615 flag: "--subbridge", 616 flagType: FlagTypeBoolean, 617 }, 618 { 619 flag: "--mainbridgeport", 620 flagType: FlagTypeArgument, 621 values: []string{"50505", "23232"}, 622 wrongValues: commonThreeErrors, 623 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 624 }, 625 { 626 flag: "--subbridgeport", 627 flagType: FlagTypeArgument, 628 values: []string{"50505", "23232"}, 629 wrongValues: commonThreeErrors, 630 errors: []int{ErrorInvalidValue, NonError, ErrorInvalidValue}, 631 }, 632 { 633 flag: "--vtrecovery", 634 flagType: FlagTypeBoolean, 635 }, 636 { 637 flag: "--vtrecoveryinterval", 638 flagType: FlagTypeArgument, 639 values: []string{"60", "100", "200"}, 640 wrongValues: commonTwoErrors, 641 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 642 }, 643 { 644 flag: "--scnewaccount", 645 flagType: FlagTypeBoolean, 646 }, 647 { 648 flag: "--dbsyncer", 649 flagType: FlagTypeBoolean, 650 }, 651 { 652 flag: "--dbsyncer.db.host", 653 flagType: FlagTypeArgument, 654 values: []string{"localhost", "123.123.123.123", "127.0.0.1"}, 655 wrongValues: commonThreeErrors, 656 errors: []int{NonError, NonError, NonError}, 657 }, 658 { 659 flag: "--dbsyncer.db.port", 660 flagType: FlagTypeArgument, 661 values: []string{"3306", "32323"}, 662 wrongValues: commonThreeErrors, 663 errors: []int{NonError, NonError, NonError}, 664 }, 665 { 666 flag: "--dbsyncer.db.name", 667 flagType: FlagTypeBoolean, 668 }, 669 { 670 flag: "--dbsyncer.db.user", 671 flagType: FlagTypeBoolean, 672 }, 673 { 674 flag: "--dbsyncer.db.password", 675 flagType: FlagTypeArgument, 676 values: []string{"aboaise", "jaooao122!@", "18231@#!@412!"}, 677 wrongValues: []string{}, 678 errors: []int{}, 679 }, 680 { 681 flag: "--dbsyncer.logmode", 682 flagType: FlagTypeBoolean, 683 }, 684 { 685 flag: "--dbsyncer.db.max.idle", 686 flagType: FlagTypeArgument, 687 values: []string{"50", "100"}, 688 wrongValues: commonTwoErrors, 689 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 690 }, 691 { 692 flag: "--dbsyncer.db.max.open", 693 flagType: FlagTypeArgument, 694 values: []string{"30", "50", "100"}, 695 wrongValues: commonTwoErrors, 696 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 697 }, 698 { 699 flag: "--dbsyncer.db.max.lifetime", 700 flagType: FlagTypeArgument, 701 values: []string{"1h0m0s", "0h0m10s"}, 702 wrongValues: commonThreeErrors, 703 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 704 }, 705 { 706 flag: "--dbsyncer.block.channel.size", 707 flagType: FlagTypeArgument, 708 values: []string{"5"}, 709 wrongValues: commonTwoErrors, 710 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 711 }, 712 { 713 flag: "--dbsyncer.mode", 714 flagType: FlagTypeArgument, 715 values: []string{"single", "multi", "context"}, 716 wrongValues: commonThreeErrors, 717 errors: []int{NonError, NonError, NonError}, 718 }, 719 { 720 flag: "--dbsyncer.genquery.th", 721 flagType: FlagTypeArgument, 722 values: []string{"50", "123"}, 723 wrongValues: commonTwoErrors, 724 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 725 }, 726 { 727 flag: "--dbsyncer.insert.th", 728 flagType: FlagTypeArgument, 729 values: []string{"30", "123"}, 730 wrongValues: commonTwoErrors, 731 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 732 }, 733 { 734 flag: "--dbsyncer.bulk.size", 735 flagType: FlagTypeArgument, 736 values: []string{"200"}, 737 wrongValues: commonTwoErrors, 738 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 739 }, 740 { 741 flag: "--dbsyncer.event.mode", 742 flagType: FlagTypeArgument, 743 values: []string{"block", "head"}, 744 wrongValues: commonThreeErrors, 745 errors: []int{NonError, NonError, NonError}, 746 }, 747 { 748 flag: "--dbsyncer.max.block.diff", 749 flagType: FlagTypeArgument, 750 values: []string{"0", "5", "100"}, 751 wrongValues: commonTwoErrors, 752 errors: []int{ErrorInvalidValue, ErrorInvalidValue}, 753 }, 754 { 755 flag: "--autorestart.daemon.path", 756 flagType: FlagTypeArgument, 757 values: []string{"~/klaytn/bin/kcnd", "~/klaytn/bin/kpnd", "~/klaytn/bin/kend"}, 758 wrongValues: commonThreeErrors, 759 errors: []int{NonError, NonError, NonError}, 760 }, 761 { 762 flag: "--autorestart.enable", 763 flagType: FlagTypeBoolean, 764 }, 765 { 766 flag: "--autorestart.timeout", 767 flagType: FlagTypeArgument, 768 values: []string{"10m", "60s", "1h"}, 769 wrongValues: commonThreeErrors, 770 errors: []int{ErrorInvalidValue, ErrorInvalidValue, ErrorInvalidValue}, 771 }, 772 } 773 774 func testFlags(t *testing.T, flag string, value string, idx int) { 775 datadir := tmpdir(t) 776 defer os.RemoveAll(datadir) 777 778 json := filepath.Join(datadir, "genesis.json") 779 if err := os.WriteFile(json, []byte(genesis), 0o600); err != nil { 780 t.Fatalf("test %d: failed to write genesis file: %v", idx, err) 781 } 782 783 runKlay(t, "klay-test-flag", "--verbosity", "0", "--datadir", datadir, "init", json).WaitExit() 784 785 klay := runKlay(t, "klay-test-flag", "--datadir", datadir, flag, value) 786 klay.ExpectExit() 787 } 788 789 func testWrongFlags(t *testing.T, flag string, value string, idx int, expectedError string) { 790 datadir := tmpdir(t) 791 defer os.RemoveAll(datadir) 792 793 json := filepath.Join(datadir, "genesis.json") 794 if err := os.WriteFile(json, []byte(genesis), 0o600); err != nil { 795 t.Fatalf("test %d: failed to write genesis file: %v", idx, err) 796 } 797 798 runKlay(t, "klay-test-flag", "--verbosity", "0", "--datadir", datadir, "init", json).WaitExit() 799 800 klay := runKlay(t, "klay-test-flag", "--datadir", datadir, flag, value) 801 klay.ExpectRegexp(expectedError) 802 } 803 804 func TestFlags(t *testing.T) { 805 expectedError := []string{ 806 "Incorrect Usage. flag provided but not defined: (.*)", 807 "Incorrect Usage. invalid value (.*)", 808 "Fatal:(.*)", 809 "(.*)", 810 } 811 for idx, fwv := range flagsWithValues { 812 switch fwv.flagType { 813 case FlagTypeBoolean: 814 t.Run("klay-test-flag"+fwv.flag, func(t *testing.T) { 815 testFlags(t, fwv.flag, "", idx) 816 }) 817 case FlagTypeArgument: 818 for _, item := range fwv.values { 819 t.Run("klay-test-flag"+fwv.flag+"-"+item, func(t *testing.T) { 820 testFlags(t, fwv.flag, item, idx) 821 }) 822 } 823 for idx2, wrongItem := range fwv.wrongValues { 824 t.Run("klay-test-flag"+fwv.flag+"-"+wrongItem, func(t *testing.T) { 825 testWrongFlags(t, fwv.flag, wrongItem, idx, expectedError[fwv.errors[idx2]]) 826 }) 827 } 828 } 829 } 830 }