Skip to content

Commit

Permalink
Add DFI-to-DUSD withdrawal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Jun 23, 2022
1 parent e1ad2d9 commit 97762a6
Showing 1 changed file with 113 additions and 7 deletions.
120 changes: 113 additions & 7 deletions test/functional/feature_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def run_test(self):
# Test DFI-to-DUSD swap
self.dfi_to_dusd()

# Test DUSD withdrawals
self.check_withdrawals_dusd()

# Test refunding of unpaid DFI-to-DUSD contract
self.unpaid_contract_dusd()

Expand Down Expand Up @@ -1216,6 +1219,109 @@ def dfi_to_dusd(self):
result = self.nodes[0].getburninfo()
assert_equal(result['dfip2206f'], [f'2.00000000@{self.symbolDFI}'])

def check_withdrawals_dusd(self):

# Create addresses for futures
address = self.nodes[0].getnewaddress("", "legacy")

# Fund addresses
self.nodes[0].utxostoaccount({address: f'10@{self.symbolDFI}'})
self.nodes[0].generate(1)

# Test swap of DFI to DUSD
self.nodes[0].futureswap(address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')
self.nodes[0].futureswap(address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')
self.nodes[0].generate(1)

# Check withdrawal failures
assert_raises_rpc_error(-32600, 'amount 2.00000000 is less than 2.00000001', self.nodes[0].withdrawfutureswap, address, f'2.00000001@{self.symbolDFI}', self.symbolDUSD)

# Withdraw both contracts
self.nodes[0].withdrawfutureswap(address, f'2.00000000@{self.symbolDFI}', self.symbolDUSD)
self.nodes[0].generate(1)

# Check user pending swap is empty
result = self.nodes[0].getpendingdusdswaps(address)
assert_equal(result, {})

# Try and withdraw smallest amount now contract empty
assert_raises_rpc_error(-32600, 'amount 0.00000000 is less than 0.00000001', self.nodes[0].withdrawfutureswap, address, f'0.00000001@{self.symbolDFI}', self.symbolDUSD)

# Create new future swap
self.nodes[0].futureswap(address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')
self.nodes[0].generate(1)

# Withdraw frm GOOGL everything but one Sat
self.nodes[0].withdrawfutureswap(address, f'0.99999999@{self.symbolDFI}', self.symbolDUSD)
self.nodes[0].generate(1)

# Check user pending swap
result = self.nodes[0].getpendingdusdswaps(address)
assert_equal(result['owner'], address)
assert_equal(result['amount'], Decimal('0.00000001'))

# Move to swap height
next_futures_block = self.nodes[0].getblockcount() + (self.futures_interval_dusd - ((self.nodes[0].getblockcount() - self.start_block_dusd) % self.futures_interval_dusd))
self.nodes[0].generate(next_futures_block - self.nodes[0].getblockcount())

# Check result, should just be DFI
result = self.nodes[0].getaccount(address)
assert_equal(len(result), 1)

# Create two more test swaps
self.nodes[0].futureswap(address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')
self.nodes[0].futureswap(address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')
self.nodes[0].generate(1)

# Withdraw one contract plus 1 Sat of the second one
self.nodes[0].withdrawfutureswap(address, f'1.00000001@{self.symbolDFI}', self.symbolDUSD)
self.nodes[0].generate(1)

# Check user pending swap
result = self.nodes[0].getpendingdusdswaps(address)
assert_equal(result['owner'], address)
assert_equal(result['amount'], Decimal('0.99999999'))

# Withdraw one Sat
self.nodes[0].withdrawfutureswap(address, f'0.00000001@{self.symbolDFI}', self.symbolDUSD)
self.nodes[0].generate(1)

# Check user pending swap
result = self.nodes[0].getpendingdusdswaps(address)
assert_equal(result['owner'], address)
assert_equal(result['amount'], Decimal('0.99999998'))

# Withdraw all but 2 Sats
self.nodes[0].withdrawfutureswap(address, f'0.99999996@{self.symbolDFI}', self.symbolDUSD)
self.nodes[0].generate(1)

# Check user pending swap
result = self.nodes[0].getpendingdusdswaps(address)
assert_equal(result['owner'], address)
assert_equal(result['amount'], Decimal('0.00000002'))

# Move to swap height
next_futures_block = self.nodes[0].getblockcount() + (self.futures_interval_dusd - ((self.nodes[0].getblockcount() - self.start_block_dusd) % self.futures_interval_dusd))
self.nodes[0].generate(next_futures_block - self.nodes[0].getblockcount())

# Check result.
result = self.nodes[0].getaccount(address)[1]
assert_equal(result, f'0.00000001@{self.symbolDUSD}')

# Check contract address
result = self.nodes[0].getaccount(self.contract_address_dusd)
assert_equal(result, [f'2.00000003@{self.symbolDFI}'])

# Check live attrs
result = self.nodes[0].listgovs()[8][0]['ATTRIBUTES']
assert_equal(result['v0/live/economy/dfip2206f_current'], [f'2.00000003@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_burned'], [f'2.00000003@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_minted'], [f'{Decimal("0.99000000") * 2 + Decimal("0.00000001")}@{self.symbolDUSD}'])

# Check burn info
result = self.nodes[0].getburninfo()
assert_equal(result['dfip2206f'], [f'2.00000003@{self.symbolDFI}'])

def unpaid_contract_dusd(self):

# Create addresses for futures
Expand Down Expand Up @@ -1257,17 +1363,17 @@ def unpaid_contract_dusd(self):

# Check contract address
result = self.nodes[0].getaccount(self.contract_address_dusd)
assert_equal(result, [f'2.00000000@{self.symbolDFI}'])
assert_equal(result, [f'2.00000003@{self.symbolDFI}'])

# Check DFI2203 address on listgovs
# Check live attrs
result = self.nodes[0].listgovs()[8][0]['ATTRIBUTES']
assert_equal(result['v0/live/economy/dfip2206f_current'], [f'2.00000000@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_burned'], [f'2.00000000@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_minted'], [f'{Decimal("0.99000000") * 2}@{self.symbolDUSD}'])
assert_equal(result['v0/live/economy/dfip2206f_current'], [f'2.00000003@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_burned'], [f'2.00000003@{self.symbolDFI}'])
assert_equal(result['v0/live/economy/dfip2206f_minted'], [f'{Decimal("0.99000000") * 2 + Decimal("0.00000001")}@{self.symbolDUSD}'])

# Check DFI2203 address on getburninfo
# Check burn info
result = self.nodes[0].getburninfo()
assert_equal(result['dfip2206f'], [f'2.00000000@{self.symbolDFI}'])
assert_equal(result['dfip2206f'], [f'2.00000003@{self.symbolDFI}'])

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

0 comments on commit 97762a6

Please sign in to comment.