Skip to content

Commit

Permalink
Return error on parse error (#113)
Browse files Browse the repository at this point in the history
* Implement GetBlockWithConfig, which is a version of GetBlock that allows you to specify the rpc.GetBlockConfig config as a parameter

* Return error on parse error

Co-authored-by: Fernando Ferreira Campos <[email protected]>
  • Loading branch information
ffc0 and Fernando Ferreira Campos authored Nov 16, 2022
1 parent 1b6a85f commit 25fc86c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func MessageDeserialize(messageData []byte) (Message, error) {
list := []*uint8{&numRequireSignatures, &numReadonlySignedAccounts, &numReadonlyUnsignedAccounts}
for i := 0; i < len(list); i++ {
t, err = parseUvarint(&messageData)
if t > 255 {
if err != nil || t > 255 {
return Message{}, fmt.Errorf("message header #%d parse error: %v", i+1, err)
}
*list[i] = uint8(t)
Expand Down
6 changes: 6 additions & 0 deletions types/message_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"testing"

"github.com/portto/solana-go-sdk/common"
Expand Down Expand Up @@ -838,6 +839,11 @@ func TestMessageDeserialize(t *testing.T) {
},
},
},
{
args: args{messageData: []byte{128}},
want: Message{},
err: fmt.Errorf("message header #1 parse error: data is empty"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 25fc86c

Please sign in to comment.