(testName string, chainID string)
| 543 | } |
| 544 | |
| 545 | func ResetTestRootWithChainID(testName string, chainID string) *Config { |
| 546 | // create a unique, concurrency-safe test directory under os.TempDir() |
| 547 | rootDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s_", chainID, testName)) |
| 548 | if err != nil { |
| 549 | panic(err) |
| 550 | } |
| 551 | // ensure config and data subdirs are created |
| 552 | if err := tmos.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { |
| 553 | panic(err) |
| 554 | } |
| 555 | if err := tmos.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { |
| 556 | panic(err) |
| 557 | } |
| 558 | |
| 559 | baseConfig := DefaultBaseConfig() |
| 560 | configFilePath := filepath.Join(rootDir, defaultConfigFilePath) |
| 561 | genesisFilePath := filepath.Join(rootDir, baseConfig.Genesis) |
| 562 | privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey) |
| 563 | privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState) |
| 564 | |
| 565 | // Write default config file if missing. |
| 566 | if !tmos.FileExists(configFilePath) { |
| 567 | writeDefaultConfigFile(configFilePath) |
| 568 | } |
| 569 | if !tmos.FileExists(genesisFilePath) { |
| 570 | if chainID == "" { |
| 571 | chainID = "tendermint_test" |
| 572 | } |
| 573 | testGenesis := fmt.Sprintf(testGenesisFmt, chainID) |
| 574 | tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0o644) |
| 575 | } |
| 576 | // we always overwrite the priv val |
| 577 | tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0o644) |
| 578 | tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0o644) |
| 579 | |
| 580 | config := TestConfig().SetRoot(rootDir) |
| 581 | return config |
| 582 | } |
| 583 | |
| 584 | var testGenesisFmt = `{ |
| 585 | "genesis_time": "2018-10-10T08:20:13.695936996Z", |
no test coverage detected