Skip to content

Commit

Permalink
fix string encoding and add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jan 16, 2024
1 parent 8f1ef76 commit e14e3cf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ venv
/dist/firehose-solana_linux_arm64.tar.gz
/dist/firehose-solana_linux_x86_64.tar.gz
/dist/metadata.json
/.fleet/settings.json
15 changes: 14 additions & 1 deletion block/fetcher/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,22 @@ func MustNewBorshIoError(a any) BorshIoError {
}

func (b BorshIoError) Encode(encoder *bin.Encoder) error {
err := encoder.WriteString(b.Msg)
err := WriteString(b.Msg, encoder)
if err != nil {
return fmt.Errorf("unable to encode borsh io error: %w", err)
}
return nil
}

func WriteString(b string, e *bin.Encoder) error {
length := len(b)
err := e.WriteInt64(int64(length), binary.LittleEndian)
if err != nil {
return fmt.Errorf("unable to encode string length: %w", err)
}
err = e.WriteRaw([]byte(b))
if err != nil {
return fmt.Errorf("unable to encode string: %w", err)
}
return nil
}
23 changes: 0 additions & 23 deletions block/fetcher/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,12 @@ package fetcher

import (
"bytes"
"encoding/json"
"os"
"testing"

"github.com/gagliardetto/solana-go/rpc"
bin "github.com/streamingfast/binary"
"github.com/test-go/testify/require"
)

func Test_ToPBTransaction(t *testing.T) {

b, err := os.ReadFile("/Users/cbillett/devel/sf/firehose-solana/block/fetcher/testdata/result_block_241179689.json")
require.NoError(t, err)

getBlockResult := &rpc.GetBlockResult{}
err = json.Unmarshal(b, getBlockResult)
require.NoError(t, err)

_, err = toPbTransactions(getBlockResult.Transactions)
require.NoError(t, err)

//trxHash, err := base58.Decode("66gBszm6ybWVVykE4Svm2CvmiSmFbQi2J3Ua2FxHrYL9B1EPsTCGgjfWNVoJHSqd86iKmS8niywSZqDmqkk7uZLM")
//require.NoError(t, err)
//for _, tx := range confirmTransactions {
// if bytes.Equal(tx.Transaction.Signatures[0], trxHash) {
// }
//}
}

func Test_TrxErrorEncode(t *testing.T) {
cases := []struct {
name string
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/klauspost/compress v1.16.5
github.com/mr-tron/base58 v1.2.0
github.com/spf13/cobra v1.7.0
github.com/streamingfast/binary v0.0.0-20210928223119-44fc44e4a0b5
github.com/streamingfast/binary v0.0.0-20240116152459-ebe30de95370
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80
github.com/streamingfast/firehose-core v1.0.1-0.20240109054458-3f1edeff522c
Expand Down Expand Up @@ -245,4 +245,5 @@ replace (
github.com/gagliardetto/solana-go => github.com/streamingfast/gagliardetto-solana-go v0.0.0-20240115191424-05c37cd0760d
github.com/graph-gophers/graphql-go => github.com/streamingfast/graphql-go v0.0.0-20210204202750-0e485a040a3c
github.com/jhump/protoreflect => github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d

)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,9 @@ github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU=
github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streamingfast/binary v0.0.0-20210928223119-44fc44e4a0b5 h1:xCVaIP9q+nqRxHrb1wCLs3AABUcCgLGK0IakN4CMQbk=
github.com/streamingfast/binary v0.0.0-20210928223119-44fc44e4a0b5/go.mod h1:LEQhe6qUvAQSYBJu7MZvDU1kx4JrZzxru3Ga1rRCCuo=
github.com/streamingfast/binary v0.0.0-20240116152459-ebe30de95370 h1:/7j4mKpSJgGPYD4de7AA3nPzy3UeObvjUqidayw+dh8=
github.com/streamingfast/binary v0.0.0-20240116152459-ebe30de95370/go.mod h1:LEQhe6qUvAQSYBJu7MZvDU1kx4JrZzxru3Ga1rRCCuo=
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4 h1:WFXOC6fg2k9CuxUhbgtH7IYOZvu0CEPXuGRitS74YwQ=
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4/go.mod h1:08GVb+DXyz6jVNIsbf+2zlaC81UeEGu5o1h49KrSR3Y=
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80 h1:UxJUTcEVkdZy8N77E3exz0iNlgQuxl4m220GPvzdZ2s=
Expand Down

0 comments on commit e14e3cf

Please sign in to comment.