Skip to content

Commit b7bc834

Browse files
committed
[Ref]:: Repeated Validation Logic remove
1 parent c53466e commit b7bc834

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
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: 7 additions & 8 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,7 +299,7 @@ pub mod Predifi {
298299
self.assert_valid_felt252(option1);
299300
self.assert_valid_felt252(option2);
300301

301-
let creator_address = get_caller_address();
302+
302303

303304
// Collect pool creation fee (1 STRK)
304305
IPredifi::collect_pool_creation_fee(ref self, creator_address);
@@ -484,14 +485,13 @@ pub mod Predifi {
484485

485486
let mut pool = self.pools.read(pool_id);
486487
self.assert_pool_exists(@pool);
488+
self.assert_pool_active(@pool);
487489

488490
let option1: felt252 = pool.option1;
489491
let option2: felt252 = pool.option2;
490492

491493
// Validation checks using SecurityTrait
492-
self.assert_valid_pool_option(option, option1, option2);
493-
self.assert_pool_not_suspended(@pool);
494-
self.assert_pool_active(@pool);
494+
self.assert_valid_pool_option(option, option1, option2);
495495
self.assert_amount_within_limits(amount, pool.minBetAmount, pool.maxBetAmount);
496496

497497
// Transfer betting amount from the user to the contract
@@ -562,12 +562,13 @@ pub mod Predifi {
562562
/// @param amount The amount to stake.
563563
fn stake(ref self: ContractState, pool_id: u256, amount: u256) {
564564
self.pausable.assert_not_paused();
565+
//Input Validatioin
565566
self.assert_greater_than_zero(amount);
566567
self.assert_greater_than_zero(pool_id);
567-
568+
568569
let pool = self.pools.read(pool_id);
569570
self.assert_pool_exists(@pool);
570-
571+
571572
// Validation checks using SecurityTrait
572573
self.assert_pool_not_suspended(@pool);
573574
self.assert_min_stake_amount(amount);
@@ -1339,7 +1340,6 @@ pub mod Predifi {
13391340
let pool = self.pools.read(pool_id);
13401341

13411342
// Validation checks using SecurityTrait
1342-
self.assert_pool_exists(@pool);
13431343
self.assert_pool_not_suspended(@pool);
13441344
}
13451345

@@ -1374,7 +1374,6 @@ pub mod Predifi {
13741374
let caller = get_caller_address();
13751375

13761376
// Validation checks using SecurityTrait
1377-
self.assert_pool_exists(@pool);
13781377
self.assert_pool_not_suspended(@pool);
13791378

13801379
// 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)