Skip to content

Commit

Permalink
test: fix network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Aug 11, 2019
1 parent 95a60d9 commit 72bfb40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
14 changes: 7 additions & 7 deletions tests/test_network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from stellar_sdk.network import Network, PUBLIC, TESTNET
from stellar_sdk.network import Network


class TestNetwork:
Expand All @@ -15,20 +15,20 @@ def test_create_a_network(self):
)

def test_public(self):
assert PUBLIC.network_passphrase == self.public_passphrase
assert Network.public_network().network_passphrase == self.public_passphrase
assert (
PUBLIC.network_id().hex()
Network.public_network().network_id().hex()
== "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a979"
)

def test_testnet(self):
assert TESTNET.network_passphrase == self.testnet_passphrase
assert Network.testnet_network().network_passphrase == self.testnet_passphrase
assert (
TESTNET.network_id().hex()
Network.testnet_network().network_id().hex()
== "cee0302d59844d32bdca915c8203dd44b33fbb7edc19051ea37abedf28ecd472"
)

def test_equals(self):
assert Network(self.public_passphrase) == PUBLIC
assert Network(self.testnet_passphrase) == TESTNET
assert Network(self.public_passphrase) == Network.public_network()
assert Network(self.testnet_passphrase) == Network.testnet_network()
assert Network(self.public_passphrase) != Network(self.testnet_passphrase)
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from stellar_sdk.client.aiohttp_client import AiohttpClient
from stellar_sdk.client.requests_client import RequestsClient
from stellar_sdk.exceptions import ValueError
from stellar_sdk.network import PUBLIC_NETWORK_PASSPHRASE
from stellar_sdk.network import Network
from stellar_sdk.server import Server


Expand Down Expand Up @@ -131,7 +131,7 @@ def test_submit_transaction_with_xdr(self):
@pytest.mark.asyncio
async def test_submit_transaction_with_te(self):
xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg=="
te = TransactionBuilder.from_xdr(xdr, PUBLIC_NETWORK_PASSPHRASE)
te = TransactionBuilder.from_xdr(xdr, Network.PUBLIC_NETWORK_PASSPHRASE)
horizon_url = "https://horizon.stellar.org"
client = AiohttpClient()
async with Server(horizon_url, client) as server:
Expand Down
16 changes: 9 additions & 7 deletions tests/test_transaction_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ReturnHashMemo,
)
from stellar_sdk.account import Account
from stellar_sdk.network import TESTNET_NETWORK_PASSPHRASE
from stellar_sdk.network import Network
from stellar_sdk.signer import Signer
from stellar_sdk.time_bounds import TimeBounds

Expand Down Expand Up @@ -136,14 +136,16 @@ def test_to_xdr(self):
print(te.to_xdr())
assert te.to_xdr() == xdr_signed

restore_te = TransactionBuilder.from_xdr(xdr_signed, TESTNET_NETWORK_PASSPHRASE)
restore_te = TransactionBuilder.from_xdr(
xdr_signed, Network.TESTNET_NETWORK_PASSPHRASE
)
assert restore_te.to_xdr() == xdr_signed

def test_set_timeout(self):
source = Account("GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", 1)
timeout = 1000
builder = TransactionBuilder(
source, TESTNET_NETWORK_PASSPHRASE, base_fee=150
source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
).set_timeout(1000)
now = int(time.time())
assert isinstance(builder.time_bounds, TimeBounds)
Expand All @@ -159,22 +161,22 @@ def test_set_timeout_timebounds_raise(self):
match="TimeBounds has been already set - setting timeout would overwrite it.",
):
TransactionBuilder(
source, TESTNET_NETWORK_PASSPHRASE, base_fee=150
source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
).add_time_bounds(0, now + timeout).set_timeout(1000)

def test_add_memo(self):
source = Account("GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", 1)
builder = TransactionBuilder(
source, TESTNET_NETWORK_PASSPHRASE, base_fee=150
source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
).add_id_memo(100)
assert builder.memo == IdMemo(100)

memo_hash = os.urandom(32)
builder = TransactionBuilder(
source, TESTNET_NETWORK_PASSPHRASE, base_fee=150
source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
).add_hash_memo(memo_hash)
assert builder.memo == HashMemo(memo_hash)
builder = TransactionBuilder(
source, TESTNET_NETWORK_PASSPHRASE, base_fee=150
source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
).add_return_hash_memo(memo_hash)
assert builder.memo == ReturnHashMemo(memo_hash)
6 changes: 3 additions & 3 deletions tests/test_transaction_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from stellar_sdk.exceptions import SignatureExistError
from stellar_sdk.keypair import Keypair
from stellar_sdk.memo import IdMemo
from stellar_sdk.network import PUBLIC
from stellar_sdk.network import Network
from stellar_sdk.operation import Payment, ManageData
from stellar_sdk.time_bounds import TimeBounds
from stellar_sdk.transaction import Transaction
Expand All @@ -26,7 +26,7 @@ def test_to_xdr(self):
time_bounds = TimeBounds(12345, 56789)
ops = [Payment(destination, asset, amount), ManageData("hello", "world")]
tx = Transaction(source, sequence, fee, ops, memo, time_bounds)
network = PUBLIC
network = Network.public_network()
te = TransactionEnvelope(tx, network)
te.sign(source)
hashx = bytes.fromhex(
Expand All @@ -52,7 +52,7 @@ def test_already_signed_raise(self):
time_bounds = TimeBounds(12345, 56789)
ops = [Payment(destination, asset, amount), ManageData("hello", "world")]
tx = Transaction(source, sequence, fee, ops, memo, time_bounds)
network = PUBLIC
network = Network.public_network()
te = TransactionEnvelope(tx, network)
te.sign(source)
hashx = bytes.fromhex(
Expand Down

0 comments on commit 72bfb40

Please sign in to comment.