generated from ApeWorX/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
6c5cfc6
commit f9cd454
Showing
8 changed files
with
110 additions
and
35 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
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,23 @@ | ||
from click.testing import CliRunner | ||
from ape_utils._cli import cli as _cli | ||
import pytest | ||
import ape | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def networks(): | ||
return ape.networks | ||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def provider(networks): | ||
with networks.ethereum.local.use_provider("test") as provider: | ||
yield provider | ||
|
||
@pytest.fixture(scope="session") | ||
def runner(): | ||
return CliRunner() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def cli(): | ||
return _cli |
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,9 @@ | ||
# import pytest | ||
from click.testing import CliRunner | ||
import rich_click as rclick | ||
|
||
|
||
def test_call_a_view_contract(runner: CliRunner, cli: rclick.RichGroup) -> None: | ||
result = runner.invoke(cli, ["call", "--function-sig", "call_this_view_function(uint256 arg1)", "--address","0x80E097a70CACA11EB71B6401FB12D48A1A61Ef54", "--args", "6147190", "--network", ":sepolia"]) | ||
# print(result) | ||
assert result.exit_code == 0 |
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,59 @@ | ||
from click.testing import CliRunner | ||
import rich_click as rclick | ||
import re | ||
|
||
|
||
regex_pat = re.compile("Encoded Calldata:\s+.*3030303030303030303064656164626565662700000000000000000000000000000000000000000000000000000000") | ||
|
||
def test_abi_encode_function_signature(runner: CliRunner, cli: rclick.RichGroup) -> None: | ||
result = runner.invoke(cli, | ||
['abi_encode', | ||
'--signature', | ||
"'call_this_view_function(uint256 arg1, string addr)'", | ||
'1234', | ||
"'0x00000000000000000000000000000000000000000000000000000000deadbeef'"] | ||
) | ||
|
||
assert result.exit_code == 0 | ||
#* These gibberish bcz of fancy coloured outputs | ||
assert regex_pat.findall(result.output) is not None | ||
# assert "32m3030303030303030303064656164626565662700000000000000000000000000000000000000000000000000000000" in result.output | ||
|
||
|
||
def test_abi_decode_function_signature(runner: CliRunner, cli: rclick.RichGroup) -> None: | ||
result = runner.invoke(cli, | ||
['abi_decode', | ||
'--signature', | ||
"'call_this_view_function(uint256 arg1, string addr)'", | ||
'0x00000000000000000000000000000000000000000000000000000000000004d20000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000a3078646561646265656600000000000000000000000000000000000000000000'] | ||
) | ||
|
||
assert result.exit_code == 0 | ||
#* Bcz of fancy coloured outputs it's very hard to match the whole string | ||
assert "0xdeadbeef" in result.output | ||
|
||
|
||
|
||
|
||
def test_encode_function_signature(runner: CliRunner, cli: rclick.RichGroup) -> None: | ||
result = runner.invoke(cli, | ||
['encode', | ||
'--signature', | ||
"'call_this_view_function(uint256 arg1)'", | ||
'1234'] | ||
) | ||
|
||
assert result.exit_code == 0 | ||
assert "0xb732f4ca00000000000000000000000000000000000000000000000000000000000004d2" in result.output | ||
|
||
|
||
def test_decode_function_signature(runner: CliRunner, cli: rclick.RichGroup) -> None: | ||
result = runner.invoke(cli, | ||
['decode', | ||
'--signature', | ||
"'call_this_view_function(uint256 arg1)'", | ||
'0x1e4f420d00000000000000000000000000000000000000000000000000000000000004d2'] | ||
) | ||
|
||
assert result.exit_code == 0 | ||
assert "1234" in result.output |