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

Enabling connections with websocket client #222

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
rufo
  • Loading branch information
kurotaky committed May 14, 2023
commit f7fca05b69b7505e1a0965ece237ef53849b7fdc
26 changes: 13 additions & 13 deletions spec/eth/client_spec.rb
Original file line number Diff line number Diff line change
@@ -436,7 +436,7 @@
end
end

describe '.send' do
describe ".send" do
let(:captured_stdout) { StringIO.new }

# Replace $stdout to capture standard output
@@ -449,37 +449,37 @@
$stdout = @orig_stdout
end

it 'should set up the WebSocket connection' do
expect(geth_dev_ws.instance_variable_get('@ws')).to be_instance_of(WebSocket::Client::Simple::Client)
it "should set up the WebSocket connection" do
expect(geth_dev_ws.instance_variable_get("@ws")).to be_instance_of(WebSocket::Client::Simple::Client)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we expose @ws with a getter?

end

it 'should send a message to the WebSocket server and receive a response' do
it "should send a message to the WebSocket server and receive a response" do
payload = {
id: 1,
jsonrpc: '2.0',
method: 'eth_subscribe',
jsonrpc: "2.0",
method: "eth_subscribe",
params: ["newHeads"],
}
received_data = nil

geth_dev_ws.instance_variable_get('@ws').on :message do |msg|
geth_dev_ws.instance_variable_get("@ws").on :message do |msg|
received_data = JSON.parse(msg.data)
end

sleep 0.001
geth_dev_ws.send(payload)
sleep 0.001
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to avoid sleeping here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into ways to avoid using sleeping.


expect(received_data['id']).to eq(payload[:id])
expect(received_data['jsonrpc']).to eq(payload[:jsonrpc])
expect(received_data['result']).to start_with('0x')
expect(received_data["id"]).to eq(payload[:id])
expect(received_data["jsonrpc"]).to eq(payload[:jsonrpc])
expect(received_data["result"]).to start_with("0x")

contract = Eth::Contract.from_file(file: "spec/fixtures/contracts/dummy.sol")
geth_http.deploy_and_wait(contract)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
geth_http.deploy_and_wait(contract)
geth_dev_ws.deploy_and_wait(contract)


expect(received_data['method']).to eq("eth_subscription")
expect(received_data['params']["subscription"]).to start_with('0x')
expect(received_data['params']["result"]["parentHash"]).to start_with('0x')
expect(received_data["method"]).to eq("eth_subscription")
expect(received_data["params"]["subscription"]).to start_with("0x")
expect(received_data["params"]["result"]["parentHash"]).to start_with("0x")
end
end
end