test_node.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:crankycoin 作者: cranklin 项目源码 文件源码
def test_broadcast_transaction_whenRequestException_thenFailsGracefully(self):
        with patch.object(FullNode, '__init__', return_value=None) as patched_init, \
                patch.object(FullNode, 'request_nodes_from_all') as patched_request_nodes_from_all, \
                patch("crankycoin.time.time", return_value="1508823223") as patched_time_time, \
                patch("crankycoin.requests.post", side_effect=requests.exceptions.RequestException()) as patched_requests:

            transaction = Transaction("source", "destination", 0, 0)
            node = FullNode("127.0.0.1", "reward_address")
            node.full_nodes = {"127.0.0.1", "127.0.0.2", "127.0.0.3"}

            node.broadcast_transaction(transaction)

            patched_request_nodes_from_all.assert_called_once()
            patched_requests.assert_has_calls([
                call("http://127.0.0.1:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'}),
                call("http://127.0.0.2:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'}),
                call("http://127.0.0.3:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'})
            ], True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号