From 42abcb1751867cec539b2d30cb71799629ecebab Mon Sep 17 00:00:00 2001 From: Silas Lenihan Date: Wed, 11 Dec 2024 16:58:25 -0500 Subject: [PATCH] merged with develop --- pkg/solana/txm/txm.go | 22 +++++++++++----------- pkg/solana/txm/txm_unit_test.go | 17 +++++++++-------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index f5d3d8705..0688b25fb 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -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 @@ -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...) @@ -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 diff --git a/pkg/solana/txm/txm_unit_test.go b/pkg/solana/txm/txm_unit_test.go index 7dfec6c57..e8dfcb584 100644 --- a/pkg/solana/txm/txm_unit_test.go +++ b/pkg/solana/txm/txm_unit_test.go @@ -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" @@ -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() @@ -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() @@ -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 }) } }) @@ -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 }) }