Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/chains/stellar/proto_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func ConvertSubmitTransactionResponseToProto(reply *stellar.SubmitTransactionRes
}

resp := &SubmitTransactionResponse{
TxStatus: txStatus,
TxStatus: &txStatus,
TxHash: reply.TxHash,
TxIdempotencyKey: reply.TxIdempotencyKey,
ResultXdr: resultXDR,
Expand All @@ -521,6 +521,9 @@ func ConvertSubmitTransactionResponseFromProto(p *SubmitTransactionResponse) (*s
if p == nil {
return nil, errors.New("submit transaction reply is nil")
}
if p.TxStatus == nil {
return nil, errors.New("txStatus is required")
}
txStatus, err := convertTxStatusFromProto(p.GetTxStatus())
if err != nil {
return nil, fmt.Errorf("txStatus: %w", err)
Expand Down Expand Up @@ -828,7 +831,7 @@ func convertEventInfoToProto(e stellar.EventInfo) (*EventInfo, error) {
}

return &EventInfo{
EventType: eventType,
EventType: &eventType,
Ledger: e.Ledger,
LedgerClosedAt: e.LedgerClosedAt,
ContractId: e.ContractID,
Expand All @@ -845,6 +848,9 @@ func convertEventInfoFromProto(p *EventInfo) (stellar.EventInfo, error) {
if p == nil {
return stellar.EventInfo{}, errors.New("event info is nil")
}
if p.EventType == nil {
return stellar.EventInfo{}, errors.New("eventType is required")
}

eventType, err := convertEventTypeFromProto(p.GetEventType())
if err != nil {
Expand Down
38 changes: 34 additions & 4 deletions pkg/chains/stellar/proto_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,21 @@ func TestConvertSubmitTransactionResponseToProto_UnsupportedTxStatus(t *testing.
}

func TestConvertSubmitTransactionResponseFromProto_UnsupportedTxStatus(t *testing.T) {
txStatus := conv.TxStatus(99)
_, err := conv.ConvertSubmitTransactionResponseFromProto(&conv.SubmitTransactionResponse{
TxStatus: conv.TxStatus(99),
TxStatus: &txStatus,
})
require.Error(t, err)
require.Contains(t, err.Error(), "txStatus")
require.Contains(t, err.Error(), "unsupported proto tx status")
}

func TestConvertSubmitTransactionResponseFromProto_MissingTxStatus(t *testing.T) {
_, err := conv.ConvertSubmitTransactionResponseFromProto(&conv.SubmitTransactionResponse{})
require.Error(t, err)
require.Contains(t, err.Error(), "txStatus is required")
}

func TestConvertSubmitTransactionRequestFromProto_BadArg(t *testing.T) {
_, err := conv.ConvertSubmitTransactionRequestFromProto(&conv.SubmitTransactionRequest{
ContractId: "C_X",
Expand Down Expand Up @@ -1213,10 +1220,11 @@ func TestConvertGetEventsResponseFromProto_NilEvent(t *testing.T) {
}

func TestConvertGetEventsResponseFromProto_MissingValue(t *testing.T) {
eventType := conv.EventType_EVENT_TYPE_CONTRACT
_, err := conv.ConvertGetEventsResponseFromProto(&conv.GetEventsResponse{
Events: []*conv.EventInfo{
{
EventType: conv.EventType_EVENT_TYPE_CONTRACT,
EventType: &eventType,
},
},
})
Expand All @@ -1226,6 +1234,7 @@ func TestConvertGetEventsResponseFromProto_MissingValue(t *testing.T) {
}

func TestConvertGetEventsResponseFromProto_UnsupportedEventType(t *testing.T) {
eventType := conv.EventType(99)
u64 := uint64(1)
value, err := stellarcap.ScValToProto(stellartypes.ScVal{
Type: stellartypes.ScValTypeU64,
Expand All @@ -1236,7 +1245,7 @@ func TestConvertGetEventsResponseFromProto_UnsupportedEventType(t *testing.T) {
_, err = conv.ConvertGetEventsResponseFromProto(&conv.GetEventsResponse{
Events: []*conv.EventInfo{
{
EventType: conv.EventType(99),
EventType: &eventType,
Value: value,
},
},
Expand All @@ -1247,6 +1256,26 @@ func TestConvertGetEventsResponseFromProto_UnsupportedEventType(t *testing.T) {
require.Contains(t, err.Error(), "unsupported proto event type")
}

func TestConvertGetEventsResponseFromProto_MissingEventType(t *testing.T) {
u64 := uint64(1)
value, err := stellarcap.ScValToProto(stellartypes.ScVal{
Type: stellartypes.ScValTypeU64,
U64: &u64,
})
require.NoError(t, err)

_, err = conv.ConvertGetEventsResponseFromProto(&conv.GetEventsResponse{
Events: []*conv.EventInfo{
{
Value: value,
},
},
})
require.Error(t, err)
require.Contains(t, err.Error(), "events[0]")
require.Contains(t, err.Error(), "eventType is required")
}

func TestConvertGetEventsResponseToProto_BadValue(t *testing.T) {
_, err := conv.ConvertGetEventsResponseToProto(stellartypes.GetEventsResponse{
Events: []stellartypes.EventInfo{
Expand Down Expand Up @@ -1286,6 +1315,7 @@ func TestConvertGetEventsResponseToProto_BadTopic(t *testing.T) {
}

func TestConvertGetEventsResponseFromProto_BadTopic(t *testing.T) {
eventType := conv.EventType_EVENT_TYPE_CONTRACT
u64 := uint64(1)
value, err := stellarcap.ScValToProto(stellartypes.ScVal{
Type: stellartypes.ScValTypeU64,
Expand All @@ -1296,7 +1326,7 @@ func TestConvertGetEventsResponseFromProto_BadTopic(t *testing.T) {
_, err = conv.ConvertGetEventsResponseFromProto(&conv.GetEventsResponse{
Events: []*conv.EventInfo{
{
EventType: conv.EventType_EVENT_TYPE_CONTRACT,
EventType: &eventType,
Topics: []*scval.ScVal{
{},
},
Expand Down
34 changes: 19 additions & 15 deletions pkg/chains/stellar/stellar.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/chains/stellar/stellar.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ message GetEventsRequest {
}

message EventInfo {
EventType event_type = 1;
optional EventType event_type = 1;

uint32 ledger = 2;
string ledger_closed_at = 3;
Expand Down Expand Up @@ -217,7 +217,7 @@ enum TxStatus {

// SubmitTransactionResponse carries the outcome of a transaction submission.
message SubmitTransactionResponse {
TxStatus tx_status = 1;
optional TxStatus tx_status = 1;
string tx_hash = 2;
string tx_idempotency_key = 3; // Assigned key (caller-supplied or TXM-generated)
bytes result_xdr = 4; // TransactionResult binary XDR; empty if unavailable
Expand Down Expand Up @@ -271,4 +271,4 @@ message GetLedgersResponse {
int64 oldest_ledger_close_time = 5;
// Cursor for the next page; pass as pagination.cursor on a subsequent request.
string cursor = 6;
}
}
Loading