forked from kkrt-labs/kakarot
-
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.
Feat/infinite allowance (kkrt-labs#508)
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: 1d ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [X] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Currently Kakarot cannot transfer ETH on behalf of the EOAs or contract accounts. <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves kkrt-labs#464 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - EOA and contract_account give infinite allowance to Kakarot ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
- Loading branch information
1 parent
efb551e
commit f519876
Showing
15 changed files
with
181 additions
and
32 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
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
74 changes: 72 additions & 2 deletions
74
tests/unit/src/kakarot/accounts/contract/test_contract_account.py
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,22 +1,92 @@ | ||
import random | ||
|
||
import pytest | ||
import pytest_asyncio | ||
from starkware.starknet.testing.contract import StarknetContract | ||
from starkware.starknet.testing.starknet import Starknet | ||
|
||
from tests.utils.errors import kakarot_error | ||
from tests.utils.reporting import traceit | ||
|
||
random.seed(0) | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module") | ||
async def contract_account(starknet: Starknet, kakarot: StarknetContract): | ||
contract = await starknet.deploy( | ||
source="./src/kakarot/accounts/contract/contract_account.cairo", | ||
cairo_path=["src"], | ||
disable_hint_validation=True, | ||
) | ||
await contract.initialize(kakarot.contract_address, 1).execute( | ||
caller_address=kakarot.contract_address | ||
) | ||
return contract | ||
|
||
|
||
@pytest.mark.asyncio | ||
class TestContractAccount: | ||
@pytest.mark.parametrize("bytecode_len", [0, 15, 16, 17, 30, 31, 32, 33]) | ||
async def test_should_store_code( | ||
self, contract_account: StarknetContract, bytecode_len | ||
self, contract_account: StarknetContract, bytecode_len, kakarot | ||
): | ||
bytecode = [random.randint(0, 255) for _ in range(bytecode_len)] | ||
|
||
with traceit.context("contract_account"): | ||
await contract_account.write_bytecode(bytecode).execute(caller_address=1) | ||
await contract_account.write_bytecode(bytecode).execute( | ||
caller_address=kakarot.contract_address | ||
) | ||
stored_bytecode = (await contract_account.bytecode().call()).result.bytecode | ||
assert stored_bytecode == bytecode | ||
|
||
class TestInitialize: | ||
async def test_should_run_only_once( | ||
self, contract_account: StarknetContract, kakarot | ||
): | ||
with kakarot_error(): | ||
await contract_account.initialize(kakarot.contract_address, 1).execute( | ||
caller_address=kakarot.contract_address | ||
) | ||
|
||
async def test_should_set_ownership( | ||
self, contract_account: StarknetContract, kakarot | ||
): | ||
with kakarot_error(): | ||
await contract_account.write_bytecode([0]).execute(caller_address=1) | ||
await contract_account.write_bytecode([0]).execute( | ||
caller_address=kakarot.contract_address | ||
) | ||
|
||
async def test_should_give_inifinite_allowance_to_kakarot( | ||
self, contract_account: StarknetContract, kakarot, eth | ||
): | ||
# Check that current allowance is MAX Uint256 | ||
assert ( | ||
str( | ||
( | ||
await eth.allowance( | ||
contract_account.contract_address, | ||
kakarot.contract_address, | ||
).call() | ||
).result.remaining | ||
) | ||
== "Uint256(low=340282366920938463463374607431768211455, high=340282366920938463463374607431768211455)" | ||
) | ||
# Test whether this actually results in having infinite allowance | ||
await eth.mint(contract_account.contract_address, (1000, 0)).execute( | ||
caller_address=2 | ||
) | ||
await eth.transferFrom( | ||
contract_account.contract_address, 1, (1000, 0) | ||
).execute(caller_address=kakarot.contract_address) | ||
assert ( | ||
str( | ||
( | ||
await eth.allowance( | ||
contract_account.contract_address, | ||
kakarot.contract_address, | ||
).call() | ||
).result.remaining | ||
) | ||
== "Uint256(low=340282366920938463463374607431768211455, high=340282366920938463463374607431768211455)" | ||
) |
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
Oops, something went wrong.