Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuidlerEVM JSON-RPC Server #438

Merged
merged 19 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
135cad9
Added simple JSON-RPC server task.
BencicAndrej Feb 6, 2020
85e9cbd
Updated body parsing and error handling logic.
BencicAndrej Feb 6, 2020
a9ab1af
Refactored JSON-RPC server into manageable components.
BencicAndrej Feb 7, 2020
66cfdc5
Addressed PR comments.
BencicAndrej Feb 7, 2020
457d18f
Addressed PR comments.
BencicAndrej Feb 7, 2020
3ddad21
Included reading the buffer inside of try/catch.
BencicAndrej Feb 7, 2020
31090f3
Refactored tests to support multiple providers under test.
BencicAndrej Feb 11, 2020
7708848
Fix json-rpc response and request's id types
alcuadrado Feb 11, 2020
fd539bf
Added check that --network parameter is not set when running `buidler…
BencicAndrej Feb 11, 2020
fb2c905
Merge remote-tracking branch 'origin/buidlerevm-rpc' into buidlerevm-rpc
BencicAndrej Feb 11, 2020
41404fe
Updated server shutdown method to include error handling.
BencicAndrej Feb 11, 2020
3b3e33a
Added explanation for empty throw.
BencicAndrej Feb 11, 2020
5e2bd43
Added specialized transaction error, and check for error codes.
BencicAndrej Feb 11, 2020
358cfa2
Added websocket support for JSON-RPC server.
BencicAndrej Feb 12, 2020
df1b070
Added eth_subscribe support for WebSocket server.
BencicAndrej Feb 12, 2020
057b4e0
Updated wording.
BencicAndrej Feb 14, 2020
e2d56f3
Changed how listeners work for eth_subscribe.
BencicAndrej Feb 14, 2020
2071817
Updated TransactionExecutionError to include parent and keep the stack.
BencicAndrej Feb 14, 2020
6355d03
Merge branch 'master' into buidlerevm-rpc
nebojsa94 Feb 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/buidler-core/src/internal/buidler-evm/provider/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RunBlockResult,
TxReceipt
} from "@nomiclabs/ethereumjs-vm/dist/runBlock";
import { RunTxResult } from "@nomiclabs/ethereumjs-vm/dist/runTx";
import { StateManager } from "@nomiclabs/ethereumjs-vm/dist/state";
import PStateManager from "@nomiclabs/ethereumjs-vm/dist/state/promisified";
import chalk from "chalk";
Expand Down Expand Up @@ -336,11 +337,16 @@ export class BuidlerNode {

await this._addTransactionToBlock(block, tx);

const result = await this._vm.runBlock({
block,
generate: true,
skipBlockValidation: true
});
let result: RunBlockResult;
try {
result = await this._vm.runBlock({
block,
generate: true,
skipBlockValidation: true
});
} catch (error) {
throw new TransactionExecutionError(error.message);
alcuadrado marked this conversation as resolved.
Show resolved Hide resolved
}
alcuadrado marked this conversation as resolved.
Show resolved Hide resolved

await this._printLogs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ export async function assertNodeBalances(
export async function assertTransactionFailure(
provider: EthereumProvider,
txData: RpcTransactionRequestInput,
message?: string
message?: string,
code?: number
) {
try {
await provider.send("eth_sendTransaction", [txData]);
} catch (error) {
if (code !== undefined) {
assert.equal(error.code, code);
}

if (message !== undefined) {
assert.include(error.message, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(txParams.gasLimit),
gasPrice: numberToRpcQuantity(txParams.gasPrice)
},
"Transaction reverted without a reason"
"Transaction reverted without a reason",
-32003
);

const tx = await this.provider.send("eth_getTransactionByHash", [
Expand Down Expand Up @@ -1413,7 +1414,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(txParams.gasLimit),
gasPrice: numberToRpcQuantity(txParams.gasPrice)
},
"Transaction reverted without a reason"
"Transaction reverted without a reason",
-32003
);

const receipt = await this.provider.send(
Expand Down Expand Up @@ -1589,7 +1591,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(21000),
gasPrice: numberToRpcQuantity(1)
},
"unknown account"
"unknown account",
-32000
);
});

Expand All @@ -1599,7 +1602,8 @@ describe("Eth module", function() {
{
from: DEFAULT_ACCOUNTS_ADDRESSES[0]
},
"contract creation without any data provided"
"contract creation without any data provided",
-32000
);

await assertTransactionFailure(
Expand All @@ -1609,7 +1613,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(21000),
gasPrice: numberToRpcQuantity(1)
},
"contract creation without any data provided"
"contract creation without any data provided",
-32000
);

await assertTransactionFailure(
Expand All @@ -1620,7 +1625,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(21000),
gasPrice: numberToRpcQuantity(1)
},
"contract creation without any data provided"
"contract creation without any data provided",
-32000
);
});
});
Expand Down Expand Up @@ -1668,7 +1674,8 @@ describe("Eth module", function() {
to: zeroAddress(),
gas: numberToRpcQuantity(1)
},
"Transaction requires at least 21000 gas but got 1"
"Transaction requires at least 21000 gas but got 1",
-32000
);

// Not enough balance
Expand All @@ -1680,7 +1687,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(21000),
gasPrice: numberToRpcQuantity(DEFAULT_ACCOUNTS_BALANCES[0])
},
"sender doesn't have enough funds to send tx"
"sender doesn't have enough funds to send tx",
-32003
);

// Gas is larger than block gas limit
Expand All @@ -1692,7 +1700,8 @@ describe("Eth module", function() {
gas: numberToRpcQuantity(DEFAULT_BLOCK_GAS_LIMIT + 1)
},
`Transaction gas limit is ${DEFAULT_BLOCK_GAS_LIMIT +
1} and exceeds block gas limit of ${DEFAULT_BLOCK_GAS_LIMIT}`
1} and exceeds block gas limit of ${DEFAULT_BLOCK_GAS_LIMIT}`,
-32000
);

// Invalid opcode. We try to deploy a contract with an invalid opcode in the deployment code
Expand All @@ -1703,7 +1712,8 @@ describe("Eth module", function() {
from: DEFAULT_ACCOUNTS_ADDRESSES[0],
data: "0xAA"
},
"Transaction failed: revert"
"Transaction failed: revert",
-32003
);

// Out of gas. This a deployment transaction that pushes 0x00 multiple times
Expand All @@ -1720,7 +1730,8 @@ describe("Eth module", function() {
"0x6000600060006000600060006000600060006000600060006000600060006000600060006000600060006000600060006000",
gas: numberToRpcQuantity(53500)
},
"out of gas"
"out of gas",
-32003
);

// Invalid nonce
Expand All @@ -1731,7 +1742,8 @@ describe("Eth module", function() {
to: DEFAULT_ACCOUNTS_ADDRESSES[0],
nonce: numberToRpcQuantity(1)
},
"Invalid nonce. Expected 2 but got 1"
"Invalid nonce. Expected 2 but got 1",
-32000
);

// Revert. This a deployment transaction that immediately reverts without a reason
Expand All @@ -1742,7 +1754,8 @@ describe("Eth module", function() {
from: DEFAULT_ACCOUNTS_ADDRESSES[0],
data: "0x60006000fd"
},
"Transaction reverted without a reason"
"Transaction reverted without a reason",
-32003
);

// This is a contract that reverts with A in its constructor
Expand All @@ -1753,7 +1766,8 @@ describe("Eth module", function() {
data:
"0x6080604052348015600f57600080fd5b506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260018152602001807f410000000000000000000000000000000000000000000000000000000000000081525060200191505060405180910390fdfe"
},
"revert A"
"revert A",
-32003
);
});

Expand All @@ -1773,7 +1787,8 @@ describe("Eth module", function() {
to: DEFAULT_ACCOUNTS_ADDRESSES[0],
nonce: numberToRpcQuantity(0)
},
`known transaction: ${bufferToHex(hash)}`
`known transaction: ${bufferToHex(hash)}`,
-32000
);
});

Expand Down Expand Up @@ -1804,7 +1819,8 @@ describe("Eth module", function() {
await assertTransactionFailure(
this.provider,
txParams,
`known transaction: ${bufferToHex(hash)}`
`known transaction: ${bufferToHex(hash)}`,
-32000
);
});
});
Expand Down