def test_create_barter_record(self): """ 1. Create a single signed barter record 2. Send signature request from SELF to NODE 3. Add signature and send barter record from NODE to SELF 4. Check database for the new record """ community = BarterCommunity.create_community(self._my_member) address = self._dispersy.socket.get_address() # create node and ensure that SELF knows the node address node = BarterNode() node.init_socket() node.set_community(community) node.init_my_member() yield 0.11 assert self.is_database_empty( community), "Database should be empty (for this community id)" # send single signed barter record message = community.create_barter_record( Member.get_instance(node.my_member.public_key), 10, 2) yield 0.11 # receive signature request _, message = node.receive_message( addresses=[address], message_names=[u"dispersy-signature-request"]) assert message.payload.message.name == u"barter-record" assert message.payload.message.authentication.members[ 0].public_key == community.my_member.public_key assert message.payload.message.authentication.members[ 1].public_key == node.my_member.public_key assert message.payload.message.authentication.signed_members[0][0] assert not message.payload.message.authentication.is_signed assert not message.payload.message.authentication.signed_members[1][0] assert message.payload.message.payload.first_upload == 10 assert message.payload.message.payload.second_upload == 2 # create signature and send data back message = message.payload.message first_signature_offset = len(message.packet) - sum( member.signature_length for member in message.authentication.members) signature = node.my_member.sign(message.packet, length=first_signature_offset) message.authentication.set_signature( Member.get_instance(node.my_member.public_key), signature) node.send_message(message, address) yield 0.11 try: community._database.execute( u"SELECT 1 FROM record WHERE community = ? AND global_time = ? AND first_member = ? AND second_member = ? AND upload_first_member = ? AND upload_second_member = ?", (community.database_id, message.distribution.global_time, node.my_member.database_id, community._my_member.database_id, 10, 2)).next() except StopIteration: assert False # cleanup community.create_dispersy_destroy_community(u"hard-kill")
def test_incoming_barter_record(self): """ 1. Create a record signed only by NODE 2. Send signature request from NODE to SELF 3. Receive signature reply from SELF to NODE 4. Check the signature 5. Send double signed record from NODE to SELF 6. Check that the record is stored in the database at SELF """ community = BarterCommunity.create_community(self._my_member) address = self._dispersy.socket.get_address() # create node and ensure that SELF knows the node address node = BarterNode() node.init_socket() node.set_community(community) node.init_my_member() yield 0.11 assert self.is_database_empty(community), "Database should be empty (for this community id)" # 1. Create a record signed only by NODE self_member = Member(community._my_member.public_key, sync_with_database=False) record = node.create_barter_record(self_member, 10, 2, 1) # 2. Send signature request from NODE to SELF request = node.create_dispersy_signature_request_message(record, 2, self_member) node.send_message(request, address) yield 0.11 # 3. Receive signature reply from SELF to NODE # 4. Check the signature _, response = node.receive_message(addresses=[address], message_names=[u"dispersy-signature-response"]) first_signature_offset = len(record.packet) - sum([member.signature_length for member in record.authentication.members]) identifier = sha1(request.packet).digest() assert response.payload.identifier == identifier assert self_member.verify(record.packet[:first_signature_offset], response.payload.signature) # 5. Send double signed record from NODE to SELF second_signature_offset = len(record.packet) - record.authentication.members[1].signature_length packet = record.packet[:second_signature_offset] + response.payload.signature node.send_packet(packet, address) yield 0.11 # 6. Check that the record is stored in the database at SELF try: community._database.execute(u"SELECT 1 FROM record WHERE community = ? AND global_time = ? AND first_member = ? AND second_member = ? AND upload_first_member = ? AND upload_second_member = ?", (community.database_id, 1, node.my_member.database_id, community._my_member.database_id, 10, 2)).next() except StopIteration: assert False # cleanup community.create_dispersy_destroy_community(u"hard-kill")
def test_create_barter_record(self): """ 1. Create a single signed barter record 2. Send signature request from SELF to NODE 3. Add signature and send barter record from NODE to SELF 4. Check database for the new record """ community = BarterCommunity.create_community(self._my_member) address = self._dispersy.socket.get_address() # create node and ensure that SELF knows the node address node = BarterNode() node.init_socket() node.set_community(community) node.init_my_member() yield 0.11 assert self.is_database_empty(community), "Database should be empty (for this community id)" # send single signed barter record message = community.create_barter_record(Member.get_instance(node.my_member.public_key), 10, 2) yield 0.11 # receive signature request _, message = node.receive_message(addresses=[address], message_names=[u"dispersy-signature-request"]) assert message.payload.message.name == u"barter-record" assert message.payload.message.authentication.members[0].public_key == community.my_member.public_key assert message.payload.message.authentication.members[1].public_key == node.my_member.public_key assert message.payload.message.authentication.signed_members[0][0] assert not message.payload.message.authentication.is_signed assert not message.payload.message.authentication.signed_members[1][0] assert message.payload.message.payload.first_upload == 10 assert message.payload.message.payload.second_upload == 2 # create signature and send data back message = message.payload.message first_signature_offset = len(message.packet) - sum(member.signature_length for member in message.authentication.members) signature = node.my_member.sign(message.packet, length=first_signature_offset) message.authentication.set_signature(Member.get_instance(node.my_member.public_key), signature) node.send_message(message, address) yield 0.11 try: community._database.execute(u"SELECT 1 FROM record WHERE community = ? AND global_time = ? AND first_member = ? AND second_member = ? AND upload_first_member = ? AND upload_second_member = ?", (community.database_id, message.distribution.global_time, node.my_member.database_id, community._my_member.database_id, 10, 2)).next() except StopIteration: assert False # cleanup community.create_dispersy_destroy_community(u"hard-kill")
def test_incoming_barter_record(self): """ 1. Create a record signed only by NODE 2. Send signature request from NODE to SELF 3. Receive signature reply from SELF to NODE 4. Check the signature 5. Send double signed record from NODE to SELF 6. Check that the record is stored in the database at SELF """ community = BarterCommunity.create_community(self._my_member) address = self._dispersy.socket.get_address() # create node and ensure that SELF knows the node address node = BarterNode() node.init_socket() node.set_community(community) node.init_my_member() yield 0.11 assert self.is_database_empty( community), "Database should be empty (for this community id)" # 1. Create a record signed only by NODE self_member = Member(community._my_member.public_key, sync_with_database=False) record = node.create_barter_record(self_member, 10, 2, 1) # 2. Send signature request from NODE to SELF request = node.create_dispersy_signature_request_message( record, 2, self_member) node.send_message(request, address) yield 0.11 # 3. Receive signature reply from SELF to NODE # 4. Check the signature _, response = node.receive_message( addresses=[address], message_names=[u"dispersy-signature-response"]) first_signature_offset = len(record.packet) - sum([ member.signature_length for member in record.authentication.members ]) identifier = sha1(request.packet).digest() assert response.payload.identifier == identifier assert self_member.verify(record.packet[:first_signature_offset], response.payload.signature) # 5. Send double signed record from NODE to SELF second_signature_offset = len( record.packet) - record.authentication.members[1].signature_length packet = record.packet[:second_signature_offset] + response.payload.signature node.send_packet(packet, address) yield 0.11 # 6. Check that the record is stored in the database at SELF try: community._database.execute( u"SELECT 1 FROM record WHERE community = ? AND global_time = ? AND first_member = ? AND second_member = ? AND upload_first_member = ? AND upload_second_member = ?", (community.database_id, 1, node.my_member.database_id, community._my_member.database_id, 10, 2)).next() except StopIteration: assert False # cleanup community.create_dispersy_destroy_community(u"hard-kill")