-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for declare, deploy, and invoke v3. Also add suppor…
…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
1 parent
fc3ce20
commit 5bc6239
Showing
49 changed files
with
8,976 additions
and
841 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
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 |
---|---|---|
|
@@ -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 |
1 change: 1 addition & 0 deletions
1
contracts/v1/artifacts/contract2_Counter2.compiled_contract_class.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
contracts/v1/artifacts/contract2_MyToken.compiled_contract_class.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,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 |
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,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 |
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,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); | ||
} | ||
} |
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,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; |
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
Oops, something went wrong.