This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from OpenZeppelin/cairo-0.5.0
- Loading branch information
Showing
5 changed files
with
66 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include LICENSE | ||
recursive-include src/nile/base_project/ * |
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,3 @@ | ||
# Build and test | ||
build :; nile compile | ||
test :; pytest tests/ |
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,30 @@ | ||
# Declare this file as a StarkNet contract and set the required | ||
# builtins. | ||
%lang starknet | ||
%builtins pedersen range_check | ||
|
||
from starkware.cairo.common.cairo_builtins import HashBuiltin | ||
|
||
# Define a storage variable. | ||
@storage_var | ||
func balance() -> (res : felt): | ||
end | ||
# Increases the balance by the given amount. | ||
@external | ||
func increase_balance{ | ||
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, | ||
range_check_ptr}(amount : felt): | ||
let (res) = balance.read() | ||
balance.write(res + amount) | ||
return () | ||
end | ||
|
||
# Returns the current balance. | ||
@view | ||
func get_balance{ | ||
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, | ||
range_check_ptr}() -> (res : felt): | ||
let (res) = balance.read() | ||
return (res) | ||
end |
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,30 @@ | ||
"""contract.cairo test file.""" | ||
import os | ||
import pytest | ||
from starkware.starknet.testing.starknet import Starknet | ||
|
||
# The path to the contract source code. | ||
CONTRACT_FILE = os.path.join("contracts", "contract.cairo") | ||
|
||
|
||
# The testing library uses python's asyncio. So the following | ||
# decorator and the ``async`` keyword are needed. | ||
@pytest.mark.asyncio | ||
async def test_increase_balance(): | ||
"""Test increase_balance method.""" | ||
# Create a new Starknet class that simulates the StarkNet | ||
# system. | ||
starknet = await Starknet.empty() | ||
|
||
# Deploy the contract. | ||
contract = await starknet.deploy( | ||
source=CONTRACT_FILE, | ||
) | ||
|
||
# Invoke increase_balance() twice. | ||
await contract.increase_balance(amount=10).invoke() | ||
await contract.increase_balance(amount=20).invoke() | ||
|
||
# Check the result of get_balance(). | ||
execution_info = await contract.get_balance().call() | ||
assert execution_info.result == (30,) |
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