def test_transfer_tournament_tokens_non_from_participant(self): participant1 = TournamentParticipantBalanceFactory().participant participant_balance2 = TournamentParticipantBalanceFactory() participant2 = participant_balance2.participant transfer_event = { 'name': 'Transfer', 'address': 'not needed', 'params': [{ 'name': 'from', 'value': participant1.address }, { 'name': 'to', 'value': participant2.address }, { 'name': 'value', 'value': 15 }] } participant1.delete() # Save event TournamentTokenReceiver().save(transfer_event) self.assertEqual( TournamentParticipant.objects.filter( address=participant1.address).count(), 0) self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant2.address).balance.__float__(), float(participant_balance2.balance + 15))
def test_tournament_serializer(self): participant1 = TournamentParticipantBalanceFactory() participant2 = TournamentParticipantBalanceFactory() scoreboard_response = self.client.get(reverse('api:scoreboard'), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_200_OK) self.assertEqual(len(json.loads(scoreboard_response.content).get('results')), 2) self.assertTrue('account' in json.loads(scoreboard_response.content).get('results')[0])
def test_transfer_tournament_tokens(self): participant_balance1 = TournamentParticipantBalanceFactory() participant1 = participant_balance1.participant participant_balance2 = TournamentParticipantBalanceFactory() participant2 = participant_balance2.participant participant1_issuance_event = { 'name': 'Issuance', 'address': 'not needed', 'params': [{ 'name': 'owner', 'value': participant1.address }, { 'name': 'amount', 'value': 150 }] } transfer_event = { 'name': 'Transfer', 'address': 'not needed', 'params': [{ 'name': 'from', 'value': participant1.address }, { 'name': 'to', 'value': participant2.address }, { 'name': 'value', 'value': 15 }] } # Save event TournamentTokenReceiver().save(participant1_issuance_event) TournamentTokenReceiver().save(transfer_event) self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant1.address).balance.__float__(), float(participant_balance1.balance + 150 - 15)) self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant2.address).balance.__float__(), float(participant_balance2.balance + 15))
def test_tournament_participant_issuance_rollback(self): amount = 123 participant_balance = TournamentParticipantBalanceFactory() participant = participant_balance.participant participant_event = { 'name': 'Issuance', 'address': 'not needed', 'params': [{ 'name': 'owner', 'value': participant.address }, { 'name': 'amount', 'value': amount }] } self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant.address).balance, participant_balance.balance) # Save event TournamentTokenReceiver().save(participant_event) self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant.address).balance, participant_balance.balance + amount) # Rollback TournamentTokenReceiver().rollback(participant_event) self.assertEqual( TournamentParticipantBalance.objects.get( participant=participant.address).balance, participant_balance.balance)
def test_scoreboard_view(self): current_users = TournamentParticipant.objects.all().count() scoreboard_response = self.client.get(reverse('api:scoreboard'), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_200_OK) self.assertEqual(current_users, len(scoreboard_response.json()['results'])) balance = TournamentParticipantBalanceFactory() scoreboard_response = self.client.get(reverse('api:scoreboard'), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_200_OK) self.assertEqual(current_users + 1, len(scoreboard_response.json()['results'])) balance = TournamentParticipantBalanceFactory() scoreboard_response = self.client.get(reverse('api:scoreboard'), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_200_OK) self.assertEqual(current_users + 2, len(scoreboard_response.json()['results']))
def test_tournament_serializer(self): balance = TournamentParticipantBalanceFactory() scoreboard_response = self.client.get(reverse( 'api:scoreboard', kwargs={'account_address': balance.participant.address}), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_200_OK) scoreboard_response = self.client.get(reverse( 'api:scoreboard', kwargs={'account_address': '0x0'}), content_type='application/json') self.assertEqual(scoreboard_response.status_code, status.HTTP_404_NOT_FOUND)
def test_issue_non_participant(self): # should not break, just don't save anything participant_balance = TournamentParticipantBalanceFactory() participant = participant_balance.participant participant_event = { 'name': 'Issuance', 'address': 'not needed', 'params': [{ 'name': 'owner', 'value': participant.address }, { 'name': 'amount', 'value': 123 }] } participant.delete() # Save event TournamentTokenReceiver().save(participant_event) self.assertEqual(TournamentParticipant.objects.all().count(), 0) self.assertIsNone(participant.pk)