コード例 #1
0
    async def test_state_list_sorted_by_many_keys(self):
        """Verifies a GET /state can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three entries with addresses/data of:
                * 'c': b'7'
                * 'b': b'5'
                * 'a': b'3'

        It should send a Protobuf request with:
            - empty paging controls
            - multiple sort controls with:
                * a key of 'address' that is reversed
                * a key of 'value' that is sorted by length

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - link with '/state?head=2&sort=-address,value.length'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - three entries that match those in Protobuf response
        """
        paging = Mocks.make_paging_response(0, 3)
        entries = Mocks.make_entries(c=b'7', b=b'5', a=b'3')
        self.connection.preset_response(state_root='beef',
                                        paging=paging,
                                        entries=entries)
        self.connection.preset_response(
            proto=client_block_pb2.ClientBlockGetResponse,
            block=block_pb2.Block(
                header_signature='2',
                header=block_pb2.BlockHeader(
                    state_root_hash='beef').SerializeToString()))

        response = await self.get_assert_200(
            '/state?sort=-address,value.length')
        page_controls = Mocks.make_paging_controls()
        sorting = (Mocks.make_sort_controls('address', reverse=True) +
                   Mocks.make_sort_controls('value', compare_length=True))
        self.connection.assert_valid_request_sent(state_root='beef',
                                                  paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(response,
                                   '/state?head=2&sort=-address,value.length')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_entries_match(entries, response['data'])
コード例 #2
0
    async def test_batch_list_sorted_by_many_keys(self):
        """Verifies a GET /batches can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three batches with ids '2', '1', and '0'

        It should send a Protobuf request with:
            - empty paging controls
            - multiple sort controls with:
                * a key of 'header_signature' that is reversed
                * a key of 'transactions' that is sorted by length

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - link with '/batches?head=2&sort=-header_signature,transactions.length'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full batches with ids '2', '1', and '0'
        """
        paging = Mocks.make_paging_response(0, 3)
        batches = Mocks.make_batches('2', '1', '0')
        self.connection.preset_response(head_id='2',
                                        paging=paging,
                                        batches=batches)

        response = await self.get_assert_200(
            '/batches?sort=-header_signature,transactions.length')
        page_controls = Mocks.make_paging_controls()
        sorting = (
            Mocks.make_sort_controls('header_signature', reverse=True) +
            Mocks.make_sort_controls('transactions', compare_length=True))
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(
            response,
            '/batches?head=2&sort=-header_signature,transactions.length')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_batches_well_formed(response['data'], '2', '1', '0')
コード例 #3
0
    async def test_state_list_sorted_in_reverse(self):
        """Verifies a GET /state can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of ID_C
            - a paging response with a start of c and  limit of 100
            - three entries with addresses/data of:
                * 'c': b'7'
                * 'b': b'5'
                * 'a': b'3'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'address' that is reversed

        It should send back a JSON response with:
            - a status of 200
            - a head property of ID_C
            - a link property ending in
                '/state?head={}&start=c&limit=100&reverse'.format(ID_C)
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - three entries that match those in Protobuf response
        """
        paging = Mocks.make_paging_response("", "c", DEFAULT_LIMIT)
        entries = Mocks.make_entries(c=b'7', b=b'5', a=b'3')
        self.connection.preset_response(state_root='beef',
                                        paging=paging,
                                        entries=entries)
        self.connection.preset_response(
            proto=client_block_pb2.ClientBlockGetResponse,
            block=block_pb2.Block(
                header_signature=ID_C,
                header=block_pb2.BlockHeader(
                    state_root_hash='beef').SerializeToString()))

        response = await self.get_assert_200('/state?reverse')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('default', reverse=True)
        self.connection.assert_valid_request_sent(state_root='beef',
                                                  paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, ID_C)
        self.assert_has_valid_link(
            response, '/state?head={}&start=c&limit=100&reverse'.format(ID_C))
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_entries_match(entries, response['data'])
コード例 #4
0
    async def test_state_list_sorted_in_reverse(self):
        """Verifies a GET /state can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of ID_C
            - a paging response with a start of c and  limit of 100
            - three entries with addresses/data of:
                * 'c': b'7'
                * 'b': b'5'
                * 'a': b'3'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'address' that is reversed

        It should send back a JSON response with:
            - a status of 200
            - a head property of ID_C
            - a link property ending in
                '/state?head={}&start=c&limit=100&reverse'.format(ID_C)
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - three entries that match those in Protobuf response
        """
        paging = Mocks.make_paging_response("", "c", DEFAULT_LIMIT)
        entries = Mocks.make_entries(c=b'7', b=b'5', a=b'3')
        self.connection.preset_response(state_root='beef', paging=paging,
                                        entries=entries)
        self.connection.preset_response(
            proto=client_block_pb2.ClientBlockGetResponse,
            block=block_pb2.Block(
                header_signature=ID_C,
                header=block_pb2.BlockHeader(
                    state_root_hash='beef').SerializeToString()))

        response = await self.get_assert_200('/state?reverse')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('default', reverse=True)
        self.connection.assert_valid_request_sent(
            state_root='beef',
            paging=page_controls,
            sorting=sorting)

        self.assert_has_valid_head(response, ID_C)
        self.assert_has_valid_link(
            response, '/state?head={}&start=c&limit=100&reverse'.format(ID_C))
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_entries_match(entries, response['data'])
コード例 #5
0
    async def test_txn_list_sorted_in_reverse(self):
        """Verifies a GET /transactions can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of ID_C
            - a paging response with start of ID_C and limit of 100
            - three transactions with ids ID_C, ID_B, and ID_A

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'header_signature' that is reversed

        It should send back a JSON response with:
            - a status of 200
            - a head property of ID_C
            - a link property ending in
                '/transactions?head={}&start={}&limit=100&reverse'
                    .format(ID_C, ID_C))
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full transactions with ids ID_C,
              ID_B, and ID_A
        """
        paging = Mocks.make_paging_response("", ID_C, DEFAULT_LIMIT)
        transactions = Mocks.make_txns(ID_C, ID_B, ID_A)
        self.connection.preset_response(
            head_id=ID_C, paging=paging, transactions=transactions)
        response = await self.get_assert_200('/transactions?reverse')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls("default", reverse=True)
        self.connection.assert_valid_request_sent(
            paging=page_controls,
            sorting=sorting)

        self.assert_has_valid_head(response, ID_C)
        self.assert_has_valid_link(
            response,
            '/transactions?head={ID_C}&start={ID_C}&limit=100&reverse'.format(
                ID_C=ID_C))
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_txns_well_formed(response['data'], ID_C, ID_B, ID_A)
コード例 #6
0
    async def test_batch_list_sorted_in_reverse(self):
        """Verifies a GET /batches can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of ID_C
            - a paging response with start of ID_C and limit of 100
            - three batches with ids ID_C, ID_B, and ID_A

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'header_signature' that is reversed

        It should send back a JSON response with:
            - a status of 200
            - a head property of ID_C
            - a link property ending in
                '/batches?head={}&start={}&limit=100&reverse'
                    .format(ID_C, ID_C))
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full batches with ids ID_C, ID_B, and ID_A
        """
        paging = Mocks.make_paging_response("", ID_C, DEFAULT_LIMIT)
        batches = Mocks.make_batches(ID_C, ID_B, ID_A)
        self.connection.preset_response(head_id=ID_C,
                                        paging=paging,
                                        batches=batches)

        response = await self.get_assert_200('/batches?reverse')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('default', reverse=True)
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, ID_C)
        self.assert_has_valid_link(
            response,
            '/batches?head={ID_C}&start={ID_C}&limit=100&reverse'.format(
                ID_C=ID_C))
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_batches_well_formed(response['data'], ID_C, ID_B, ID_A)
コード例 #7
0
    async def test_state_list_sorted_by_length(self):
        """Verifies a GET /state can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three leaves with addresses/data of:
                * 'c': b'7'
                * 'b': b'45'
                * 'a': b'123'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'value' sorted by length

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - a link property ending in '/state?head=2&sort=value.length'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - three leaves that match those in Protobuf response
        """
        paging = Mocks.make_paging_response(0, 3)
        leaves = Mocks.make_leaves(c=b'7', b=b'45', a=b'123')
        self.connection.preset_response(head_id='2',
                                        paging=paging,
                                        leaves=leaves)

        response = await self.get_assert_200('/state?sort=value.length')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('value', compare_length=True)
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(response, '/state?head=2&sort=value.length')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_leaves_match(leaves, response['data'])
コード例 #8
0
    async def test_state_list_sorted(self):
        """Verifies GET /state can send proper sort controls.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three entries with addresses/data of:
                * 'a': b'3'
                * 'b': b'5'
                * 'c': b'7'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'address'

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - a link property ending in '/state?head=2&sort=address'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - three entries that match those in Protobuf response
        """
        paging = Mocks.make_paging_response(0, 3)
        entries = Mocks.make_entries(a=b'3', b=b'5', c=b'7')
        self.connection.preset_response(head_id='2',
                                        paging=paging,
                                        entries=entries)

        response = await self.get_assert_200('/state?sort=address')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('address')
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(response, '/state?head=2&sort=address')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_entries_match(entries, response['data'])
コード例 #9
0
    async def test_batch_list_sorted_with_nested_keys(self):
        """Verifies GET /batches can send proper sort controls with nested keys.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three batches with ids '0', '1', and '2'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with keys of 'header' and 'signer_public_key'

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - a link ending in '/batches?head=2&sort=header.signer_public_key'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full batches with ids '0', '1', and '2'
        """
        paging = Mocks.make_paging_response(0, 3)
        batches = Mocks.make_batches('0', '1', '2')
        self.connection.preset_response(head_id='2',
                                        paging=paging,
                                        batches=batches)

        response = await self.get_assert_200(
            '/batches?sort=header.signer_public_key')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('header', 'signer_public_key')
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(
            response, '/batches?head=2&sort=header.signer_public_key')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_batches_well_formed(response['data'], '0', '1', '2')
コード例 #10
0
    async def test_txn_list_sorted_by_length(self):
        """Verifies a GET /transactions can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three transactions with ids '0', '1', and '2'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'payload' sorted by length

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - a link property ending in '/transactions?head=2&sort=payload.length'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full transactions with ids '0', '1', and '2'
        """
        paging = Mocks.make_paging_response(0, 3)
        transactions = Mocks.make_txns('0', '1', '2')
        self.connection.preset_response(head_id='2',
                                        paging=paging,
                                        transactions=transactions)

        response = await self.get_assert_200(
            '/transactions?sort=payload.length')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls('payload', compare_length=True)
        self.connection.assert_valid_request_sent(paging=page_controls,
                                                  sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(response,
                                   '/transactions?head=2&sort=payload.length')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_txns_well_formed(response['data'], '0', '1', '2')
コード例 #11
0
    async def test_block_list_sorted_in_reverse(self):
        """Verifies a GET /blocks can send proper sort parameters.

        It will receive a Protobuf response with:
            - a head id of '2'
            - a paging response with a start of 0, and 3 total resources
            - three blocks with ids '2', '1', and '0'

        It should send a Protobuf request with:
            - empty paging controls
            - sort controls with a key of 'header_signature' that is reversed

        It should send back a JSON response with:
            - a status of 200
            - a head property of '2'
            - a link property ending in '/blocks?head=2&sort=-header_signature'
            - a paging property that matches the paging response
            - a data property that is a list of 3 dicts
            - and those dicts are full blocks with ids '2', '1', and '0'
        """
        paging = Mocks.make_paging_response(0, 3)
        blocks = Mocks.make_blocks('2', '1', '0')
        self.connection.preset_response(head_id='2', paging=paging, blocks=blocks)

        response = await self.get_assert_200('/blocks?sort=-header_signature')
        page_controls = Mocks.make_paging_controls()
        sorting = Mocks.make_sort_controls(
            'header_signature', reverse=True)
        self.connection.assert_valid_request_sent(
            paging=page_controls,
            sorting=sorting)

        self.assert_has_valid_head(response, '2')
        self.assert_has_valid_link(response,
            '/blocks?head=2&sort=-header_signature')
        self.assert_has_valid_paging(response, paging)
        self.assert_has_valid_data_list(response, 3)
        self.assert_blocks_well_formed(response['data'], '2', '1', '0')