Exemplo n.º 1
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, ))
Exemplo n.º 2
0
    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
    # check balance
    assert node.balance(asset=asset_type) == 99 * constant.COIN
    # burn
    assert contract.execute("burn", asset_value=98 * constant.COIN, asset_type=asset_type).check() is constant.SUCCESS