Skip to content

Commit

Permalink
read_provider_test migrate to devnet (#384)
Browse files Browse the repository at this point in the history
* scratch changes

* in progress

* in progress

* fix

* fix

* in progress

* in progress

* added simulation_flags

* fix

* clean up

* fix recipit

* fix tests

* clean up

* clean up

* clean up

* clean up

* fix devnet ci

* clean up

* clean up

* satisfy review

* clean up

* clean up

* fix hello contract

* fix hello contract
  • Loading branch information
tonypony220 authored and PaulRbl committed Jul 30, 2024
1 parent 61f21a2 commit c123054
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 134 deletions.
16 changes: 7 additions & 9 deletions .env.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ STARKNET_RPC="http://0.0.0.0:5050/rpc"
STARKNET_CHAIN_ID="SN_SEPOLIA"
SALT="0x42"
DEVNET_DUMP_PATH="./assets/devnet-dump.json"

CAIRO_VERSION=2.6.2
SCARB_VERSION=2.6.2
STARKNET_DEVNET_VERSION=0.0.5
STARKLI_VERSION=0.2.9
export CAIRO_VERSION=2.6.2
export SCARB_VERSION=2.6.2
export STARKNET_DEVNET_VERSION=0.0.7
export STARKLI_VERSION=0.2.9

STARKNET_ACCOUNT=.starkli/account_0.json
STARKNET_ACCOUNT_ADDRESS="0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691"
STARKNET_PRIVATE_KEY="0x71d7bb07b9a64f6f78ac4c816aff4da9"
STARKNET_PUBLIC_KEY="0x39d9e6ce352ad4530a0ef5d5a18fd3303c3606a7fa6ac5b620020ad681cc33b"

HELLO_CLASS_HASH="0x010ca227019cc2e511a7e6519fc1f547d50e461b330fe5f448476f16c28d677a"
HELLO_CONTRACT_ADDRESS="0x018b585732af21e763fca1048a2a91c8996b9f477cb2b85310df0a17606433f0"

ACCOUNT_CLASS_HASH="0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c"
set +a # Turn off auto-export
set +a # Turn off auto-export
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ coverage/
.env.*
!.env.example
!.env.mainnet.example
!.env.devnet.example
!.env.devnet.example
!.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",
"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(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
# 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

0 comments on commit c123054

Please sign in to comment.