Skip to content

Commit

Permalink
Merge pull request #1083 from cyyber/master
Browse files Browse the repository at this point in the history
Updated Genesis Headerhash + Unit test
  • Loading branch information
cyyber authored Mar 24, 2018
2 parents 70cb421 + ef696ab commit c9ce68d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 88 deletions.
70 changes: 2 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,77 +89,11 @@ pip3 install -U qrl --log ~/pip3-Qrl.log

* * *

## Wallet

Create a new wallet using the `qrl` command. After you create a wallet you can create a new `slaves.json` file and use it to mine with.

### Create New Wallet

```bash
# Create a new wallet
qrl wallet_gen
```
### Get Mnemonic/hexseed

```bash
# Get mnemonic phrase and hexseed
qrl wallet_secret
```
### Recover QRL Wallet

```bash
# Options:
# --seed-type [hexseed|mnemonic]
# --help Show this message and exit.

qrl wallet_recover --seed-type mnemonic
```

### Generate a slaves.json file

Using the wallet you just created generate the slaves.json file against a know working node. You can switch the ip-address with a trusted open node.

```
# QRL Nodes
104.237.3.185
104.237.3.184
104.251.219.145
104.251.219.40
```

```bash
# Generate slaves.json file
qrl -r --host 104.237.3.185 slave_tx_generate
```
This will prompt with some questions:

```bash
Src []: # The wallet you generated by #ID
Addr from []: # (Leave blank in case same as source)
Number of slaves [0]: # Enter 4
Access type [0]: # Mining only or transfer coins [0],[1]
# 0 Gives all permissions from the master wallet to slave wallet
# 1 Only mining permissions to slave wallet
# This setting allows incoming only transfers (SAFE)
Fee [0.0]: 0 # How much fee
```

This will generate a `slaves.json` in the directory you are in.

If you have saved the **Mnemonic** or **hexseed** somewhere safe you can delete the open `wallet.qrl` file and use the `slaves.json` file to mine with.

Move this fie into your `~/.qrl` directory. If needed, create the directory.

* * *

## Start QRL Node

Now that we have a `slaves.json` file in our ~/.qrl folder we can start qrl.

```bash
# start qrl
start_qrl
start_qrl --miningCreditWallet=YOUR_QRL_ADDRESS
```

Check out all the options with a simple `start_qrl --help`
Expand All @@ -168,7 +102,7 @@ Using `screen` you can run in the background and reconnect later. You may need t

```bash
# run in background
screen -d -m start_qrl
screen -d -m start_qrl --miningCreditWallet=YOUR_QRL_ADDRESS
```
You can see the progress in the `~/.qrl/qrl.log` file.

Expand Down
6 changes: 3 additions & 3 deletions qrl/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self):

self.version = version
self.required_version = '0.0.'
self.genesis_prev_headerhash = b'The Burning Ice'
self.genesis_prev_headerhash = b'Excession'

################################################################
# Warning: Don't change following configuration. #
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(self):
self.ots_bitfield_size = ceil(self.max_ots_tracking_index / 8)

self.default_nonce = 0
self.default_account_balance = 100 * (10 ** 9)
self.default_account_balance = 0 * (10 ** 9)
self.hash_buffer_size = 4
self.minimum_minting_delay = 45 # Minimum delay in second before a block is being created
self.mining_setpoint_blocktime = 60
Expand All @@ -158,7 +158,7 @@ def __init__(self):
self.slave_dat_filename = 'slave.qrl'
self.banned_peers_filename = 'banned_peers.qrl'

self.genesis_timestamp = 1519601074
self.genesis_timestamp = 1521888567

self.supplied_coins = 65000000 * (10 ** 9)

Expand Down
4 changes: 2 additions & 2 deletions qrl/core/genesis.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"header": {
"hashHeader": "HCAERhKw6N0g2VahApsS21eJFXCztfjSev0QYVqPLYw=",
"hashHeaderPrev": "VGhlIEJ1cm5pbmcgSWNl",
"hashHeader": "PW0i0dvkzO+WGAuMZWYBdXYv9i/4SeEOj75peRnF3eA=",
"hashHeaderPrev": "RXhjZXNzaW9u",
"rewardBlock": "65000000000000000",
"merkleRoot": "D9OP1iojqiWK3nIasICIdc8OJOVT+LVBiMGfMQyfeQA="
},
Expand Down
40 changes: 28 additions & 12 deletions tests/core/test_ChainManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from qrl.core.GenesisBlock import GenesisBlock
from qrl.core.State import State
from qrl.core.Transaction import SlaveTransaction, TransferTransaction
from tests.misc.helper import get_alice_xmss, get_bob_xmss, set_data_dir
from tests.misc.helper import get_alice_xmss, get_bob_xmss, set_data_dir, set_default_balance_size


class TestChainManager(TestCase):
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_simple_add_block(self):
prevblock_headerhash=genesis_block.headerhash,
transactions=[],
miner_address=alice_xmss.address)
block_1.set_mining_nonce(162)
block_1.set_mining_nonce(219)

# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
Expand All @@ -70,6 +70,7 @@ def test_simple_add_block(self):
self.assertTrue(result)
self.assertEqual(chain_manager.last_block, block_1)

@set_default_balance_size()
def test_multi_output_transaction_add_block(self):
with set_data_dir('no_data'):
with State() as state:
Expand Down Expand Up @@ -108,7 +109,7 @@ def test_multi_output_transaction_add_block(self):
prevblock_headerhash=genesis_block.headerhash,
transactions=[transfer_transaction],
miner_address=alice_xmss.address)
block_1.set_mining_nonce(339)
block_1.set_mining_nonce(237)

# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
Expand Down Expand Up @@ -170,7 +171,12 @@ def test_add_block(self, mock_difficulty_tracker_get):
prevblock_headerhash=genesis_block.headerhash,
transactions=[slave_tx],
miner_address=alice_xmss.address)
block_1.set_mining_nonce(1)
block_1.set_mining_nonce(0)
# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
# while not PoWValidator().validate_mining_nonce(state, block_1.blockheader, False):
# block_1.set_mining_nonce(block_1.mining_nonce + 1)
# print(block_1.mining_nonce)
result = chain_manager.add_block(block_1)

self.assertTrue(result)
Expand All @@ -188,7 +194,12 @@ def test_add_block(self, mock_difficulty_tracker_get):
transactions=[],
miner_address=bob_xmss.address)

block.set_mining_nonce(4)
block.set_mining_nonce(0)
# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
# while not PoWValidator().validate_mining_nonce(state, block.blockheader, False):
# block.set_mining_nonce(block.mining_nonce + 1)
# print(block.mining_nonce)
result = chain_manager.add_block(block)

self.assertTrue(result)
Expand All @@ -204,7 +215,12 @@ def test_add_block(self, mock_difficulty_tracker_get):
transactions=[],
miner_address=bob_xmss.address)

block_2.set_mining_nonce(0)
block_2.set_mining_nonce(1)
# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
# while not PoWValidator().validate_mining_nonce(state, block_2.blockheader, False):
# block_2.set_mining_nonce(block_2.mining_nonce + 1)
# print(block_2.mining_nonce)
result = chain_manager.add_block(block_2)

self.assertTrue(result)
Expand Down Expand Up @@ -239,12 +255,12 @@ def test_orphan_block(self):
alice_xmss = get_alice_xmss()

with mock.patch('qrl.core.misc.ntp.getTime') as time_mock:
time_mock.return_value = 1519601174 # Very high to get an easy difficulty
time_mock.return_value = 1521889325 # Very high to get an easy difficulty
block_1 = Block.create(block_number=1,
prevblock_headerhash=genesis_block.headerhash,
transactions=[],
miner_address=alice_xmss.address)
block_1.set_mining_nonce(71)
block_1.set_mining_nonce(78)
# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
# while not PoWValidator().validate_mining_nonce(state, block_1.blockheader, False):
Expand All @@ -258,12 +274,12 @@ def test_orphan_block(self):
bob_xmss = get_bob_xmss()

with mock.patch('qrl.core.misc.ntp.getTime') as time_mock:
time_mock.return_value = 1519601174 + devconfig.minimum_minting_delay * 2
time_mock.return_value = 1521889326 + devconfig.minimum_minting_delay * 2
block = Block.create(block_number=1,
prevblock_headerhash=genesis_block.headerhash,
transactions=[],
miner_address=bob_xmss.address)
block.set_mining_nonce(91)
block.set_mining_nonce(221)

# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
Expand All @@ -272,12 +288,12 @@ def test_orphan_block(self):
# print(block.mining_nonce)

with mock.patch('qrl.core.misc.ntp.getTime') as time_mock:
time_mock.return_value = 1519601174 + devconfig.minimum_minting_delay * 3
time_mock.return_value = 1521889327 + devconfig.minimum_minting_delay * 3
block_2 = Block.create(block_number=2,
prevblock_headerhash=block.headerhash,
transactions=[],
miner_address=bob_xmss.address)
block_2.set_mining_nonce(5)
block_2.set_mining_nonce(1)

# Uncomment only to determine the correct mining_nonce of above blocks
# from qrl.core.PoWValidator import PoWValidator
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_State.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from qrl.core.Block import Block
from qrl.core.BlockMetadata import BlockMetadata
from qrl.generated import qrl_pb2
from tests.misc.helper import set_data_dir, get_alice_xmss, get_bob_xmss, get_token_transaction
from tests.misc.helper import set_data_dir, get_alice_xmss, get_bob_xmss, get_token_transaction, \
set_default_balance_size

logger.initialize_default()

Expand Down Expand Up @@ -198,6 +199,7 @@ def test_address_state(self):
with self.assertRaises(Exception):
state.set_addresses_state({"state": 'test'}, 0)

@set_default_balance_size()
def test_basic_state_funcs(self):
with set_data_dir('no_data'):
with State() as state:
Expand Down
10 changes: 10 additions & 0 deletions tests/misc/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
from tests.misc.random_number_generator import RNG


@contextlib.contextmanager
def set_default_balance_size(new_value=100 * int(config.dev.shor_per_quanta)):
old_value = config.dev.block_timeseries_size
try:
config.dev.default_account_balance = new_value
yield
finally:
config.dev.default_account_balance = old_value


@contextlib.contextmanager
def set_wallet_dir(wallet_name):
dst_dir = tempfile.mkdtemp()
Expand Down
8 changes: 6 additions & 2 deletions tests/services/test_PublicAPIService_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from qrl.crypto.misc import sha256
from qrl.generated import qrl_pb2
from qrl.services.PublicAPIService import PublicAPIService
from tests.misc.helper import get_alice_xmss, set_data_dir, set_wallet_dir, get_bob_xmss
from tests.misc.helper import get_alice_xmss, set_data_dir, set_wallet_dir, get_bob_xmss, set_default_balance_size

logger.initialize_default()

Expand All @@ -25,6 +25,7 @@ class TestPublicAPI(TestCase):
def __init__(self, *args, **kwargs):
super(TestPublicAPI, self).__init__(*args, **kwargs)

@set_default_balance_size()
def test_transferCoins_get_unsigned(self):
with set_data_dir('no_data'):
with State() as db_state:
Expand Down Expand Up @@ -59,7 +60,8 @@ def test_transferCoins_get_unsigned(self):

self.assertIsNotNone(response)
self.assertIsNotNone(response.extended_transaction_unsigned)
self.assertEqual('transfer', response.extended_transaction_unsigned.tx.WhichOneof('transactionType'))
self.assertEqual('transfer',
response.extended_transaction_unsigned.tx.WhichOneof('transactionType'))

self.assertEqual(12, response.extended_transaction_unsigned.tx.fee)
self.assertEqual(alice.pk, response.extended_transaction_unsigned.tx.public_key)
Expand All @@ -71,6 +73,7 @@ def test_transferCoins_get_unsigned(self):
self.assertEqual(bob.address, response.extended_transaction_unsigned.tx.transfer.addrs_to[0])
self.assertEqual(101, response.extended_transaction_unsigned.tx.transfer.amounts[0])

@set_default_balance_size()
def test_transferCoins_push_unsigned(self):
with set_data_dir('no_data'):
with State() as db_state:
Expand Down Expand Up @@ -125,6 +128,7 @@ def test_transferCoins_push_unsigned(self):
self.assertEqual(qrl_pb2.PushTransactionResp.VALIDATION_FAILED,
resp_push.error_code)

@set_default_balance_size()
def test_transferCoins_sign(self):
with set_data_dir('no_data'):
with State() as db_state:
Expand Down

0 comments on commit c9ce68d

Please sign in to comment.