Skip to content

Commit

Permalink
Add faucet auth token to tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWalker562 authored Oct 28, 2024
1 parent 46682d8 commit f7ea445
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 32 deletions.
1 change: 1 addition & 0 deletions examples/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"APTOS_FAUCET_URL",
"https://faucet.devnet.aptoslabs.com",
)
FAUCET_AUTH_TOKEN = os.getenv("FAUCET_AUTH_TOKEN")
INDEXER_URL = os.getenv(
"APTOS_INDEXER_URL",
"https://api.devnet.aptoslabs.com/v1/graphql",
Expand Down
6 changes: 4 additions & 2 deletions examples/fee_payer_transfer_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
TransactionPayload,
)

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main():
# :!:>section_1
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1

# :!:>section_2
alice = Account.generate()
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
TransactionPayload,
)

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


class HelloBlockchainClient(RestClient):
Expand Down Expand Up @@ -65,7 +65,7 @@ async def set_message(
async def publish_contract(package_dir: str) -> AccountAddress:
contract_publisher = Account.generate()
rest_client = HelloBlockchainClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)
await faucet_client.fund_account(contract_publisher.address(), 10_000_000)

AptosCLIWrapper.compile_package(
Expand Down Expand Up @@ -104,7 +104,7 @@ async def main(contract_address: AccountAddress):
print(f"Bob: {bob.address()}")

rest_client = HelloBlockchainClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

alice_fund = faucet_client.fund_account(alice.address(), 10_000_000)
bob_fund = faucet_client.fund_account(bob.address(), 10_000_000)
Expand Down
6 changes: 3 additions & 3 deletions examples/large_package_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from aptos_sdk.async_client import ClientConfig, FaucetClient, RestClient
from aptos_sdk.package_publisher import MODULE_ADDRESS, PackagePublisher

from .common import APTOS_CORE_PATH, FAUCET_URL, NODE_URL
from .common import APTOS_CORE_PATH, FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def publish_large_packages(large_packages_dir) -> AccountAddress:
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

alice = Account.generate()
await faucet_client.fund_account(alice.address(), 1_000_000_000)
Expand All @@ -42,7 +42,7 @@ async def main(
client_config.transaction_wait_in_seconds = 120
client_config.max_gas_amount = 1_000_000
rest_client = RestClient(NODE_URL, client_config)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

alice = Account.generate()
req0 = faucet_client.fund_account(alice.address(), 1_000_000_000)
Expand Down
6 changes: 4 additions & 2 deletions examples/multikey.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
TransactionPayload,
)

from .common import FAUCET_URL, INDEXER_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, INDEXER_URL, NODE_URL


async def main():
# :!:>section_1
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1
if INDEXER_URL and INDEXER_URL != "none":
IndexerClient(INDEXER_URL)
else:
Expand Down
4 changes: 2 additions & 2 deletions examples/multisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from aptos_sdk.type_tag import StructTag, TypeTag

from .common import APTOS_CORE_PATH, FAUCET_URL, NODE_URL
from .common import APTOS_CORE_PATH, FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL

should_wait = True

Expand All @@ -38,7 +38,7 @@ async def main(should_wait_input=True):
should_wait = should_wait_input

rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

# :!:>section_1
alice = Account.generate()
Expand Down
4 changes: 2 additions & 2 deletions examples/object_code_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from aptos_sdk.async_client import FaucetClient, RestClient
from aptos_sdk.package_publisher import MODULE_ADDRESS, PackagePublisher, PublishMode

from .common import APTOS_CORE_PATH, FAUCET_URL, NODE_URL
from .common import APTOS_CORE_PATH, FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main(package_dir):
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)
package_publisher = PackagePublisher(rest_client)
alice = Account.generate()

Expand Down
4 changes: 2 additions & 2 deletions examples/rotate_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TransactionPayload,
)

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL

WIDTH = 19

Expand Down Expand Up @@ -125,7 +125,7 @@ def rotation_payload(
async def main():
# Initialize the clients used to interact with the blockchain
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

# Generate random accounts Alice and Bob
alice = Account.generate()
Expand Down
6 changes: 4 additions & 2 deletions examples/secp256k1_ecdsa_transfer_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from aptos_sdk.account import Account
from aptos_sdk.async_client import FaucetClient, RestClient

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main():
# :!:>section_1
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1

# :!:>section_2
alice = Account.generate_secp256k1_ecdsa()
Expand Down
6 changes: 4 additions & 2 deletions examples/simple_aptos_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from aptos_sdk.async_client import FaucetClient, RestClient

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


def get_owner(obj: ReadObject) -> AccountAddress:
Expand Down Expand Up @@ -54,7 +54,9 @@ async def main():
# Create API and faucet clients.
# :!:>section_1a
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1a
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1a

# Create client for working with the token module.
# :!:>section_1b
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from aptos_sdk.aptos_tokenv1_client import AptosTokenV1Client
from aptos_sdk.async_client import FaucetClient, RestClient

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main():
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)
token_client = AptosTokenV1Client(rest_client)

# :!:>section_2
Expand Down
6 changes: 4 additions & 2 deletions examples/simulate_transfer_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
)
from aptos_sdk.type_tag import StructTag, TypeTag

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main():
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1

alice = Account.generate()
bob = Account.generate()
Expand Down
4 changes: 2 additions & 2 deletions examples/transaction_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TransactionPayload,
)

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


def generate_rest_client(node_url: str) -> RestClient:
Expand Down Expand Up @@ -295,7 +295,7 @@ def load(path: str, num_accounts: int) -> Accounts:


async def fund_from_faucet(rest_client: RestClient, source: Account):
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

fund_txns = []
for _ in range(40):
Expand Down
6 changes: 4 additions & 2 deletions examples/transfer_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from aptos_sdk.account import Account
from aptos_sdk.async_client import FaucetClient, IndexerClient, RestClient

from .common import FAUCET_URL, INDEXER_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, INDEXER_URL, NODE_URL


async def main():
# :!:>section_1
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client) # <:!:section_1
faucet_client = FaucetClient(
FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN
) # <:!:section_1
if INDEXER_URL and INDEXER_URL != "none":
indexer_client = IndexerClient(INDEXER_URL)
else:
Expand Down
4 changes: 2 additions & 2 deletions examples/transfer_two_by_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from aptos_sdk.async_client import FaucetClient, RestClient
from aptos_sdk.transactions import Script, ScriptArgument, TransactionPayload

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


async def main():
rest_client = RestClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

alice = Account.generate()
bob = Account.generate()
Expand Down
4 changes: 2 additions & 2 deletions examples/your_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from aptos_sdk.type_tag import StructTag, TypeTag

from .common import FAUCET_URL, NODE_URL
from .common import FAUCET_AUTH_TOKEN, FAUCET_URL, NODE_URL


class CoinClient(RestClient):
Expand Down Expand Up @@ -88,7 +88,7 @@ async def main(moon_coin_path: str):
print(f"Bob: {bob.address()}")

rest_client = CoinClient(NODE_URL)
faucet_client = FaucetClient(FAUCET_URL, rest_client)
faucet_client = FaucetClient(FAUCET_URL, rest_client, FAUCET_AUTH_TOKEN)

alice_fund = faucet_client.fund_account(alice.address(), 20_000_000)
bob_fund = faucet_client.fund_account(bob.address(), 20_000_000)
Expand Down

0 comments on commit f7ea445

Please sign in to comment.