Esempio n. 1
0
    def test_request(self, score_invoke):
        inner_task = generate_inner_task(3)
        IconScoreContext.engine.prep.preps = Mock()

        # noinspection PyUnusedLocal
        def intercept_invoke(*args, **kwargs):
            ContextContainer._push_context(args[0])

            context_db = inner_task._icon_service_engine._icx_context_db

            score_address = create_address(AddressPrefix.CONTRACT, b'address')
            score = SampleScore(IconScoreDatabase(score_address, context_db))

            address = create_address(AddressPrefix.EOA, b'address')
            score.SampleEvent(b'i_data', address, 10, b'data', 'text')

            ContextContainer._pop_context()

        score_invoke.side_effect = intercept_invoke

        from_ = create_address(AddressPrefix.EOA, b'from')
        to_ = create_address(AddressPrefix.CONTRACT, b'score')

        request = create_request([
            ReqData(bytes.hex(create_tx_hash(b'tx1')), from_, to_, 0, 'call',
                    {}),
            ReqData(bytes.hex(create_tx_hash(b'tx2')), from_, to_, 0, 'call',
                    {})
        ])
        response = inner_task._invoke(request)

        step_total = 0

        for tx_hash in response['txResults'].keys():
            result = response['txResults'][tx_hash]
            step_total += int(result['stepUsed'], 16)
            self.assertIn('status', result)
            self.assertIn('txHash', result)
            self.assertIn('txIndex', result)
            self.assertIn('blockHeight', result)
            self.assertIn('blockHash', result)
            self.assertIn('cumulativeStepUsed', result)
            self.assertIn('stepUsed', result)
            self.assertEqual(1, len(result['eventLogs']))
            self.assertEqual(step_total, int(result['cumulativeStepUsed'], 16))

        clear_inner_task()
Esempio n. 2
0
 def tearDown(self):
     ContextContainer._clear_context()
     clear_inner_task()