Skip to content

Commit

Permalink
Add test for raw transaction flow (#17)
Browse files Browse the repository at this point in the history
* Add test for raw* transaction flow

* When any asset fees is enabled, use transaction asset for fee asset even when options parameter is not provided
  • Loading branch information
JBetz authored Apr 22, 2024
1 parent 44b2bf0 commit d3911fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
bool lockUnspents = false;
UniValue subtractFeeFromOutputs;
std::set<int> setSubtractFeeFromOutputs;
if (g_con_any_asset_fees && !tx.vout.empty()) {
coinControl.m_fee_asset = tx.vout[0].nAsset.GetAsset();
}

if (!options.isNull()) {
if (options.type() == UniValue::VBOOL) {
Expand Down Expand Up @@ -516,8 +519,6 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown label and invalid asset hex for fee: %s", feeAsset.GetHex()));
}
coinControl.m_fee_asset = feeAsset;
} else {
coinControl.m_fee_asset = tx.vout[0].nAsset.GetAsset();
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/functional/feature_any_asset_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ def transfer_asset_amount_including_fee(self):
node1_new_balance = self.nodes[1].getbalances()["mine"]
assert len(node1_new_balance["trusted"]) == 0

def raw_transfer_asset_to_node1(self):
node0 = self.nodes[0]
node1 = self.nodes[1]

node1_balance = node1.getbalances()['mine']

raw_tx = node0.createrawtransaction(outputs=[{self.node1_address: 1.0, 'asset': self.asset }])
funded_tx = node0.fundrawtransaction(raw_tx)['hex']
assert node0.decoderawtransaction(funded_tx)['fee'] == { self.asset: Decimal('0.00049820')}
blinded_tx = node0.blindrawtransaction(funded_tx)
signed_tx = node0.signrawtransactionwithwallet(blinded_tx)['hex']
sent_tx = node0.sendrawtransaction(signed_tx)
tx = node0.gettransaction(sent_tx)
assert tx['fee'] == { self.asset: Decimal('-0.00049820') }

self.generatetoaddress(node0, 1, self.node1_address)
self.sync_all()
node1_new_balance = node1.getbalances()['mine']
assert_equal(node1_new_balance['trusted'][self.asset], Decimal('1'))

def run_test(self):
self.init()

Expand All @@ -178,5 +198,7 @@ def run_test(self):

self.transfer_asset_amount_including_fee()

self.raw_transfer_asset_to_node1()

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

0 comments on commit d3911fd

Please sign in to comment.