11#!/usr/bin/env python3
2- # copyright (c) 2018 the navcoin core developers
3- # distributed under the mit software license, see the accompanying
4- # file copying or http://www.opensource.org/licenses/mit-license.php.
2+ # Copyright (c) 2018 The Navcoin Core developers
3+ # Distributed under the MIT software license, see the accompanying
4+ # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
56import decimal
67from test_framework .test_framework import NavCoinTestFramework
7- from test_framework .util import *
8+ from test_framework .staticr_util import *
9+
810class ColdStakingSpending (NavCoinTestFramework ):
911 """Tests spending and staking to/from a spending wallet."""
1012 # set up num of nodes
@@ -20,23 +22,12 @@ def setup_network(self, split=False):
2022 def run_test (self ):
2123 self .nodes [0 ].staking (False )
2224
23- """generate first 300 blocks to lock in softfork, verify coldstaking is active"""
24-
25- slow_gen (self .nodes [0 ], 100 )
26- # verify that cold staking has started
27- assert (self .nodes [0 ].getblockchaininfo ()["bip9_softforks" ]["coldstaking" ]["status" ] == "started" )
28- slow_gen (self .nodes [0 ], 100 )
29- # verify that cold staking is locked_in
30- assert (self .nodes [0 ].getblockchaininfo ()["bip9_softforks" ]["coldstaking" ]["status" ] == "locked_in" )
31- slow_gen (self .nodes [0 ], 100 )
32- # verify that cold staking is active
33- assert (self .nodes [0 ].getblockchaininfo ()["bip9_softforks" ]["coldstaking" ]["status" ] == "active" )
34-
35- """set up transaction-related constants and addresses"""
25+ # Make it to the static rewards fork!
26+ activate_staticr (self .nodes [0 ])
3627
3728 # declare transaction-related constants
3829 SENDING_FEE = 0.00010000
39- MIN_COLDSTAKING_SENDING_FEE = 0.0028850
30+ MIN_COLDSTAKING_SENDING_FEE = 0.0033947
4031 BLOCK_REWARD = 50
4132 # generate address owned by the wallet
4233 spending_address_public_key = self .nodes [0 ].getnewaddress ()
@@ -55,7 +46,7 @@ def run_test(self):
5546 balance_before_send = self .nodes [0 ].getbalance ()
5647 staking_weight_before_send = self .nodes [0 ].getstakinginfo ()["weight" ]
5748 # check wallet staking weight roughly equals wallet balance
58- assert (round (staking_weight_before_send / 100000000.0 , - 5 ) == round (balance_before_send , - 5 ))
49+ assert_equal (round (staking_weight_before_send / 100000000.0 , - 5 ), round (balance_before_send , - 5 ))
5950
6051 """send navcoin to our coldstaking address, grab balance & staking weight"""
6152
@@ -70,22 +61,22 @@ def run_test(self):
7061 assert (len (listunspent_txs ) > 0 )
7162 # asserts that the number of utxo recieved is only 1:
7263 assert (len (listunspent_txs ) == 1 )
73- # asserts if amount recieved is what it should be; ~59812449.99711600 NAV
74- assert (listunspent_txs [0 ]["amount" ] <= Decimal ('59812449.99711600 ' ))
64+ # asserts if amount recieved is what it should be; ~59814699.99660530 NAV
65+ assert_equal (listunspent_txs [0 ]["amount" ], Decimal ('59814699.99660530 ' ))
7566 # grabs updated wallet balance and staking weight
7667 balance_post_send_one = self .nodes [0 ].getbalance ()
7768 staking_weight_post_send = self .nodes [0 ].getstakinginfo ()["weight" ]
7869
7970 """check balance decreased by just the fees"""
80-
71+
8172 # difference between balance after sending and previous balance is the same when block reward is removed
82- # values are converted to string and "00" is added to right of == operand because values must have equal num of
73+ # values are converted to string and "00" is added to right of == operand because values must have equal num of
8374 # decimals
8475 assert (str (balance_post_send_one - BLOCK_REWARD ) <= (str (float (balance_before_send ) - MIN_COLDSTAKING_SENDING_FEE ) + "00" ))
85-
76+
8677 """check staking weight now == 0 (we don't hold the staking key)"""
87-
88- # sent ~all funds to coldstaking address where we do not own the staking key hence our
78+
79+ # sent ~all funds to coldstaking address where we do not own the staking key hence our
8980 # staking weight will be 0 as our recieved BLOCK_REWARD navcoin isn't mature enough to count towards
9081 # our staking weight
9182 assert ((staking_weight_post_send / 100000000.0 ) - BLOCK_REWARD <= 1 )
@@ -98,10 +89,10 @@ def run_test(self):
9889 to_be_sent = round (float (balance_post_send_one ) * float (0.5 ) - SENDING_FEE , 8 )
9990 self .nodes [0 ].sendtoaddress (address_Y_public_key , (to_be_sent ))
10091 # put transaction in new block & update blockchain
101- slow_gen (self .nodes [0 ], 1 )
92+ slow_gen (self .nodes [0 ], 1 )
10293 # wallet balance after sending
10394 balance_post_send_two = self .nodes [0 ].getbalance ()
104- #check balance will not be less than ~half our balance before sending - this
95+ #check balance will not be less than ~half our balance before sending - this
10596 # will occurs if we send to an address we do not own
10697 assert (balance_post_send_two - BLOCK_REWARD >= (float (balance_post_send_one ) * float (0.5 ) - SENDING_FEE ))
10798
@@ -111,7 +102,7 @@ def run_test(self):
111102 self .nodes [0 ].sendtoaddress (coldstaking_address_spending , round (float (balance_post_send_two ) - SENDING_FEE , 8 ))
112103 slow_gen (self .nodes [0 ], 1 )
113104 listunspent_txs = [n for n in self .nodes [0 ].listunspent () if n ["address" ] == coldstaking_address_spending ]
114- # send funds to a third party address using a signed raw transaction
105+ # send funds to a third party address using a signed raw transaction
115106 # get unspent tx inputs
116107 self .send_raw_transaction (decoded_raw_transaction = listunspent_txs [0 ], \
117108 to_address = address_Y_public_key , \
@@ -120,7 +111,7 @@ def run_test(self):
120111 )
121112 # put transaction in new block & update blockchain
122113 slow_gen (self .nodes [0 ], 1 )
123- # get new balance
114+ # get new balance
124115 balance_post_send_three = self .nodes [0 ].getbalance ()
125116 # we expect our balance to be zero
126117 assert (balance_post_send_three - (BLOCK_REWARD * 2 ) == 0 )
@@ -138,13 +129,13 @@ def run_test(self):
138129 self .nodes [0 ].sendtoaddress (spending_address_public_key , float (current_balance ) * 0.5 - 1 )
139130 slow_gen (self .nodes [0 ], 1 )
140131 # our balance should be the same minus fees, as we own the address we sent to
141- assert (self .nodes [0 ].getbalance () >= current_balance - 1 + BLOCK_REWARD )
132+ assert (self .nodes [0 ].getbalance () >= current_balance - 1 + BLOCK_REWARD )
142133 send_worked = True
143134 except Exception as e :
144135 print (e )
145136
146137 assert (send_worked == True )
147-
138+
148139 slow_gen (self .nodes [0 ], 1 )
149140
150141 # send to our staking address
@@ -155,11 +146,11 @@ def run_test(self):
155146 self .nodes [0 ].sendtoaddress (staking_address_public_key , float (self .nodes [0 ].getbalance ()) * 0.5 - 1 )
156147 slow_gen (self .nodes [0 ], 1 )
157148 # our balance should be half minus fees, as we dont own the address we sent to
158- assert (self .nodes [0 ].getbalance () - BLOCK_REWARD <= float (current_balance ) * 0.5 - 1 + 2 )
149+ assert (self .nodes [0 ].getbalance () - BLOCK_REWARD <= float (current_balance ) * 0.5 - 1 + 2 )
159150 send_worked = True
160151 except Exception as e :
161152 print (e )
162-
153+
163154 assert (send_worked == True )
164155
165156 def send_raw_transaction (self , decoded_raw_transaction , to_address , change_address , amount ):
@@ -172,7 +163,7 @@ def send_raw_transaction(self, decoded_raw_transaction, to_address, change_addre
172163 assert (signresult ["complete" ])
173164 # send raw transaction
174165 return self .nodes [0 ].sendrawtransaction (signresult ['hex' ])
175-
166+
176167
177168if __name__ == '__main__' :
178169 ColdStakingSpending ().main ()
0 commit comments