func setup(t *testing.T) (string, func(), error) { wltName := fmt.Sprintf(".wallet%d", rand.Int31n(100)) teardown := func() {} tmpDir := filepath.Join(os.TempDir(), wltName) if err := os.MkdirAll(tmpDir, 0777); err != nil { return "", teardown, err } teardown = func() { if err := os.RemoveAll(tmpDir); err != nil { panic(err) } } wallet.InitDir(tmpDir) return tmpDir, teardown, nil }
func TestInitDir(t *testing.T) { wltName := fmt.Sprintf(".wallet%d", rand.Int31n(100)) tmpDir := filepath.Join(os.TempDir(), wltName) wallet.InitDir(tmpDir) // check if the dir is created. if _, err := os.Stat(tmpDir); os.IsNotExist(err) { t.Error("init dir failed") return } if wallet.GetWalletDir() != tmpDir { t.Error("GetWalletDir function failed") return } // remove the created wallet dir. err := os.RemoveAll(tmpDir) assert.Nil(t, err) }
func makeWallets(dir string, items []walletItem) (wallets, error) { f := func() { logger.Debug("wallet dir:%s", dir) wallet.InitDir(dir) } initWalletOnce.Do(f) wlts := wallets{ids: make(map[string]string)} // create wallets if not exist. for _, item := range items { id := wallet.MakeWltID(item.Type, item.Seed) if !wallet.IsExist(id) { _, err := wallet.New(item.Type, item.Seed) if err != nil { return wallets{}, err } } wlts.ids[item.Type] = id } return wlts, nil }
// Run start the client service. func (se *Service) Run() { // init wallet dir wallet.InitDir(se.cfg.WalletDir) // init account dir account.InitDir(se.cfg.AccountDir) // register coins r := router.New(se) addr := fmt.Sprintf("localhost:%d", se.cfg.Port) if err := gui.LaunchWebInterface(addr, se.cfg.GuiDir, r); err != nil { panic(err) } go func() { // Wait a moment just to make sure the http service is up time.Sleep(time.Millisecond * 100) fulladdress := fmt.Sprintf("http://%s", addr) logger.Info("Launching System Browser with %s", fulladdress) if err := util.OpenBrowser(fulladdress); err != nil { logger.Error(err.Error()) } }() }