Skip to content

Commit 47480df

Browse files
authored
Merge pull request #232 from ryzen-xp/feat_Repeated_Validation_Logic
[Ref]:: Repeated Validation Logic remove
2 parents 3078a1d + 4d496b0 commit 47480df

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

.devcontainer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "dev",
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"StarkWare.cairo1",
8+
"tamasfe.even-better-toml",
9+
"rust-lang.rust-analyzer"
10+
]
11+
}
12+
},
13+
"features": {
14+
"ghcr.io/devcontainers/features/rust:1": {
15+
"version": "stable"
16+
}
17+
},
18+
"postCreateCommand": "bash .devcontainer/install-tools.sh",
19+
"remoteUser": "vscode"
20+
}

.devcontainer/install-tools.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# @ryzen-xp
2+
3+
set -e
4+
5+
echo "🚀 Setting up development environment..."
6+
7+
# Install dependencies
8+
apt-get update && apt-get install -y curl git build-essential
9+
10+
# Install asdf
11+
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
12+
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
13+
echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc
14+
. ~/.asdf/asdf.sh
15+
16+
# Read versions from .tool-versions
17+
SCARB_VERSION=$(grep "^scarb " .tool-versions | awk '{print $2}')
18+
FOUNDRY_VERSION=$(grep "^starknet-foundry " .tool-versions | awk '{print $2}')
19+
20+
echo "📦 Installing Scarb $SCARB_VERSION and Starknet Foundry $FOUNDRY_VERSION..."
21+
22+
# Add and install plugins
23+
asdf plugin add scarb || true
24+
asdf install scarb "$SCARB_VERSION"
25+
asdf global scarb "$SCARB_VERSION"
26+
27+
asdf plugin add starknet-foundry || true
28+
asdf install starknet-foundry "$FOUNDRY_VERSION"
29+
asdf global starknet-foundry "$FOUNDRY_VERSION"
30+
31+
echo "✅ Environment ready!"

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ scarb build
104104
snforge test
105105
```
106106

107+
## 🐳 DevContainer Setup (Docker)
108+
109+
We provide a **Docker DevContainer** to simplify development and avoid local dependency issues.
110+
111+
### Prerequisites
112+
- [Docker](https://docs.docker.com/get-docker/) installed and running
113+
- [Visual Studio Code](https://code.visualstudio.com/) with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
114+
115+
### Setup
116+
1. Open the project in **VS Code**.
117+
2. Press **CTRL + SHIFT + P** → select **“Dev Containers: Reopen in Container”**.
118+
3. The container will build and install all required tools automatically.
119+
120+
### Verify
121+
Inside the container, run:
122+
123+
```bash
124+
scarb build
125+
scarb test
126+
scarb fmt
127+
scarb fmt --check
128+
```
129+
### Note :
130+
- If During running `scarb build` throw error `killed` , Then increase your docker ram allocation and cores. and restart !
131+
107132
# Contributing
108133

109134
We welcome contributions! Please follow these steps:

src/predifi.cairo

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub mod Predifi {
288288
self.pausable.assert_not_paused();
289289
// Convert u8 to Pool enum with validation
290290
let pool_type_enum = u8_to_pool(poolType);
291+
let creator_address = get_caller_address();
291292

292293
// Validation checks using SecurityTrait
293294
self.assert_valid_pool_timing(poolStartTime, poolLockTime, poolEndTime);
@@ -298,8 +299,6 @@ pub mod Predifi {
298299
self.assert_valid_felt252(option1);
299300
self.assert_valid_felt252(option2);
300301

301-
let creator_address = get_caller_address();
302-
303302
// Collect pool creation fee (1 STRK)
304303
IPredifi::collect_pool_creation_fee(ref self, creator_address);
305304

@@ -488,14 +487,13 @@ pub mod Predifi {
488487

489488
let mut pool = self.pools.read(pool_id);
490489
self.assert_pool_exists(@pool);
490+
self.assert_pool_active(@pool);
491491

492492
let option1: felt252 = pool.option1;
493493
let option2: felt252 = pool.option2;
494494

495495
// Validation checks using SecurityTrait
496496
self.assert_valid_pool_option(option, option1, option2);
497-
self.assert_pool_not_suspended(@pool);
498-
self.assert_pool_active(@pool);
499497
self.assert_amount_within_limits(amount, pool.minBetAmount, pool.maxBetAmount);
500498

501499
// Transfer betting amount from the user to the contract
@@ -569,6 +567,7 @@ pub mod Predifi {
569567
/// @custom:delegation Allows delegation of stake to other validators if desired
570568
fn stake(ref self: ContractState, pool_id: u256, amount: u256) {
571569
self.pausable.assert_not_paused();
570+
//Input Validatioin
572571
self.assert_greater_than_zero(amount);
573572
self.assert_greater_than_zero(pool_id);
574573

@@ -1355,7 +1354,6 @@ pub mod Predifi {
13551354
let pool = self.pools.read(pool_id);
13561355

13571356
// Validation checks using SecurityTrait
1358-
self.assert_pool_exists(@pool);
13591357
self.assert_pool_not_suspended(@pool);
13601358
}
13611359

@@ -1390,7 +1388,6 @@ pub mod Predifi {
13901388
let caller = get_caller_address();
13911389

13921390
// Validation checks using SecurityTrait
1393-
self.assert_pool_exists(@pool);
13941391
self.assert_pool_not_suspended(@pool);
13951392

13961393
// Check if caller is an authorized validator

tests/test_dispute.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ fn test_get_suspended_pools() {
305305
}
306306

307307
#[test]
308-
#[should_panic(expected: 'Pool is suspended')]
308+
#[should_panic(expected: 'Pool is inactive')]
309309
fn test_vote_on_suspended_pool() {
310310
let (contract, dispute_contract, _, pool_creator, erc20_address) = deploy_predifi();
311311

0 commit comments

Comments
 (0)