Skip to content

Commit

Permalink
init protostar
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Dec 18, 2023
1 parent c0a32f9 commit 3882417
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 2,042 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
.snfoundry_cache/
build
.protostar_cache
138 changes: 0 additions & 138 deletions deployment/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion deployment/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ verify_ssl = true
name = "pypi"

[packages]
cairo-nile = "*"

[dev-packages]

Expand Down
1,869 changes: 2 additions & 1,867 deletions deployment/Pipfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions deployment/README.md
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
```
7 changes: 7 additions & 0 deletions deployment/protostar.toml
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 deployment/contracts/contract.cairo → deployment/src/main.cairo
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 ();
}
31 changes: 0 additions & 31 deletions deployment/tests/test_contract.py

This file was deleted.

28 changes: 28 additions & 0 deletions deployment/tests/test_main.cairo
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 ();
}

0 comments on commit 3882417

Please sign in to comment.