Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions node-gui/backend/src/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@ impl Backend {
},
)
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;
.map_err(|e| BackendError::WalletError(e.to_string()))?
.tx;

Ok(TransactionInfo {
wallet_id,
Expand Down Expand Up @@ -872,7 +873,8 @@ impl Backend {
},
)
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;
.map_err(|e| BackendError::WalletError(e.to_string()))?
.tx;

Ok(TransactionInfo {
wallet_id,
Expand Down Expand Up @@ -904,7 +906,8 @@ impl Backend {
},
)
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;
.map_err(|e| BackendError::WalletError(e.to_string()))?
.tx;

Ok(TransactionInfo {
wallet_id,
Expand Down Expand Up @@ -940,7 +943,7 @@ impl Backend {

Ok(TransactionInfo {
wallet_id,
tx: SignedTransactionWrapper::new(tx),
tx: SignedTransactionWrapper::new(tx.tx),
})
}

Expand Down Expand Up @@ -975,7 +978,8 @@ impl Backend {
},
)
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;
.map_err(|e| BackendError::WalletError(e.to_string()))?
.tx;

Ok(TransactionInfo {
wallet_id,
Expand Down Expand Up @@ -1018,7 +1022,8 @@ impl Backend {
},
)
.await
.map_err(|e| BackendError::WalletError(e.to_string()))?;
.map_err(|e| BackendError::WalletError(e.to_string()))?
.tx;

Ok(TransactionInfo {
wallet_id,
Expand Down
5 changes: 3 additions & 2 deletions test/functional/test_framework/wallet_cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ async def create_from_cold_address(self, address: str, amount: int, selected_utx
change_address_str = '' if change_address is None else f"--change {change_address}"
return await self._write_command(f"transaction-create-from-cold-input {address} {amount} {str(selected_utxo)} {change_address_str}\n")

async def sweep_addresses(self, destination_address: str, from_addresses: List[str] = []) -> str:
return await self._write_command(f"address-sweep-spendable {destination_address} {' '.join(from_addresses)}\n")
async def sweep_addresses(self, destination_address: str, from_addresses: List[str] = [], all_addresses: bool = False) -> str:
all_addresses_str = "--all" if all_addresses else ""
return await self._write_command(f"address-sweep-spendable {destination_address} {' '.join(from_addresses)} {all_addresses_str}\n")

async def sweep_delegation(self, destination_address: str, delegation_id: str) -> str:
return await self._write_command(f"staking-sweep-delegation {destination_address} {delegation_id}\n")
Expand Down
28 changes: 19 additions & 9 deletions test/functional/test_framework/wallet_rpc_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import base64
from operator import itemgetter

from typing import Optional, List, Union
from typing import Optional, List, Union, TypedDict

from test_framework.util import assert_in, rpc_port
from test_framework.wallet_controller_common import PartialSigInfo, TokenTxOutput, UtxoOutpoint, WalletCliControllerBase
Expand All @@ -46,6 +46,16 @@ def to_json(self):
else:
return {'Transfer': [ { 'Coin': {"atoms": str(self.atoms)} }, f"HexifiedDestination{{0x02{self.pub_key_hex}}}" ]}

@dataclass
class Balances:
coins: str
tokens: dict

class NewTxResult(TypedDict):
tx_id: str
tx: str
fees: Balances
broadcasted: bool

@dataclass
class PoolData:
Expand Down Expand Up @@ -295,30 +305,30 @@ async def issue_new_token(self,
else:
return None, None, result['error']

async def mint_tokens(self, token_id: str, address: str, amount: int) -> str:
async def mint_tokens(self, token_id: str, address: str, amount: int) -> NewTxResult:
return self._write_command("token_mint", [self.account, token_id, address, {'decimal': str(amount)}, {'in_top_x_mb': 5}])['result']

# Note: unlike mint_tokens, this function behaves identically both for wallet_cli_controller and wallet_rpc_controller.
async def mint_tokens_or_fail(self, token_id: str, address: str, amount: int):
# self.mint_tokens already fails on error
await self.mint_tokens(token_id, address, amount)

async def unmint_tokens(self, token_id: str, amount: int) -> str:
async def unmint_tokens(self, token_id: str, amount: int) -> NewTxResult:
return self._write_command("token_unmint", [self.account, token_id, {'decimal': str(amount)}, {'in_top_x_mb': 5}])['result']

async def lock_token_supply(self, token_id: str) -> str:
async def lock_token_supply(self, token_id: str) -> NewTxResult:
return self._write_command("token_lock_supply", [self.account, token_id, {'in_top_x_mb': 5}])['result']

async def freeze_token(self, token_id: str, is_unfreezable: str) -> str:
async def freeze_token(self, token_id: str, is_unfreezable: str) -> NewTxResult:
return self._write_command("token_freeze", [self.account, token_id, is_unfreezable, {'in_top_x_mb': 5}])['result']

async def unfreeze_token(self, token_id: str) -> str:
async def unfreeze_token(self, token_id: str) -> NewTxResult:
return self._write_command("token_unfreeze", [self.account, token_id, {'in_top_x_mb': 5}])['result']

async def change_token_authority(self, token_id: str, new_authority: str) -> str:
async def change_token_authority(self, token_id: str, new_authority: str) -> NewTxResult:
return self._write_command("token_change_authority", [self.account, token_id, new_authority, {'in_top_x_mb': 5}])['result']

async def change_token_metadata_uri(self, token_id: str, new_metadata_uri: str) -> str:
async def change_token_metadata_uri(self, token_id: str, new_metadata_uri: str) -> NewTxResult:
return self._write_command("token_change_metadata_uri", [self.account, token_id, new_metadata_uri, {'in_top_x_mb': 5}])['result']

async def issue_new_nft(self,
Expand Down Expand Up @@ -571,7 +581,7 @@ async def create_htlc_transaction(self,
secret_hash: str,
spend_address: str,
refund_address: str,
refund_lock_for_blocks: int) -> str:
refund_lock_for_blocks: int) -> NewTxResult:
timelock = { "type": "ForBlockCount", "content": refund_lock_for_blocks }
htlc = { "secret_hash": secret_hash, "spend_address": spend_address, "refund_address": refund_address, "refund_timelock": timelock }
object = [self.account, {'decimal': str(amount)}, token_id, htlc, {'in_top_x_mb': 5}]
Expand Down
28 changes: 14 additions & 14 deletions test/functional/wallet_htlc_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def async_test(self):
assert_equal(await wallet.get_best_block(), block_id)

balance = await wallet.get_balance()
assert_in(f"Coins amount: 151", balance)
assert_in("Coins amount: 151", balance)
assert_not_in("Tokens", balance)

# issue a valid token
Expand All @@ -142,7 +142,7 @@ async def async_test(self):
self.generate_block()
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 50", balance)
assert_in("Coins amount: 50", balance)
assert_not_in("Tokens", balance)

amount_to_mint = random.randint(1, 10000)
Expand All @@ -153,7 +153,7 @@ async def async_test(self):
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
print(balance)
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_in(f"Token: {token_id} amount: {amount_to_mint}", balance)

########################################################################################
Expand All @@ -165,7 +165,7 @@ async def async_test(self):

alice_amount_to_swap = amount_to_mint
alice_htlc_tx = await wallet.create_htlc_transaction(alice_amount_to_swap, token_id, alice_secret_hash, bob_address, refund_address, 6)
alice_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + alice_htlc_tx))
alice_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + alice_htlc_tx['tx']))
alice_htlc_outputs = alice_signed_tx_obj['transaction']['outputs']
alice_htlc_change_dest = alice_htlc_outputs[1]['Transfer'][1]
alice_htlc_tx_id = hash_object(base_tx_obj, alice_signed_tx_obj['transaction'])
Expand Down Expand Up @@ -200,7 +200,7 @@ async def async_test(self):

bob_amount_to_swap = 150
bob_htlc_tx = await wallet.create_htlc_transaction(bob_amount_to_swap, None, alice_secret_hash, alice_address, refund_address, 6)
bob_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + bob_htlc_tx))
bob_signed_tx_obj = signed_tx_obj.decode(ScaleBytes("0x" + bob_htlc_tx['tx']))
bob_htlc_outputs = bob_signed_tx_obj['transaction']['outputs']
bob_htlc_change_dest = bob_htlc_outputs[1]['Transfer'][1]
bob_htlc_tx_id = hash_object(base_tx_obj, bob_signed_tx_obj['transaction'])
Expand All @@ -227,7 +227,7 @@ async def async_test(self):
alice_refund_ptx = output.split('\n')[2]

# Alice's htlc tx can now be broadcasted
output = await wallet.submit_transaction(alice_htlc_tx)
output = await wallet.submit_transaction(alice_htlc_tx['tx'])
assert_in("The transaction was submitted successfully", output)

# Alice signs Bob's refund
Expand All @@ -238,22 +238,22 @@ async def async_test(self):
bob_refund_ptx = output.split('\n')[2]

# Bob's htlc tx can now be broadcasted
output = await wallet.submit_transaction(bob_htlc_tx)
output = await wallet.submit_transaction(bob_htlc_tx['tx'])
assert_in("The transaction was submitted successfully", output)

self.generate_block()
assert_in("Success", await wallet.sync())

# Check Alice's balance
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

# Check Bob's balance now
await self.switch_to_wallet(wallet, 'bob_wallet')
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

########################################################################################
Expand All @@ -270,7 +270,7 @@ async def async_test(self):
assert_in("Spending at height 9, locked until height 10", output)

balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

# Bob signs and spends the refund
Expand All @@ -286,7 +286,7 @@ async def async_test(self):
assert_in("Spending at height 9, locked until height 10", output)

balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

########################################################################################
Expand All @@ -304,7 +304,7 @@ async def async_test(self):
self.generate_block()
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

self.generate_block()
Expand All @@ -316,13 +316,13 @@ async def async_test(self):
await self.switch_to_wallet(wallet, 'alice_wallet')
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_in(f"Token: {token_id} amount: {alice_amount_to_swap}", balance)

await self.switch_to_wallet(wallet, 'bob_wallet')
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 150", balance)
assert_in(f"Coins amount: {bob_amount_to_swap}", balance)
assert_not_in("Tokens", balance)


Expand Down
18 changes: 9 additions & 9 deletions test/functional/wallet_htlc_spend.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def async_test(self):
assert_equal(await wallet.get_best_block(), block_id)

balance = await wallet.get_balance()
assert_in(f"Coins amount: 151", balance)
assert_in("Coins amount: 151", balance)
assert_not_in("Tokens", balance)

# issue a valid token
Expand All @@ -142,7 +142,7 @@ async def async_test(self):
self.generate_block()
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 50", balance)
assert_in("Coins amount: 50", balance)
assert_not_in("Tokens", balance)

amount_to_mint = random.randint(1, 10000)
Expand All @@ -152,7 +152,7 @@ async def async_test(self):
self.generate_block()
assert_in("Success", await wallet.sync())
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_in(f"Token: {token_id} amount: {amount_to_mint}", balance)

########################################################################################
Expand All @@ -164,7 +164,7 @@ async def async_test(self):
alice_amount_to_swap = amount_to_mint
refund_address = await wallet.add_standalone_multisig_address(2, [alice_pub_key, bob_pub_key], None)
alice_htlc_tx = await wallet.create_htlc_transaction(alice_amount_to_swap, token_id, alice_secret_hash, bob_address, refund_address, 2)
output = await wallet.submit_transaction(alice_htlc_tx)
output = await wallet.submit_transaction(alice_htlc_tx['tx'])
alice_htlc_tx_id = output.split('\n')[2]
self.generate_block()
assert_in("Success", await wallet.sync())
Expand All @@ -175,7 +175,7 @@ async def async_test(self):

bob_amount_to_swap = 150
bob_htlc_tx = await wallet.create_htlc_transaction(bob_amount_to_swap, None, alice_secret_hash, alice_address, refund_address, 2)
output = await wallet.submit_transaction(bob_htlc_tx)
output = await wallet.submit_transaction(bob_htlc_tx['tx'])
bob_htlc_tx_id = output.split('\n')[2]
self.generate_block()
assert_in("Success", await wallet.sync())
Expand All @@ -189,7 +189,7 @@ async def async_test(self):
random_secret_hex = random_secret.hex()

balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

# Alice can't spend Alice's htlc without a secret
Expand All @@ -214,7 +214,7 @@ async def async_test(self):
assert_in("Success", await wallet.sync())

balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_not_in("Tokens", balance)

# Bob can't spend it without secret
Expand Down Expand Up @@ -264,7 +264,7 @@ async def async_test(self):
assert_in("Success", await wallet.sync())

balance = await wallet.get_balance()
assert_in(f"Coins amount: 150", balance)
assert_in(f"Coins amount: {bob_amount_to_swap}", balance)
assert_not_in("Tokens", balance)

########################################################################################
Expand All @@ -283,7 +283,7 @@ async def async_test(self):
assert_in("Success", await wallet.sync())

balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
assert_in(f"Token: {token_id} amount: {alice_amount_to_swap}", balance)


Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_multisig_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def async_test(self):
await wallet.open_wallet('wallet0')
output = await wallet.send_to_address(multisig_address, 1)
assert_in("The transaction was submitted successfully", output)
multisig_tx_id = output.splitlines()[1]
multisig_tx_id = output.splitlines()[-1]
self.generate_block()
assert not node.mempool_contains_tx(multisig_tx_id)
assert_not_in("No transaction found", await wallet.get_raw_signed_transaction(multisig_tx_id))
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_sweep_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ def make_locked_output(pub_key_bytes):
acc1_address = await wallet.new_address()

await wallet.select_account(0)
assert_in("The transaction was submitted successfully", await wallet.sweep_addresses(acc1_address, addresses))
assert_in("The transaction was submitted successfully", await wallet.sweep_addresses(acc1_address, all_addresses=True))

block_id = self.generate_block()
assert_in("Success", await wallet.sync())

# check we sent all our coins
balance = await wallet.get_balance()
assert_in(f"Coins amount: 0", balance)
assert_in("Coins amount: 0", balance)
# check we still have the locked balance

balance = await wallet.get_balance('locked')
Expand Down
Loading