Ejemplo n.º 1
0
func TestIsExist(t *testing.T) {
	_, teardown, err := setup(t)
	if err != nil {
		t.Fatal(err)
	}

	defer teardown()

	testData := []struct {
		Type coin.Type
		Seed string
	}{
		{coin.Bitcoin, "sd666"},
		{coin.Bitcoin, "sd667"},
		{coin.Skycoin, "sd666"},
		{coin.Skycoin, "sd667"},
	}

	for _, d := range testData {
		id := wallet.MakeWltID(d.Type, d.Seed)
		if wallet.IsExist(id) {
			t.Fatalf("wallet:%s should not exist", id)
		}

		_, err := wallet.New(d.Type, d.Seed)
		if err != nil {
			t.Fatalf("creat wallet :%s failed", id)
		}

		if !wallet.IsExist(id) {
			t.Fatalf("wallet:%s should exist", id)
		}
	}
}
Ejemplo n.º 2
0
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
}