-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from collections import namedtuple | ||
|
||
import pytest | ||
|
||
from clove.network.bitcoin import BitcoinWallet | ||
|
||
Key = namedtuple('Key', ['secret', 'address']) | ||
|
||
|
||
@pytest.fixture | ||
def alice_wallet(): | ||
return BitcoinWallet(private_key='cSYq9JswNm79GUdyz6TiNKajRTiJEKgv4RxSWGthP3SmUHiX9WKe', testnet=True) | ||
|
||
|
||
@pytest.fixture | ||
def bob_wallet(): | ||
return BitcoinWallet(private_key='cRoFBWMvcLXrLsYFt794NRBEPUgMLf5AmnJ7VQwiEenc34z7zSpK', testnet=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
from clove.network.bitcoin import Bitcoin, BitcoinTransaction | ||
from clove.network.bitcoin import BitcoinTransaction, TestNetBitcoin | ||
|
||
|
||
def test_swap_contract(): | ||
first_address = '1JvDywcLY4mKVPb2RvsjYri8qiuMNG13cr' | ||
second_address = '12BTnbfFRBLEwsfYVyexpUEADyNfEKwY8h' | ||
transaction = BitcoinTransaction(Bitcoin, first_address, second_address, 0.5, outpoints={}) | ||
def test_swap_contract(alice_wallet, bob_wallet): | ||
transaction = BitcoinTransaction( | ||
TestNetBitcoin(), | ||
alice_wallet.get_address(), | ||
bob_wallet.get_address(), | ||
0.5, | ||
outpoints={} | ||
) | ||
transaction.set_locktime(number_of_hours=48) | ||
transaction.generate_hash() | ||
transaction.build_atomic_swap_contract() | ||
assert transaction.contract.is_valid() | ||
|
||
|
||
def test_initiate_atomic_swap(alice_wallet, bob_wallet): | ||
btc_network = TestNetBitcoin() | ||
outpoints = [ | ||
{ | ||
'txid': '6ecd66d88b1a976cde70ebbef1909edec5db80cff9b8b97024ea3805dbe28ab8', | ||
'vout': 1, | ||
'value': 0.78956946, | ||
'scriptPubKey': '76a914812ff3e5afea281eb3dd7fce9b077e4ec6fba08b88ac' | ||
}, | ||
] | ||
transaction = btc_network.initiate_atomic_swap( | ||
alice_wallet.get_address(), | ||
bob_wallet.get_address(), | ||
0.00001, | ||
outpoints | ||
) | ||
first_script_signature = transaction.tx.vin[0].scriptSig | ||
transaction.sign(alice_wallet) | ||
second_first_script_signature = transaction.tx.vin[0].scriptSig | ||
assert first_script_signature != second_first_script_signature |