| 120 | |
| 121 | |
| 122 | def check_coin_moves(n, account_id, expected_moves, chainparams): |
| 123 | moves = n.rpc.call('listcoinmoves_plugin')['coin_moves'] |
| 124 | # moves can lag; wait for a few seconds if we don't have correct number. |
| 125 | # then move on: we'll get details below. |
| 126 | expected_count = 0 |
| 127 | for m in enumerate(expected_moves): |
| 128 | if isinstance(m, list): |
| 129 | expected_count += len(m) |
| 130 | else: |
| 131 | expected_count += 1 |
| 132 | |
| 133 | if len(moves) != expected_count: |
| 134 | time.sleep(5) |
| 135 | moves = n.rpc.call('listcoinmoves_plugin')['coin_moves'] |
| 136 | |
| 137 | node_id = n.info['id'] |
| 138 | acct_moves = [m for m in moves if m['account_id'] == account_id] |
| 139 | for mv in acct_moves: |
| 140 | print("{{'type': '{}', 'credit_msat': {}, 'debit_msat': {}, 'tags': '{}' , ['fees_msat'?: '{}']}}," |
| 141 | .format(mv['type'], |
| 142 | Millisatoshi(mv['credit_msat']).millisatoshis, |
| 143 | Millisatoshi(mv['debit_msat']).millisatoshis, |
| 144 | mv['tags'], |
| 145 | mv['fees_msat'] if 'fees_msat' in mv else '')) |
| 146 | assert mv['version'] == 2 |
| 147 | assert mv['node_id'] == node_id |
| 148 | assert mv['timestamp'] > 0 |
| 149 | assert mv['coin_type'] == chainparams['bip173_prefix'] |
| 150 | # chain moves should have blockheights |
| 151 | if mv['type'] == 'chain_mvt' and mv['account_id'] != 'external': |
| 152 | assert mv['blockheight'] is not None |
| 153 | |
| 154 | for num, m in enumerate(expected_moves): |
| 155 | # They can group things which are in any order. |
| 156 | if isinstance(m, list): |
| 157 | number_moves = len(m) |
| 158 | for acct_move in acct_moves[:number_moves]: |
| 159 | found = None |
| 160 | for i in range(len(m)): |
| 161 | if move_matches(m[i], acct_move): |
| 162 | found = i |
| 163 | break |
| 164 | if found is None: |
| 165 | raise ValueError("Unexpected move {} amongst {}".format(acct_move, m)) |
| 166 | del m[i] |
| 167 | acct_moves = acct_moves[number_moves:] |
| 168 | else: |
| 169 | if not move_matches(m, acct_moves[0]): |
| 170 | raise ValueError("Unexpected move {}: {} != {}".format(num, acct_moves[0], m)) |
| 171 | acct_moves = acct_moves[1:] |
| 172 | |
| 173 | assert acct_moves == [] |
| 174 | |
| 175 | |
| 176 | def account_balance(n, account_id): |