Skip to content

Commit 5e548d8

Browse files
committed
Factor out reusable names
1 parent 65bfe3a commit 5e548d8

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

test/functional/blockprod_generate_pos_blocks.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717
from hashlib import blake2b
1818
from scalecodec.base import ScaleBytes, RuntimeConfiguration, ScaleDecoder
1919
from test_framework.authproxy import JSONRPCException
20-
from test_framework.mintlayer import mintlayer_hash
20+
from test_framework.mintlayer import (
21+
base_tx_obj,
22+
block_input_data_obj,
23+
mintlayer_hash,
24+
MLT_COIN,
25+
outpoint_obj,
26+
signed_tx_obj,
27+
)
2128
from test_framework.test_framework import BitcoinTestFramework
2229
from test_framework.util import (
2330
assert_equal,
2431
)
2532

2633
import random, time
2734

28-
COIN = 100_000_000_000
29-
3035
GENESIS_POOL_ID = "123c4c600097c513e088b9be62069f0c74c7671c523c8e3469a1c3f14b7ea2c4"
3136
GENESIS_STAKE_PRIVATE_KEY = "8717e6946febd3a33ccdc3f3a27629ec80c33461c33a0fc56b4836fcedd26638"
3237
GENESIS_STAKE_PUBLIC_KEY = "03c53526caf73cd990148e127cb57249a5e266d78df23968642c976a532197fdaa"
@@ -37,11 +42,6 @@
3742
"e9f3cd7b78d45750afd17292031373fddb5e7a8090db51221038f5e05f29998e"
3843
)
3944

40-
block_input_data_obj = RuntimeConfiguration().create_scale_object('GenerateBlockInputData')
41-
outpoint_obj = RuntimeConfiguration().create_scale_object('OutPoint')
42-
signed_transaction_obj = RuntimeConfiguration().create_scale_object('SignedTransaction')
43-
transaction_obj = RuntimeConfiguration().create_scale_object('TransactionV1')
44-
4545
class GeneratePoSBlocksTest(BitcoinTestFramework):
4646
def set_test_params(self):
4747
self.setup_clean_chain = True
@@ -135,9 +135,9 @@ def new_vrf_keys(self):
135135
return (new_vrf_private_key, new_vrf_public_key)
136136

137137
def pack_transaction(self, transaction):
138-
transaction_encoded = signed_transaction_obj.encode(transaction).to_hex()[2:]
138+
transaction_encoded = signed_tx_obj.encode(transaction).to_hex()[2:]
139139
transaction_id = ScaleBytes(
140-
mintlayer_hash(transaction_obj.encode(transaction["transaction"]).data)
140+
mintlayer_hash(base_tx_obj.encode(transaction["transaction"]).data)
141141
).to_hex()[2:]
142142

143143
return (transaction_encoded, transaction_id)
@@ -207,7 +207,7 @@ def run_test(self):
207207
"CreateStakePool": [
208208
self.genesis_pool_id(),
209209
{
210-
"value": 40_000*COIN,
210+
"value": 40_000*MLT_COIN,
211211
"staker": {
212212
"PublicKey": self.stake_public_key(GENESIS_STAKE_PUBLIC_KEY),
213213
},
@@ -242,7 +242,7 @@ def run_test(self):
242242
{
243243
"Transfer": [
244244
{
245-
"Coin": 100_000*COIN,
245+
"Coin": 100_000*MLT_COIN,
246246
},
247247
"AnyoneCanSpend",
248248
],
@@ -315,7 +315,7 @@ def run_test(self):
315315
"CreateStakePool": [
316316
new_pool_id,
317317
{
318-
"value": 100_000*COIN,
318+
"value": 100_000*MLT_COIN,
319319
"staker": {
320320
"PublicKey": new_stake_public_key,
321321
},
@@ -353,7 +353,7 @@ def run_test(self):
353353
"CreateStakePool": [
354354
new_pool_id,
355355
{
356-
"value": 100_000*COIN,
356+
"value": 100_000*MLT_COIN,
357357
"staker": {
358358
"PublicKey": new_stake_public_key,
359359
},

test/functional/blockprod_generate_pos_blocks_rand_genesis_keys.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
from hashlib import blake2b
1818
from scalecodec.base import ScaleBytes, RuntimeConfiguration, ScaleDecoder
1919
from test_framework.authproxy import JSONRPCException
20-
from test_framework.mintlayer import mintlayer_hash
20+
from test_framework.mintlayer import (
21+
base_tx_obj,
22+
block_input_data_obj,HHH
23+
outpoint_obj,
24+
mintlayer_hash,
25+
MLT_COIN,
26+
signed_tx_obj,
27+
)
2128
from test_framework.test_framework import BitcoinTestFramework
2229
from test_framework.util import (
2330
assert_equal,
2431
)
2532

2633
import random, secrets, time
2734

28-
COIN = 100_000_000_000
29-
30-
block_input_data_obj = RuntimeConfiguration().create_scale_object('GenerateBlockInputData')
31-
outpoint_obj = RuntimeConfiguration().create_scale_object('OutPoint')
32-
signed_transaction_obj = RuntimeConfiguration().create_scale_object('SignedTransaction')
33-
transaction_obj = RuntimeConfiguration().create_scale_object('TransactionV1')
34-
3535
class GenerateGenesisKeys(BitcoinTestFramework):
3636
def set_test_params(self):
3737
self.setup_clean_chain = True
@@ -153,9 +153,9 @@ def new_vrf_keys(self):
153153
return (new_vrf_private_key, new_vrf_public_key)
154154

155155
def pack_transaction(self, transaction):
156-
transaction_encoded = signed_transaction_obj.encode(transaction).to_hex()[2:]
156+
transaction_encoded = signed_tx_obj.encode(transaction).to_hex()[2:]
157157
transaction_id = ScaleBytes(
158-
mintlayer_hash(transaction_obj.encode(transaction["transaction"]).data)
158+
mintlayer_hash(base_tx_obj.encode(transaction["transaction"]).data)
159159
).to_hex()[2:]
160160

161161
return (transaction_encoded, transaction_id)
@@ -233,7 +233,7 @@ def run_test(self):
233233
"CreateStakePool": [
234234
genesis_pool_id,
235235
{
236-
"value": 40_000*COIN,
236+
"value": 40_000*MLT_COIN,
237237
"staker": {
238238
"PublicKey": genesis_stake_public_key,
239239
},
@@ -268,7 +268,7 @@ def run_test(self):
268268
{
269269
"Transfer": [
270270
{
271-
"Coin": 100_000*COIN,
271+
"Coin": 100_000*MLT_COIN,
272272
},
273273
"AnyoneCanSpend",
274274
],
@@ -341,7 +341,7 @@ def run_test(self):
341341
"CreateStakePool": [
342342
new_pool_id,
343343
{
344-
"value": 100_000*COIN,
344+
"value": 100_000*MLT_COIN,
345345
"staker": {
346346
"PublicKey": new_stake_public_key,
347347
},
@@ -379,7 +379,7 @@ def run_test(self):
379379
"CreateStakePool": [
380380
new_pool_id,
381381
{
382-
"value": 100_000*COIN,
382+
"value": 100_000*MLT_COIN,
383383
"staker": {
384384
"PublicKey": new_stake_public_key,
385385
},

test/functional/blockprod_generate_pos_genesis_blocks.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717
from hashlib import blake2b
1818
from scalecodec.base import ScaleBytes, RuntimeConfiguration, ScaleDecoder
1919
from test_framework.authproxy import JSONRPCException
20-
from test_framework.mintlayer import mintlayer_hash
20+
from test_framework.mintlayer import (
21+
base_tx_obj,
22+
block_input_data_obj,
23+
mintlayer_hash,
24+
MLT_COIN,
25+
outpoint_obj,
26+
signed_tx_obj,
27+
)
2128
from test_framework.test_framework import BitcoinTestFramework
2229
from test_framework.util import (
2330
assert_equal,
2431
)
2532

2633
import random, time
2734

28-
COIN = 100_000_000_000
29-
3035
GENESIS_POOL_ID = "123c4c600097c513e088b9be62069f0c74c7671c523c8e3469a1c3f14b7ea2c4"
3136
GENESIS_STAKE_PRIVATE_KEY = "8717e6946febd3a33ccdc3f3a27629ec80c33461c33a0fc56b4836fcedd26638"
3237
GENESIS_STAKE_PUBLIC_KEY = "03c53526caf73cd990148e127cb57249a5e266d78df23968642c976a532197fdaa"
@@ -37,11 +42,6 @@
3742
"e9f3cd7b78d45750afd17292031373fddb5e7a8090db51221038f5e05f29998e"
3843
)
3944

40-
block_input_data_obj = RuntimeConfiguration().create_scale_object('GenerateBlockInputData')
41-
outpoint_obj = RuntimeConfiguration().create_scale_object('OutPoint')
42-
signed_transaction_obj = RuntimeConfiguration().create_scale_object('SignedTransaction')
43-
transaction_obj = RuntimeConfiguration().create_scale_object('TransactionV1')
44-
4545
class GeneratePoSGenesisBlocksTest(BitcoinTestFramework):
4646
def set_test_params(self):
4747
self.setup_clean_chain = True
@@ -117,9 +117,9 @@ def hex_to_dec_array(self, hex_string):
117117
return [int(hex_string[i:i+2], 16) for i in range(0, len(hex_string), 2)]
118118

119119
def pack_transaction(self, transaction):
120-
transaction_encoded = signed_transaction_obj.encode(transaction).to_hex()[2:]
120+
transaction_encoded = signed_tx_obj.encode(transaction).to_hex()[2:]
121121
transaction_id = ScaleBytes(
122-
mintlayer_hash(transaction_obj.encode(transaction["transaction"]).data)
122+
mintlayer_hash(base_tx_obj.encode(transaction["transaction"]).data)
123123
).to_hex()[2:]
124124

125125
return (transaction_encoded, transaction_id)
@@ -189,7 +189,7 @@ def run_test(self):
189189
"CreateStakePool": [
190190
self.genesis_pool_id(),
191191
{
192-
"value": 40_000*COIN,
192+
"value": 40_000*MLT_COIN,
193193
"staker": {
194194
"PublicKey": self.stake_public_key(GENESIS_STAKE_PUBLIC_KEY),
195195
},

test/functional/blockprod_generate_pow_blocks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
from scalecodec.base import ScaleBytes, RuntimeConfiguration, ScaleDecoder
1818
from test_framework.authproxy import JSONRPCException
19+
from test_framework.mintlayer import block_input_data_obj
1920
from test_framework.test_framework import BitcoinTestFramework
2021
from test_framework.util import (
2122
assert_equal,
2223
)
2324

2425
import random, scalecodec, time
2526

26-
block_input_data_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('GenerateBlockInputData')
27-
2827
class GeneratePoWBlocksTest(BitcoinTestFramework):
2928
def set_test_params(self):
3029
self.setup_clean_chain = True

test/functional/test_framework/mintlayer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import scalecodec
2020
import time
2121

22+
MLT_COIN = 100_000_000_000
23+
2224
base_tx_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('TransactionV1')
2325
block_header_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('BlockHeader')
2426
block_input_data_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('GenerateBlockInputData')
2527
block_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('BlockV1')
28+
outpoint_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('OutPoint')
2629
signed_tx_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('SignedTransaction')
2730
vec_output_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('Vec<TxOutput>')
2831

0 commit comments

Comments
 (0)