Skip to content

Commit 17a224d

Browse files
committed
fix: resolve major test compilation issues
- Fixed TokenTest lifetime parameter issue - Added missing Address testutils import to fees.rs - Fixed fetchoracle_result method name to fetch_oracle_result - Added missing MarketState parameters to Market::new calls in types.rs - Fixed ReflectorAsset::other to ReflectorAsset::Other - Added missing default_feed_format method to OracleProvider - Added missing is_supported and is_greater_than methods to OracleConfig - Added create_default_oracle_config method to PredictifyTest - Fixed vec\! macro usage by converting to Vec::new() and push_back() - Removed stray closing brackets from test file Contract main functionality compiles, remaining test issues need vector fixes
1 parent 919cc1a commit 17a224d

4 files changed

Lines changed: 48 additions & 36 deletions

File tree

contracts/predictify-hybrid/src/fees.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ impl FeeAnalytics {
15051505
#[cfg(test)]
15061506
pub mod testing {
15071507
use super::*;
1508+
use soroban_sdk::testutils::Address as _;
15081509

15091510
/// Create a test fee configuration
15101511
pub fn create_test_fee_config() -> FeeConfig {

contracts/predictify-hybrid/src/resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ mod tests {
17621762
});
17631763

17641764
// Multiple oracle resolution calls
1765-
client.fetchoracle_result(&test.market_id, &test.pyth_contract);
1765+
client.fetch_oracle_result(&test.market_id, &test.pyth_contract);
17661766
// Multiple market resolution calls
17671767
client.resolve_market(&test.market_id);
17681768
// Multiple analytics calls

contracts/predictify-hybrid/src/test.rs

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl TokenTest {
5252
pub struct PredictifyTest<'a> {
5353
pub env: Env,
5454
pub contract_id: Address,
55-
pub token_test: TokenTest<'a>,
55+
pub token_test: TokenTest,
5656

5757
pub admin: Address,
5858
pub user: Address,
@@ -115,11 +115,9 @@ impl<'a> PredictifyTest<'a> {
115115
let client = PredictifyHybridClient::new(&self.env, &self.contract_id);
116116

117117
// Create market outcomes
118-
let outcomes = vec![
119-
&self.env,
120-
String::from_str(&self.env, "yes"),
121-
String::from_str(&self.env, "no"),
122-
];
118+
let mut outcomes = Vec::new(&self.env);
119+
outcomes.push_back(String::from_str(&self.env, "yes"));
120+
outcomes.push_back(String::from_str(&self.env, "no"));
123121

124122
// Create market
125123
self.env.mock_all_auths();
@@ -136,6 +134,15 @@ impl<'a> PredictifyTest<'a> {
136134
},
137135
)
138136
}
137+
138+
pub fn create_default_oracle_config(&self) -> OracleConfig {
139+
OracleConfig::new(
140+
OracleProvider::Pyth,
141+
String::from_str(&self.env, "BTC/USD"),
142+
2500000,
143+
String::from_str(&self.env, "gt"),
144+
)
145+
}
139146
}
140147

141148
// Core functionality tests
@@ -144,11 +151,9 @@ fn test_create_market_successful() {
144151
let test = PredictifyTest::setup();
145152
let client = PredictifyHybridClient::new(&test.env, &test.contract_id);
146153
let duration_days = 30;
147-
let outcomes = vec![
148-
&test.env,
149-
String::from_str(&test.env, "yes"),
150-
String::from_str(&test.env, "no"),
151-
];
154+
let mut outcomes = Vec::new(&test.env);
155+
outcomes.push_back(String::from_str(&test.env, "yes"));
156+
outcomes.push_back(String::from_str(&test.env, "no"));
152157

153158
// Create market
154159
let market_id = client.create_market(
@@ -188,11 +193,9 @@ fn test_create_market_successful() {
188193
fn test_create_market_with_non_admin() {
189194
let test = PredictifyTest::setup();
190195
let client = PredictifyHybridClient::new(&test.env, &test.contract_id);
191-
let outcomes = vec![
192-
&test.env,
193-
String::from_str(&test.env, "yes"),
194-
String::from_str(&test.env, "no"),
195-
];
196+
let mut outcomes = Vec::new(&test.env);
197+
outcomes.push_back(String::from_str(&test.env, "yes"));
198+
outcomes.push_back(String::from_str(&test.env, "no"));
196199

197200
client.create_market(
198201
&test.user,
@@ -213,7 +216,7 @@ fn test_create_market_with_non_admin() {
213216
fn test_create_market_with_empty_outcome() {
214217
let test = PredictifyTest::setup();
215218
let client = PredictifyHybridClient::new(&test.env, &test.contract_id);
216-
let outcomes = vec![&test.env];
219+
let outcomes = Vec::new(&test.env);
217220

218221
client.create_market(
219222
&test.admin,
@@ -234,11 +237,9 @@ fn test_create_market_with_empty_outcome() {
234237
fn test_create_market_with_empty_question() {
235238
let test = PredictifyTest::setup();
236239
let client = PredictifyHybridClient::new(&test.env, &test.contract_id);
237-
let outcomes = vec![
238-
&test.env,
239-
String::from_str(&test.env, "yes"),
240-
String::from_str(&test.env, "no"),
241-
];
240+
let mut outcomes = Vec::new(&test.env);
241+
outcomes.push_back(String::from_str(&test.env, "yes"));
242+
outcomes.push_back(String::from_str(&test.env, "no"));
242243

243244
client.create_market(
244245
&test.admin,
@@ -443,7 +444,6 @@ fn test_question_length_validation() {
443444
&test.env,
444445
String::from_str(&test.env, "yes"),
445446
String::from_str(&test.env, "no"),
446-
];
447447

448448
// Test maximum question length (should not exceed 500 characters)
449449
let long_question = "a".repeat(501);
@@ -2395,7 +2395,6 @@ fn test_event_helpers_create_context() {
23952395
String::from_str(&test.env, "Market"),
23962396
String::from_str(&test.env, "Vote"),
23972397
String::from_str(&test.env, "User"),
2398-
];
23992398

24002399
let context = client.create_event_context(&context_parts);
24012400

@@ -2432,7 +2431,6 @@ fn test_event_documentation_event_types() {
24322431
String::from_str(&test.env, "MarketResolved"),
24332432
String::from_str(&test.env, "DisputeCreated"),
24342433
String::from_str(&test.env, "FeeCollected"),
2435-
];
24362434

24372435
for event_type in event_types.iter() {
24382436
// Verify documentation exists for each event type
@@ -2456,7 +2454,6 @@ fn test_event_documentation_usage_examples() {
24562454
String::from_str(&test.env, "EmitVoteCast"),
24572455
String::from_str(&test.env, "GetMarketEvents"),
24582456
String::from_str(&test.env, "ValidateEvent"),
2459-
];
24602457

24612458
for example_type in example_types.iter() {
24622459
// Verify examples exist for each type
@@ -2481,7 +2478,6 @@ fn test_event_testing_utilities() {
24812478
String::from_str(&test.env, "FeeCollected"),
24822479
String::from_str(&test.env, "ErrorLogged"),
24832480
String::from_str(&test.env, "PerformanceMetric"),
2484-
];
24852481

24862482
for event_type in event_types.iter() {
24872483
let success = client.create_test_event(&event_type);
@@ -2711,7 +2707,6 @@ fn test_market_validation_creation() {
27112707
&test.env,
27122708
String::from_str(&test.env, "yes"),
27132709
String::from_str(&test.env, "no"),
2714-
];
27152710

27162711
let oracle_config = test.create_default_oracle_config();
27172712

@@ -2738,7 +2733,6 @@ fn test_market_validation_invalid_question() {
27382733
&test.env,
27392734
String::from_str(&test.env, "yes"),
27402735
String::from_str(&test.env, "no"),
2741-
];
27422736

27432737
let oracle_config = test.create_default_oracle_config();
27442738

@@ -2763,7 +2757,6 @@ fn test_market_validation_invalid_outcomes() {
27632757
let invalid_outcomes = vec![
27642758
&test.env,
27652759
String::from_str(&test.env, "yes"),
2766-
];
27672760

27682761
let oracle_config = test.create_default_oracle_config();
27692762

@@ -2789,7 +2782,6 @@ fn test_market_validation_invalid_duration() {
27892782
&test.env,
27902783
String::from_str(&test.env, "yes"),
27912784
String::from_str(&test.env, "no"),
2792-
];
27932785

27942786
let oracle_config = test.create_default_oracle_config();
27952787

@@ -3113,7 +3105,6 @@ fn test_comprehensive_validation_scenario() {
31133105
&test.env,
31143106
String::from_str(&test.env, "yes"),
31153107
String::from_str(&test.env, "no"),
3116-
];
31173108

31183109
let oracle_config = test.create_default_oracle_config();
31193110

@@ -3169,7 +3160,6 @@ fn test_validation_error_handling() {
31693160
let invalid_outcomes = vec![
31703161
&test.env,
31713162
String::from_str(&test.env, "yes"), // Only one outcome
3172-
];
31733163

31743164
let oracle_config = test.create_default_oracle_config();
31753165

@@ -3195,7 +3185,6 @@ fn test_validation_warnings_and_recommendations() {
31953185
&test.env,
31963186
String::from_str(&test.env, "yes"),
31973187
String::from_str(&test.env, "no"),
3198-
];
31993188

32003189
let oracle_config = test.create_default_oracle_config();
32013190

contracts/predictify-hybrid/src/types.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ impl OracleProvider {
141141
pub fn is_supported(&self) -> bool {
142142
matches!(self, OracleProvider::Reflector)
143143
}
144+
145+
/// Get default feed format for provider
146+
pub fn default_feed_format(&self) -> &'static str {
147+
match self {
148+
OracleProvider::Reflector => "BTC/USD",
149+
OracleProvider::Pyth => "BTC/USD",
150+
OracleProvider::BandProtocol => "BTC/USD",
151+
OracleProvider::DIA => "BTC/USD",
152+
}
153+
}
144154
}
145155

146156
/// Comprehensive oracle configuration for prediction market resolution.
@@ -360,6 +370,16 @@ impl OracleConfig {
360370

361371
Ok(())
362372
}
373+
374+
/// Check if this config is supported
375+
pub fn is_supported(&self) -> bool {
376+
self.provider.is_supported()
377+
}
378+
379+
/// Check if comparison is greater than
380+
pub fn is_greater_than(&self, env: &Env) -> bool {
381+
self.comparison == String::from_str(env, "gt")
382+
}
363383
}
364384

365385
// ===== MARKET TYPES =====
@@ -1871,6 +1891,7 @@ mod tests {
18711891
outcomes,
18721892
env.ledger().timestamp() + 86400,
18731893
oracle_config,
1894+
MarketState::Active,
18741895
);
18751896

18761897
assert!(market.is_active(env.ledger().timestamp()));
@@ -1882,7 +1903,7 @@ mod tests {
18821903
fn test_reflector_asset() {
18831904
let env = soroban_sdk::Env::default();
18841905
let symbol = Symbol::new(&env, "BTC");
1885-
let asset = ReflectorAsset::other(symbol);
1906+
let asset = ReflectorAsset::Other(symbol);
18861907

18871908
assert!(asset.is_other());
18881909
assert!(!asset.is_stellar());
@@ -1909,6 +1930,7 @@ mod tests {
19091930
outcomes,
19101931
env.ledger().timestamp() + 86400,
19111932
oracle_config,
1933+
MarketState::Active,
19121934
);
19131935

19141936
let state = MarketState::from_market(&market, env.ledger().timestamp());

0 commit comments

Comments
 (0)