예제 #1
0
    def setUp(self):
        self.local_node_fileno = 1
        self.remote_node_fileno = 2

        self.gateway_node = spies.make_spy_node(BtcGatewayNode,
                                                8000,
                                                include_default_btc_args=True)
        self.btc_node_connection = spies.make_spy_connection(
            BtcNodeConnection, self.local_node_fileno, 8001, self.gateway_node)
        self.btc_remote_node_connection = spies.make_spy_connection(
            BtcRemoteConnection, self.remote_node_fileno, 8002,
            self.gateway_node)
        self.gateway_node.sdn_connection = MagicMock()
        self.gateway_node.node_conn = self.btc_node_connection
        self.gateway_node.remote_node_conn = self.btc_remote_node_connection
        self.gateway_node.connection_pool.add(self.local_node_fileno,
                                              LOCALHOST, 8001,
                                              self.btc_node_connection)
        self.gateway_node.connection_pool.add(self.remote_node_fileno,
                                              LOCALHOST, 8002,
                                              self.btc_remote_node_connection)
        self.gateway_node.account_id = "1234"

        self.handshake = \
            bytearray(VersionBtcMessage(100, 1000, "127.0.0.1", 8333, "0.0.0.0", 8333,
                                        13, 0, bytearray("hello", "utf-8"), 0).rawbytes()) + \
            bytearray(VerAckBtcMessage(100).rawbytes())

        inps = [
            TxIn(prev_outpoint_hash=bytearray("0" * 32, "utf-8"),
                 prev_out_index=10,
                 sig_script=bytearray(1000),
                 sequence=32)
        ]
        outs = [TxOut(value=10, pk_script=bytearray(1000))]

        self.txmsg = bytearray(
            TxBtcMessage(magic=100,
                         version=0,
                         tx_in=inps,
                         tx_out=outs,
                         lock_time=12345).rawbytes())
        self.blockmsg = bytearray(
            BlockBtcMessage(magic=100,
                            version=0,
                            prev_block=get_object_hash(bytearray(32)),
                            merkle_root=get_object_hash(bytearray(32)),
                            timestamp=1023,
                            bits=1,
                            txns=[bytearray(64)] * 32000,
                            nonce=34).rawbytes())
        self.transform = MessageTransformations()
예제 #2
0
    def setUp(self):
        self.local_node_fileno = 1
        self.local_node_fileno_2 = 2
        self.remote_node_fileno = 3
        self.local_blockchain_ip = "127.0.0.1"
        self.local_blockchain_port = 30303
        self.local_blockchain_port_2 = 30302

        eth_node_private_key = crypto_utils.make_private_key(helpers.generate_bytearray(111))
        self.gateway_node = spies.make_spy_node(
            EthGatewayNode, 8000, include_default_eth_args=True, blockchain_protocol="Ethereum",
            blockchain_address=(self.local_blockchain_ip, self.local_blockchain_port),
            blockchain_peers="enode://d76d7d11a822fab02836f8b0ea462205916253eb630935d15191fb6f9d218cd94a768fc5b3d5516b9ed5010a4765f95aea7124a39d0ab8aaf6fa3d57e21ef396@127.0.0.1:30302",
            pub_key="d76d7d11a822fab02836f8b0ea462205916253eb630935d15191fb6f9d218cd94a768fc5b3d5516b9ed5010a4765f95aea7124a39d0ab8aaf6fa3d57e21ef396")
        gateway_node_private_key = convert.hex_to_bytes(self.gateway_node.opts.private_key)
        eth_node_public_key = crypto_utils.private_to_public_key(eth_node_private_key)

        self.eth_node_cipher, gateway_cipher = self.setup_ciphers(eth_node_private_key, gateway_node_private_key)

        self.gateway_node._node_public_key = eth_node_public_key
        self.gateway_node._remote_public_key = eth_node_public_key

        self.eth_node_connection = spies.make_spy_connection(EthNodeConnection, self.local_node_fileno,
                                                             self.local_blockchain_port, self.gateway_node)

        self.eth_node_connection_2 = spies.make_spy_connection(EthNodeConnection, self.local_node_fileno_2,
                                                               self.local_blockchain_port_2, self.gateway_node)
        self.eth_remote_node_connection = spies.make_spy_connection(EthRemoteConnection, self.remote_node_fileno, 8003,
                                                                    self.gateway_node)

        self.eth_node_connection._rlpx_cipher = gateway_cipher
        self.eth_node_connection_2._rlpx_cipher = gateway_cipher
        self.eth_node_connection.message_factory = EthProtocolMessageFactory(gateway_cipher)
        self.eth_node_connection_2.message_factory = EthProtocolMessageFactory(gateway_cipher)
        self.eth_remote_node_connection._rlpx_cipher = gateway_cipher
        self.eth_remote_node_connection.message_factory = EthProtocolMessageFactory(gateway_cipher)
        self.gateway_node.remote_node_conn = self.eth_remote_node_connection

        self.gateway_node.connection_pool.add(
            self.local_node_fileno, LOCALHOST, self.local_blockchain_port, self.eth_node_connection
        )
        self.gateway_node.connection_pool.add(
            self.local_node_fileno_2, LOCALHOST, self.local_blockchain_port_2, self.eth_node_connection_2
        )
        self.gateway_node.connection_pool.add(self.remote_node_fileno, LOCALHOST, 8003, self.eth_remote_node_connection)
예제 #3
0
    def setUp(self):
        self.local_node_fileno = 1
        self.remote_node_fileno = 2

        self.gateway_node = spies.make_spy_node(BtcGatewayNode,
                                                8000,
                                                include_default_btc_args=True)
        self.btc_node_connection = spies.make_spy_connection(
            BtcNodeConnection, self.local_node_fileno, 8001, self.gateway_node)
        self.btc_remote_node_connection = spies.make_spy_connection(
            BtcRemoteConnection, self.remote_node_fileno, 8002,
            self.gateway_node)
        self.gateway_node.remote_node_conn = self.btc_remote_node_connection
        self.gateway_node.connection_pool.add(self.local_node_fileno,
                                              LOCALHOST, 8001,
                                              self.btc_node_connection)
        self.gateway_node.connection_pool.add(self.remote_node_fileno,
                                              LOCALHOST, 8002,
                                              self.btc_remote_node_connection)