Merge #828: Add test to test unconfirmed asset balances

521e357f9 Add test to test unconfirmed asset balances (Steven Roose)

Pull request description:

  Addresses https://github.com/ElementsProject/elements/issues/827.

Tree-SHA512: 00f75d5b43b2f676b83e2929eb9b213e48ccb65f7c421f66475bf90d56a4607aa67f1f9c3edc78ced01a694c9f5e4fb3aba7a8110e15cef370fd8707958a62c5
This commit is contained in:
Steven Roose 2020-03-16 15:51:43 +00:00
commit bef78a0447
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87

View file

@ -138,5 +138,37 @@ class WalletTest(BitcoinTestFramework):
# getbalance with minconf=2 will show the new balance.
assert_equal(self.nodes[1].getbalance(minconf=2)['bitcoin'], Decimal('0'))
# Balances of assets
for blind in [True, False]:
self.log.info("Testing {} issued asset balances".format("blinded" if blind else "unblinded"))
asset = self.nodes[0].issueasset(100, 0, blind)["asset"]
# Balances with unconfirmed issuance.
# They are indicated as confirmed because they are sent by the RPC and thus "trusted".
walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo["balance"].get(asset, 0), Decimal('100'))
assert_equal(walletinfo["unconfirmed_balance"].get(asset, 0), Decimal('0'))
# Balances with confirmed issuance.
self.nodes[0].generatetoaddress(1, RANDOM_COINBASE_ADDRESS)
walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo["balance"].get(asset, 0), Decimal('100'))
assert_equal(walletinfo["unconfirmed_balance"].get(asset, 0), Decimal('0'))
# Sending coins to other wallet.
self.nodes[0].sendtoaddress(address=self.nodes[1].getnewaddress(), amount="50", assetlabel=asset)
self.sync_all()
# Balances with unconfirmed receive
walletinfo = self.nodes[1].getwalletinfo()
assert_equal(walletinfo["balance"].get(asset, 0), Decimal('0'))
assert_equal(walletinfo["unconfirmed_balance"].get(asset, 0), Decimal('50'))
# Balances with confirmed receive
self.nodes[1].generatetoaddress(1, RANDOM_COINBASE_ADDRESS)
walletinfo = self.nodes[1].getwalletinfo()
assert_equal(walletinfo["balance"].get(asset, 0), Decimal('50'))
assert_equal(walletinfo["unconfirmed_balance"].get(asset, 0), Decimal('0'))
if __name__ == '__main__':
WalletTest().main()