-
Notifications
You must be signed in to change notification settings - Fork 24
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
c0a32f9
commit 3882417
Showing
9 changed files
with
55 additions
and
2,042 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,2 +1,4 @@ | ||
target | ||
.snfoundry_cache/ | ||
build | ||
.protostar_cache |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ verify_ssl = true | |
name = "pypi" | ||
|
||
[packages] | ||
cairo-nile = "*" | ||
|
||
[dev-packages] | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
docker run -p 5050:5050 shardlabs/starknet-devnet-rs --seed 0 | ||
|
||
``` | ||
export PROTOSTAR_ACCOUNT_PRIVATE_KEY=0x71d7bb07b9a64f6f78ac4c816aff4da9 && protostar declare-cairo0 --account-address 0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691 --max-fee auto --gateway-url http://localhost:5050/ --chain-id 1536727068981429685321 build/main.json | ||
``` |
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,7 @@ | ||
[project] | ||
protostar-version = "0.14.0" | ||
lib-path = "lib" | ||
|
||
[contracts] | ||
main = ["src/main.cairo"] | ||
|
16 changes: 11 additions & 5 deletions
16
deployment/contracts/contract.cairo → deployment/src/main.cairo
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,26 +1,32 @@ | ||
// Declare this file as a StarkNet contract. | ||
%lang starknet | ||
|
||
from starkware.cairo.common.math import assert_nn | ||
from starkware.cairo.common.cairo_builtins import HashBuiltin | ||
|
||
// Define a storage variable. | ||
@storage_var | ||
func balance() -> (res: felt) { | ||
} | ||
|
||
// Increases the balance by the given amount. | ||
@external | ||
func increase_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( | ||
amount: felt | ||
) { | ||
with_attr error_message("Amount must be positive. Got: {amount}.") { | ||
assert_nn(amount); | ||
} | ||
|
||
let (res) = balance.read(); | ||
balance.write(res + amount); | ||
return (); | ||
} | ||
|
||
// 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,); | ||
} | ||
|
||
@constructor | ||
func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { | ||
balance.write(0); | ||
return (); | ||
} |
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
%lang starknet | ||
from src.main import balance, increase_balance | ||
from starkware.cairo.common.cairo_builtins import HashBuiltin | ||
|
||
@external | ||
func test_increase_balance{syscall_ptr: felt*, range_check_ptr, pedersen_ptr: HashBuiltin*}() { | ||
let (result_before) = balance.read(); | ||
assert result_before = 0; | ||
|
||
increase_balance(42); | ||
|
||
let (result_after) = balance.read(); | ||
assert result_after = 42; | ||
return (); | ||
} | ||
|
||
@external | ||
func test_cannot_increase_balance_with_negative_value{ | ||
syscall_ptr: felt*, range_check_ptr, pedersen_ptr: HashBuiltin* | ||
}() { | ||
let (result_before) = balance.read(); | ||
assert result_before = 0; | ||
|
||
%{ expect_revert("TRANSACTION_FAILED", "Amount must be positive") %} | ||
increase_balance(-42); | ||
|
||
return (); | ||
} |