Skip to content

Commit

Permalink
Borsh test are failing good lock @arnaud
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jan 16, 2024
1 parent 4370c3e commit 5c7f2c6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
6 changes: 3 additions & 3 deletions block/fetcher/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,19 @@ func (i InstructionCustomError) Encode(encoder *bin.Encoder) error {
}

type BorshIoError struct {
msg string
Msg string
}

func MustNewBorshIoError(a any) BorshIoError {
msg, ok := a.(string)
if !ok {
panic(fmt.Errorf("expected string, got: %T", a))
}
return BorshIoError{msg: msg}
return BorshIoError{Msg: msg}
}

func (b BorshIoError) Encode(encoder *bin.Encoder) error {
err := encoder.WriteString(b.msg)
err := encoder.WriteString(b.Msg)
if err != nil {
return fmt.Errorf("unable to encode borsh io error: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions block/fetcher/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"math"
"time"

bin "github.com/streamingfast/binary"

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
bin "github.com/streamingfast/binary"
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
pbsol "github.com/streamingfast/firehose-solana/pb/sf/solana/type/v1"
sfsol "github.com/streamingfast/solana-go"
Expand Down
74 changes: 74 additions & 0 deletions block/fetcher/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,80 @@ func Test_ToPBTransaction(t *testing.T) {
//}
}

func Test_TrxErrorEncode(t *testing.T) {
cases := []struct {
name string
trxErr *TransactionError
expected []byte
}{
{
name: "AccountLoadedTwice",
trxErr: &TransactionError{
TrxErrCode: TrxErr_AccountLoadedTwice,
},
expected: []byte{1, 0, 0, 0},
},
{
name: "DuplicateInstruction",
trxErr: &TransactionError{
TrxErrCode: TrxErr_DuplicateInstruction,
detail: &DuplicateInstructionError{
duplicateInstructionIndex: 42,
},
},
expected: []byte{30, 0, 0, 0, 42},
},
{
name: "InsufficientFundsForRent { account_index: u8 }",
trxErr: &TransactionError{
TrxErrCode: TrxErr_InsufficientFundsForRent,
detail: &InsufficientFundsForRentError{
AccountIndex: 42,
},
},
expected: []byte{31, 0, 0, 0, 42},
},
{
name: "BorshIoError",
trxErr: &TransactionError{
TrxErrCode: TrxErr_InstructionError,
detail: &InstructionError{
InstructionErrorCode: InstructionError_BorshIoError,
detail: &BorshIoError{
Msg: "error.1",
},
},
},
expected: []byte{8, 0, 0, 0, 1, 44, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 101, 114, 114, 111, 114, 46, 49},
},
{
name: "custom",
trxErr: &TransactionError{
TrxErrCode: TrxErr_InstructionError,
detail: &InstructionError{
InstructionErrorCode: 25,
InstructionIndex: 0,
detail: InstructionCustomError{
CustomErrorCode: 42,
},
},
},
expected: []byte{8, 0, 0, 0, 0, 25, 0, 0, 0, 42, 0, 0, 0},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
encoder := bin.NewEncoder(buf)
err := c.trxErr.Encode(encoder)
require.NoError(t, err)
require.Equal(t, c.expected, buf.Bytes())

})
}
}

func Test_InstructionEncode(t *testing.T) {
cases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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/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 @@ -160,7 +161,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/streamingfast/binary v0.0.0-20210928223119-44fc44e4a0b5 // indirect
github.com/streamingfast/dauth v0.0.0-20231120142446-843f4e045cc2 // indirect
github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c // indirect
github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,7 @@ github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 h1:K6mJPvh1
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839/go.mod h1:huOJyjMYS6K8upTuxDxaNd+emD65RrXoVBvh8f1/7Ns=
github.com/streamingfast/firehose-core v1.0.1-0.20240109054458-3f1edeff522c h1:PpAiQiKbJq91jrW739fAPCwyOMjO23HHvf+0HqeJq2Y=
github.com/streamingfast/firehose-core v1.0.1-0.20240109054458-3f1edeff522c/go.mod h1:Y/Sza/3iOeabRhVC/hPoRx21jZDcyQFBYRNR8wgIk7I=
github.com/streamingfast/gagliardetto-solana-go v0.0.0-20240111145418-2be68b59fe4c h1:GWlMGvspp2Mb5iCZBV31FeOHwliPI/LoIowvlx253qA=
github.com/streamingfast/gagliardetto-solana-go v0.0.0-20240111145418-2be68b59fe4c/go.mod h1:i+7aAyNDTHG0jK8GZIBSI4OVvDqkt2Qx+LklYclRNG8=
github.com/streamingfast/gagliardetto-solana-go v0.0.0-20240115191424-05c37cd0760d h1:Db3yKJeN5DWPz8pesR9tuFXdbs0MnpRLmov+ttsHoTU=
github.com/streamingfast/gagliardetto-solana-go v0.0.0-20240115191424-05c37cd0760d/go.mod h1:i+7aAyNDTHG0jK8GZIBSI4OVvDqkt2Qx+LklYclRNG8=
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 h1:g8eEYbFSykyzIyuxNMmHEUGGUvJE0ivmqZagLDK42gw=
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0/go.mod h1:cTNObq2Uofb330y05JbbZZ6RwE6QUXw5iVcHk1Fx3fk=
Expand Down

0 comments on commit 5c7f2c6

Please sign in to comment.