From fd818bd28f158859881d8b5d5453e0f04600e8f4 Mon Sep 17 00:00:00 2001 From: shemnon Date: Wed, 22 May 2019 14:09:26 -0600 Subject: [PATCH 1/2] PAN-2715 - return block not found reasons in error When looking for a specific block and failing we should explain why in the error message. Also, clean up test names and grouping --- .../ethereum/graphql/GraphQLDataFetchers.java | 5 +- .../internal/response/GraphQLError.java | 45 +++++++++++++- .../EthGraphQLHttpBySpecErrorCaseTest.java | 4 -- .../graphql/EthGraphQLHttpBySpecTest.java | 58 +++++++++++-------- .../graphql/eth_getBalance_without_addr.json | 15 ++++- ... eth_getBlockTransactionCount_byHash.json} | 0 ...th_getBlockTransactionCount_byNumber.json} | 0 .../graphql/eth_getBlockWrongParams.json | 7 --- ...ckByHash.json => eth_getBlock_byHash.json} | 4 +- .../graphql/eth_getBlock_byHashInvalid.json | 21 +++++++ ...Number.json => eth_getBlock_byNumber.json} | 0 .../graphql/eth_getBlock_byNumberInvalid.json | 21 +++++++ .../graphql/eth_getBlock_wrongParams.json | 25 ++++++++ ...h_getTransaction_byBlockHashAndIndex.json} | 0 ...getTransaction_byBlockNumberAndIndex.json} | 0 ...saction_byBlockNumberAndInvalidIndex.json} | 0 ...sh.json => eth_getTransaction_byHash.json} | 0 ...son => eth_getTransaction_byHashNull.json} | 0 ...s_noTo.json => graphql_blocks_byFrom.json} | 0 ...Range.json => graphql_blocks_byRange.json} | 0 ....json => graphql_blocks_byWrongRange.json} | 0 21 files changed, 166 insertions(+), 39 deletions(-) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlockTransactionCountByHash.json => eth_getBlockTransactionCount_byHash.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlockTransactionCountByNumber.json => eth_getBlockTransactionCount_byNumber.json} (100%) delete mode 100644 ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockWrongParams.json rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlockByHash.json => eth_getBlock_byHash.json} (99%) create mode 100644 ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHashInvalid.json rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlockByNumber.json => eth_getBlock_byNumber.json} (100%) create mode 100644 ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumberInvalid.json create mode 100644 ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_wrongParams.json rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getTransactionByBlockHashAndIndex.json => eth_getTransaction_byBlockHashAndIndex.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getTransactionByBlockNumberAndIndex.json => eth_getTransaction_byBlockNumberAndIndex.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getTransactionByBlockNumberAndInvalidIndex.json => eth_getTransaction_byBlockNumberAndInvalidIndex.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getTransactionByHash.json => eth_getTransaction_byHash.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getTransactionByHashNull.json => eth_getTransaction_byHashNull.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{graphql_blocks_noTo.json => graphql_blocks_byFrom.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlocksByRange.json => graphql_blocks_byRange.json} (100%) rename ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/{eth_getBlocksByWrongRange.json => graphql_blocks_byWrongRange.json} (100%) diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java index c2794acb6a..2a1b53848c 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/GraphQLDataFetchers.java @@ -78,11 +78,12 @@ DataFetcher> getSendRawTransactionDataFetcher() { transactionPool.addLocalTransaction(transaction); if (validationResult.isValid()) { return Optional.of(transaction.hash()); + } else { + throw new GraphQLException(GraphQLError.of(validationResult.getInvalidReason())); } } catch (final IllegalArgumentException | RLPException e) { throw new GraphQLException(GraphQLError.INVALID_PARAMS); } - throw new GraphQLException(GraphQLError.INVALID_PARAMS); }; } @@ -153,8 +154,10 @@ public DataFetcher> getBlockDataFetcher() { final Optional> block; if (number != null) { block = blockchain.blockByNumber(number); + checkArgument(block.isPresent(), "Block number %s was not found", number); } else if (hash != null) { block = blockchain.blockByHash(Hash.wrap(hash)); + checkArgument(block.isPresent(), "Block hash %s was not found", hash); } else { block = blockchain.latestBlock(); } diff --git a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/response/GraphQLError.java b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/response/GraphQLError.java index 8e11dd9ef7..613a2a532a 100644 --- a/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/response/GraphQLError.java +++ b/ethereum/graphql/src/main/java/tech/pegasys/pantheon/ethereum/graphql/internal/response/GraphQLError.java @@ -12,6 +12,8 @@ */ package tech.pegasys.pantheon.ethereum.graphql.internal.response; +import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonGetter; @@ -21,7 +23,19 @@ public enum GraphQLError { INVALID_PARAMS(-32602, "Invalid params"), INTERNAL_ERROR(-32603, "Internal error"), - CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE(-32008, "Initial sync is still in progress"); + // Transaction validation failures + NONCE_TOO_LOW(-32001, "Nonce too low"), + INVALID_TRANSACTION_SIGNATURE(-32002, "Invalid signature"), + INTRINSIC_GAS_EXCEEDS_LIMIT(-32003, "Intrinsic gas exceeds gas limit"), + TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE(-32004, "Upfront cost exceeds account balance"), + EXCEEDS_BLOCK_GAS_LIMIT(-32005, "Transaction gas limit exceeds block gas limit"), + INCORRECT_NONCE(-32006, "Incorrect nonce"), + TX_SENDER_NOT_AUTHORIZED(-32007, "Sender account not authorized to send transactions"), + CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE(-32008, "Initial sync is still in progress"), + WRONG_CHAIN_ID(-32000, "Wrong Chain ID in transaction signature"), + REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED( + -32000, "Signatures with replay protection are not supported"), + PRIVATE_TRANSACTION_FAILED(-32000, "Private transaction failed"); private final int code; private final String message; @@ -40,4 +54,33 @@ public int getCode() { public String getMessage() { return message; } + + public static GraphQLError of(final TransactionInvalidReason transactionInvalidReason) { + switch (transactionInvalidReason) { + case WRONG_CHAIN_ID: + return WRONG_CHAIN_ID; + case REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED: + return REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED; + case INVALID_SIGNATURE: + return INVALID_TRANSACTION_SIGNATURE; + case UPFRONT_COST_EXCEEDS_BALANCE: + return TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE; + case NONCE_TOO_LOW: + return NONCE_TOO_LOW; + case INCORRECT_NONCE: + return INCORRECT_NONCE; + case INTRINSIC_GAS_EXCEEDS_GAS_LIMIT: + return INTRINSIC_GAS_EXCEEDS_LIMIT; + case EXCEEDS_BLOCK_GAS_LIMIT: + return EXCEEDS_BLOCK_GAS_LIMIT; + case TX_SENDER_NOT_AUTHORIZED: + return TX_SENDER_NOT_AUTHORIZED; + case CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE: + return CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE; + case PRIVATE_TRANSACTION_FAILED: + return PRIVATE_TRANSACTION_FAILED; + default: + return INTERNAL_ERROR; + } + } } diff --git a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecErrorCaseTest.java b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecErrorCaseTest.java index 2644eddf5d..34edf3a2f7 100644 --- a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecErrorCaseTest.java +++ b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecErrorCaseTest.java @@ -42,10 +42,6 @@ public EthGraphQLHttpBySpecErrorCaseTest(final String specFileName) { @Parameters(name = "{index}: {0}") public static Collection specs() { final List specs = new ArrayList<>(); - specs.add("eth_getBlockWrongParams"); - specs.add("eth_getBlocksByWrongRange"); - specs.add("eth_getBalance_toobig_bn"); - specs.add("eth_getBalance_without_addr"); return specs; } diff --git a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecTest.java b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecTest.java index e874c3c384..9131b55437 100644 --- a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecTest.java +++ b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/EthGraphQLHttpBySpecTest.java @@ -44,51 +44,63 @@ public static Collection specs() { final List specs = new ArrayList<>(); specs.add("eth_blockNumber"); - specs.add("eth_getTransactionByHash"); - specs.add("eth_getTransactionByHashNull"); - specs.add("eth_getBlockByHash"); - specs.add("eth_getBlockByNumber"); - specs.add("eth_getBlockTransactionCountByHash"); - specs.add("eth_getBlockTransactionCountByNumber"); - specs.add("eth_getTransactionByBlockHashAndIndex"); - specs.add("eth_getTransactionByBlockNumberAndIndex"); + + specs.add("eth_call_Block8"); + specs.add("eth_call_BlockLatest"); specs.add("eth_estimateGas_transfer"); specs.add("eth_estimateGas_noParams"); specs.add("eth_estimateGas_contractDeploy"); + specs.add("eth_gasPrice"); + + specs.add("eth_getBalance_0x19"); + specs.add("eth_getBalance_invalidAccountBlockNumber"); + specs.add("eth_getBalance_invalidAccountLatest"); + specs.add("eth_getBalance_latest"); + specs.add("eth_getBalance_toobig_bn"); + specs.add("eth_getBalance_without_addr"); + + specs.add("eth_getBlock_byHash"); + specs.add("eth_getBlock_byHashInvalid"); + specs.add("eth_getBlock_byNumber"); + specs.add("eth_getBlock_byNumberInvalid"); + specs.add("eth_getBlock_wrongParams"); + + specs.add("eth_getBlockTransactionCount_byHash"); + specs.add("eth_getBlockTransactionCount_byNumber"); + specs.add("eth_getCode"); specs.add("eth_getCode_noCode"); + specs.add("eth_getLogs_matchTopic"); + specs.add("eth_getStorageAt"); specs.add("eth_getStorageAt_illegalRangeGreaterThan"); - specs.add("eth_getTransactionCount"); - - specs.add("eth_getTransactionByBlockNumberAndInvalidIndex"); + specs.add("eth_getTransaction_byBlockHashAndIndex"); + specs.add("eth_getTransaction_byBlockNumberAndIndex"); + specs.add("eth_getTransaction_byBlockNumberAndInvalidIndex"); + specs.add("eth_getTransaction_byHash"); + specs.add("eth_getTransaction_byHashNull"); - specs.add("eth_getBlocksByRange"); - specs.add("eth_call_Block8"); - specs.add("eth_call_BlockLatest"); - specs.add("eth_getBalance_latest"); - specs.add("eth_getBalance_0x19"); - specs.add("eth_getBalance_invalidAccountBlockNumber"); - specs.add("eth_getBalance_invalidAccountLatest"); - specs.add("eth_gasPrice"); + specs.add("eth_getTransactionCount"); specs.add("eth_getTransactionReceipt"); - specs.add("eth_syncing"); specs.add("eth_sendRawTransaction_contractCreation"); - specs.add("eth_sendRawTransaction_messageCall"); specs.add("eth_sendRawTransaction_transferEther"); specs.add("eth_sendRawTransaction_unsignedTransaction"); - specs.add("eth_getLogs_matchTopic"); + specs.add("eth_syncing"); + + specs.add("graphql_blocks_byFrom"); + specs.add("graphql_blocks_byRange"); + specs.add("graphql_blocks_byWrongRange"); - specs.add("graphql_blocks_noTo"); specs.add("graphql_pending"); + return specs; } diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBalance_without_addr.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBalance_without_addr.json index c47196ffc8..c06d1ca598 100644 --- a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBalance_without_addr.json +++ b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBalance_without_addr.json @@ -1,5 +1,18 @@ { - "request": "{account(address: \"0x8895ee1b4f6dd65047762f924ecd367c17eabf8f\") { balance } }", + "request": "{account { balance } }", + "response": { + "errors": [ + { + "message": "Validation error of type MissingFieldArgument: Missing field argument address @ 'account'", + "locations": [ + { + "line": 1, + "column": 2 + } + ] + } + ] + }, "statusCode": 400 } diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCountByHash.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCount_byHash.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCountByHash.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCount_byHash.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCountByNumber.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCount_byNumber.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCountByNumber.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockTransactionCount_byNumber.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockWrongParams.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockWrongParams.json deleted file mode 100644 index 01c8691816..0000000000 --- a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockWrongParams.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "request": - - "{block (number: \"0x03\", hash : \"0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6\") {number transactions{hash} timestamp difficulty totalDifficulty gasUsed gasLimit hash nonce ommerCount logsBloom mixHash ommerHash extraData stateRoot receiptsRoot transactionCount transactionsRoot}} ", - - "statusCode": 400 -} \ No newline at end of file diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockByHash.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHash.json similarity index 99% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockByHash.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHash.json index bfaef823d6..9b44e00ba3 100644 --- a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockByHash.json +++ b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHash.json @@ -1,6 +1,6 @@ { - "request": - + "request": + "{block (hash : \"0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6\") {number transactions{hash} timestamp difficulty totalDifficulty gasUsed gasLimit hash nonce ommerCount logsBloom mixHash ommerHash extraData stateRoot receiptsRoot transactionCount transactionsRoot}} ", diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHashInvalid.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHashInvalid.json new file mode 100644 index 0000000000..c05007a125 --- /dev/null +++ b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byHashInvalid.json @@ -0,0 +1,21 @@ +{ + "request": "{block (hash : \"0x123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0\") {number } }", + "response": { + "data": null, + "errors": [ + { + "message": "Exception while fetching data (/block) : Block hash 0x123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0 was not found", + "locations": [ + { + "line": 1, + "column": 2 + } + ], + "path": [ + "block" + ] + } + ] + }, + "statusCode": 400 +} \ No newline at end of file diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockByNumber.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumber.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlockByNumber.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumber.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumberInvalid.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumberInvalid.json new file mode 100644 index 0000000000..aa113b68d7 --- /dev/null +++ b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_byNumberInvalid.json @@ -0,0 +1,21 @@ +{ + "request": "{block (number: 88888888) {number }} ", + "response": { + "data": null, + "errors": [ + { + "message": "Exception while fetching data (/block) : Block number 88888888 was not found", + "locations": [ + { + "line": 1, + "column": 2 + } + ], + "path": [ + "block" + ] + } + ] + }, + "statusCode": 400 +} \ No newline at end of file diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_wrongParams.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_wrongParams.json new file mode 100644 index 0000000000..8b9e8810e5 --- /dev/null +++ b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlock_wrongParams.json @@ -0,0 +1,25 @@ +{ + "request": "{block (number: \"0x03\", hash : \"0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6\") {number transactions{hash} timestamp difficulty totalDifficulty gasUsed gasLimit hash nonce ommerCount logsBloom mixHash ommerHash extraData stateRoot receiptsRoot transactionCount transactionsRoot}} ", + "response": { + "data": null, + "errors": [ + { + "message": "Exception while fetching data (/block) : Invalid params", + "locations": [ + { + "line": 1, + "column": 2 + } + ], + "path": [ + "block" + ], + "extensions": { + "errorCode": -32602, + "errorMessage": "Invalid params" + } + } + ] + }, + "statusCode": 400 +} \ No newline at end of file diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockHashAndIndex.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockHashAndIndex.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockHashAndIndex.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockHashAndIndex.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockNumberAndIndex.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockNumberAndIndex.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockNumberAndIndex.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockNumberAndIndex.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockNumberAndInvalidIndex.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockNumberAndInvalidIndex.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByBlockNumberAndInvalidIndex.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byBlockNumberAndInvalidIndex.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByHash.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byHash.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByHash.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byHash.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByHashNull.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byHashNull.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransactionByHashNull.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getTransaction_byHashNull.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_noTo.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byFrom.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_noTo.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byFrom.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlocksByRange.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byRange.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlocksByRange.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byRange.json diff --git a/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlocksByWrongRange.json b/ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byWrongRange.json similarity index 100% rename from ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/eth_getBlocksByWrongRange.json rename to ethereum/graphql/src/test/resources/tech/pegasys/pantheon/ethereum/graphql/graphql_blocks_byWrongRange.json From 9ea15dd94add8f0ad3b685f54ea1c4362bbef62f Mon Sep 17 00:00:00 2001 From: shemnon Date: Thu, 23 May 2019 15:17:27 -0600 Subject: [PATCH 2/2] need an extra mocked call now. --- .../pantheon/ethereum/graphql/BlockDataFetcherTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/BlockDataFetcherTest.java b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/BlockDataFetcherTest.java index a78d64564e..2e43732a5d 100644 --- a/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/BlockDataFetcherTest.java +++ b/ethereum/graphql/src/test/java/tech/pegasys/pantheon/ethereum/graphql/BlockDataFetcherTest.java @@ -12,12 +12,16 @@ */ package tech.pegasys.pantheon.ethereum.graphql; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.graphql.internal.BlockWithMetadata; import tech.pegasys.pantheon.util.bytes.BytesValue; +import java.util.Optional; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @@ -43,6 +47,8 @@ public void onlyNumber() throws Exception { when(environment.getContext()).thenReturn(context); when(context.getBlockchainQuery()).thenReturn(query); + when(query.blockByNumber(anyLong())) + .thenReturn(Optional.of(new BlockWithMetadata<>(null, null, null, null, 0))); fetcher.get(environment); }