forked from hush/hush3
![michaeltoutonghi@gmail.com](/assets/img/avatar_default.png)
38 changed files with 1000 additions and 519 deletions
@ -1,118 +0,0 @@ |
|||
#!/usr/bin/env python2 |
|||
# Copyright (c) 2018 The Zcash developers |
|||
# Distributed under the MIT software license, see the accompanying |
|||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
|||
|
|||
from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \ |
|||
msg_ping, SPROUT_PROTO_VERSION, OVERWINTER_PROTO_VERSION |
|||
from test_framework.test_framework import BitcoinTestFramework |
|||
from test_framework.util import initialize_chain_clean, start_nodes, \ |
|||
p2p_port, assert_equal |
|||
|
|||
import time |
|||
|
|||
# |
|||
# In this test we connect Sprout and Overwinter mininodes to a Zcashd node |
|||
# which will activate Overwinter at block 10. |
|||
# |
|||
# We test: |
|||
# 1. the mininodes stay connected to Zcash with Sprout consensus rules |
|||
# 2. when Overwinter activates, the Sprout mininodes are dropped |
|||
# 3. new Overwinter nodes can connect to Zcash |
|||
# 4. new Sprout nodes cannot connect to Zcash |
|||
# |
|||
# This test *does not* verify that prior to Overwinter activation, the Zcashd |
|||
# node will prefer connections with Overwinter nodes, with an eviction process |
|||
# that prioritizes Sprout connections. |
|||
# |
|||
|
|||
|
|||
class TestManager(NodeConnCB): |
|||
def __init__(self): |
|||
NodeConnCB.__init__(self) |
|||
self.create_callback_map() |
|||
|
|||
def on_close(self, conn): |
|||
pass |
|||
|
|||
def on_reject(self, conn, message): |
|||
conn.rejectMessage = message |
|||
|
|||
|
|||
class OverwinterPeerManagementTest(BitcoinTestFramework): |
|||
|
|||
def setup_chain(self): |
|||
print "Initializing test directory "+self.options.tmpdir |
|||
initialize_chain_clean(self.options.tmpdir, 1) |
|||
|
|||
def setup_network(self): |
|||
self.nodes = start_nodes(1, self.options.tmpdir, |
|||
extra_args=[['-nuparams=5ba81b19:10', '-debug', '-whitelist=127.0.0.1']]) |
|||
|
|||
def run_test(self): |
|||
test = TestManager() |
|||
|
|||
# Launch 10 Sprout and 10 Overwinter mininodes |
|||
nodes = [] |
|||
for x in xrange(10): |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], |
|||
test, "regtest", SPROUT_PROTO_VERSION)) |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], |
|||
test, "regtest", OVERWINTER_PROTO_VERSION)) |
|||
|
|||
# Start up network handling in another thread |
|||
NetworkThread().start() |
|||
|
|||
# Sprout consensus rules apply at block height 9 |
|||
self.nodes[0].generate(9) |
|||
assert_equal(9, self.nodes[0].getblockcount()) |
|||
|
|||
# Verify mininodes are still connected to zcashd node |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(10, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
|
|||
# Overwinter consensus rules activate at block height 10 |
|||
self.nodes[0].generate(1) |
|||
assert_equal(10, self.nodes[0].getblockcount()) |
|||
|
|||
# Mininodes send ping message to zcashd node. |
|||
pingCounter = 1 |
|||
for node in nodes: |
|||
node.send_message(msg_ping(pingCounter)) |
|||
pingCounter = pingCounter + 1 |
|||
|
|||
time.sleep(3) |
|||
|
|||
# Verify Sprout mininodes have been dropped and Overwinter mininodes are still connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
|
|||
# Extend the Overwinter chain with another block. |
|||
self.nodes[0].generate(1) |
|||
|
|||
# Connect a new Overwinter mininode to the zcashd node, which is accepted. |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", OVERWINTER_PROTO_VERSION)) |
|||
time.sleep(3) |
|||
assert_equal(11, len(self.nodes[0].getpeerinfo())) |
|||
|
|||
# Try to connect a new Sprout mininode to the zcashd node, which is rejected. |
|||
sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SPROUT_PROTO_VERSION) |
|||
nodes.append(sprout) |
|||
time.sleep(3) |
|||
assert("Version must be 170003 or greater" in str(sprout.rejectMessage)) |
|||
|
|||
# Verify that only Overwinter mininodes are connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(11, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
|
|||
for node in nodes: |
|||
node.disconnect_node() |
|||
|
|||
if __name__ == '__main__': |
|||
OverwinterPeerManagementTest().main() |
@ -0,0 +1,192 @@ |
|||
#!/usr/bin/env python2 |
|||
# Copyright (c) 2018 The Zcash developers |
|||
# Distributed under the MIT software license, see the accompanying |
|||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
|||
|
|||
from test_framework.mininode import ( |
|||
NodeConn, |
|||
NodeConnCB, |
|||
NetworkThread, |
|||
msg_ping, |
|||
SPROUT_PROTO_VERSION, |
|||
OVERWINTER_PROTO_VERSION, |
|||
SAPLING_PROTO_VERSION, |
|||
) |
|||
from test_framework.test_framework import BitcoinTestFramework |
|||
from test_framework.util import initialize_chain_clean, start_nodes, \ |
|||
p2p_port, assert_equal |
|||
|
|||
import time |
|||
|
|||
# |
|||
# In this test we connect Sprout, Overwinter, and Sapling mininodes to a Zcashd |
|||
# node which will activate Overwinter at block 10 and Sapling at block 15. |
|||
# |
|||
# We test: |
|||
# 1. the mininodes stay connected to Zcash with Sprout consensus rules |
|||
# 2. when Overwinter activates, the Sprout mininodes are dropped |
|||
# 3. new Overwinter and Sapling nodes can connect to Zcash |
|||
# 4. new Sprout nodes cannot connect to Zcash |
|||
# 5. when Sapling activates, the Overwinter mininodes are dropped |
|||
# 6. new Sapling nodes can connect to Zcash |
|||
# 7. new Sprout and Overwinter nodes cannot connect to Zcash |
|||
# |
|||
# This test *does not* verify that prior to each activation, the Zcashd |
|||
# node will prefer connections with NU-aware nodes, with an eviction process |
|||
# that prioritizes non-NU-aware connections. |
|||
# |
|||
|
|||
|
|||
class TestManager(NodeConnCB): |
|||
def __init__(self): |
|||
NodeConnCB.__init__(self) |
|||
self.create_callback_map() |
|||
|
|||
def on_close(self, conn): |
|||
pass |
|||
|
|||
def on_reject(self, conn, message): |
|||
conn.rejectMessage = message |
|||
|
|||
|
|||
class NUPeerManagementTest(BitcoinTestFramework): |
|||
|
|||
def setup_chain(self): |
|||
print "Initializing test directory "+self.options.tmpdir |
|||
initialize_chain_clean(self.options.tmpdir, 1) |
|||
|
|||
def setup_network(self): |
|||
self.nodes = start_nodes(1, self.options.tmpdir, extra_args=[[ |
|||
'-nuparams=5ba81b19:10', # Overwinter |
|||
'-nuparams=76b809bb:15', # Sapling |
|||
'-debug', |
|||
'-whitelist=127.0.0.1', |
|||
]]) |
|||
|
|||
def run_test(self): |
|||
test = TestManager() |
|||
|
|||
# Launch Sprout, Overwinter, and Sapling mininodes |
|||
nodes = [] |
|||
for x in xrange(10): |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], |
|||
test, "regtest", SPROUT_PROTO_VERSION)) |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], |
|||
test, "regtest", OVERWINTER_PROTO_VERSION)) |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], |
|||
test, "regtest", SAPLING_PROTO_VERSION)) |
|||
|
|||
# Start up network handling in another thread |
|||
NetworkThread().start() |
|||
|
|||
# Sprout consensus rules apply at block height 9 |
|||
self.nodes[0].generate(9) |
|||
assert_equal(9, self.nodes[0].getblockcount()) |
|||
|
|||
# Verify mininodes are still connected to zcashd node |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(10, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(SAPLING_PROTO_VERSION)) |
|||
|
|||
# Overwinter consensus rules activate at block height 10 |
|||
self.nodes[0].generate(1) |
|||
assert_equal(10, self.nodes[0].getblockcount()) |
|||
print('Overwinter active') |
|||
|
|||
# Mininodes send ping message to zcashd node. |
|||
pingCounter = 1 |
|||
for node in nodes: |
|||
node.send_message(msg_ping(pingCounter)) |
|||
pingCounter = pingCounter + 1 |
|||
|
|||
time.sleep(3) |
|||
|
|||
# Verify Sprout mininodes have been dropped, while Overwinter and |
|||
# Sapling mininodes are still connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
assert_equal(10, versions.count(SAPLING_PROTO_VERSION)) |
|||
|
|||
# Extend the Overwinter chain with another block. |
|||
self.nodes[0].generate(1) |
|||
|
|||
# Connect a new Overwinter mininode to the zcashd node, which is accepted. |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", OVERWINTER_PROTO_VERSION)) |
|||
time.sleep(3) |
|||
assert_equal(21, len(self.nodes[0].getpeerinfo())) |
|||
|
|||
# Connect a new Sapling mininode to the zcashd node, which is accepted. |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SAPLING_PROTO_VERSION)) |
|||
time.sleep(3) |
|||
assert_equal(22, len(self.nodes[0].getpeerinfo())) |
|||
|
|||
# Try to connect a new Sprout mininode to the zcashd node, which is rejected. |
|||
sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SPROUT_PROTO_VERSION) |
|||
nodes.append(sprout) |
|||
time.sleep(3) |
|||
assert("Version must be 170003 or greater" in str(sprout.rejectMessage)) |
|||
|
|||
# Verify that only Overwinter and Sapling mininodes are connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(11, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
assert_equal(11, versions.count(SAPLING_PROTO_VERSION)) |
|||
|
|||
# Sapling consensus rules activate at block height 15 |
|||
self.nodes[0].generate(4) |
|||
assert_equal(15, self.nodes[0].getblockcount()) |
|||
print('Sapling active') |
|||
|
|||
# Mininodes send ping message to zcashd node. |
|||
pingCounter = 1 |
|||
for node in nodes: |
|||
node.send_message(msg_ping(pingCounter)) |
|||
pingCounter = pingCounter + 1 |
|||
|
|||
time.sleep(3) |
|||
|
|||
# Verify Sprout and Overwinter mininodes have been dropped, while |
|||
# Sapling mininodes are still connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(0, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
assert_equal(11, versions.count(SAPLING_PROTO_VERSION)) |
|||
|
|||
# Extend the Sapling chain with another block. |
|||
self.nodes[0].generate(1) |
|||
|
|||
# Connect a new Sapling mininode to the zcashd node, which is accepted. |
|||
nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SAPLING_PROTO_VERSION)) |
|||
time.sleep(3) |
|||
assert_equal(12, len(self.nodes[0].getpeerinfo())) |
|||
|
|||
# Try to connect a new Sprout mininode to the zcashd node, which is rejected. |
|||
sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SPROUT_PROTO_VERSION) |
|||
nodes.append(sprout) |
|||
time.sleep(3) |
|||
assert("Version must be 170006 or greater" in str(sprout.rejectMessage)) |
|||
|
|||
# Try to connect a new Overwinter mininode to the zcashd node, which is rejected. |
|||
sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", OVERWINTER_PROTO_VERSION) |
|||
nodes.append(sprout) |
|||
time.sleep(3) |
|||
assert("Version must be 170006 or greater" in str(sprout.rejectMessage)) |
|||
|
|||
# Verify that only Sapling mininodes are connected. |
|||
peerinfo = self.nodes[0].getpeerinfo() |
|||
versions = [x["version"] for x in peerinfo] |
|||
assert_equal(0, versions.count(SPROUT_PROTO_VERSION)) |
|||
assert_equal(0, versions.count(OVERWINTER_PROTO_VERSION)) |
|||
assert_equal(12, versions.count(SAPLING_PROTO_VERSION)) |
|||
|
|||
for node in nodes: |
|||
node.disconnect_node() |
|||
|
|||
if __name__ == '__main__': |
|||
NUPeerManagementTest().main() |
@ -0,0 +1,46 @@ |
|||
#!/usr/bin/env python2 |
|||
|
|||
from test_framework.test_framework import BitcoinTestFramework |
|||
from test_framework.util import assert_equal, assert_true, initialize_chain_clean, start_node |
|||
|
|||
class SignOfflineTest (BitcoinTestFramework): |
|||
# Setup Methods |
|||
def setup_chain(self): |
|||
print "Initializing test directory " + self.options.tmpdir |
|||
initialize_chain_clean(self.options.tmpdir, 2) |
|||
|
|||
def setup_network(self): |
|||
self.nodes = [ start_node(0, self.options.tmpdir, ["-nuparams=5ba81b19:10"]) ] |
|||
self.is_network_split = False |
|||
self.sync_all() |
|||
|
|||
# Tests |
|||
def run_test(self): |
|||
print "Mining blocks..." |
|||
self.nodes[0].generate(101) |
|||
|
|||
offline_node = start_node(1, self.options.tmpdir, ["-maxconnections=0", "-nuparams=5ba81b19:10"]) |
|||
self.nodes.append(offline_node) |
|||
|
|||
assert_equal(0, len(offline_node.getpeerinfo())) # make sure node 1 has no peers |
|||
|
|||
privkeys = [self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())] |
|||
taddr = self.nodes[0].getnewaddress() |
|||
|
|||
tx = self.nodes[0].listunspent()[0] |
|||
txid = tx['txid'] |
|||
scriptpubkey = tx['scriptPubKey'] |
|||
|
|||
create_inputs = [{'txid': txid, 'vout': 0}] |
|||
sign_inputs = [{'txid': txid, 'vout': 0, 'scriptPubKey': scriptpubkey, 'amount': 10}] |
|||
|
|||
create_hex = self.nodes[0].createrawtransaction(create_inputs, {taddr: 9.9999}) |
|||
|
|||
signed_tx = offline_node.signrawtransaction(create_hex, sign_inputs, privkeys) |
|||
|
|||
# If we return the transaction hash, then we have have not thrown an error (success) |
|||
online_tx_hash = self.nodes[0].sendrawtransaction(signed_tx['hex']) |
|||
assert_true(len(online_tx_hash) > 0) |
|||
|
|||
if __name__ == '__main__': |
|||
SignOfflineTest().main() |
@ -0,0 +1,82 @@ |
|||
#!/usr/bin/env python2 |
|||
# Copyright (c) 2018 The Zcash developers |
|||
# Distributed under the MIT software license, see the accompanying |
|||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
|||
|
|||
from test_framework.test_framework import BitcoinTestFramework |
|||
from test_framework.util import assert_equal, assert_true, start_nodes |
|||
|
|||
class WalletImportExportTest (BitcoinTestFramework): |
|||
def setup_network(self, split=False): |
|||
num_nodes = 3 |
|||
extra_args = [["-exportdir={}/export{}".format(self.options.tmpdir, i)] for i in range(num_nodes)] |
|||
self.nodes = start_nodes(num_nodes, self.options.tmpdir, extra_args) |
|||
|
|||
def run_test(self): |
|||
sapling_address2 = self.nodes[2].z_getnewaddress('sapling') |
|||
privkey2 = self.nodes[2].z_exportkey(sapling_address2) |
|||
self.nodes[0].z_importkey(privkey2) |
|||
|
|||
sprout_address0 = self.nodes[0].z_getnewaddress('sprout') |
|||
sapling_address0 = self.nodes[0].z_getnewaddress('sapling') |
|||
|
|||
# node 0 should have the keys |
|||
dump_path0 = self.nodes[0].z_exportwallet('walletdump') |
|||
(t_keys0, sprout_keys0, sapling_keys0) = parse_wallet_file(dump_path0) |
|||
|
|||
sapling_line_lengths = [len(sapling_key0.split(' #')[0].split()) for sapling_key0 in sapling_keys0.splitlines()] |
|||
assert_equal(2, len(sapling_line_lengths), "Should have 2 sapling keys") |
|||
assert_true(2 in sapling_line_lengths, "Should have a key with 2 parameters") |
|||
assert_true(4 in sapling_line_lengths, "Should have a key with 4 parameters") |
|||
|
|||
assert_true(sprout_address0 in sprout_keys0) |
|||
assert_true(sapling_address0 in sapling_keys0) |
|||
assert_true(sapling_address2 in sapling_keys0) |
|||
|
|||
# node 1 should not have the keys |
|||
dump_path1 = self.nodes[1].z_exportwallet('walletdumpbefore') |
|||
(t_keys1, sprout_keys1, sapling_keys1) = parse_wallet_file(dump_path1) |
|||
|
|||
assert_true(sprout_address0 not in sprout_keys1) |
|||
assert_true(sapling_address0 not in sapling_keys1) |
|||
|
|||
# import wallet to node 1 |
|||
self.nodes[1].z_importwallet(dump_path0) |
|||
|
|||
# node 1 should now have the keys |
|||
dump_path1 = self.nodes[1].z_exportwallet('walletdumpafter') |
|||
(t_keys1, sprout_keys1, sapling_keys1) = parse_wallet_file(dump_path1) |
|||
|
|||
assert_true(sprout_address0 in sprout_keys1) |
|||
assert_true(sapling_address0 in sapling_keys1) |
|||
assert_true(sapling_address2 in sapling_keys1) |
|||
|
|||
# make sure we have perserved the metadata |
|||
for sapling_key0 in sapling_keys0.splitlines(): |
|||
assert_true(sapling_key0 in sapling_keys1) |
|||
|
|||
# Helper functions |
|||
def parse_wallet_file(dump_path): |
|||
file_lines = open(dump_path, "r").readlines() |
|||
# We expect information about the HDSeed and fingerpring in the header |
|||
assert_true("HDSeed" in file_lines[4], "Expected HDSeed") |
|||
assert_true("fingerprint" in file_lines[4], "Expected fingerprint") |
|||
(t_keys, i) = parse_wallet_file_lines(file_lines, 0) |
|||
(sprout_keys, i) = parse_wallet_file_lines(file_lines, i) |
|||
(sapling_keys, i) = parse_wallet_file_lines(file_lines, i) |
|||
|
|||
return (t_keys, sprout_keys, sapling_keys) |
|||
|
|||
def parse_wallet_file_lines(file_lines, i): |
|||
keys = [] |
|||
# skip blank lines and comments |
|||
while i < len(file_lines) and (file_lines[i] == '\n' or file_lines[i].startswith("#")): |
|||
i += 1 |
|||
# add keys until we hit another blank line or comment |
|||
while i < len(file_lines) and not (file_lines[i] == '\n' or file_lines[i].startswith("#")): |
|||
keys.append(file_lines[i]) |
|||
i += 1 |
|||
return ("".join(keys), i) |
|||
|
|||
if __name__ == '__main__': |
|||
WalletImportExportTest().main() |
Loading…
Reference in new issue