This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
86 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from ape_starknet.accounts import OPEN_ZEPPELIN_ACCOUNT_CONTRACT_TYPE | ||
|
||
|
||
def test_get_contract_type_tokens(tokens, explorer): | ||
actual = explorer.get_contract_type(tokens.token_address_map["eth"]["local"]) | ||
expected = tokens.contract_type | ||
assert actual == expected | ||
|
||
|
||
def test_get_contract_type_accounts(account, second_account, explorer): | ||
actual_0 = explorer.get_contract_type(account.address) | ||
actual_1 = explorer.get_contract_type(second_account.address) | ||
assert actual_0 == OPEN_ZEPPELIN_ACCOUNT_CONTRACT_TYPE | ||
assert actual_1 == OPEN_ZEPPELIN_ACCOUNT_CONTRACT_TYPE | ||
|
||
|
||
def test_get_contract_type_after_deploy(contract, explorer): | ||
actual = explorer.get_contract_type(contract.address) | ||
expected = contract.contract_type | ||
assert actual.abi == expected.abi |
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,22 @@ | ||
from ape.contracts import ContractInstance | ||
|
||
|
||
def test_multiple_networks_in_test( | ||
networks, provider, eth_account, eth_contract_container, contract, account | ||
): | ||
starknet_chain_id = provider.chain_id | ||
|
||
with networks.ethereum.local.use_provider("test") as eth_provider: | ||
# Verify the chain changed | ||
assert eth_provider.chain_id != starknet_chain_id | ||
|
||
# Deploy and interact with a contract on Ethereum | ||
eth_contract = eth_contract_container.deploy(sender=eth_account) | ||
receipt = eth_contract.setNumber(123, sender=eth_account) | ||
assert not receipt.failed | ||
assert isinstance(eth_contract, ContractInstance) | ||
assert eth_contract.myNumber() == 123 | ||
|
||
# Switch back to Starknet | ||
receipt = contract.increase_balance(account.address, 123, sender=account) | ||
assert not receipt.failed |
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,40 @@ | ||
import pytest | ||
|
||
AMOUNT_0 = 10 | ||
AMOUNT_1 = 2**128 + 42 | ||
|
||
|
||
@pytest.fixture | ||
def receipt(token_contract, account, second_account): | ||
return token_contract.fire_events(second_account.address, AMOUNT_0, AMOUNT_1, sender=account) | ||
|
||
|
||
def test_decode_logs(receipt, token_contract, account, second_account): | ||
transfer_logs = list(receipt.decode_logs(token_contract.Transfer)) | ||
assert len(transfer_logs) == 1 | ||
log = transfer_logs[0] | ||
assert log.from_ == int(account.address, 16) | ||
assert log.to == int(second_account.address, 16) | ||
assert log.value == AMOUNT_0 | ||
|
||
mint_logs = list(receipt.decode_logs(token_contract.Mint)) | ||
assert len(mint_logs) == 1 | ||
log = mint_logs[0] | ||
assert log.sender == int(account.address, 16) | ||
assert log.amount0 == AMOUNT_0 | ||
assert log.amount1 == AMOUNT_1 | ||
assert log.to == int(second_account.address, 16) | ||
|
||
|
||
def test_decode_logs_no_specify_abi(receipt, account, second_account): | ||
logs = list(receipt.decode_logs()) | ||
assert len(logs) == 2 | ||
transfer_log, mint_log = logs | ||
|
||
assert transfer_log.from_ == int(account.address, 16) | ||
assert transfer_log.to == int(second_account.address, 16) | ||
assert transfer_log.value == AMOUNT_0 | ||
assert mint_log.sender == int(account.address, 16) | ||
assert mint_log.amount0 == AMOUNT_0 | ||
assert mint_log.amount1 == AMOUNT_1 | ||
assert mint_log.to == int(second_account.address, 16) |