Skip to content

Commit

Permalink
Merge pull request bitcoin#1156 from Bushstar/experimental-0.20
Browse files Browse the repository at this point in the history
Check Omni token balance is consistent after reorg
  • Loading branch information
Bushstar authored Aug 11, 2020
2 parents d63fb57 + c9e4874 commit b73c297
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
69 changes: 69 additions & 0 deletions test/functional/omni_reorg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/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 token balance after reorg."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, connect_nodes)

class OmniReorgTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True

def run_test(self):
self.log.info("check token balance after reorg")

# Get address for mining and token issuance
token_address = self.nodes[0].getnewaddress()
self.nodes[0].generatetoaddress(101, token_address)

# Create test token
creation_tx = self.nodes[0].omni_sendissuancefixed(token_address, 2, 2, 0, "", "", "TESTTOKEN", "", "", "100000")
self.nodes[0].generatetoaddress(1, token_address)
self.sync_all()

# Send token
property_id = self.nodes[0].omni_gettransaction(creation_tx)["propertyid"]
destination = self.nodes[1].getnewaddress()
self.nodes[0].omni_send(token_address, destination, property_id, "1")

# Stop second node
self.stop_node(1)

# Mine block at height 103 on first node
self.nodes[0].generatetoaddress(1, token_address)

# Stop first node and start second node
self.stop_node(0)
self.start_node(1)

# Mine block at height 103 on second node
self.nodes[1].generatetoaddress(1, destination)
self.start_node(0)

# Reconnect nodes and make sure they're fully sycnced
connect_nodes(self.nodes[0], 1)

# Make sure nodes are at the expected height and hashes differ
assert_equal(self.nodes[0].getblockcount(), 103)
assert_equal(self.nodes[1].getblockcount(), 103)
if self.nodes[0].getblockhash(103) == self.nodes[1].getblockhash(103):
raise AssertionError("reorg test expects block hash to differ between nodes at the same height")

self.nodes[0].generatetoaddress(1, token_address)
self.sync_all()

# Make sure nodes are at the expected height and hashes now the same
assert_equal(self.nodes[0].getblockcount(), 104)
assert_equal(self.nodes[1].getblockcount(), 104)
assert_equal(self.nodes[0].getblockhash(104), self.nodes[1].getblockhash(104))

# We now expect the token balances to be the same in both nodes after the reorg
assert_equal(str(self.nodes[0].omni_getbalance(destination, property_id)["balance"]), "1.00000000")
assert_equal(str(self.nodes[1].omni_getbalance(destination, property_id)["balance"]), "1.00000000")

if __name__ == '__main__':
OmniReorgTest().main()

3 changes: 2 additions & 1 deletion test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
'feature_help.py',
'feature_shutdown.py',
'framework_test_script.py',
'omni_reorg.py',
# Don't append tests at the end to avoid merge conflicts
# Put them in a random line within the section that fits their approximate run-time
]
Expand Down Expand Up @@ -609,7 +610,7 @@ def was_successful(self):
def check_script_prefixes():
"""Check that test scripts start with one of the allowed name prefixes."""

good_prefixes_re = re.compile("^(example|feature|interface|mempool|mining|p2p|rpc|wallet|tool|framework_test)_")
good_prefixes_re = re.compile("^(example|feature|interface|mempool|mining|omni|p2p|rpc|wallet|tool|framework_test)_")
bad_script_names = [script for script in ALL_SCRIPTS if good_prefixes_re.match(script) is None]

if bad_script_names:
Expand Down

0 comments on commit b73c297

Please sign in to comment.