コード例 #1
0
ファイル: test_rollback.py プロジェクト: DONTEAM/gnosisdb
    def test_oracle_owner_replacement_rollback(self):
        # Create the oracle
        oracle = CentralizedOracleFactory()
        oracle2 = CentralizedOracleFactory()
        new_owner_address = oracle2.creator
        block = {'number': 1, 'timestamp': self.to_timestamp(datetime.now())}
        change_owner_event = {
            'name': 'OwnerReplacement',
            'address': oracle.address,
            'params': [{
                'name': 'newOwner',
                'value': new_owner_address
            }]
        }

        centralized_oracle_without_owner_replacement = CentralizedOracle.objects.get(
            address=oracle.address)
        # Change owner
        CentralizedOracleInstanceReceiver().save(change_owner_event)
        centralized_oracle_with_owner_replacement = CentralizedOracle.objects.get(
            address=oracle.address)
        self.assertEquals(centralized_oracle_with_owner_replacement.owner,
                          new_owner_address)
        # Rollback
        CentralizedOracleInstanceReceiver().rollback(change_owner_event, block)
        centralized_oracle_with_owner_rollback = CentralizedOracle.objects.get(
            address=oracle.address)
        self.assertEquals(centralized_oracle_with_owner_rollback.owner,
                          centralized_oracle_without_owner_replacement.owner)
コード例 #2
0
ファイル: test_rollback.py プロジェクト: DONTEAM/gnosisdb
    def test_centralized_oracle_factory_rollback(self):
        oracle = CentralizedOracleFactory()

        # saving event_description to IPFS
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': oracle.event_description.outcomes
        }

        ipfs_hash = self.ipfs_api.post(event_description_json)

        block = {
            'number': oracle.creation_block,
            'timestamp': self.to_timestamp(oracle.creation_date_time)
        }

        oracle_address = oracle.address

        oracle_event = {
            'name':
            'CentralizedOracleCreation',
            'address':
            oracle.factory,
            'params': [{
                'name': 'creator',
                'value': oracle.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle_address,
            }, {
                'name': 'ipfsHash',
                'value': ipfs_hash
            }]
        }
        oracle.delete()

        CentralizedOracleFactoryReceiver().save(oracle_event, block)
        created_oracle = CentralizedOracle.objects.get(address=oracle_address)
        self.assertIsNotNone(created_oracle.pk)
        # Rollback
        CentralizedOracleFactoryReceiver().rollback(oracle_event, block)
        with self.assertRaises(CentralizedOracle.DoesNotExist):
            CentralizedOracle.objects.get(address=oracle_address)

        # Rollback over nonexistent centralized oracle should fail
        self.assertRaises(Exception,
                          CentralizedOracleFactoryReceiver().rollback,
                          oracle_event, block)
コード例 #3
0
    def test_centralized_oracle_receiver(self):
        oracle = CentralizedOracleFactory()
        # saving event_description to IPFS
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': oracle.event_description.outcomes
        }

        ipfs_hash = self.ipfs_api.post(event_description_json)

        block = {
            'number': oracle.creation_block,
            'timestamp': self.to_timestamp(oracle.creation_date_time)
        }

        oracle_address = oracle.address
        oracle_event = {
            'name':
            'CentralizedOracleCreation',
            'address':
            oracle.factory,
            'params': [{
                'name': 'creator',
                'value': oracle.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle_address,
            }, {
                'name': 'ipfsHash',
                'value': ipfs_hash
            }]
        }
        oracle.delete()
        CentralizedOracleFactoryReceiver().save(oracle_event, block)
        saved_oracle1 = CentralizedOracle.objects.get(address=oracle_address)
        self.assertIsNotNone(saved_oracle1.pk)

        # Cannot save twice
        oracle2 = CentralizedOracleFactory()
        oracle_event.get('params')[0].update({'value': oracle2.creator})
        oracle_event.get('params')[2].update(
            {'value': oracle2.event_description.ipfs_hash})
        instance = CentralizedOracleFactoryReceiver().save(oracle_event, block)
        self.assertIsNone(instance)
        saved_oracle2 = CentralizedOracle.objects.get(address=oracle_address)
        self.assertEqual(saved_oracle1.event_description.ipfs_hash,
                         saved_oracle2.event_description.ipfs_hash)
        self.assertEqual(saved_oracle1.creator, saved_oracle2.creator)
コード例 #4
0
    def test_create_centralized_oracle_scalar_event_with_outcomes(self):
        oracle = CentralizedOracleFactory()

        block = {
            'number': oracle.creation_block,
            'timestamp': mktime(oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            oracle.factory,
            'params': [{
                'name': 'creator',
                'value': oracle.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address,
            }, {
                'name': 'ipfsHash',
                'value': 'something unknown'
            }]
        }
        # remove test oracle before creating it again
        oracle.delete()
        s = CentralizedOracleSerializer(data=oracle_event, block=block)
        # ipfs_hash not saved to IPFS
        self.assertFalse(s.is_valid(), s.errors)
        # oracle.event_description
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': [],
            'unit': 'unit',
            'decimals': 2
        }

        # save event_description to IPFS
        ipfs_hash = self.ipfs.post(event_description_json)
        oracle_event.get('params')[2]['value'] = ipfs_hash

        s = CentralizedOracleSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)

        self.assertEqual(
            ScalarEventDescription.objects.filter(
                ipfs_hash=instance.event_description.ipfs_hash).count(), 1)
コード例 #5
0
    def test_create_scalar_with_categorical_description(self):

        event_description = CategoricalEventDescriptionFactory()
        oracle = CentralizedOracleFactory(event_description=event_description)

        # Scalar Event with different outcomes
        event = ScalarEventFactory()

        block = {
            'number': event.creation_block,
            'timestamp': mktime(event.creation_date_time.timetuple())
        }

        scalar_event = {
            'address':
            event.factory,
            'params': [{
                'name': 'creator',
                'value': event.creator
            }, {
                'name': 'collateralToken',
                'value': event.creator
            }, {
                'name': 'oracle',
                'value': oracle.address
            }, {
                'name': 'upperBound',
                'value': event.upper_bound
            }, {
                'name': 'lowerBound',
                'value': event.lower_bound
            }, {
                'name': 'scalarEvent',
                'value': event.address,
            }]
        }

        event.delete()
        s = ScalarEventSerializer(data=scalar_event, block=block)
        self.assertFalse(s.is_valid())
        scalar_event['params'][3]['value'] = 3
        scalar_descripion = ScalarEventDescriptionFactory()
        oracle.event_description = scalar_descripion
        oracle.save()
        s2 = ScalarEventSerializer(data=scalar_event, block=block)
        self.assertTrue(s2.is_valid(), s.errors)
        instance = s2.save()
        self.assertIsNotNone(instance)
コード例 #6
0
ファイル: test_views.py プロジェクト: DONTEAM/gnosisdb
    def test_shares_by_account(self):
        account1 = '{:040d}'.format(13)
        account2 = '{:040d}'.format(14)

        url = reverse('api:shares-by-account', kwargs={'account_address': account1})
        empty_shares_response = self.client.get(url, content_type='application/json')
        self.assertEquals(len(json.loads(empty_shares_response.content).get('results')), 0)

        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory(event=event, creator=account1)
        outcome_token = OutcomeTokenFactory(event=market.event)
        OutcomeTokenBalanceFactory(owner=market.creator, outcome_token=outcome_token)
        BuyOrderFactory(outcome_token=outcome_token, sender=account1, market=market)

        url = reverse('api:shares-by-account', kwargs={'account_address': account1})
        shares_response = self.client.get(url, content_type='application/json')
        decoded_response = json.loads(shares_response.content)
        self.assertEquals(len(decoded_response.get('results')), 1)
        self.assertEquals(
            decoded_response.get('results')[0].get('eventDescription').get('title'),
            oracle.event_description.title
        )
        self.assertEquals(
            decoded_response.get('results')[0].get('marginalPrice'),
            0.5
        )

        url = reverse('api:shares-by-account', kwargs={'account_address': account2})
        no_shares_response = self.client.get(url, content_type='application/json')
        self.assertEquals(len(json.loads(no_shares_response.content).get('results')), 0)
コード例 #7
0
ファイル: test_views.py プロジェクト: jzvelc/gnosisdb
    def test_events(self):
        # test empty events response
        empty_events_response = self.client.get(
            reverse('api:events'), content_type='application/json')
        self.assertEquals(
            len(json.loads(empty_events_response.content).get('results')), 0)

        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        # self.assertEquals(event.outcome_tokens.count(), len(outcomes))
        events_response = self.client.get(reverse('api:events'),
                                          content_type='application/json')
        self.assertEquals(
            len(json.loads(events_response.content).get('results')), 1)

        event_filtered_response = self.client.get(
            reverse('api:events-by-address',
                    kwargs={'event_address': "abcdef0"}),
            content_type='application/json')
        self.assertEquals(event_filtered_response.status_code,
                          status.HTTP_404_NOT_FOUND)

        event_filtered_response = self.client.get(
            reverse('api:events-by-address',
                    kwargs={'event_address': event.address}),
            content_type='application/json')
        self.assertEquals(event_filtered_response.status_code,
                          status.HTTP_200_OK)
        self.assertEquals(
            json.loads(events_response.content).get('results')[0].get(
                'contract').get('address'), add_0x_prefix(event.address))
コード例 #8
0
ファイル: test_views.py プロジェクト: jzvelc/gnosisdb
    def test_markets_by_resolution_date(self):
        # test empty events response
        empty_markets_response = self.client.get(
            reverse('api:markets'), content_type='application/json')
        self.assertEquals(
            len(json.loads(empty_markets_response.content).get('results')), 0)

        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory(event=event)
        from_date = (datetime.now() -
                     timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')

        url = reverse('api:markets') + '?resolution_date_time_0=' + from_date
        correct_date_time_range_response = self.client.get(
            url, content_type='application/json')
        self.assertEquals(
            len(
                json.loads(
                    correct_date_time_range_response.content).get('results')),
            1)

        url = reverse(
            'api:markets'
        ) + '?resolution_date_time_0=' + from_date + '&resolution_date_time_1=' + from_date
        empty_date_time_range_response = self.client.get(
            url, content_type='application/json')
        self.assertEquals(
            len(
                json.loads(
                    empty_date_time_range_response.content).get('results')), 0)
コード例 #9
0
    def test_markets_with_event_description(self):
        # test empty events response
        empty_markets_response = self.client.get(
            reverse('api:markets'), content_type='application/json')
        self.assertEquals(
            len(json.loads(empty_markets_response.content).get('results')), 0)

        # create markets
        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory(event=event)

        market_response_data = self.client.get(reverse('api:markets'),
                                               content_type='application/json')
        self.assertEquals(market_response_data.status_code, status.HTTP_200_OK)
        results = json.loads(market_response_data.content).get('results')
        self.assertEquals(len(results), 1)

        self.assertIsNotNone(
            results[0]['event']['oracle'].get('eventDescription'))
        self.assertIsNotNone(
            results[0]['event']['oracle']['eventDescription'].get('ipfsHash'))
        self.assertEqual(
            results[0]['event']['oracle']['eventDescription']['ipfsHash'],
            oracle.event_description.ipfs_hash)
コード例 #10
0
    def test_create_market(self):
        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory()

        block = {
            'number': market.creation_block,
            'timestamp': mktime(market.creation_date_time.timetuple())
        }

        market_dict = {
            'address':
            market.factory,
            'params': [{
                'name': 'creator',
                'value': market.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address,
            }, {
                'name': 'marketMaker',
                'value': market.market_maker
            }, {
                'name': 'fee',
                'value': market.fee
            }, {
                'name': 'market',
                'value': market.address
            }]
        }
        market.delete()

        s = MarketSerializer(data=market_dict, block=block)
        self.assertFalse(s.is_valid(), s.errors)

        market_dict.get('params').append({
            'name': 'eventContract',
            'value': market.address
        })

        market_dict.get('params').append({'name': 'fee', 'value': market.fee})

        s = MarketSerializer(data=market_dict, block=block)
        self.assertFalse(s.is_valid(), s.errors)

        market_dict.get('params')[-2]['value'] = event.address

        s = MarketSerializer(data=market_dict, block=block)
        self.assertFalse(s.is_valid(), s.errors)

        marketMaker = [
            x for x in market_dict.get('params')
            if x.get('name') == 'marketMaker'
        ][0]
        marketMaker.update({'value': settings.LMSR_MARKET_MAKER})

        s = MarketSerializer(data=market_dict, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
コード例 #11
0
ファイル: test_rollback.py プロジェクト: DONTEAM/gnosisdb
    def test_oracle_outcome_assignment_rollback(self):
        # Create the oracle
        oracle_factory = CentralizedOracleFactory()
        block = {'number': 1, 'timestamp': self.to_timestamp(datetime.now())}
        outcome_assignment_event = {
            'name': 'OutcomeAssignment',
            'address': oracle_factory.address,
            'params': [{
                'name': 'outcome',
                'value': 1,
            }]
        }

        CentralizedOracleInstanceReceiver().save(outcome_assignment_event)
        centralized_oracle_with_outcome_assignment = CentralizedOracle.objects.get(
            address=oracle_factory.address)
        self.assertTrue(
            centralized_oracle_with_outcome_assignment.is_outcome_set)
        self.assertEqual(centralized_oracle_with_outcome_assignment.outcome, 1)
        CentralizedOracleInstanceReceiver().rollback(outcome_assignment_event,
                                                     block)
        centralized_oracle_with_outcome_assignment_rollback = CentralizedOracle.objects.get(
            address=oracle_factory.address)
        self.assertFalse(
            centralized_oracle_with_outcome_assignment_rollback.is_outcome_set)
        self.assertIsNone(
            centralized_oracle_with_outcome_assignment_rollback.outcome)
コード例 #12
0
    def test_centralized_oracle_instance_owner_replacement_receiver(self):
        oracle0 = CentralizedOracleFactory()
        oracle1 = CentralizedOracleFactory()
        new_owner = oracle1.address
        change_owner_event = {
            'name': 'OwnerReplacement',
            'address': oracle0.address,
            'params': [{
                'name': 'newOwner',
                'value': new_owner
            }]
        }

        CentralizedOracleInstanceReceiver().save(change_owner_event)
        saved_oracle = CentralizedOracle.objects.get(address=oracle0.address)
        self.assertEquals(saved_oracle.owner, new_owner)
コード例 #13
0
ファイル: test_serializers.py プロジェクト: jzvelc/gnosisdb
 def test_categorical_event_serializer(self):
     oracle = CentralizedOracleFactory()
     event = CategoricalEventFactory(oracle=oracle)
     events_response = self.client.get(reverse('api:events'),
                                       content_type='application/json')
     self.assertEquals(
         json.loads(events_response.content).get('results')[0]['type'],
         'CATEGORICAL')
コード例 #14
0
ファイル: test_rollback.py プロジェクト: DONTEAM/gnosisdb
    def test_market_outcome_token_purchase_rollback(self):
        oracle_factory = CentralizedOracleFactory()
        event_factory = CategoricalEventFactory(oracle=oracle_factory)
        outcome_token = OutcomeTokenFactory(event=event_factory, index=0)
        market_without_rollback = MarketFactory(event=event_factory)
        buyer_address = '{:040d}'.format(100)
        self.assertIsNotNone(market_without_rollback.pk)

        block = {
            'number': oracle_factory.creation_block,
            'timestamp': self.to_timestamp(oracle_factory.creation_date_time)
        }

        outcome_token_purchase_event = {
            'name':
            'OutcomeTokenPurchase',
            'address':
            market_without_rollback.address,
            'params': [
                {
                    'name': 'outcomeTokenCost',
                    'value': 100
                },
                {
                    'name': 'marketFees',
                    'value': 10
                },
                {
                    'name': 'buyer',
                    'value': buyer_address
                },
                {
                    'name': 'outcomeTokenIndex',
                    'value': 0
                },
                {
                    'name': 'outcomeTokenCount',
                    'value': 10
                },
            ]
        }

        # Send outcome token purchase event
        MarketInstanceReceiver().save(outcome_token_purchase_event, block)
        orders_before_rollback = BuyOrder.objects.filter(
            creation_block=block.get('number'),
            sender=buyer_address,
            market=market_without_rollback)
        self.assertEquals(len(orders_before_rollback), 1)

        # Outcome token purchase rollback
        MarketInstanceReceiver().rollback(outcome_token_purchase_event, block)
        market_with_rollback = Market.objects.get(event=event_factory.address)
        orders_after_rollback = BuyOrder.objects.filter(
            creation_block=block.get('number'),
            sender=buyer_address,
            market=market_with_rollback)
        self.assertEquals(len(orders_after_rollback), 0)
コード例 #15
0
ファイル: test_serializers.py プロジェクト: jzvelc/gnosisdb
 def test_oracle_types(self):
     centralized_oracle = CentralizedOracleFactory()
     centralized_response = self.client.get(
         reverse('api:centralized-oracles'),
         content_type='application/json')
     self.assertEquals(
         json.loads(
             centralized_response.content).get('results')[0].get('type'),
         'CENTRALIZED')
コード例 #16
0
    def test_create_centralized_oracle(self):
        oracle = CentralizedOracleFactory()

        block = {
            'number': oracle.creation_block,
            'timestamp': mktime(oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            oracle.factory,
            'params': [{
                'name': 'creator',
                'value': oracle.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address,
            }, {
                'name': 'ipfsHash',
                'value': oracle.event_description.ipfs_hash[1:-7] + ''
            }]
        }
        oracle.delete()
        s = CentralizedOracleSerializer(data=oracle_event, block=block)
        # ipfs_hash not saved to IPFS
        self.assertFalse(s.is_valid(), s.errors)
        # oracle.event_description
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': ['Yes', 'No']
        }

        # save event_description to IPFS
        ipfs_hash = self.ipfs.post(event_description_json)
        oracle_event.get('params')[2]['value'] = ipfs_hash

        s = CentralizedOracleSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
コード例 #17
0
    def test_market_receiver(self):
        oracle = CentralizedOracleFactory()
        oracle.event_description.outcomes = ['1', '2', '3']
        oracle.event_description.save()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory()
        event_address = event.address

        block = {
            'number': market.creation_block,
            'timestamp': self.to_timestamp(market.creation_date_time)
        }

        market_dict = {
            'name':
            'StandardMarketCreation',
            'address':
            market.factory,
            'params': [{
                'name': 'creator',
                'value': market.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address,
            }, {
                'name': 'marketMaker',
                'value': market.market_maker
            }, {
                'name': 'fee',
                'value': market.fee
            }, {
                'name': 'eventContract',
                'value': event_address
            }, {
                'name': 'fee',
                'value': market.fee
            }, {
                'name': 'market',
                'value': market.address
            }]
        }

        market.delete()

        MarketFactoryReceiver().save(market_dict, block)
        with self.assertRaises(Market.DoesNotExist):
            Market.objects.get(event=event_address)

        market_dict.get('params')[2].update(
            {'value': settings.LMSR_MARKET_MAKER})
        MarketFactoryReceiver().save(market_dict, block)
        saved_market = Market.objects.get(event=event_address)
        self.assertIsNotNone(saved_market.pk)
        self.assertEquals(len(market.net_outcome_tokens_sold), 2)
        self.assertEquals(len(saved_market.net_outcome_tokens_sold), 3)
コード例 #18
0
    def test_centralized_oracle(self):
        # test empty centralized-oracles response
        empty_centralized_response = self.client.get(
            reverse('api:centralized-oracles'),
            content_type='application/json')
        self.assertEquals(
            len(json.loads(empty_centralized_response.content).get('results')),
            0)
        # create centralized oracles
        centralized_oracles = [
            CentralizedOracleFactory() for x in range(0, 10)
        ]
        centralized_oraclesdb = CentralizedOracle.objects.all()
        self.assertEquals(len(centralized_oracles),
                          centralized_oraclesdb.count())

        centralized_response_data = self.client.get(
            reverse('api:centralized-oracles'),
            content_type='application/json')
        self.assertEquals(centralized_response_data.status_code,
                          status.HTTP_200_OK)
        self.assertEquals(
            len(json.loads(centralized_response_data.content).get('results')),
            len(centralized_oracles))

        centralized_search_response = self.client.get(
            reverse('api:centralized-oracles-by-address',
                    kwargs={'addr': centralized_oracles[0].address}),
            content_type='application/json')
        self.assertEquals(centralized_search_response.status_code,
                          status.HTTP_200_OK)
        self.assertEquals(
            json.loads(centralized_search_response.content).get(
                'contract').get('creator'),
            add_0x_prefix(centralized_oracles[0].creator))
        # test empty response
        centralized_empty_search_response = self.client.get(
            reverse('api:centralized-oracles-by-address',
                    kwargs={'addr': "abcdef0"}),
            content_type='application/json')
        self.assertEquals(centralized_empty_search_response.status_code,
                          status.HTTP_404_NOT_FOUND)

        centralized_empty_search_response = self.client.get(
            reverse('api:centralized-oracles-by-address',
                    kwargs={'addr': centralized_oracles[0].creator}),
            content_type='application/json')
        self.assertEquals(centralized_empty_search_response.status_code,
                          status.HTTP_200_OK)
        self.assertEquals(
            json.loads(centralized_empty_search_response.content).get(
                'contract').get('creator'),
            add_0x_prefix(centralized_oracles[0].address))
コード例 #19
0
ファイル: test_views.py プロジェクト: DONTEAM/gnosisdb
    def test_market_marginal_prices(self):
        oracle = CentralizedOracleFactory()
        categorical_event = CategoricalEventFactory(oracle=oracle)
        outcome_token = OutcomeTokenFactory(event=categorical_event)
        market = MarketFactory(event=categorical_event)
        sender_address = '{:040d}'.format(100)

        # Buy Order
        order_one = BuyOrderFactory(market=market, sender=sender_address)
        order_two = BuyOrderFactory(market=market, sender=sender_address)
        market_response = self.client.get(reverse('api:markets-by-name', kwargs={'market_address': market.address}), content_type='application/json')
        market_data = json.loads(market_response.content)
        self.assertEquals(market_data.get('marginalPrices'), order_two.marginal_prices)
コード例 #20
0
    def test_market_factory_rollback(self):
        oracle = CentralizedOracleFactory()
        event = CategoricalEventFactory(oracle=oracle)
        market = MarketFactory()

        block = {
            'number': oracle.creation_block,
            'timestamp': self.to_timestamp(oracle.creation_date_time)
        }

        market_creation_event = {
            'name': 'StandardMarketCreation',
            'address': market.factory,
            'params': [
                {
                    'name': 'creator',
                    'value': market.creator
                },
                {
                    'name': 'centralizedOracle',
                    'value': oracle.address,
                },
                {
                    'name': 'marketMaker',
                    'value': settings.LMSR_MARKET_MAKER
                },
                {
                    'name': 'fee',
                    'value': market.fee
                },
                {
                    'name': 'eventContract',
                    'value': event.address
                },
                {
                    'name': 'market',
                    'value': market.address
                }
            ]
        }
        market.delete()

        MarketFactoryReceiver().save(market_creation_event, block)
        market_without_rollback = Market.objects.get(event=event.address)
        self.assertIsNotNone(market_without_rollback.pk)
        # Rollback
        MarketFactoryReceiver().rollback(market_creation_event, block)
        with self.assertRaises(Market.DoesNotExist):
            Market.objects.get(event=event.address)
コード例 #21
0
    def test_create_centralized_oracle_instance(self):
        oracle = CentralizedOracleFactory()
        oracle.delete()
        # oracle.event_description
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': oracle.event_description.outcomes
        }

        block = {
            'number': oracle.creation_block,
            'timestamp': mktime(oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            oracle.factory,
            'params': [{
                'name': 'creator',
                'value': oracle.creator
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address,
            }, {
                'name': 'ipfsHash',
                'value': oracle.event_description.ipfs_hash
            }]
        }

        s = CentralizedOracleInstanceSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
コード例 #22
0
    def test_centralized_oracle_instance_outcome_assignment_receiver(self):
        oracle = CentralizedOracleFactory()
        assignment_event = {
            'name': 'OutcomeAssignment',
            'address': oracle.address,
            'params': [{
                'name': 'outcome',
                'value': 1,
            }]
        }

        CentralizedOracleInstanceReceiver().save(assignment_event)
        saved_oracle = CentralizedOracle.objects.get(address=oracle.address)
        self.assertTrue(saved_oracle.is_outcome_set)
        self.assertEqual(saved_oracle.outcome, 1)
コード例 #23
0
 def test_oracle_types(self):
     ultimate_oracle = UltimateOracleFactory(forwarded_oracle=None)
     centralized_oracle = CentralizedOracleFactory()
     ultimate_response = self.client.get(reverse('api:ultimate-oracles'),
                                         content_type='application/json')
     centralized_response = self.client.get(
         reverse('api:centralized-oracles'),
         content_type='application/json')
     self.assertEquals(
         json.loads(
             ultimate_response.content).get('results')[0].get('type'),
         'ULTIMATE')
     self.assertEquals(
         json.loads(
             centralized_response.content).get('results')[0].get('type'),
         'CENTRALIZED')
コード例 #24
0
    def test_create_ultimate_oracle_no_forwarded(self):
        forwarded_oracle = CentralizedOracleFactory()
        ultimate_oracle = UltimateOracleFactory()

        block = {
            'number': ultimate_oracle.creation_block,
            'timestamp': mktime(ultimate_oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            ultimate_oracle.factory[0:-8] + 'another',
            'params': [{
                'name': 'creator',
                'value': ultimate_oracle.creator
            }, {
                'name': 'ultimateOracle',
                'value': ultimate_oracle.address[0:-8] + 'another',
            }, {
                'name':
                'oracle',
                'value':
                ultimate_oracle.forwarded_oracle.address[0:-5] + 'wrong'
            }, {
                'name': 'collateralToken',
                'value': ultimate_oracle.collateral_token
            }, {
                'name': 'spreadMultiplier',
                'value': ultimate_oracle.spread_multiplier
            }, {
                'name': 'challengePeriod',
                'value': ultimate_oracle.challenge_period
            }, {
                'name': 'challengeAmount',
                'value': ultimate_oracle.challenge_amount
            }, {
                'name': 'frontRunnerPeriod',
                'value': ultimate_oracle.front_runner_period
            }]
        }

        s = UltimateOracleSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
        self.assertIsNotNone(instance.pk)
        self.assertIsNone(instance.forwarded_oracle)
コード例 #25
0
    def test_event_description_different_outcomes(self):

        oracle = CentralizedOracleFactory()

        oracle.event_description.outcomes = ['Yes', 'No', 'Third']
        oracle.event_description.save()

        event = CategoricalEventFactory(oracle=oracle)

        # Categorical Event with different outcomes

        block = {
            'number': event.creation_block,
            'timestamp': mktime(event.creation_date_time.timetuple())
        }

        categorical_event = {
            'address':
            event.factory,
            'params': [{
                'name': 'creator',
                'value': event.creator
            }, {
                'name': 'collateralToken',
                'value': event.creator
            }, {
                'name': 'oracle',
                'value': oracle.address
            }, {
                'name': 'outcomeCount',
                'value': 2
            }, {
                'name': 'categoricalEvent',
                'value': event.address,
            }]
        }

        event.delete()

        s = CategoricalEventSerializer(data=categorical_event, block=block)
        self.assertFalse(s.is_valid())
        categorical_event['params'][3]['value'] = 3
        s2 = CategoricalEventSerializer(data=categorical_event, block=block)
        self.assertTrue(s2.is_valid(), s.errors)
        instance = s2.save()
        self.assertIsNotNone(instance)
コード例 #26
0
    def test_ultimate_oracle_receiver(self):
        forwarded_oracle = CentralizedOracleFactory()
        ultimate_oracle = UltimateOracleFactory()

        block = {
            'number': ultimate_oracle.creation_block,
            'timestamp': mktime(ultimate_oracle.creation_date_time.timetuple())
        }

        oracle_address = ultimate_oracle.address[0:7] + 'another'

        oracle_event = {
            'address':
            ultimate_oracle.factory[0:7] + 'another',
            'params': [{
                'name': 'creator',
                'value': ultimate_oracle.creator
            }, {
                'name': 'ultimateOracle',
                'value': oracle_address,
            }, {
                'name': 'oracle',
                'value': forwarded_oracle.address
            }, {
                'name': 'collateralToken',
                'value': ultimate_oracle.collateral_token
            }, {
                'name': 'spreadMultiplier',
                'value': ultimate_oracle.spread_multiplier
            }, {
                'name': 'challengePeriod',
                'value': ultimate_oracle.challenge_period
            }, {
                'name': 'challengeAmount',
                'value': ultimate_oracle.challenge_amount
            }, {
                'name': 'frontRunnerPeriod',
                'value': ultimate_oracle.front_runner_period
            }]
        }

        UltimateOracleFactoryReceiver().save(oracle_event, block)
        created_oracle = UltimateOracle.objects.get(address=oracle_address)
        self.assertIsNotNone(created_oracle.pk)
コード例 #27
0
    def test_create_scalar_event(self):
        event = ScalarEventFactory()
        event_description = ScalarEventDescriptionFactory()
        oracle = CentralizedOracleFactory(event_description=event_description)

        block = {
            'number': event.creation_block,
            'timestamp': mktime(event.creation_date_time.timetuple())
        }

        scalar_event = {
            'address':
            event.factory,
            'params': [{
                'name': 'creator',
                'value': event.creator
            }, {
                'name': 'collateralToken',
                'value': event.collateral_token
            }, {
                'name': 'oracle',
                'value': oracle.address
            }, {
                'name': 'upperBound',
                'value': 1
            }, {
                'name': 'lowerBound',
                'value': 0
            }]
        }
        event.delete()
        s = ScalarEventSerializer(data=scalar_event, block=block)
        self.assertFalse(s.is_valid(), s.errors)

        scalar_event.get('params').append({
            'name': 'scalarEvent',
            'value': event.address
        })

        s = ScalarEventSerializer(data=scalar_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
コード例 #28
0
    def test_deserialize_ultimate_oracle(self):
        forwarded_oracle = CentralizedOracleFactory()
        ultimate_oracle = UltimateOracleFactory()

        block = {
            'number': ultimate_oracle.creation_block,
            'timestamp': mktime(ultimate_oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            ultimate_oracle.factory[0:-7] + 'GIACOMO',
            'params': [{
                'name': 'creator',
                'value': ultimate_oracle.creator
            }, {
                'name': 'ultimateOracle',
                'value': ultimate_oracle.address
            }, {
                'name': 'oracle',
                'value': forwarded_oracle.address
            }, {
                'name': 'collateralToken',
                'value': ultimate_oracle.collateral_token
            }, {
                'name': 'spreadMultiplier',
                'value': ultimate_oracle.spread_multiplier
            }, {
                'name': 'challengePeriod',
                'value': ultimate_oracle.challenge_period
            }, {
                'name': 'challengeAmount',
                'value': ultimate_oracle.challenge_amount
            }, {
                'name': 'frontRunnerPeriod',
                'value': ultimate_oracle.front_runner_period
            }]
        }

        s = UltimateOracleSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
コード例 #29
0
    def test_create_categorical_event(self):
        event = CategoricalEventFactory()
        oracle = CentralizedOracleFactory()

        block = {
            'number': event.creation_block,
            'timestamp': mktime(event.creation_date_time.timetuple())
        }

        categorical_event = {
            'address':
            event.factory,
            'params': [{
                'name': 'creator',
                'value': event.creator
            }, {
                'name': 'collateralToken',
                'value': event.collateral_token
            }, {
                'name': 'oracle',
                'value': oracle.address
            }, {
                'name': 'outcomeCount',
                'value': 2
            }]
        }
        event.delete()
        s = CategoricalEventSerializer(data=categorical_event, block=block)
        self.assertFalse(s.is_valid(), s.errors)

        categorical_event.get('params').append({
            'name': 'categoricalEvent',
            'value': event.address
        })

        s = CategoricalEventSerializer(data=categorical_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)
コード例 #30
0
    def test_create_centralized_oracle_instance(self):
        oracle = CentralizedOracleFactory()
        # oracle.event_description
        event_description_json = {
            'title': oracle.event_description.title,
            'description': oracle.event_description.description,
            'resolutionDate':
            oracle.event_description.resolution_date.isoformat(),
            'outcomes': ['Yes', 'No']
        }

        # save event_description to IPFS
        ipfs_hash = self.ipfs.post(event_description_json)

        block = {
            'number': oracle.creation_block,
            'timestamp': mktime(oracle.creation_date_time.timetuple())
        }

        oracle_event = {
            'address':
            oracle.factory[0:-7] + 'GIACOMO',
            'params': [{
                'name': 'creator',
                'value': oracle.address
            }, {
                'name': 'centralizedOracle',
                'value': oracle.address[1:-8] + 'INSTANCE',
            }, {
                'name': 'ipfsHash',
                'value': ipfs_hash
            }]
        }

        s = CentralizedOracleInstanceSerializer(data=oracle_event, block=block)
        self.assertTrue(s.is_valid(), s.errors)
        instance = s.save()
        self.assertIsNotNone(instance)