Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_provider_test migrate to devnet #384

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export DEVNET_DUMP_PATH="./assets/devnet-dump.json"

export CAIRO_VERSION=2.6.2
export SCARB_VERSION=2.6.2
export STARKNET_DEVNET_VERSION=0.0.5
export STARKNET_DEVNET_VERSION=0.0.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Security Risk: API Key Exposure

The private and public keys are exposed in the environment file, which could lead to unauthorized access if not properly secured. Consider using secrets management tools or environment-specific encryption to protect these keys.

export STARKLI_VERSION=0.2.9

export STARKNET_ACCOUNT=.starkli/account_0.json
export STARKNET_ACCOUNT_ADDRESS="0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691"
export STARKNET_PRIVATE_KEY="0x71d7bb07b9a64f6f78ac4c816aff4da9"
export STARKNET_PUBLIC_KEY="0x39d9e6ce352ad4530a0ef5d5a18fd3303c3606a7fa6ac5b620020ad681cc33b"
Comment on lines 15 to 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Security Risk: API Key Exposure

The private and public keys are exposed in the environment file, which could lead to unauthorized access if not properly secured. Consider using secrets management tools or environment-specific encryption to protect these keys.

Tools
Gitleaks

15-15: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key)


16-16: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key)


export HELLO_CLASS_HASH="0x010ca227019cc2e511a7e6519fc1f547d50e461b330fe5f448476f16c28d677a"
export HELLO_CONTRACT_ADDRESS="0x018b585732af21e763fca1048a2a91c8996b9f477cb2b85310df0a17606433f0"
export HELLO_CLASS_HASH="0x065fa938e267ea36a5f7ba1373fbe5d1af3a6d2ec1b040e4640aaeb706d5df24"
export HELLO_CONTRACT_ADDRESS="0x03cdc588f4f1bff66c8a6896e7008cc39c7804d36b16e93792625bd18bffd249"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
-p 5050:5050 \
--entrypoint tini \
shardlabs/starknet-devnet-rs:$STARKNET_DEVNET_VERSION -- \
starknet-devnet --host 0.0.0.0 --seed 0 --dump-path $DEVNET_DUMP_PATH
starknet-devnet --host 0.0.0.0 --seed 0 --dump-path $DEVNET_DUMP_PATH --state-archive-capacity full
sleep 3 # Wait for 3 seconds for the Docker container to initialize
- run: melos test:dart:integration
- name: Cleanup
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ coverage/
!contracts/build

.env.*
!.env.devnet
!.env.devnet

# deploy for test
.starkli/account_1.json

14 changes: 14 additions & 0 deletions .starkli/account_for_devnet_setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"variant": {
"type": "open_zeppelin",
"version": 1,
"public_key": "0x39d9e6ce352ad4530a0ef5d5a18fd3303c3606a7fa6ac5b620020ad681cc33b",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Security Risk: Public Key Exposure

The public key is exposed in the configuration file, which might lead to security risks if this file is not properly secured. Consider encrypting this key or using environment variables to handle sensitive information securely.

Tools
Gitleaks

6-6: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

"legacy": false
},
"deployment": {
"status": "undeployed",
"class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
"salt": "0x38fd00cc183cb6326ff3ae90148331bd76a070ee489608fc832f2cf2c0d5aef"
}
}
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.5
starknet-devnet 0.0.7
2 changes: 1 addition & 1 deletion assets/devnet-dump.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contracts/v2.6.2/src/hello.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
trait IHello<T> {
fn get_name(self: @T) -> felt252;
fn set_name(ref self: T, name: felt252);
fn sum(ref self: T, a: felt252, b: felt252) -> felt252;
}

#[starknet::contract]
Expand All @@ -25,5 +26,9 @@ mod hello {
fn set_name(ref self: ContractState, name: felt252) {
self.name.write(name);
}

fn sum(self: @ContractState, a: felt252, b: felt252) -> felt252 {
a + b
}
}
}

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ scripts:
devnet:start:
description: Start local devnet
run: |
starknet-devnet --seed 0 --dump-path $DEVNET_DUMP_PATH
devnet:start-dump:
description: Start local devnet in dump mode
starknet-devnet --seed 0 --dump-path $DEVNET_DUMP_PATH --state-archive-capacity full --port 3030
devnet:start:dump:
description: Start local devnet from scratch and dump on exit
run: |
rm ./assets/devnet-dump.json
starknet-devnet --seed 0 --dump-path $DEVNET_DUMP_PATH --dump-on exit
rm $DEVNET_DUMP_PATH
starknet-devnet --seed 0 --dump-path $DEVNET_DUMP_PATH --state-archive-capacity full --dump-on exit --port 3030
devnet:setup:
description: Setup local devnet
run: |
melos contracts:build
melos contracts:declare
melos contracts:deploy
melos contracts:invoke

contracts:build:
description: Build cairo contracts
Expand All @@ -82,10 +83,16 @@ scripts:
description: Deploy cairo contracts
run: |
starkli deploy $HELLO_CLASS_HASH --salt $SALT 0x0
hello:get_name:
description: Call hello get_name

contracts:invoke:
description: creating invoke tx for tests with hash 0x03b2911796e0024f9e23d7337997538058eca267d5ddaa582d482cbe1fb64897 and deploy_account tx with hash 0x055ba13c33a12506d2eab8dfbc618a8ce0d247c24959a64ee18fbf393c873b83
run: |
starkli call $HELLO_CONTRACT_ADDRESS get_name
starkli invoke $HELLO_CONTRACT_ADDRESS set_name 0x0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing spaces to clean up the code.

Trailing spaces on lines 90 and 92 should be removed to adhere to good coding practices.

-      starkli invoke $HELLO_CONTRACT_ADDRESS set_name 0x0 
+      starkli invoke $HELLO_CONTRACT_ADDRESS set_name 0x0
-      
+

Also applies to: 92-92

Tools
yamllint

[error] 90-90: trailing spaces (trailing-spaces)

# should create tx hash 0x029583643cd8932f1955bf28bfebf4c907b13df1e5c2d202b133cfbf783697a2

cp -f .starkli/account_for_devnet_setup.json .starkli/account_1.json
starkli invoke eth transfer 0x016a0d7df981d681537dc2ce648722ff1d1c2cbe59412b492d35bac69825f104 0x100000000000000000 0x0
echo | starkli account deploy .starkli/account_1.json

test:
description: Run all tests
Expand Down
2 changes: 1 addition & 1 deletion melos_monorepo.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>
1 change: 1 addition & 0 deletions packages/starknet/lib/src/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class Account {
EstimateFeeRequest estimateFeeRequest = EstimateFeeRequest(
request: [broadcastedTxn],
blockId: blockId,
simulation_flags: [],
);

final estimateFeeResponse = await provider.estimateFee(
Expand Down
1 change: 1 addition & 0 deletions packages/starknet_provider/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
starknet-devnet 0.0.7
25 changes: 25 additions & 0 deletions packages/starknet_provider/lib/src/model/estimate_fee.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,38 @@ class EstimateFee with _$EstimateFee {
: EstimateFeeResult.fromJson(json);
}

/// Flags that indicate how to simulate a given transaction.
/// By default, the sequencer behavior is replicated locally (enough funds are expected to be in the
/// account, and fee will be deducted from the balance before the simulation of the next
/// transaction). To skip the fee charge, use the SKIP_FEE_CHARGE flag.
@freezed
class SimulationFlag with _$SimulationFlag {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory SimulationFlag.skipValidate() = SkipValidate;

@JsonSerializable(fieldRename: FieldRename.snake)
const factory SimulationFlag.skipFeeCharge() = SkipFeeCharge;

factory SimulationFlag.fromJson(Map<String, dynamic> json) =>
_$SimulationFlagFromJson(json);

Map<String, dynamic> toJson() => {
'type': this.when(
skipValidate: () => "SKIP_VALIDATE",
skipFeeCharge: () => "SKIP_FEE_CHARGE",
),
};
}

@JsonSerializable()
class EstimateFeeRequest {
final List<BroadcastedTxn> request;
final BlockId blockId;
final List<SimulationFlag> simulation_flags;
EstimateFeeRequest({
required this.request,
required this.blockId,
required this.simulation_flags,
});

factory EstimateFeeRequest.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading