diff --git a/clients/gateway/gateway.go b/clients/gateway/gateway.go index d50c83a1ec..9c1253d330 100644 --- a/clients/gateway/gateway.go +++ b/clients/gateway/gateway.go @@ -19,20 +19,21 @@ import ( ) var ( - InvalidContractClass ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS" - UndeclaredClass ErrorCode = "StarknetErrorCode.UNDECLARED_CLASS" - ClassAlreadyDeclared ErrorCode = "StarknetErrorCode.CLASS_ALREADY_DECLARED" - InsufficientMaxFee ErrorCode = "StarknetErrorCode.INSUFFICIENT_MAX_FEE" - InsufficientAccountBalance ErrorCode = "StarknetErrorCode.INSUFFICIENT_ACCOUNT_BALANCE" - ValidateFailure ErrorCode = "StarknetErrorCode.VALIDATE_FAILURE" - ContractBytecodeSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_BYTECODE_SIZE_TOO_LARGE" - DuplicatedTransaction ErrorCode = "StarknetErrorCode.DUPLICATED_TRANSACTION" - InvalidTransactionNonce ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_NONCE" - CompilationFailed ErrorCode = "StarknetErrorCode.COMPILATION_FAILED" - InvalidCompiledClassHash ErrorCode = "StarknetErrorCode.INVALID_COMPILED_CLASS_HASH" - ContractClassObjectSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_CLASS_OBJECT_SIZE_TOO_LARGE" - InvalidTransactionVersion ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_VERSION" - InvalidContractClassVersion ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS_VERSION" + InvalidContractClass ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS" + UndeclaredClass ErrorCode = "StarknetErrorCode.UNDECLARED_CLASS" + ClassAlreadyDeclared ErrorCode = "StarknetErrorCode.CLASS_ALREADY_DECLARED" + InsufficientMaxFee ErrorCode = "StarknetErrorCode.INSUFFICIENT_MAX_FEE" + InsufficientResourcesForValidate ErrorCode = "StarknetErrorCode.INSUFFICIENT_RESOURCES_FOR_VALIDATE" + InsufficientAccountBalance ErrorCode = "StarknetErrorCode.INSUFFICIENT_ACCOUNT_BALANCE" + ValidateFailure ErrorCode = "StarknetErrorCode.VALIDATE_FAILURE" + ContractBytecodeSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_BYTECODE_SIZE_TOO_LARGE" + DuplicatedTransaction ErrorCode = "StarknetErrorCode.DUPLICATED_TRANSACTION" + InvalidTransactionNonce ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_NONCE" + CompilationFailed ErrorCode = "StarknetErrorCode.COMPILATION_FAILED" + InvalidCompiledClassHash ErrorCode = "StarknetErrorCode.INVALID_COMPILED_CLASS_HASH" + ContractClassObjectSizeTooLarge ErrorCode = "StarknetErrorCode.CONTRACT_CLASS_OBJECT_SIZE_TOO_LARGE" + InvalidTransactionVersion ErrorCode = "StarknetErrorCode.INVALID_TRANSACTION_VERSION" + InvalidContractClassVersion ErrorCode = "StarknetErrorCode.INVALID_CONTRACT_CLASS_VERSION" ) type Client struct { diff --git a/rpc/rpccore/rpccore.go b/rpc/rpccore/rpccore.go index 128bb56cd5..2811c32370 100644 --- a/rpc/rpccore/rpccore.go +++ b/rpc/rpccore/rpccore.go @@ -33,39 +33,40 @@ type TraceCacheKey struct { } var ( - ErrContractNotFound = &jsonrpc.Error{Code: 20, Message: "Contract not found"} - ErrBlockNotFound = &jsonrpc.Error{Code: 24, Message: "Block not found"} - ErrInvalidTxHash = &jsonrpc.Error{Code: 25, Message: "Invalid transaction hash"} - ErrInvalidBlockHash = &jsonrpc.Error{Code: 26, Message: "Invalid block hash"} - ErrInvalidTxIndex = &jsonrpc.Error{Code: 27, Message: "Invalid transaction index in a block"} - ErrClassHashNotFound = &jsonrpc.Error{Code: 28, Message: "Class hash not found"} - ErrTxnHashNotFound = &jsonrpc.Error{Code: 29, Message: "Transaction hash not found"} - ErrPageSizeTooBig = &jsonrpc.Error{Code: 31, Message: "Requested page size is too big"} - ErrNoBlock = &jsonrpc.Error{Code: 32, Message: "There are no blocks"} - ErrInvalidContinuationToken = &jsonrpc.Error{Code: 33, Message: "Invalid continuation token"} - ErrTooManyKeysInFilter = &jsonrpc.Error{Code: 34, Message: "Too many keys provided in a filter"} - ErrContractError = &jsonrpc.Error{Code: 40, Message: "Contract error"} - ErrTransactionExecutionError = &jsonrpc.Error{Code: 41, Message: "Transaction execution error"} - ErrStorageProofNotSupported = &jsonrpc.Error{Code: 42, Message: "The node doesn't support storage proofs for blocks that are too far in the past"} //nolint:lll - ErrInvalidContractClass = &jsonrpc.Error{Code: 50, Message: "Invalid contract class"} - ErrClassAlreadyDeclared = &jsonrpc.Error{Code: 51, Message: "Class already declared"} - ErrInternal = &jsonrpc.Error{Code: jsonrpc.InternalError, Message: "Internal error"} - ErrInvalidTransactionNonce = &jsonrpc.Error{Code: 52, Message: "Invalid transaction nonce"} - ErrInsufficientMaxFee = &jsonrpc.Error{Code: 53, Message: "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)"} //nolint:lll - ErrInsufficientAccountBalance = &jsonrpc.Error{Code: 54, Message: "Account balance is smaller than the transaction's max_fee"} - ErrValidationFailure = &jsonrpc.Error{Code: 55, Message: "Account validation failed"} - ErrCompilationFailed = &jsonrpc.Error{Code: 56, Message: "Compilation failed"} - ErrContractClassSizeTooLarge = &jsonrpc.Error{Code: 57, Message: "Contract class size is too large"} - ErrNonAccount = &jsonrpc.Error{Code: 58, Message: "Sender address is not an account contract"} - ErrDuplicateTx = &jsonrpc.Error{Code: 59, Message: "A transaction with the same hash already exists in the mempool"} - ErrCompiledClassHashMismatch = &jsonrpc.Error{Code: 60, Message: "the compiled class hash did not match the one supplied in the transaction"} //nolint:lll - ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"} - ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"} - ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"} - ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"} - ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"} - ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", MaxBlocksBack)} - ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"} + ErrContractNotFound = &jsonrpc.Error{Code: 20, Message: "Contract not found"} + ErrBlockNotFound = &jsonrpc.Error{Code: 24, Message: "Block not found"} + ErrInvalidTxHash = &jsonrpc.Error{Code: 25, Message: "Invalid transaction hash"} + ErrInvalidBlockHash = &jsonrpc.Error{Code: 26, Message: "Invalid block hash"} + ErrInvalidTxIndex = &jsonrpc.Error{Code: 27, Message: "Invalid transaction index in a block"} + ErrClassHashNotFound = &jsonrpc.Error{Code: 28, Message: "Class hash not found"} + ErrTxnHashNotFound = &jsonrpc.Error{Code: 29, Message: "Transaction hash not found"} + ErrPageSizeTooBig = &jsonrpc.Error{Code: 31, Message: "Requested page size is too big"} + ErrNoBlock = &jsonrpc.Error{Code: 32, Message: "There are no blocks"} + ErrInvalidContinuationToken = &jsonrpc.Error{Code: 33, Message: "Invalid continuation token"} + ErrTooManyKeysInFilter = &jsonrpc.Error{Code: 34, Message: "Too many keys provided in a filter"} + ErrContractError = &jsonrpc.Error{Code: 40, Message: "Contract error"} + ErrTransactionExecutionError = &jsonrpc.Error{Code: 41, Message: "Transaction execution error"} + ErrStorageProofNotSupported = &jsonrpc.Error{Code: 42, Message: "The node doesn't support storage proofs for blocks that are too far in the past"} //nolint:lll + ErrInvalidContractClass = &jsonrpc.Error{Code: 50, Message: "Invalid contract class"} + ErrClassAlreadyDeclared = &jsonrpc.Error{Code: 51, Message: "Class already declared"} + ErrInternal = &jsonrpc.Error{Code: jsonrpc.InternalError, Message: "Internal error"} + ErrInvalidTransactionNonce = &jsonrpc.Error{Code: 52, Message: "Invalid transaction nonce"} + ErrInsufficientMaxFee = &jsonrpc.Error{Code: 53, Message: "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)"} //nolint:lll + ErrInsufficientResourcesForValidate = &jsonrpc.Error{Code: 53, Message: "The transaction’s resources don’t cover validation or the minimal transaction fee"} //nolint:lll + ErrInsufficientAccountBalance = &jsonrpc.Error{Code: 54, Message: "Account balance is smaller than the transaction's max_fee"} + ErrValidationFailure = &jsonrpc.Error{Code: 55, Message: "Account validation failed"} + ErrCompilationFailed = &jsonrpc.Error{Code: 56, Message: "Compilation failed"} + ErrContractClassSizeTooLarge = &jsonrpc.Error{Code: 57, Message: "Contract class size is too large"} + ErrNonAccount = &jsonrpc.Error{Code: 58, Message: "Sender address is not an account contract"} + ErrDuplicateTx = &jsonrpc.Error{Code: 59, Message: "A transaction with the same hash already exists in the mempool"} + ErrCompiledClassHashMismatch = &jsonrpc.Error{Code: 60, Message: "the compiled class hash did not match the one supplied in the transaction"} //nolint:lll + ErrUnsupportedTxVersion = &jsonrpc.Error{Code: 61, Message: "the transaction version is not supported"} + ErrUnsupportedContractClassVersion = &jsonrpc.Error{Code: 62, Message: "the contract class version is not supported"} + ErrUnexpectedError = &jsonrpc.Error{Code: 63, Message: "An unexpected error occurred"} + ErrInvalidSubscriptionID = &jsonrpc.Error{Code: 66, Message: "Invalid subscription id"} + ErrTooManyAddressesInFilter = &jsonrpc.Error{Code: 67, Message: "Too many addresses in filter sender_address filter"} + ErrTooManyBlocksBack = &jsonrpc.Error{Code: 68, Message: fmt.Sprintf("Cannot go back more than %v blocks", MaxBlocksBack)} + ErrCallOnPending = &jsonrpc.Error{Code: 69, Message: "This method does not support being called on the pending block"} // These errors can be only be returned by Juno-specific methods. ErrSubscriptionNotFound = &jsonrpc.Error{Code: 100, Message: "Subscription not found"} diff --git a/rpc/v8/transaction.go b/rpc/v8/transaction.go index 3288788726..cc0f4c67fe 100644 --- a/rpc/v8/transaction.go +++ b/rpc/v8/transaction.go @@ -686,8 +686,8 @@ func makeJSONErrorFromGatewayError(err error) *jsonrpc.Error { return rpccore.ErrClassHashNotFound case gateway.ClassAlreadyDeclared: return rpccore.ErrClassAlreadyDeclared - case gateway.InsufficientMaxFee: - return rpccore.ErrInsufficientMaxFee + case gateway.InsufficientResourcesForValidate: + return rpccore.ErrInsufficientResourcesForValidate case gateway.InsufficientAccountBalance: return rpccore.ErrInsufficientAccountBalance case gateway.ValidateFailure: diff --git a/rpc/v8/transaction_test.go b/rpc/v8/transaction_test.go index 3907d65315..6e446e28c5 100644 --- a/rpc/v8/transaction_test.go +++ b/rpc/v8/transaction_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/NethermindEth/juno/clients/feeder" + "github.com/NethermindEth/juno/clients/gateway" "github.com/NethermindEth/juno/core" "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/juno/db" @@ -1173,6 +1174,22 @@ func TestAddTransaction(t *testing.T) { }, got) }) } + + t.Run("gateway returns InsufficientResourcesForValidate error", func(t *testing.T) { + mockCtrl := gomock.NewController(t) + t.Cleanup(mockCtrl.Finish) + + mockGateway := mocks.NewMockGateway(mockCtrl) + mockGateway. + EXPECT(). + AddTransaction(gomock.Any(), gomock.Any()). + Return(nil, &gateway.Error{Code: gateway.InsufficientResourcesForValidate}) + + handler := rpc.New(nil, nil, nil, "", utils.NewNopZapLogger()).WithGateway(mockGateway) + addTxRes, rpcErr := handler.AddTransaction(context.Background(), tests["invoke v0"].txn) + require.Nil(t, addTxRes) + require.Equal(t, rpccore.ErrInsufficientResourcesForValidate, rpcErr) + }) } func TestTransactionStatus(t *testing.T) {