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

	defer teardown()

	// new account
	a := account.New()
	account.Set(a)

	act, err := account.Get(a.Pubkey)
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, act, a)

	// add wallet id
	act.WltIDs[bitcoin.Type] = "bitcoin_sd19"
	act.WltIDs[skycoin.Type] = "skycoin_sd19"
	account.Set(act)

	newA, err := account.Get(act.Pubkey)
	if err != nil {
		t.Fatal(err)
	}

	assert.Equal(t, newA, act)
}
Esempio n. 2
0
func TestInitDir(t *testing.T) {
	// dir, teardown, err := setup(t)
	dir, _, err := setup(t)
	if err != nil {
		t.Fatal(err)
	}

	fmt.Println(dir)
	// defer teardown()
	// check the exitence of dir.
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		t.Fatal("account init dir failed")
	}

	// store some account.
	p, s := cipher.GenerateKeyPair()
	acnt := account.Account{
		Pubkey: p.Hex(),
		Seckey: s.Hex(),
	}

	v := fmt.Sprintf(`{"active_account":"%s","accounts":[{"pubkey":"%s", "seckey":"%s"}]}`, p.Hex(), p.Hex(), s.Hex())

	if err := ioutil.WriteFile(filepath.Join(dir, "data.act"), []byte(v), 0777); err != nil {
		t.Fatal(err)
	}

	// init dir again.
	account.InitDir(dir)

	// check if the account is loaded.
	a, err := account.Get(p.Hex())
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, acnt.Pubkey, a.Pubkey)
	assert.Equal(t, acnt.Seckey, a.Seckey)

	activeAccount, err := account.GetActive()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, activeAccount.Pubkey, p.Hex())
}