Skip to content

Commit

Permalink
merged with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
silaslenihan committed Dec 11, 2024
1 parent ae77a59 commit 42abcb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
22 changes: 11 additions & 11 deletions pkg/solana/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func (txm *Txm) simulateTx(ctx context.Context, tx *solanaGo.Transaction) (res *
}

// processError parses and handles relevant errors found in simulation results
func (txm *Txm) ProcessError(sig solanaGo.Signature, resErr interface{}, simulation bool) (txState TxState, errType TxErrType) {
func (txm *Txm) ProcessError(sig solanaGo.Signature, resErr interface{}, simulation bool) (txState txmutils.TxState, errType TxErrType) {
if resErr != nil {
// handle various errors
// https://github.com/solana-labs/solana/blob/master/sdk/src/transaction/error.rs
Expand All @@ -766,7 +766,7 @@ func (txm *Txm) ProcessError(sig solanaGo.Signature, resErr interface{}, simulat
if simulation {
return txState, NoFailure
}
return Errored, errType
return txmutils.Errored, errType
// transaction is already processed in the chain
case strings.Contains(errStr, "AlreadyProcessed"):
txm.lggr.Debugw("AlreadyProcessed", logValues...)
Expand All @@ -775,39 +775,39 @@ func (txm *Txm) ProcessError(sig solanaGo.Signature, resErr interface{}, simulat
if simulation {
return txState, NoFailure
}
return Errored, errType
return txmutils.Errored, errType
// transaction will encounter execution error/revert
case strings.Contains(errStr, "InstructionError"):
txm.lggr.Debugw("InstructionError", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// transaction contains an invalid account reference
case strings.Contains(errStr, "InvalidAccountIndex"):
txm.lggr.Debugw("InvalidAccountIndex", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// transaction loads a writable account that cannot be written
case strings.Contains(errStr, "InvalidWritableAccount"):
txm.lggr.Debugw("InvalidWritableAccount", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// address lookup table not found
case strings.Contains(errStr, "AddressLookupTableNotFound"):
txm.lggr.Debugw("AddressLookupTableNotFound", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// attempted to lookup addresses from an invalid account
case strings.Contains(errStr, "InvalidAddressLookupTableData"):
txm.lggr.Debugw("InvalidAddressLookupTableData", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// address table lookup uses an invalid index
case strings.Contains(errStr, "InvalidAddressLookupTableIndex"):
txm.lggr.Debugw("InvalidAddressLookupTableIndex", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// attempt to debit an account but found no record of a prior credit.
case strings.Contains(errStr, "AccountNotFound"):
txm.lggr.Debugw("AccountNotFound", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// attempt to load a program that does not exist
case strings.Contains(errStr, "ProgramAccountNotFound"):
txm.lggr.Debugw("ProgramAccountNotFound", logValues...)
return FatallyErrored, errType
return txmutils.FatallyErrored, errType
// unrecognized errors (indicates more concerning failures)
default:
// if simulating, return TxFailSimOther if error unknown
Expand Down
17 changes: 9 additions & 8 deletions pkg/solana/txm/txm_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/smartcontractkit/chainlink-solana/pkg/solana/fees"
solanatxm "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm"
keyMocks "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm/mocks"
txmutils "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm/utils"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
Expand Down Expand Up @@ -174,12 +175,12 @@ func TestTxm_ProcessError(t *testing.T) {
// returns no failure if BlockhashNotFound encountered during simulation
txState, errType := txm.ProcessError(solana.Signature{}, err, true)
require.Equal(t, solanatxm.NoFailure, errType)
require.Equal(t, solanatxm.NotFound, txState) // default enum value
require.Equal(t, txmutils.NotFound, txState) // default enum value

// returns error if BlockhashNotFound encountered during normal processing
txState, errType = txm.ProcessError(solana.Signature{}, err, false)
require.Equal(t, solanatxm.TxFailRevert, errType)
require.Equal(t, solanatxm.Errored, txState) // default enum value
require.Equal(t, txmutils.Errored, txState) // default enum value
})
t.Run("process AlreadyProcessed error", func(t *testing.T) {
t.Parallel()
Expand All @@ -191,12 +192,12 @@ func TestTxm_ProcessError(t *testing.T) {
// returns no failure if AlreadyProcessed encountered during simulation
txState, errType := txm.ProcessError(solana.Signature{}, err, true)
require.Equal(t, solanatxm.NoFailure, errType)
require.Equal(t, solanatxm.NotFound, txState) // default enum value
require.Equal(t, txmutils.NotFound, txState) // default enum value

// returns error if AlreadyProcessed encountered during normal processing
txState, errType = txm.ProcessError(solana.Signature{}, err, false)
require.Equal(t, solanatxm.TxFailRevert, errType)
require.Equal(t, solanatxm.Errored, txState) // default enum value
require.Equal(t, txmutils.Errored, txState) // default enum value
})
t.Run("process fatal error cases", func(t *testing.T) {
t.Parallel()
Expand All @@ -212,12 +213,12 @@ func TestTxm_ProcessError(t *testing.T) {
// returns fatal error if InstructionError encountered during simulation
txState, errType := txm.ProcessError(solana.Signature{}, err, true)
require.Equal(t, solanatxm.TxFailSimRevert, errType)
require.Equal(t, solanatxm.FatallyErrored, txState) // default enum value
require.Equal(t, txmutils.FatallyErrored, txState) // default enum value

// returns fatal error if InstructionError encountered during normal processing
txState, errType = txm.ProcessError(solana.Signature{}, err, false)
require.Equal(t, solanatxm.TxFailRevert, errType)
require.Equal(t, solanatxm.FatallyErrored, txState) // default enum value
require.Equal(t, txmutils.FatallyErrored, txState) // default enum value
})
}
})
Expand All @@ -231,12 +232,12 @@ func TestTxm_ProcessError(t *testing.T) {
// returns fatal error if InstructionError encountered during simulation
txState, errType := txm.ProcessError(solana.Signature{}, err, true)
require.Equal(t, solanatxm.TxFailSimOther, errType)
require.Equal(t, solanatxm.Errored, txState) // default enum value
require.Equal(t, txmutils.Errored, txState) // default enum value

// returns fatal error if InstructionError encountered during normal processing
txState, errType = txm.ProcessError(solana.Signature{}, err, false)
require.Equal(t, solanatxm.TxFailRevert, errType)
require.Equal(t, solanatxm.Errored, txState) // default enum value
require.Equal(t, txmutils.Errored, txState) // default enum value
})
}

Expand Down

0 comments on commit 42abcb1

Please sign in to comment.