forked from FeatherCoin/Feathercoin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathomni_stospec.py
130 lines (106 loc) · 7.06 KB
/
omni_stospec.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
# Copyright (c) 2017-2018 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test STO spec."""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from decimal import Decimal
class OmniSTOSpec(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
def run_test(self):
self.log.info("test STO spec")
# Preparing some mature Bitcoins
coinbase_address = self.nodes[0].getnewaddress()
self.nodes[0].generatetoaddress(110, coinbase_address)
# Obtaining a master address to work with
address = self.nodes[0].getnewaddress()
# Funding the address with some testnet BTC for fees
self.nodes[0].sendtoaddress(address, 10)
self.nodes[0].generatetoaddress(1, coinbase_address)
NUM_OWNERS = "30" # Was 70 in OmniJ tests but very slow in python!
params = [{"maxN": NUM_OWNERS, "amountStartPerOwner": "1", "amountDistributePerOwner": "1", "propertyType": 1},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1", "amountDistributePerOwner": "3", "propertyType": 1},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1", "amountDistributePerOwner": "100000000", "propertyType": 1},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "100000000", "amountDistributePerOwner": "1", "propertyType": 1},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "100000000", "amountDistributePerOwner": "3", "propertyType": 1},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "0.00000001", "amountDistributePerOwner": "1.00000000", "propertyType": 2},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "0.00000001", "amountDistributePerOwner": "2.00000000", "propertyType": 2},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1.00000000", "amountDistributePerOwner": "0.00000001", "propertyType": 2},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1.00000000", "amountDistributePerOwner": "0.00000002", "propertyType": 2},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1.00000000", "amountDistributePerOwner": "0.50000000", "propertyType": 2},
{"maxN": NUM_OWNERS, "amountStartPerOwner": "1.00000000", "amountDistributePerOwner": "3.00000000", "propertyType": 2},
{"maxN": "1", "amountStartPerOwner": "1", "amountDistributePerOwner": "9223372036854775806", "propertyType": 1},
{"maxN": "1", "amountStartPerOwner": "9223372036854775806", "amountDistributePerOwner": "1", "propertyType": 1},
{"maxN": "1", "amountStartPerOwner": "0.00000001", "amountDistributePerOwner": "92233720368.54775806", "propertyType": 2},
{"maxN": "1", "amountStartPerOwner": "92233720368.54775806", "amountDistributePerOwner": "0.00000001", "propertyType": 2}]
for settings in params:
maxN = Decimal(settings['maxN'])
propertyType = settings['propertyType']
amountStartPerOwner = Decimal(settings['amountStartPerOwner'])
amountDistributePerOwner = Decimal(settings['amountDistributePerOwner'])
if propertyType == 1:
print("PropertyType:", propertyType, ": start with n *", amountStartPerOwner, "and send n *", amountDistributePerOwner, "to", maxN, "owners")
else:
print("PropertyType:", propertyType, ": start with n *", str(amountStartPerOwner), "and send n *", amountDistributePerOwner, "to", maxN, "owners")
# Preparation
fundingSPT = ((maxN * (maxN + 1)) / 2) * (amountStartPerOwner + amountDistributePerOwner)
if propertyType == 1:
actorSPT = ((maxN * (maxN + 1)) / 2) * amountDistributePerOwner
else:
actorSPT = "{:.8f}".format(((maxN * (maxN + 1)) / 2) * amountDistributePerOwner)
# Create actor
actorAddress = self.nodes[0].getnewaddress()
self.nodes[0].sendtoaddress(actorAddress, "1")
self.nodes[0].generatetoaddress(1, coinbase_address)
# Create property
txid = self.nodes[0].omni_sendissuancefixed(actorAddress, 1, settings['propertyType'], 0, "", "", "TST", "", "", str(fundingSPT))
self.nodes[0].generatetoaddress(1, coinbase_address)
# Checking the transaction was valid...
result = self.nodes[0].omni_gettransaction(txid)
assert_equal(result['valid'], True)
# Get currency ID
currencySPT = result['propertyid']
# Check funding balances of actor
startingBalanceSPT = self.nodes[0].omni_getbalance(actorAddress, currencySPT)
assert_equal(Decimal(startingBalanceSPT['balance']), fundingSPT)
# Create owners
owners = []
for n in range(1, int(maxN) + 1):
index = n - 1
if propertyType == 1:
starting = n * amountStartPerOwner
else:
starting = "{:.8f}".format(n * amountStartPerOwner)
owners.append(self.nodes[0].getnewaddress())
self.nodes[0].omni_send(actorAddress, owners[index], currencySPT, str(starting))
if (index % 10 == 0):
self.nodes[0].generatetoaddress(1, coinbase_address)
self.nodes[0].generatetoaddress(1, coinbase_address)
# Check starting balances of actor
reallyBalanceSPT = self.nodes[0].omni_getbalance(actorAddress, currencySPT)
assert_equal(Decimal(reallyBalanceSPT['balance']), Decimal(actorSPT))
# Check owner balances
for n in range(1, int(maxN) + 1):
index = n - 1
expectedBalanceOwnerSPT = n * amountStartPerOwner
startingBalanceOwnerSPT = self.nodes[0].omni_getbalance(owners[index], currencySPT)
assert_equal(Decimal(startingBalanceOwnerSPT['balance']), expectedBalanceOwnerSPT)
stoTxid = self.nodes[0].omni_sendsto(actorAddress, currencySPT, actorSPT)
self.nodes[0].generatetoaddress(1, coinbase_address)
stoTx = self.nodes[0].omni_gettransaction(stoTxid)
assert_equal(stoTx['valid'], True)
assert_equal(stoTx['confirmations'], 1)
# Check updated owner balances
for n in range(1, int(maxN) + 1):
index = n - 1
expectedFinalBalanceOwnerSPT = n * (amountStartPerOwner + amountDistributePerOwner)
finalBalanceOwnerSPT = self.nodes[0].omni_getbalance(owners[index], currencySPT)
assert_equal(Decimal(finalBalanceOwnerSPT['balance']), expectedFinalBalanceOwnerSPT)
# Check final balances of actor
finalBalanceSPT = self.nodes[0].omni_getbalance(actorAddress, currencySPT)
assert_equal(Decimal(finalBalanceSPT['balance']), 0)
if __name__ == '__main__':
OmniSTOSpec().main()