Skip to content

Commit f4b59d5

Browse files
squadgazzzxdecentralix
authored andcommitted
Drop CIP-20 data (cowprotocol#3771)
# Description This PR drops the CIP-20 data, which has become obsolete. # Changes - [ ] univ2 test still uses this data to validate it is updated in some way, since we don't have other test to cover that. - [ ] Instead of using the CIP-20 structs, the queries migrated to separate function. ## How to test Updated existing tests.
1 parent 9d18354 commit f4b59d5

File tree

2 files changed

+47
-61
lines changed

2 files changed

+47
-61
lines changed

crates/e2e/tests/e2e/database.rs

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use {
55
database::{Address, TransactionHash, byte_array::ByteArray, order_events},
66
e2e::setup::Db,
77
model::order::OrderUid,
8+
sqlx::PgConnection,
89
std::ops::DerefMut,
910
};
1011

@@ -41,57 +42,36 @@ pub struct AuctionTransaction {
4142
pub solution_uid: i64,
4243
}
4344

44-
#[allow(dead_code)]
45-
#[derive(Clone, Debug)]
46-
pub struct Cip20Data {
47-
pub txs: Vec<AuctionTransaction>,
48-
pub participants: Vec<database::solver_competition_v2::AuctionParticipant>,
49-
pub prices: Vec<database::auction_prices::AuctionPrice>,
50-
pub reference_scores: Vec<database::reference_scores::Score>,
51-
pub competition: serde_json::Value,
45+
pub async fn auction_participants(
46+
ex: &mut PgConnection,
47+
auction_id: i64,
48+
) -> anyhow::Result<Vec<Address>> {
49+
const QUERY: &str = r#"
50+
SELECT DISTINCT ps.solver
51+
FROM proposed_solutions ps
52+
WHERE ps.auction_id = $1
53+
"#;
54+
Ok(sqlx::query_as(QUERY).bind(auction_id).fetch_all(ex).await?)
5255
}
5356

54-
/// Returns `Some(data)` if the all the expected CIP-20 data has been indexed
55-
/// for the most recent `auction_id` from `settlements` table.
56-
pub async fn most_recent_cip_20_data(db: &Db) -> Option<Cip20Data> {
57-
let mut db = db.acquire().await.unwrap();
58-
59-
const LAST_AUCTION_ID: &str = "SELECT auction_id FROM settlements WHERE auction_id IS NOT \
60-
NULL ORDER BY auction_id DESC LIMIT 1";
61-
let auction_id: i64 = sqlx::query_scalar(LAST_AUCTION_ID)
62-
.fetch_optional(db.deref_mut())
63-
.await
64-
.unwrap()?;
65-
66-
const TX_QUERY: &str = r"
67-
SELECT * FROM settlements WHERE auction_id = $1";
68-
69-
let txs: Vec<AuctionTransaction> = sqlx::query_as(TX_QUERY)
70-
.bind(auction_id)
71-
.fetch_all(db.deref_mut())
72-
.await
73-
.ok()?;
57+
pub async fn auction_prices(
58+
ex: &mut PgConnection,
59+
auction_id: i64,
60+
) -> anyhow::Result<Vec<database::auction_prices::AuctionPrice>> {
61+
const QUERY: &str = "SELECT * FROM auction_prices WHERE auction_id = $1";
62+
Ok(sqlx::query_as(QUERY).bind(auction_id).fetch_all(ex).await?)
63+
}
7464

75-
let participants =
76-
database::solver_competition_v2::fetch_auction_participants(&mut db, auction_id)
77-
.await
78-
.unwrap();
79-
let prices = database::auction_prices::fetch(&mut db, auction_id)
80-
.await
81-
.unwrap();
82-
let reference_scores = database::reference_scores::fetch(&mut db, auction_id)
83-
.await
84-
.unwrap();
85-
let competition = database::solver_competition::load_by_id(&mut db, auction_id)
86-
.await
87-
.unwrap()?
88-
.json;
65+
pub async fn reference_scores(
66+
ex: &mut PgConnection,
67+
auction_id: i64,
68+
) -> anyhow::Result<Vec<database::reference_scores::Score>> {
69+
const QUERY: &str = "SELECT * FROM reference_scores WHERE auction_id = $1";
70+
Ok(sqlx::query_as(QUERY).bind(auction_id).fetch_all(ex).await?)
71+
}
8972

90-
Some(Cip20Data {
91-
txs,
92-
participants,
93-
prices,
94-
reference_scores,
95-
competition,
96-
})
73+
pub async fn latest_auction_id(ex: &mut PgConnection) -> anyhow::Result<Option<i64>> {
74+
const QUERY: &str = "SELECT auction_id FROM settlements WHERE auction_id IS NOT NULL ORDER BY \
75+
auction_id DESC LIMIT 1";
76+
Ok(sqlx::query_scalar(QUERY).fetch_optional(ex).await?)
9777
}

crates/e2e/tests/e2e/univ2.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,30 @@ async fn test(web3: Web3) {
126126
.await
127127
.unwrap();
128128

129-
let cip_20_data_updated = || async {
130-
onchain.mint_block().await;
131-
let data = match crate::database::most_recent_cip_20_data(services.db()).await {
132-
Some(data) => data,
133-
None => return false,
129+
let data_updated = || async {
130+
let mut db = services.db().acquire().await.unwrap();
131+
let Some(auction_id) = crate::database::latest_auction_id(&mut db).await.unwrap() else {
132+
return false;
134133
};
135134

135+
let participants = crate::database::auction_participants(&mut db, auction_id)
136+
.await
137+
.unwrap();
138+
let prices = crate::database::auction_prices(&mut db, auction_id)
139+
.await
140+
.unwrap();
141+
let scores = crate::database::reference_scores(&mut db, auction_id)
142+
.await
143+
.unwrap();
136144
// sell and buy token price can be found
137-
data.prices.iter().any(|p| p.token.0 == onchain.contracts().weth.address().0)
138-
&& data.prices.iter().any(|p| p.token.0 == token.address().0)
145+
prices.iter().any(|p| p.token.0 == onchain.contracts().weth.address().0)
146+
&& prices.iter().any(|p| p.token.0 == token.address().0)
139147
// solver participated in the competition
140-
&& data.participants.iter().any(|p| p.participant.0 == solver.address().0)
148+
&& participants.iter().any(|p| p.0 == solver.address().0)
141149
// and won the auction
142-
&& data.reference_scores.first().is_some_and(|score| score.solver.0 == solver.address().0)
150+
&& scores.first().is_some_and(|score| score.solver.0 == solver.address().0)
143151
};
144-
wait_for_condition(TIMEOUT, cip_20_data_updated)
145-
.await
146-
.unwrap();
152+
wait_for_condition(TIMEOUT, data_updated).await.unwrap();
147153
}
148154

149155
fn order_events_matching_fuzzy(actual: &[OrderEvent], expected: &[OrderEventLabel]) -> bool {

0 commit comments

Comments
 (0)