コード例 #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)
}
コード例 #2
0
func TestNewAndSet(t *testing.T) {
	dir, teardown, err := setup(t)
	// dir, _, err := setup(t)
	if err != nil {
		t.Fatal(err)
	}
	defer teardown()

	a := account.New()
	a.WltIDs[bitcoin.Type] = "bitcoin_sd110"
	a.WltIDs[skycoin.Type] = "skycoin_sd110"
	account.Set(a)

	// get account
	d, err := ioutil.ReadFile(filepath.Join(dir, account.FileName()))
	if err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(string(d), a.Pubkey) {
		t.Fatal("new account failed")
	}

	if !strings.Contains(string(d), a.Seckey) {
		t.Fatal("new account failed")
	}

	if !strings.Contains(string(d), "bitcoin_sd110") {
		t.Fatal("new account failed")
	}

	if !strings.Contains(string(d), "skycoin_sd110") {
		t.Fatal("new account failed")
	}
}
コード例 #3
0
ファイル: account.go プロジェクト: skycoin/skycoin-exchange
// CreateAccount handle the request of creating account.
func CreateAccount(se Servicer) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
		// generate account pubkey/privkey pair, pubkey is the account id.
		errRlt := &pp.EmptyRes{}
		for {
			a := account.New()
			r := pp.CreateAccountReq{
				Pubkey: pp.PtrString(a.Pubkey),
			}
			res := pp.CreateAccountRes{}
			if err := sknet.EncryGet(se.GetServAddr(), "/create/account", r, &res); err != nil {
				logger.Error(err.Error())
				errRlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
				break
			}

			// acntRes := res.(*pp.CreateAccountRes)
			if !res.GetResult().GetSuccess() {
				sendJSON(w, res)
			} else {
				ret := struct {
					Result    pp.Result `json:"result"`
					Pubkey    string    `json:"pubkey"`
					CreatedAt int64     `json:"created_at"`
				}{
					Result:    *res.Result,
					Pubkey:    a.Pubkey,
					CreatedAt: res.GetCreatedAt(),
				}
				account.Set(a)
				sendJSON(w, &ret)
			}
			return
		}
		sendJSON(w, errRlt)
	}
}