fix the scenario with change

This commit is contained in:
Yostra 2020-04-16 02:08:29 -07:00
parent adda69eff7
commit f47aac8b95
2 changed files with 13 additions and 8 deletions

View File

@ -410,7 +410,9 @@ class CCWallet:
selected_coins: Optional[List[Coin]] = await self.select_coins(amount)
if selected_coins is None:
return None
change = sum([x.amount for x in selected_coins]) - amount
total_amount = sum([x.amount for x in selected_coins])
change = total_amount - amount
# first coin becomes the auditor special case
auditor = selected_coins.pop()
@ -430,7 +432,7 @@ class CCWallet:
auditor.parent_coin_info,
inner_puzzle.get_hash(),
auditor.amount,
amount + change,
total_amount,
)
]
for coin in selected_coins:
@ -486,12 +488,15 @@ class CCWallet:
),
)
list_of_solutions.append(main_coin_solution)
# main = SpendBundle([main_coin_solution], ZERO96)
ephemeral_coin_solution = create_spend_for_ephemeral(auditor, auditor, amount)
ephemeral_coin_solution = create_spend_for_ephemeral(auditor, auditor, total_amount)
list_of_solutions.append(ephemeral_coin_solution)
# eph = SpendBundle([ephemeral_coin_solution], ZERO96)
auditor_coin_colution= create_spend_for_auditor(auditor, auditor)
list_of_solutions.append(auditor_coin_colution)
# aud = SpendBundle([auditor_coin_colution], ZERO96)
# loop through remaining spends, treating them as aggregatees
for coin in selected_coins:

View File

@ -138,7 +138,7 @@ class TestWalletSimulator:
assert cc_wallet.cc_info.my_core == cc_wallet_2.cc_info.my_core
cc_2_hash = await cc_wallet_2.get_new_inner_hash()
await cc_wallet.cc_spend(uint64(100), cc_2_hash)
await cc_wallet.cc_spend(uint64(60), cc_2_hash)
for i in range(1, num_blocks):
await full_node_1.farm_new_block(FarmNewBlockProtocol(ph))
@ -147,14 +147,14 @@ class TestWalletSimulator:
confirmed_balance = await cc_wallet.get_confirmed_balance()
unconfirmed_balance = await cc_wallet.get_unconfirmed_balance()
assert confirmed_balance == 0
assert unconfirmed_balance == 0
assert confirmed_balance == 40
assert unconfirmed_balance == 40
confirmed_balance = await cc_wallet_2.get_confirmed_balance()
unconfirmed_balance = await cc_wallet_2.get_unconfirmed_balance()
assert confirmed_balance == 100
assert unconfirmed_balance == 100
assert confirmed_balance == 60
assert unconfirmed_balance == 60
"""
@pytest.mark.asyncio
async def test_generate_zero_val(self, two_wallet_nodes):