forked from OpenBazaar/OpenBazaar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test peer discovery and fetching market page.
- Loading branch information
Showing
6 changed files
with
107 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def after_scenario(context, scenario): | ||
if hasattr(context, 'proc'): | ||
for proc in context.proc: | ||
proc.terminate() | ||
proc.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,53 @@ | ||
from behave import * | ||
from node.tornadoloop import start_node | ||
from threading import Thread | ||
from test_util import * | ||
import time | ||
from multiprocessing import Process | ||
|
||
@given('there is a node') | ||
def step_impl(context): | ||
context.proc = Process(target=start_node, | ||
args=('ppl/default', | ||
'127.0.0.1', | ||
12345, | ||
None, | ||
'test1.log')) | ||
context.proc.start() | ||
time.sleep(0.1) | ||
create_nodes(context, 1) | ||
|
||
|
||
@when('we connect') | ||
def step_impl(context): | ||
context.response = ws_connect(8888) | ||
context.response = ws_connect(0) | ||
|
||
|
||
@then('it will introduce itself') | ||
def step_impl(context): | ||
assert context.response['result']['type'] == u'myself' | ||
context.proc.terminate() | ||
time.sleep(0.1) | ||
|
||
|
||
@given('there are two nodes') | ||
def step_impl(context): | ||
context.proc = [] | ||
context.proc.append(Process(target=start_node, | ||
args=('ppl/default', '127.0.0.1', 12345, None, 'test1.log'))) | ||
time.sleep(0.1) | ||
context.proc.append(Process(target=start_node, | ||
args=('ppl/default', '127.0.0.2', 12345, None, 'test1.log'))) | ||
context.proc[0].start() | ||
context.proc[1].start() | ||
time.sleep(0.1) | ||
|
||
|
||
@when('a node connects to another') | ||
def step_impl(context): | ||
response1 = ws_connect(8888) | ||
response2 = ws_connect(8889) | ||
context.pubkeys = [] | ||
context.pubkeys.append(response1[u'result'][u'pubkey']) | ||
context.pubkeys.append(response2[u'result'][u'pubkey']) | ||
print context.pubkeys | ||
ws_send(8888, 'connect', {'uri': 'tcp://127.0.0.2:12345'}) | ||
time.sleep(0.5) | ||
@given('there are {num_nodes} connected nodes') | ||
def step_impl(context, num_nodes): | ||
create_connected_nodes(context, int(num_nodes)) | ||
|
||
|
||
@then('they will have each other as peers') | ||
def step_impl(context): | ||
response1 = ws_send(8888, 'peers') | ||
response1 = response1[u'result'] | ||
response2 = ws_send(8889, 'peers')[u'result'] | ||
print 'resp1', response1 | ||
print 'resp2', response2 | ||
assert response1['type'] == u'peers' | ||
assert response1['type'] == u'peers' | ||
assert response1['peers'][0]['pubkey'] == context.pubkeys[1] | ||
assert response1['peers'][0]['uri'] == u'tcp://127.0.0.2:12345' | ||
assert response2['peers'][0]['pubkey'] == context.pubkeys[0] | ||
assert response2['peers'][0]['uri'] == u'tcp://127.0.0.1:12345' | ||
context.proc[0].terminate() | ||
context.proc[1].terminate() | ||
@given('there are {num_nodes} nodes') | ||
def step_impl(context, num_nodes): | ||
create_nodes(context, int(num_nodes)) | ||
|
||
|
||
@when('node {i} connects to node {j}') | ||
def step_impl(context, i, j): | ||
ws_send(int(i), 'connect', {'uri': node_addr(int(j))}) | ||
|
||
|
||
@then('node {i} is connected to node {j}') | ||
def step_impl(context, i, j): | ||
pubkey_j = ws_connect(int(j))[u'result'][u'pubkey'] | ||
|
||
response = ws_send(int(i), 'peers')[u'result'] | ||
assert response['type'] == 'peers' | ||
assert {'pubkey': pubkey_j, 'uri': node_addr(int(j))} in response['peers'] | ||
|
||
|
||
@then('node {i} can query page of node {j}') | ||
def step_impl(context, i, j): | ||
pubkey_j = ws_connect(int(j))[u'result'][u'pubkey'] | ||
|
||
response = ws_send(int(i), 'query_page', {'pubkey': pubkey_j})[u'result'] | ||
f = open('ppl/default') | ||
data = json.loads(f.read()) | ||
assert response[u'type'] == u'page' | ||
assert response['nickname'] == data['nickname'] | ||
assert response['text'] == data['nickname'] + ': ' + data['desc'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters