Пример #1
0
    def test_erc721(self):
        contract_a = make_contract("", "uint256")
        vm = create_evm_vm([contract_a], False, False)
        output_handler = create_output_handler([contract_a])

        erc721 = contract_templates.get_erc721_contract()
        erc721["address"] = "0xfff6baf0b45129dc8d4cd67ddc28a78d8c599faf"
        erc721_abi = ContractABI(erc721)
        inbox = value.Tuple([])
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [3, 2345, value.Tuple([erc721_abi.address, address, 100000])]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [3, 2345, value.Tuple([erc721_abi.address, address, 150000])]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [
                            CALL_TX_TYPE,
                            address,
                            erc721_abi.call_tokensOfOwner(address_string),
                        ]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [
                            0,
                            address,
                            erc721_abi.withdraw(0, 0, dest_address_string, 50000),
                        ]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [
                            0,
                            address,
                            erc721_abi.withdraw(1, 0, dest_address_string, 100000),
                        ]
                    )  # type  # sender
                )
            ),
        )
        vm.env.messages = inbox
        run_until_block(vm, self)
        self.assertEqual(len(vm.logs), 5)
        parsed_out0 = output_handler(vm.logs[0])
        parsed_out1 = output_handler(vm.logs[1])
        parsed_out2 = output_handler(vm.logs[2])
        parsed_out3 = output_handler(vm.logs[3])
        parsed_out4 = output_handler(vm.logs[4])
        self.assertIsInstance(parsed_out0, EVMStop)
        self.assertIsInstance(parsed_out1, EVMStop)
        self.assertIsInstance(parsed_out2, EVMReturn)
        self.assertIsInstance(parsed_out3, EVMRevert)
        self.assertIsInstance(parsed_out4, EVMStop)

        out = parsed_out2.output_values
        self.assertEqual(len(out), 1)
        self.assertEqual(out[0], (100000, 150000))

        self.assertEqual(len(vm.sent_messages), 1)
        self.assertEqual(
            vm.sent_messages[0],
            value.Tuple(
                [3, address, value.Tuple([erc721_abi.address, dest_address, 100000])]
            ),
        )
Пример #2
0
    def test_erc20(self):
        contract_a = make_contract("", "uint256")
        vm = create_evm_vm([contract_a], False, False)

        output_handler = create_output_handler([contract_a])

        erc20 = contract_templates.get_erc20_contract()
        erc20["address"] = "0xfff6baf0b45129dc8d4cd67ddc28a78d8c599faf"
        erc20_abi = ContractABI(erc20)

        inbox = value.Tuple([])
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [2, 2345, value.Tuple([erc20_abi.address, address, 100000])]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [
                            0,
                            address,
                            erc20_abi.withdraw(0, 0, dest_address_string, 150000),
                        ]
                    )  # type  # sender
                )
            ),
        )
        inbox = messagestack.addMessage(
            inbox,
            value.Tuple(
                make_msg_val(
                    value.Tuple(
                        [
                            0,
                            address,
                            erc20_abi.withdraw(1, 0, dest_address_string, 50000),
                        ]
                    )  # type  # sender
                )
            ),
        )
        vm.env.messages = inbox
        run_until_block(vm, self)
        self.assertEqual(len(vm.logs), 3)
        parsed_out0 = output_handler(vm.logs[0])
        parsed_out1 = output_handler(vm.logs[1])
        parsed_out2 = output_handler(vm.logs[2])
        self.assertIsInstance(parsed_out0, EVMStop)
        self.assertIsInstance(parsed_out1, EVMRevert)
        self.assertIsInstance(parsed_out2, EVMStop)

        self.assertEqual(len(vm.sent_messages), 1)
        self.assertEqual(
            vm.sent_messages[0],
            value.Tuple(
                [2, address, value.Tuple([erc20_abi.address, dest_address, 50000])]
            ),
        )