Skip to content

Commit

Permalink
fix InsufficientRentError handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Jan 17, 2024
1 parent e4d3234 commit f39b9a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 26 additions & 5 deletions block/fetcher/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,43 @@ func (e *InsufficientFundsForRentError) Encode(encoder *bin.Encoder) error {
}

func MustNewProgramExecutionTemporarilyRestrictedError(e any) *ProgramExecutionTemporarilyRestrictedError {
accountIndex, ok := e.(uint8)
mapE, ok := e.(map[string]interface{})
if !ok {
panic(fmt.Errorf("expected map[string]interface{}, got: %T", e))
}

accountIndex, ok := mapE["account_index"]
if !ok {
panic(fmt.Errorf("expected account_index, got: %T", e))
}

accountIndexFloat64, ok := accountIndex.(float64)

if !ok {
panic(fmt.Errorf("expected byte, got: %T", e))
}
return &ProgramExecutionTemporarilyRestrictedError{
AccountIndex: accountIndex,
AccountIndex: uint8(accountIndexFloat64),
}
}

func MustNewInsufficientFundsForRentError(e any) *InsufficientFundsForRentError {
accountIndex, ok := e.(uint8)
mapE, ok := e.(map[string]interface{})
if !ok {
panic(fmt.Errorf("expected byte, got: %T", e))
panic(fmt.Errorf("expected map[string]interface{}, got: %T", e))
}

accountIndex, ok := mapE["account_index"]
if !ok {
panic(fmt.Errorf("expected account_index, got: %T", e))
}

accountIndexFloat64, ok := accountIndex.(float64)
if !ok {
panic(fmt.Errorf("expected float64, got: %T", e))
}
return &InsufficientFundsForRentError{
AccountIndex: accountIndex,
AccountIndex: uint8(accountIndexFloat64),
}
}
func MustNewDuplicateInstructionError(e any) *DuplicateInstructionError {
Expand Down
4 changes: 2 additions & 2 deletions block/fetcher/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
)

func Test_DoIt(t *testing.T) {
t.Skip("TODO: fix this test")
//t.Skip("TODO: fix this test")
ctx := context.Background()
rpcClient := rpc.New(quicknodeURL) //put your own URL in a file call secret.go that will be ignore by git
f := NewRPC(rpcClient, 0*time.Millisecond, 0*time.Millisecond, zap.NewNop())
_, err := f.Fetch(ctx, 240816644)
_, err := f.Fetch(ctx, 240816742)

require.NoError(t, err)
}
Expand Down

0 comments on commit f39b9a7

Please sign in to comment.