-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathpatch4.py
More file actions
79 lines (61 loc) · 2.4 KB
/
Copy pathpatch4.py
File metadata and controls
79 lines (61 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
lib_path = 'contracts/accountability_vault/src/lib.rs'
with open(lib_path, 'w') as f:
f.write('''#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, Symbol};
#[contracttype]
pub enum DataKey {
DisputeWindow,
}
#[contracttype]
pub struct Milestone {
pub verified: bool,
pub verified_at: u64,
}
#[contract]
pub struct AccountabilityVault;
#[contractimpl]
impl AccountabilityVault {
pub fn configure_window(env: Env, window: u64) {
// Admin or Guardian would call this to configure the window
env.storage().instance().set(&DataKey::DisputeWindow, &window);
}
pub fn dispute_milestone(env: Env, creator: Address, index: u32) {
creator.require_auth();
// Fetch the configured window, default to 86400 seconds (24 hours) if not set
let dispute_window: u64 = env.storage().instance().get(&DataKey::DisputeWindow).unwrap_or(86400);
// Mocking the stored milestone retrieval for this patch
let mut milestone = Milestone { verified: true, verified_at: env.ledger().timestamp() - 100 };
assert!(milestone.verified, "Milestone must be verified to dispute");
let current_time = env.ledger().timestamp();
assert!(
current_time <= milestone.verified_at + dispute_window,
"Dispute window has passed"
);
milestone.verified = false;
let event_name = Symbol::new(&env, "milestone_disputed");
env.events().publish((event_name, creator), index);
}
}
''')
test_path = 'contracts/accountability_vault/src/test.rs'
with open(test_path, 'w') as f:
f.write('''#![cfg(test)]
use super::*;
use soroban_sdk::{testutils::{Address as _, Events, Ledger}, Address, Env};
#[test]
fn test_dispute() {
let env = Env::default();
env.ledger().set_timestamp(1690000000);
let contract_id = env.register_contract(None, AccountabilityVault);
let client = AccountabilityVaultClient::new(&env, &contract_id);
let creator = Address::generate(&env);
env.mock_all_auths();
// Configure window to 1 hour
client.configure_window(&3600u64);
// Call strictly with creator and index
client.dispute_milestone(&creator, &1u32);
assert_eq!(env.events().all().len(), 1);
}
''')
print('Patch 4 applied: Secured the dispute window in contract storage and fixed function signature.')