Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Fix account ID destinations in /payment
Browse files Browse the repository at this point in the history
Close #55
  • Loading branch information
bartekn committed Mar 27, 2017
1 parent 5ec190d commit 250aafb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import (
"github.com/stellar/gateway/protocols/bridge"
callback "github.com/stellar/gateway/protocols/compliance"
"github.com/stellar/gateway/server"
"github.com/stellar/go/address"
"github.com/stellar/go/amount"
b "github.com/stellar/go/build"
"github.com/stellar/go/keypair"
"github.com/stellar/go/protocols/compliance"
"github.com/stellar/go/protocols/federation"
"github.com/stellar/go/xdr"
)

Expand Down Expand Up @@ -118,11 +120,18 @@ func (rh *RequestHandler) Payment(w http.ResponseWriter, r *http.Request) {
submitResponse, submitError = rh.TransactionSubmitter.SignAndSubmitRawTransaction(request.Source, &tx)
} else {
// Payment without compliance server
destinationObject, err := rh.FederationResolver.LookupByAddress(request.Destination)
destinationObject := &federation.NameResponse{}

_, _, err := address.Split(request.Destination)
if err != nil {
log.WithFields(log.Fields{"destination": request.Destination, "err": err}).Print("Cannot resolve address")
server.Write(w, bridge.PaymentCannotResolveDestination)
return
destinationObject.AccountID = request.Destination
} else {
destinationObject, err = rh.FederationResolver.LookupByAddress(request.Destination)
if err != nil {
log.WithFields(log.Fields{"destination": request.Destination, "err": err}).Print("Cannot resolve address")
server.Write(w, bridge.PaymentCannotResolveDestination)
return
}
}

_, err = keypair.Parse(destinationObject.AccountID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,57 @@ func TestRequestHandlerPayment(t *testing.T) {
})
})

Convey("When destination is a public key", func() {
validParams := url.Values{
// GBKGH7QZVCZ2ZA5OUGZSTHFNXTBHL3MPCKSCBJUAQODGPMWP7OMMRKDW
"source": {"SDRAS7XIQNX25UDCCX725R4EYGBFYGJE4HJ2A3DFCWJIHMRSMS7CXX42"},
"destination": {"GAPCT362RATBUJ37RN2MOKQIZLHSJMO33MMCSRUXTTHIGVDYWOFG5HDS"},
"amount": {"20.0"},
}

// Loading sequence number
mockHorizon.On(
"LoadAccount",
"GBKGH7QZVCZ2ZA5OUGZSTHFNXTBHL3MPCKSCBJUAQODGPMWP7OMMRKDW",
).Return(
horizon.AccountResponse{
SequenceNumber: "100",
},
nil,
).Once()

// Checking if destination account exists
mockHorizon.On(
"LoadAccount",
"GAPCT362RATBUJ37RN2MOKQIZLHSJMO33MMCSRUXTTHIGVDYWOFG5HDS",
).Return(horizon.AccountResponse{}, nil).Once()

var ledger uint64
ledger = 1988728
horizonResponse := horizon.SubmitTransactionResponse{
Hash: "6a0049b44e0d0341bd52f131c74383e6ccd2b74b92c829c990994d24bbfcfa7a",
Ledger: &ledger,
Extras: nil,
}

mockHorizon.On(
"SubmitTransaction",
"AAAAAFRj/hmos6yDrqGzKZytvMJ17Y8SpCCmgIOGZ7LP+5jIAAAAZAAAAAAAAABlAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAHinv2ogmGid/i3THKgjKzySx29sYKUaXnM6DVHizim4AAAAAAAAAAAvrwgAAAAAAAAAAAc/7mMgAAABAh6unGAOSOD3+9vbZXHwhDq4xdp/hl4MqZu0VVdLwldKPVy9MpXstDDxnNBBBzU48Hto+jH3qL73bbu+7zVXvCQ==",
).Return(horizonResponse, nil).Once()

Convey("it should return success", func() {
statusCode, response := net.GetResponse(testServer, validParams)
responseString := strings.TrimSpace(string(response))

assert.Equal(t, 200, statusCode)
expected := test.StringToJSONMap(`{
"hash": "6a0049b44e0d0341bd52f131c74383e6ccd2b74b92c829c990994d24bbfcfa7a",
"ledger": 1988728
}`)
assert.Equal(t, expected, test.StringToJSONMap(responseString))
})
})

Convey("When destination is a Stellar address", func() {
params := url.Values{
"source": {"SDRAS7XIQNX25UDCCX725R4EYGBFYGJE4HJ2A3DFCWJIHMRSMS7CXX42"},
Expand Down

0 comments on commit 250aafb

Please sign in to comment.