forked from theblockcade/stellarcade
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.py
More file actions
103 lines (86 loc) · 2.73 KB
/
Copy pathgen.py
File metadata and controls
103 lines (86 loc) · 2.73 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
contracts = [
{
"name": "treasury-streams",
"methods": "pub fn stream_liability_summary(env: Env) -> Summary { Summary {} }\n pub fn pause_impact(env: Env) -> Impact { Impact {} }"
},
{
"name": "sponsor-payouts",
"methods": "pub fn pending_disbursement_summary(env: Env) -> Summary { Summary {} }\n pub fn release_band(env: Env) -> Band { Band {} }"
},
{
"name": "raffle-escrow",
"methods": "pub fn ticket_liability_summary(env: Env) -> Summary { Summary {} }\n pub fn draw_release(env: Env) -> Release { Release {} }"
},
{
"name": "badge-ledger",
"methods": "pub fn issuance_coverage_snapshot(env: Env) -> Snapshot { Snapshot {} }\n pub fn revocation_window(env: Env) -> Window { Window {} }"
}
]
for c in contracts:
base = f"contracts/{c['name']}"
os.makedirs(f"{base}/src", exist_ok=True)
with open(f"{base}/Cargo.toml", "w") as f:
f.write(f'''[package]
name = "{c['name']}"
version = "0.1.0"
edition = "2021"
[dependencies]
soroban-sdk = "20.0.0"
[features]
testutils = ["soroban-sdk/testutils"]
''')
with open(f"{base}/src/lib.rs", "w") as f:
f.write(f'''#![no_std]
use soroban_sdk::{{contract, contractimpl, Env}};
mod storage;
mod types;
#[cfg(test)]
mod test;
use types::*;
#[contract]
pub struct Contract;
#[contractimpl]
impl Contract {{
{c['methods']}
}}
''')
with open(f"{base}/src/storage.rs", "w") as f:
f.write('''use soroban_sdk::contracttype;
#[contracttype]
pub enum DataKey {
State,
}
''')
with open(f"{base}/src/types.rs", "w") as f:
if c['name'] == 'treasury-streams':
types = "pub struct Summary {}\n#[soroban_sdk::contracttype]\npub struct Impact {}"
elif c['name'] == 'sponsor-payouts':
types = "pub struct Summary {}\n#[soroban_sdk::contracttype]\npub struct Band {}"
elif c['name'] == 'raffle-escrow':
types = "pub struct Summary {}\n#[soroban_sdk::contracttype]\npub struct Release {}"
else:
types = "pub struct Snapshot {}\n#[soroban_sdk::contracttype]\npub struct Window {}"
f.write(f'''use soroban_sdk::contracttype;
#[contracttype]
{types}
''')
with open(f"{base}/src/test.rs", "w") as f:
f.write('''#![cfg(test)]
use super::*;
use soroban_sdk::Env;
#[test]
fn test_success_path() {
let env = Env::default();
let contract_id = env.register(Contract, ());
let client = ContractClient::new(&env, &contract_id);
// Success path logic
}
#[test]
fn test_empty_state_path() {
let env = Env::default();
let contract_id = env.register(Contract, ());
let client = ContractClient::new(&env, &contract_id);
// Empty state logic
}
''')