Skip to content

Commit

Permalink
feat: Add support for declare, deploy, and invoke v3. Also add suppor…
Browse files Browse the repository at this point in the history
…t for estimate_fee (#423)

* Added support for declare, deploy, and invoke v3. Also added support for estimate_fee. All tested in devnet 0.1.2 with "melos test".

* Fix lint format

* fix aicoderabbit and CI issues

* Fix lint format

* Add debug info to catch Contract error on account_test

* Replace account to avoid race condition in account_test: succeeds to declare a simple sierra contract with provided CASM file

* Change account number in all 'declare cairo 1' group tests to avoid race condition with other groups

* Fix account name

* Add different account for each group test and avoid race condition

* Wait for getClass before check declared test

* melos: set concurrency to 1 when running integration tests

* Remove call_rpc_endpoint debug logs

---------

Co-authored-by: Patrice Tisserand <[email protected]>
  • Loading branch information
rukafe0x and ptisserand authored Dec 23, 2024
1 parent fc3ce20 commit 5bc6239
Show file tree
Hide file tree
Showing 49 changed files with 8,976 additions and 841 deletions.
2 changes: 1 addition & 1 deletion .env.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEVNET_DUMP_PATH="./assets/devnet-dump.json"

CAIRO_VERSION=2.6.2
SCARB_VERSION=2.6.2
STARKNET_DEVNET_VERSION=0.0.5
STARKNET_DEVNET_VERSION=0.1.2
STARKLI_VERSION=0.2.9

STARKNET_ACCOUNT=.starkli/account_0.json
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ scarb 2.6.2
action-validator 0.6.0

starkli 0.2.9
starknet-devnet 0.0.7
starknet-devnet 0.1.2

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion contracts/v2.6.2/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
version = 1

[[package]]
name = "starknet_dart"
name = "contract2"
version = "0.1.0"
dependencies = [
"openzeppelin",
]

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
10 changes: 7 additions & 3 deletions contracts/v2.6.2/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[package]
name = "starknet_dart"
name = "contract2"
version = "0.1.0"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = ">=2.5.4"
starknet = ">=2.6.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }

[lib]

[[target.starknet-contract]]

sierra = true
casm = true
caml = true
83 changes: 83 additions & 0 deletions contracts/v2.6.2/src/counter.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#[starknet::interface]
trait ICounter<TState> {
fn increment(ref self: TState);
fn decrement(ref self: TState);
fn increase_count_by(ref self: TState, number: u64);
fn get_current_count(self: @TState) -> u64;
}

#[starknet::contract]
mod Counter {
#[storage]
struct Storage {
_count: u64,
}

#[constructor]
fn constructor(ref self: ContractState) {
self._count.write(1);
}

#[abi(embed_v0)]
impl CounterImpl of super::ICounter<ContractState> {

fn increment(ref self: ContractState,) {
let current_count = self._count.read();
self._count.write(current_count + 1);
}
fn decrement(ref self: ContractState,) {
let current_count = self._count.read();
self._count.write(current_count -1);
}
fn increase_count_by(ref self: ContractState, number: u64) {
let current_count = self._count.read();
self._count.write(current_count + number);
}

fn get_current_count(self: @ContractState) -> u64 {
self._count.read()
}
}
}


#[cfg(test)]
mod tests {
use starknet_dart::counter::ICounterDispatcherTrait;
use openzeppelin::tests::utils::{deploy};
use starknet_dart::counter::{ICounterDispatcher, Counter};
use starknet::{ContractAddress};
use debug::PrintTrait;

fn deploy_counter() -> ICounterDispatcher {
let calldata: Array<felt252> = array![];
let address: ContractAddress = deploy(Counter::TEST_CLASS_HASH, calldata);
ICounterDispatcher { contract_address: address }
}

#[test]
#[available_gas(2000000)]
fn test_counter_functions() {

/// doing deplyment of the contract settonh the contractor at one
let counter = deploy_counter();

/// getting the contract count
assert(counter.get_current_count() == 1, 'Count should be initially 1');

/// test increasing the count by a certain number
counter.increase_count_by(10);
assert(counter.get_current_count() == 11, 'Count should be 11');

/// testing if the conter is incrementing as expected
counter.increment();
assert(counter.get_current_count() == 12, 'Count should be 12');

///testing decrement of the counter
counter.decrement();
assert(counter.get_current_count() == 11, 'Count should be 11');
}
}

//class_hash: 0x5d54ff3c67be0231b8e8ed0ce98dca2fb3fbc6529957756f2eea53ac23d202a
// contract_address: 0x716ea2ba1dc8f1e7f9faad442a109adebe4a80a2ec0c937c7e84aca58136859
41 changes: 41 additions & 0 deletions contracts/v2.6.2/src/erc20.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#[starknet::contract]
mod MyToken {
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
#[abi(embed_v0)]
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc20: ERC20Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC20Event: ERC20Component::Event
}

#[constructor]
fn constructor(
ref self: ContractState,
initial_supply: u256,
recipient: ContractAddress
) {
let name = "MyToken";
let symbol = "MTK";

self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, initial_supply);
}
}
28 changes: 1 addition & 27 deletions contracts/v2.6.2/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
mod hello;

fn main() -> u32 {
fib(16)
}

fn fib(mut n: u32) -> u32 {
let mut a: u32 = 0;
let mut b: u32 = 1;
while n != 0 {
n = n - 1;
let temp = b;
b = a + b;
a = temp;
};
a
}

#[cfg(test)]
mod tests {
use super::fib;

#[test]
fn it_works() {
assert(fib(16) == 987, 'it works?');
}
}
mod erc20;
2 changes: 1 addition & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ scripts:
flutter: false
test:dart:integration:
description: Run all dart integration tests
run: melos exec --dir-exists="test" -- dart test --tags integration --fail-fast
run: melos exec -c 1 --dir-exists="test" -- dart test --tags integration --fail-fast
packageFilters:
ignore: "*starknet_builder*"
flutter: false
Expand Down
Loading

0 comments on commit 5bc6239

Please sign in to comment.