def test_history_loooks_at_first_node_only(chain, requests_mock):
    chain.instances[1] = None  # shouldn't interfere
    ip = chain.instances[0].public_ip_address
    t = datetime.now(tz=pytz.UTC)

    requests_mock.add(
        requests_mock.GET,
        re.compile(r'http://' + ip +
                   r':46657/blockchain\?minHeight=1\&maxHeight=10'),
        json={
            "result": [
                0, {
                    'block_metas':
                    10 * [{
                        'header': {
                            'app_hash': "",
                            'height': "",
                            'time': t.isoformat()
                        }
                    }]
                }
            ]
        },
        status=200)

    Chainmanager.get_history(chain, 1, 10)
def test_history_default_to_fromm(requests_mock, chain,
                                  mock_ethermint_requests):
    ip = chain.instances[0].public_ip_address
    t = datetime.now(tz=pytz.UTC)

    def reset_mocks():
        mock_ethermint_requests(
            10, t, "hash",
            [inst.public_ip_address for inst in chain.instances])
        requests_mock.add(
            requests_mock.GET,
            re.compile(r'http://' + ip +
                       r':46657/blockchain\?minHeight=9\&maxHeight=10'),
            json={
                "result": [
                    0, {
                        'block_metas': [{
                            'header': {
                                'app_hash': "",
                                'height': "",
                                'time': t.isoformat()
                            }
                        }]
                    }
                ]
            },
            status=200)

    reset_mocks()
    history1 = Chainmanager.get_history(chain, 9)

    reset_mocks()
    history2 = Chainmanager.get_history(chain)

    assert history1 == history2
def test_history_gets_blocks(requests_mock, chain):
    ip = chain.instances[0].public_ip_address
    t = datetime.now(tz=pytz.UTC)
    height = 18

    requests_mock.add(
        requests_mock.GET,
        re.compile(r'http://' + ip +
                   r':46657/blockchain\?minHeight=1\&maxHeight=10'),
        json={
            "result": [
                0, {
                    'block_metas':
                    10 * [{
                        'header': {
                            'app_hash': "",
                            'height': height,
                            'time': t.isoformat()
                        }
                    }]
                }
            ]
        },
        status=200)

    history = Chainmanager.get_history(chain, 1, 10)

    check_history(history, 9, 0, height, t)
Example #4
0
def history(chain_file, fromm, to):
    chain = Chain.deserialize(json.loads(chain_file.read()))
    to_print = "\n".join(
        [str(c) for c in Chainmanager.get_history(chain, fromm, to)])
    print(to_print)
def test_history_invalid_from_to(chain):
    with pytest.raises(ValueError):
        Chainmanager.get_history(chain, 123, 1)