Skip to content

Commit

Permalink
last changes before commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gouthamp-stellar committed Sep 25, 2024
1 parent f10d239 commit e857b80
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion internal/tss/utils/transaction_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ func BuildOriginalTransaction(txOpXDRs []string) (*txnbuild.Transaction, error)
operations = append(operations, &paymentOp)
}

tx, _ := txnbuild.NewTransaction(txnbuild.TransactionParams{
tx, err := txnbuild.NewTransaction(txnbuild.TransactionParams{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: keypair.MustRandom().Address(),
},
Operations: operations,
BaseFee: 104,
Preconditions: txnbuild.Preconditions{TimeBounds: txnbuild.NewTimeout(10)},
})
if err != nil {
return nil, fmt.Errorf("cannot create new transaction: %w", err)
}
return tx, nil
}
20 changes: 12 additions & 8 deletions internal/tss/utils/transaction_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,31 @@ func (t *transactionService) SendTransaction(transactionXdr string) (tss.RPCSend
sendTxResponse.TransactionXDR = transactionXdr
if err != nil {
sendTxResponse.Code.OtherCodes = tss.RPCFailCode
return sendTxResponse, fmt.Errorf("RPC fail: %s", err.Error())
return sendTxResponse, fmt.Errorf("RPC fail: %w", err)
}
sendTxResponse.Status = tss.RPCTXStatus(rpcResponse.RPCResult.Status)
sendTxResponse.Code, err = t.parseErrorResultXDR(rpcResponse.RPCResult.ErrorResultXDR)
sendTxResponse.TransactionHash = rpcResponse.RPCResult.Hash
return sendTxResponse, err
sendTxResponse.Code, err = t.parseErrorResultXDR(rpcResponse.RPCResult.ErrorResultXDR)
if err != nil {
return sendTxResponse, fmt.Errorf("parse error result xdr string: %w", err)
}
return sendTxResponse, nil
}

func (t *transactionService) GetTransaction(transactionHash string) (tss.RPCGetIngestTxResponse, error) {
rpcResponse, err := t.sendRPCRequest("getTransaction", map[string]string{"hash": transactionHash})
if err != nil {
return tss.RPCGetIngestTxResponse{Status: tss.ErrorStatus}, fmt.Errorf("RPC Fail: %s", err.Error())
}
getIngestTxResponse := tss.RPCGetIngestTxResponse{}
getIngestTxResponse.Status = tss.RPCTXStatus(rpcResponse.RPCResult.Status)
getIngestTxResponse.EnvelopeXDR = rpcResponse.RPCResult.EnvelopeXDR
getIngestTxResponse.ResultXDR = rpcResponse.RPCResult.ResultXDR
getIngestTxResponse := tss.RPCGetIngestTxResponse{
Status: tss.RPCTXStatus(rpcResponse.RPCResult.Status),
EnvelopeXDR: rpcResponse.RPCResult.EnvelopeXDR,
ResultXDR: rpcResponse.RPCResult.ResultXDR,
}
if getIngestTxResponse.Status != tss.NotFoundStatus {
getIngestTxResponse.CreatedAt, err = strconv.ParseInt(rpcResponse.RPCResult.CreatedAt, 10, 64)
if err != nil {
return tss.RPCGetIngestTxResponse{Status: tss.ErrorStatus}, fmt.Errorf("unable to parse createAt: %s", err.Error())
return tss.RPCGetIngestTxResponse{Status: tss.ErrorStatus}, fmt.Errorf("unable to parse createAt: %w", err)
}
}
return getIngestTxResponse, nil
Expand Down
19 changes: 18 additions & 1 deletion internal/tss/utils/transaction_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,23 @@ func TestSendTransaction(t *testing.T) {
assert.Equal(t, tss.RPCFailCode, resp.Code.OtherCodes)
assert.Equal(t, "RPC fail: sendTransaction: sending POST request to rpc: RPC Connection fail", err.Error())

})
t.Run("response_has_empty_errorResultXdr", func(t *testing.T) {
httpResponse := &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(`{"result": {"status": "PENDING", "errorResultXdr": ""}}`)),
}
mockHTTPClient.
On("Post", rpcURL, "application/json", bytes.NewBuffer(jsonData)).
Return(httpResponse, nil).
Once()

resp, err := txService.SendTransaction("ABCD")

assert.Equal(t, tss.PendingStatus, resp.Status)
assert.Equal(t, tss.UnMarshalBinaryCode, resp.Code.OtherCodes)
assert.Equal(t, "parse error result xdr string: unable to unmarshal errorResultXdr: ", err.Error())

})
t.Run("response_has_unparsable_errorResultXdr", func(t *testing.T) {
httpResponse := &http.Response{
Expand All @@ -510,7 +527,7 @@ func TestSendTransaction(t *testing.T) {
resp, err := txService.SendTransaction("ABCD")

assert.Equal(t, tss.UnMarshalBinaryCode, resp.Code.OtherCodes)
assert.Equal(t, "unable to unmarshal errorResultXdr: ABC123", err.Error())
assert.Equal(t, "parse error result xdr string: unable to unmarshal errorResultXdr: ABC123", err.Error())
})
t.Run("response_has_errorResultXdr", func(t *testing.T) {
httpResponse := &http.Response{
Expand Down

0 comments on commit e857b80

Please sign in to comment.