forked from qtumproject/qtum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtum_no_exec_call_disabled.py
executable file
·75 lines (63 loc) · 3.18 KB
/
qtum_no_exec_call_disabled.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.script import *
from test_framework.mininode import *
from test_framework.address import *
from test_framework.qtum import *
from test_framework.blocktools import *
import sys
import random
import time
import io
def rpc_sign_transaction(node, tx):
tx_signed_raw_hex = node.signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize()))['hex']
f = io.BytesIO(hex_str_to_bytes(tx_signed_raw_hex))
tx_signed = CTransaction()
tx_signed.deserialize(f)
return tx_signed
class QtumNoExecCallDisabledTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
self.node = self.nodes[0]
self.node.generate(10 + COINBASE_MATURITY)
"""
pragma solidity ^0.4.12;
contract Test {
function () payable {}
}
"""
bytecode = "60606040523415600e57600080fd5b5b603580601c6000396000f30060606040525b5b5b0000a165627a7a723058208938cb174ee70dbb41b522af1feac2c7e0e252b7bc9ecb92c8d87a50c445a26c0029"
contract_address = self.node.createcontract(bytecode)['address']
self.node.generate(1)
self.node.sendtocontract(contract_address, "00", 1)
self.node.generate(1)
tx = CTransaction()
tx.vin = [make_vin(self.node, int(COIN+1000000))]
tx.vout = [CTxOut(int(COIN), scriptPubKey=CScript([b"\x00", CScriptNum(0), CScriptNum(0), b"\x00", hex_str_to_bytes(contract_address), OP_CALL]))]
tx = rpc_sign_transaction(self.node, tx)
assert_raises_rpc_error(-26, "bad-tx-version-rootvm", self.node.sendrawtransaction, bytes_to_hex_str(tx.serialize()))
tx.vout = [CTxOut(int(COIN - 10000000), scriptPubKey=CScript([b"\x00", CScriptNum(100000), CScriptNum(QTUM_MIN_GAS_PRICE), b"\x00", hex_str_to_bytes(contract_address), OP_CALL]))]
tx = rpc_sign_transaction(self.node, tx)
assert_raises_rpc_error(-26, "bad-tx-version-rootvm", self.node.sendrawtransaction, bytes_to_hex_str(tx.serialize()))
tip = self.node.getblock(self.node.getbestblockhash())
block = create_block(int(tip['hash'], 16), create_coinbase(tip['height']+1), tip['time']+1)
block.vtx.append(tx)
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
blockcount = self.node.getblockcount()
self.node.submitblock(bytes_to_hex_str(block.serialize()))
assert_equal(self.node.getblockcount(), blockcount)
block.vtx[1].vout = [CTxOut(int(COIN), scriptPubKey=CScript([b"\x00", CScriptNum(0), CScriptNum(0), b"\x00", hex_str_to_bytes(contract_address), OP_CALL]))]
block.vtx[1] = rpc_sign_transaction(self.node, block.vtx[1])
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
blockcount = self.node.getblockcount()
self.node.submitblock(bytes_to_hex_str(block.serialize()))
assert_equal(self.node.getblockcount(), blockcount)
if __name__ == '__main__':
QtumNoExecCallDisabledTest().main()