From e14e3cfa494a39003719fa63ffb8b398ba692921 Mon Sep 17 00:00:00 2001 From: billettc Date: Tue, 16 Jan 2024 10:28:27 -0500 Subject: [PATCH] fix string encoding and add unittest --- .gitignore | 1 + block/fetcher/error.go | 15 ++++++++++++++- block/fetcher/rpc_test.go | 23 ----------------------- go.mod | 3 ++- go.sum | 3 ++- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 6bd172a4..b07ebaf2 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/block/fetcher/error.go b/block/fetcher/error.go index a59dc4f0..01237e25 100644 --- a/block/fetcher/error.go +++ b/block/fetcher/error.go @@ -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 +} diff --git a/block/fetcher/rpc_test.go b/block/fetcher/rpc_test.go index ad2db690..b9618b52 100644 --- a/block/fetcher/rpc_test.go +++ b/block/fetcher/rpc_test.go @@ -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 diff --git a/go.mod b/go.mod index 3071633a..51c4c145 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 + ) diff --git a/go.sum b/go.sum index e6d86ebd..3a4407e5 100644 --- a/go.sum +++ b/go.sum @@ -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=