Skip to content

Commit

Permalink
Renamed package to cartridge_vrf (#18)
Browse files Browse the repository at this point in the history
* Added workspace scarb toml to allow for importing

* Cleaned up imports and scarb toml

* Renamed
  • Loading branch information
bengineer42 authored Oct 15, 2024
1 parent 4a1de29 commit 284f498
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 54 deletions.
12 changes: 12 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[workspace]
members = ["contracts"]

[workspace.package]
version = "0.1.0"

[workspace.dependencies]
starknet = "2.7.0"
stark_vrf = { git = "https://github.com/dojoengine/stark-vrf.git" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" }
# Scripts are not supported for virtual workspaces.
12 changes: 6 additions & 6 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "vrf_contracts"
name = "cartridge_vrf"
version = "0.1.0"
edition = "2023_10"

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

[dependencies]
starknet = "2.7.0"
stark_vrf = { git = "https://github.com/dojoengine/stark-vrf.git"}
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" }
starknet.workspace = true
stark_vrf.workspace = true
openzeppelin.workspace = true
snforge_std.workspace = true

[dev-dependencies]
openzeppelin_testing = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a13bae3" }
Expand All @@ -21,4 +21,4 @@ allowed-libfuncs-list.name = "experimental"
[lib]

[script]
test = "snforge test"
test = "snforge test"
6 changes: 3 additions & 3 deletions contracts/dojo/vrf_consumer_template.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod consumer_template {
use starknet::ContractAddress;
use starknet::get_caller_address;

use vrf_contracts::vrf_consumer::vrf_consumer_component::VrfConsumerComponent;
use vrf_contracts::vrf_provider::vrf_provider_component::Source;
use cartridge_vrf::vrf_consumer::vrf_consumer_component::VrfConsumerComponent;
use cartridge_vrf::vrf_provider::vrf_provider_component::Source;

component!(path: VrfConsumerComponent, storage: vrf_consumer, event: VrfConsumerEvent);

Expand Down Expand Up @@ -42,7 +42,7 @@ mod consumer_template {
let player_id = get_caller_address();
let random: u256 = self.vrf_consumer.consume_random(Source::Nonce(player_id)).into();
let value: u8 = (random % 6).try_into().unwrap() + 1;
// do the right things
// do the right things
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/dojo/vrf_provider_mock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod vrf_provider_mock {

use openzeppelin::access::ownable::OwnableComponent;

use vrf_contracts::vrf_provider::vrf_provider_component::VrfProviderComponent;
use vrf_contracts::vrf_provider::vrf_provider_component::PublicKey;
use cartridge_vrf::vrf_provider::vrf_provider_component::VrfProviderComponent;
use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: VrfProviderComponent, storage: vrf_provider, event: VrfProviderEvent);
Expand Down
5 changes: 5 additions & 0 deletions contracts/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ pub mod vrf_consumer {
pub mod vrf_consumer_example;
}

pub use vrf_provider::vrf_provider_component::{
IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, Source
};
pub use vrf_consumer::vrf_consumer_component::VrfConsumerComponent;

#[cfg(test)]
pub mod tests {
pub mod common;
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/tests/common.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use openzeppelin_testing as utils;
use openzeppelin_utils::serde::SerializedAppend;
use snforge_std::{start_cheat_caller_address, stop_cheat_caller_address, cheat_max_fee_global };
use snforge_std::{start_cheat_caller_address, stop_cheat_caller_address, cheat_max_fee_global};
use starknet::{ContractAddress, contract_address_const};
use stark_vrf::ecvrf::Proof;
use utils::constants::{AUTHORIZED, OWNER};

use vrf_contracts::vrf_provider::vrf_provider::VrfProvider;
use vrf_contracts::vrf_provider::vrf_provider_component::{
use cartridge_vrf::vrf_provider::vrf_provider::VrfProvider;
use cartridge_vrf::vrf_provider::vrf_provider_component::{
IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey,
};

use vrf_contracts::vrf_consumer::vrf_consumer_example::{
use cartridge_vrf::vrf_consumer::vrf_consumer_example::{
VrfConsumer, IVrfConsumerExample, IVrfConsumerExampleDispatcher,
IVrfConsumerExampleDispatcherTrait
};
Expand Down
43 changes: 11 additions & 32 deletions contracts/src/tests/test_dice.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl};

use openzeppelin_utils::serde::SerializedAppend;

use vrf_contracts::vrf_provider::vrf_provider::VrfProvider;
use vrf_contracts::vrf_provider::vrf_provider_component::{
use cartridge_vrf::vrf_provider::vrf_provider::VrfProvider;
use cartridge_vrf::vrf_provider::vrf_provider_component::{
IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey, Source
};

use vrf_contracts::vrf_consumer::vrf_consumer_example::{
use cartridge_vrf::vrf_consumer::vrf_consumer_example::{
VrfConsumer, IVrfConsumerExample, IVrfConsumerExampleDispatcher,
IVrfConsumerExampleDispatcherTrait
};
Expand All @@ -23,7 +23,6 @@ use super::common::{setup, submit_random, SetupResult, CONSUMER1, CONSUMER2, PLA
// private key: 420
// {"public_key_x":"0x66da5d53168d591c55d4c05f3681663ac51bcdccd5ca09e366b71b0c40ccff4","public_key_y":"0x6d3eb29920bf55195e5ec76f69e247c0942c7ef85f6640896c058ec75ca2232"}


const SEED: felt252 = 0x334b8c0ea68406b183b5affd81ce11bec1a0807d3fd68a54ee75ec148053b09;

// curl -X POST -H "Content-Type: application/json" -d '{"seed": ["0x334b8c0ea68406b183b5affd81ce11bec1a0807d3fd68a54ee75ec148053b09"]}' http://0.0.0.0:3000/stark_vrf
Expand Down Expand Up @@ -60,11 +59,7 @@ fn test_dice() {

setup.provider.request_random(CONSUMER1(), Source::Nonce(PLAYER1()));

submit_random(
setup.provider,
SEED,
proof(),
);
submit_random(setup.provider, SEED, proof(),);

// PLAYER1 call dice, CONSUMER1 is caller of consume_random
start_cheat_caller_address(setup.consumer1.contract_address, PLAYER1());
Expand All @@ -83,11 +78,7 @@ fn test_not_consuming__must_consume() {
// noop just here for example
setup.provider.request_random(CONSUMER1(), Source::Nonce(PLAYER1()));

submit_random(
setup.provider,
SEED,
proof(),
);
submit_random(setup.provider, SEED, proof(),);

// PLAYER1 dont consume
start_cheat_caller_address(setup.consumer1.contract_address, PLAYER1());
Expand All @@ -106,11 +97,7 @@ fn test_dice__cannot_consume_twice() {
setup.provider.request_random(CONSUMER1(), Source::Nonce(PLAYER1()));

// provider submit_random
submit_random(
setup.provider,
SEED,
proof(),
);
submit_random(setup.provider, SEED, proof(),);

// PLAYER1 consume twice
start_cheat_caller_address(setup.consumer1.contract_address, PLAYER1());
Expand All @@ -125,13 +112,9 @@ fn test_dice_with_salt() {
let setup = setup();

// noop just here for example
setup.provider.request_random(CONSUMER1(),Source::Salt('salt'));
setup.provider.request_random(CONSUMER1(), Source::Salt('salt'));

submit_random(
setup.provider,
SEED_FROM_SALT,
proof_from_salt(),
);
submit_random(setup.provider, SEED_FROM_SALT, proof_from_salt(),);

// PLAYER1 call dice_with_salt, CONSUMER1 is caller of consume_random
start_cheat_caller_address(setup.consumer1.contract_address, PLAYER1());
Expand All @@ -148,15 +131,11 @@ fn test_dice_with_salt__wrong_proof() {
let setup = setup();

// noop just here for example
setup.provider.request_random(CONSUMER1(),Source::Salt('salt'));
setup.provider.request_random(CONSUMER1(), Source::Salt('salt'));

submit_random(
setup.provider,
SEED,
proof(),
);
submit_random(setup.provider, SEED, proof(),);

// PLAYER1 consume
start_cheat_caller_address(setup.consumer1.contract_address, PLAYER1());
let _dice1 = setup.consumer1.dice_with_salt();
}
}
4 changes: 2 additions & 2 deletions contracts/src/vrf_consumer/vrf_consumer_component.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;
use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl};
use vrf_contracts::vrf_provider::vrf_provider_component::PublicKey;
use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey;

#[starknet::interface]
trait IVrfConsumer<TContractState> {
Expand All @@ -18,7 +18,7 @@ pub mod VrfConsumerComponent {

use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl};

use vrf_contracts::vrf_provider::vrf_provider_component::{
use cartridge_vrf::vrf_provider::vrf_provider_component::{
IVrfProvider, IVrfProviderDispatcher, IVrfProviderDispatcherTrait, PublicKey,
PublicKeyIntoPoint, Source
};
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/vrf_consumer/vrf_consumer_example.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ mod VrfConsumer {

use stark_vrf::ecvrf::{Point, Proof, ECVRF, ECVRFImpl};

use vrf_contracts::vrf_consumer::vrf_consumer_component::{VrfConsumerComponent};
use vrf_contracts::vrf_provider::vrf_provider_component::Source;
use cartridge_vrf::vrf_consumer::vrf_consumer_component::{VrfConsumerComponent};
use cartridge_vrf::vrf_provider::vrf_provider_component::Source;

component!(path: VrfConsumerComponent, storage: vrf_consumer, event: VrfConsumerEvent);

Expand Down Expand Up @@ -69,7 +69,7 @@ mod VrfConsumer {

fn not_consuming(ref self: ContractState) {
let _player_id = get_caller_address();
// do the nothing
// do the nothing
}

fn set_vrf_provider(ref self: ContractState, new_vrf_provider: ContractAddress) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/vrf_provider/vrf_provider.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod VrfProvider {
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;

use vrf_contracts::vrf_provider::vrf_provider_component::VrfProviderComponent;
use vrf_contracts::vrf_provider::vrf_provider_component::PublicKey;
use cartridge_vrf::vrf_provider::vrf_provider_component::VrfProviderComponent;
use cartridge_vrf::vrf_provider::vrf_provider_component::PublicKey;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);
Expand Down

0 comments on commit 284f498

Please sign in to comment.