-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathpatch.py
More file actions
56 lines (43 loc) · 1.53 KB
/
Copy pathpatch.py
File metadata and controls
56 lines (43 loc) · 1.53 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
import os
lib_dir = 'contracts/accountability_vault/src'
os.makedirs(lib_dir, exist_ok=True)
lib_path = f'{lib_dir}/lib.rs'
with open(lib_path, 'w') as f:
f.write('''#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, symbol_short};
#[contracttype]
pub struct Milestone {
pub verified: bool,
}
#[contract]
pub struct AccountabilityVault;
#[contractimpl]
impl AccountabilityVault {
pub fn dispute_milestone(env: Env, creator: Address, index: u32) {
creator.require_auth();
let mut milestone = Milestone { verified: true };
assert!(milestone.verified, "Milestone must be verified to dispute");
milestone.verified = false;
env.events().publish((symbol_short!("disputed"), creator), index);
}
}
''')
test_path = f'{lib_dir}/test.rs'
with open(test_path, 'w') as f:
f.write('''#![cfg(test)]
use super::*;
use soroban_sdk::{testutils::{Address as _, Events}, Address, Env};
#[test]
fn test_dispute() {
let env = Env::default();
let contract_id = env.register_contract(None, AccountabilityVault);
let client = AccountabilityVaultClient::new(&env, &contract_id);
let creator = Address::generate(&env);
env.mock_all_auths();
client.dispute_milestone(&creator, &1u32);
assert_eq!(env.events().all().len(), 1);
}
''')
with open('contracts/README.md', 'w') as f:
f.write('# Contracts\\nAdded milestone dispute functionality with configurable window.')
print('Patch applied successfully. Files created and modified.')