コード例 #1
0
    def _check_node_exists(self, remote_node, node_id, node_status=None):
        member = self.get_any_active_member()
        with remote_node.client(*member.auth()) as c:
            r = c.post(
                "/gov/read", {"table": "public:ccf.gov.nodes.info", "key": node_id}
            )

            if r.status_code != http.HTTPStatus.OK.value or (
                node_status and r.body.json()["status"] != node_status.name
            ):
                return False

        return True
コード例 #2
0
    def retire_node(self, remote_node, node_to_retire):
        proposal_body, careful_vote = self.make_proposal(
            "retire_node", node_to_retire.node_id
        )
        proposal = self.get_any_active_member().propose(remote_node, proposal_body)
        self.vote_using_majority(remote_node, proposal, careful_vote)

        member = self.get_any_active_member()
        with remote_node.client(*member.auth(write=True)) as c:
            r = c.post(
                "/gov/read",
                {"table": "public:ccf.gov.nodes.info", "key": node_to_retire.node_id},
            )
            assert r.body.json()["status"] == infra.node.NodeStatus.RETIRED.name
コード例 #3
0
    def check_for_service(self, remote_node, status):
        """
        Check via the member frontend of the given node that the certificate
        associated with current CCF service signing key has been recorded in
        the KV store with the appropriate status.
        """
        # When opening the service in BFT, the first transaction to be
        # completed when f = 1 takes a significant amount of time
        member = self.get_any_active_member()
        with remote_node.client(*member.auth()) as c:
            r = c.post(
                "/gov/query",
                {
                    "text":
                    """tables = ...
                    service = tables["public:ccf.gov.service.info"]:get(0)
                    if service == nil then
                        LOG_DEBUG("Service is nil")
                    else
                        LOG_DEBUG("Service version: ", tostring(service.version))
                        LOG_DEBUG("Service status: ", tostring(service.status_code))
                        cert_len = #service.cert
                        LOG_DEBUG("Service cert len: ", tostring(cert_len))
                        LOG_DEBUG("Service cert bytes: " ..
                            tostring(service.cert[math.ceil(cert_len / 4)]) .. " " ..
                            tostring(service.cert[math.ceil(cert_len / 3)]) .. " " ..
                            tostring(service.cert[math.ceil(cert_len / 2)])
                        )
                    end
                    return service
                    """
                },
                timeout=3,
            )
            current_status = r.body.json()["status"]
            current_cert = r.body.json()["cert"]

            expected_cert = open(
                os.path.join(self.common_dir, "networkcert.pem"), "rb").read()

            assert (
                current_cert == expected_cert[:-1].decode()
            ), "Current service certificate did not match with networkcert.pem"
            assert (
                current_status == status.name
            ), f"Service status {current_status} (expected {status.name})"
コード例 #4
0
    def get_proposals(self, remote_node):
        script = """
        tables = ...
        local proposals = {}
        tables["public:ccf.gov.proposals"]:foreach( function(k, v)
            proposals[tostring(k)] = v;
        end )
        return proposals;
        """

        proposals = []
        member = self.get_any_active_member()
        with remote_node.client(*member.auth()) as c:
            r = c.post("/gov/query", {"text": script})
            assert r.status_code == http.HTTPStatus.OK.value
            for proposal_id, attr in r.body.json().items():
                proposals.append(
                    infra.proposal.Proposal(
                        proposal_id=proposal_id,
                        proposer_id=attr["proposer"],
                        state=infra.proposal.ProposalState(attr["state"]),
                    ))
        return proposals
コード例 #5
0
ファイル: consortium.py プロジェクト: lynshi/CCF
 def get_proposal(self, remote_node, proposal_id):
     member = self.get_any_active_member()
     with remote_node.client(*member.auth()) as c:
         r = c.get(f"/gov/proposals/{proposal_id}")
         assert r.status_code == http.HTTPStatus.OK.value
         return r.body.json()