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 leaves 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 leaves that match those in Protobuf response """ paging = Mocks.make_paging_response(0, 3) leaves = Mocks.make_leaves(c=b'7', b=b'5', a=b'3') self.connection.preset_response(head_id='2', paging=paging, leaves=leaves) 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(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_leaves_match(leaves, response['data'])
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.stream.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.stream.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')
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 leaves 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 leaves that match those in Protobuf response """ paging = Mocks.make_paging_response(0, 3) leaves = Mocks.make_leaves(c=b'7', b=b'5', a=b'3') self.connection.preset_response(head_id='2', paging=paging, leaves=leaves) 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( 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_leaves_match(leaves, response['data'])
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')
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 leaves 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 leaves that match those in Protobuf response """ paging = Mocks.make_paging_response(0, 3) leaves = Mocks.make_leaves(a=b'3', b=b'5', c=b'7') self.connection.preset_response(head_id='2', paging=paging, leaves=leaves) 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_leaves_match(leaves, response['data'])
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_pubkey' 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_pubkey' - 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.stream.preset_response(head_id='2', paging=paging, batches=batches) response = await self.get_assert_200( '/batches?sort=header.signer_pubkey') page_controls = Mocks.make_paging_controls() sorting = Mocks.make_sort_controls('header', 'signer_pubkey') self.stream.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_pubkey') 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')
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')
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 leaves 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 leaves that match those in Protobuf response """ paging = Mocks.make_paging_response(0, 3) leaves = Mocks.make_leaves(a=b'3', b=b'5', c=b'7') self.connection.preset_response(head_id='2', paging=paging, leaves=leaves) 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_leaves_match(leaves, response['data'])
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_pubkey' 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_pubkey' - 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_pubkey') page_controls = Mocks.make_paging_controls() sorting = Mocks.make_sort_controls('header', 'signer_pubkey') 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_pubkey') 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')
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')
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')
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')