Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Oct 18, 2024
1 parent e5a3227 commit a71c383
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 41 deletions.
59 changes: 32 additions & 27 deletions cairo_zero/openzeppelin/ERC20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256

from openzeppelin.access.ownable.library import Ownable
from openzeppelin.token.erc20.library import ERC20

@constructor
Expand All @@ -15,7 +14,6 @@ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
) {
ERC20.initializer(name, symbol, decimals);
ERC20._mint(recipient, initial_supply);
Ownable.initializer(owner);
return ();
}

Expand All @@ -41,6 +39,13 @@ func totalSupply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
return (totalSupply=totalSupply);
}

@view
func total_supply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
total_supply: Uint256
) {
return ERC20.total_supply();
}

@view
func decimals{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
decimals: felt
Expand All @@ -55,18 +60,20 @@ func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
return ERC20.balance_of(account);
}

@view
func balance_of{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(account: felt) -> (
balance: Uint256
) {
return ERC20.balance_of(account);
}

@view
func allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
owner: felt, spender: felt
) -> (remaining: Uint256) {
return ERC20.allowance(owner, spender);
}

@view
func owner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (owner: felt) {
return Ownable.owner();
}

//
// Externals
//
Expand All @@ -85,6 +92,13 @@ func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_pt
return ERC20.transfer_from(sender, recipient, amount);
}

@external
func transfer_from{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
sender: felt, recipient: felt, amount: Uint256
) -> (success: felt) {
return ERC20.transfer_from(sender, recipient, amount);
}

@external
func approve{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, amount: Uint256
Expand All @@ -100,31 +114,22 @@ func increaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_che
}

@external
func decreaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
func increase_allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, added_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}

@external
func mint{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
to: felt, amount: Uint256
) {
Ownable.assert_only_owner();
ERC20._mint(to, amount);
return ();
return ERC20.increase_allowance(spender, added_value);
}

@external
func transferOwnership{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newOwner: felt
) {
Ownable.transfer_ownership(newOwner);
return ();
func decreaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}

@external
func renounceOwnership{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
Ownable.renounce_ownership();
return ();
func decrease_allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}
2 changes: 0 additions & 2 deletions kakarot_scripts/deployment/dualvm_token_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
from uvloop import run

from kakarot_scripts.constants import (
ETH_TOKEN_ADDRESS,
EVM_ADDRESS,
NETWORK,
RPC_CLIENT,
STRK_TOKEN_ADDRESS,
TOKEN_ADDRESSES_DIR,
NetworkType,
)
Expand Down
33 changes: 21 additions & 12 deletions tests/end_to_end/CairoPrecompiles/test_dual_vm_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import pytest_asyncio
from eth_utils import keccak

from kakarot_scripts.constants import NETWORK
from kakarot_scripts.utils.kakarot import get_contract as get_contract_evm
from kakarot_scripts.utils.kakarot import get_deployments as get_evm_deployments
from kakarot_scripts.utils.starknet import get_contract as get_contract_starknet, wait_for_transaction
from kakarot_scripts.utils.starknet import get_starknet_account, invoke
from kakarot_scripts.utils.starknet import get_contract as get_contract_starknet
from kakarot_scripts.utils.starknet import (
get_starknet_account,
invoke,
wait_for_transaction,
)
from tests.utils.errors import cairo_error


@pytest_asyncio.fixture(scope="function", autouse=True)
async def fund_owner(owner, starknet_token, max_fee):
breakpoint()
Expand All @@ -31,21 +35,30 @@ async def fund_owner(owner, starknet_token, max_fee):
(balance,) = await starknet_token.functions["balance_of"].call(
owner.starknet_contract.address
)
assert balance >= amount, f"Transfer failed. Expected min balance: {amount}, Actual balance: {balance}"
assert (
balance >= amount
), f"Transfer failed. Expected min balance: {amount}, Actual balance: {balance}"


@pytest_asyncio.fixture(scope="function")
async def starknet_token(dual_vm_token):
starknet_address = await dual_vm_token.starknetToken()
deployer = await get_starknet_account()
return get_contract_starknet("StarknetToken", address=starknet_address, provider=deployer)
return get_contract_starknet(
"StarknetToken", address=starknet_address, provider=deployer
)


@pytest_asyncio.fixture(scope="function")
async def dual_vm_token(owner):
evm_deployments = get_evm_deployments()
ether = evm_deployments["Ether"]["address"]
return await get_contract_evm("CairoPrecompiles", "DualVmToken", address=ether, caller_eoa=owner.starknet_contract)
return await get_contract_evm(
"CairoPrecompiles",
"DualVmToken",
address=ether,
caller_eoa=owner.starknet_contract,
)


@pytest.mark.asyncio(scope="module")
Expand Down Expand Up @@ -184,9 +197,7 @@ async def test_should_transfer_starknet_address(
async def test_should_revert_transfer_insufficient_balance(
self, dual_vm_token, owner, other, signature, to_address
):
balance = await dual_vm_token.functions["balanceOf(address)"](
other.address
)
balance = await dual_vm_token.functions["balanceOf(address)"](other.address)
# No wrapping of errors for OZ 0.10 contracts
with cairo_error("u256_sub Overflow"):
await dual_vm_token.functions[signature](
Expand All @@ -202,9 +213,7 @@ async def test_should_revert_transfer_starknet_address_invalid_address(
2**256 - 1, 1
)

async def test_should_approve(
self, dual_vm_token, owner, other
):
async def test_should_approve(self, dual_vm_token, owner, other):
amount = 1
allowance_before = await dual_vm_token.functions[
"allowance(address,address)"
Expand Down

0 comments on commit a71c383

Please sign in to comment.