forked from qtumproject/qtum-bitcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dupe-contract.py
executable file
·55 lines (41 loc) · 2.59 KB
/
dupe-contract.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
#!/usr/bin/env python3
# Copyright (c) 2015-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
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.blocktools import *
from test_framework.qtum import *
import sys
import io
class QtumDupeContractTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False):
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [[]])
self.node = self.nodes[0]
def run_test(self):
self.node.generate(10+COINBASE_MATURITY)
tx = CTransaction()
tx.vin = [make_vin(self.node, 6*COIN)]
tx.vout = []
# First we append two OP_CREATE outputs (vout = 0, 1 (mod 256))
tx.vout.append(CTxOut(0, CScript([1, 1000000, 1, bytes.fromhex("60606040523415600b57fe5b5b60398060196000396000f30060606040525b600b5b5b565b0000a165627a7a72305820e3bed070fd3a81dd00e02efd22d18a3b47b70860155d6063e47e1e2674fc5acb0029"), OP_CREATE])))
tx.vout.append(CTxOut(0, CScript([1, 1000000, 1, bytes.fromhex("60606040523415600b57fe5b5b60398060196000396000f30060606040525b600b5b5b565b0000a165627a7a72305820e3bed070fd3a81dd00e02efd22d18a3b47b70860155d6063e47e1e2674fc5acb0029"), OP_CREATE])))
# Now we append 255 vouts that spend no gas
for _ in range(2, 256):
tx.vout.append(CTxOut(1000000, CScript([OP_TRUE])))
# Now we append another two more vouts that should create contracts (vout = 0, 1 (mod 256))
tx.vout.append(CTxOut(0, CScript([1, 1000000, 1, bytes.fromhex("60606040523415600b57fe5b5b60398060196000396000f30060606040525b600b5b5b565b0000a165627a7a72305820e3bed070fd3a81dd00e02efd22d18a3b47b70860155d6063e47e1e2674fc5acb0029"), OP_CREATE])))
tx.vout.append(CTxOut(0, CScript([1, 1000000, 1, bytes.fromhex("60606040523415600b57fe5b5b60398060196000396000f30060606040525b600b5b5b565b0000a165627a7a72305820e3bed070fd3a81dd00e02efd22d18a3b47b70860155d6063e47e1e2674fc5acb0029"), OP_CREATE])))
ret = self.node.signrawtransaction(bytes_to_hex_str(tx.serialize()))
self.node.sendrawtransaction(ret['hex'])
self.node.generate(1)
# This should result in 4 contracts being created.
assert_equal(len(self.node.listcontracts()), 4)
if __name__ == '__main__':
QtumDupeContractTest().main()