Пример #1
0
 def test_parse_log(self, node: Node):
     with patch.object(Session, "post", side_effect=self.post):
         contract = Contract(
             node, "0x6361d0441973eb4457d2f8092bbbe303db5eb0f981")
         logs = contract.fetch(
             "6d1240e174059991087b43250caa920f559cff16d32863be75f02a1a0d781992"
         )
         logs.to_dict()
Пример #2
0
    def test_deploy_according_template(self, node: Node, contract_template):
        mock_tx = Mock()
        mock_tx.broadcast().check.return_value = constant.SUCCESS

        with patch.multiple(
                node,
                get_contract_template=Mock(return_value=contract_template),
                call_write_function=Mock(return_value=mock_tx),
                _calc_contract_address=Mock(
                    return_value="0x6361d0441973eb4457d2f8092bbbe303db5eb0f981"
                )):
            Contract(node, template_name="test_template")
Пример #3
0
 def test_execute_contract(self, node: Node, call_type):
     with patch.object(Session, "post", side_effect=self.post):
         contract = Contract(
             node, "0x6361d0441973eb4457d2f8092bbbe303db5eb0f981")
         if call_type == "write":
             contract.execute("withdraw", (1000, ))
         elif call_type == "vote":
             contract.vote("withdraw", (1000, ))
Пример #4
0
    # create template
    t = Template(node)
    template_name = ''.join(random.choices(string.ascii_letters + string.digits, k=5))
    tx = t.submit("./contracts/tutorial.sol", template_name, 'Tutorial')

    # wait for confirmation
    assert tx.check() is constant.SUCCESS

    # deploy contract
    org_name = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
    deploy_tx, contract_address = t.deploy_contract(tx.id, [org_name])
    assert deploy_tx.check() is constant.SUCCESS
    print(f"contract address: {contract_address}")

    contract = Contract(node, contract_address)
    # contract = Contract(node, c=compiled_contract, args=[org_name])

    # mint asset
    assert contract.execute("mint", [10000 * constant.COIN]).check() is constant.SUCCESS
    # get asset type
    asset_type = Asset.asset2str(contract.read("assettype"))
    # check contract balance
    assert contract.read("checkBalance") == 10000 * constant.COIN
    # transfer asset from contract
    assert contract.execute("transfer", [node.address, 100 * constant.COIN]).check() is constant.SUCCESS
    assert node.balance(asset=asset_type) == 100 * constant.COIN
    # check contract balance
    assert contract.read("checkBalance") == 9900 * constant.COIN
    # transfer to other address
    assert node.send(AccountFactory.new().address, 1 * constant.COIN, asset_type).check() is constant.SUCCESS
Пример #5
0
 def test_read_contract(self, node: Node):
     with patch.object(Session, "post", side_effect=self.post):
         contract = Contract(
             node, "0x6361d0441973eb4457d2f8092bbbe303db5eb0f981")
         assert contract.read("dict", (0, )) == 1
Пример #6
0
 def test_init_from_existing(self, node: Node):
     with patch.object(Session, "post", side_effect=self.post):
         Contract(node, "0x6361d0441973eb4457d2f8092bbbe303db5eb0f981")
Пример #7
0
 def test_deploy(self, node: Node, complied_contract):
     with patch.object(Session, "post", side_effect=self.post):
         Contract(node, c=complied_contract)