-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Fixes #2745 This table is supposed to be populated for each `Auction`. All orders that are part of the `Auction` will be saved to this table, during competition. This information is important so we can reconstruct the whole competition environment needed for circuit breaker and on_settlement_event actions. ## How to test Added unit test. CI.
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use { | ||
crate::{auction::AuctionId, OrderUid}, | ||
sqlx::PgConnection, | ||
}; | ||
|
||
pub async fn insert( | ||
ex: &mut PgConnection, | ||
auction_id: AuctionId, | ||
orders: &[OrderUid], | ||
) -> Result<(), sqlx::Error> { | ||
const QUERY: &str = r#"INSERT INTO auction_orders (auction_id, order_uids) VALUES ($1, $2);"#; | ||
sqlx::query(QUERY) | ||
.bind(auction_id) | ||
.bind(orders) | ||
.execute(ex) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn fetch( | ||
ex: &mut PgConnection, | ||
auction_id: AuctionId, | ||
) -> Result<Option<Vec<OrderUid>>, sqlx::Error> { | ||
const QUERY: &str = r#"SELECT order_uids FROM auction_orders WHERE auction_id = $1;"#; | ||
let row = sqlx::query_scalar(QUERY) | ||
.bind(auction_id) | ||
.fetch_optional(ex) | ||
.await?; | ||
Ok(row) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use {super::*, crate::byte_array::ByteArray, sqlx::Connection}; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn postgres_roundtrip() { | ||
let mut db = PgConnection::connect("postgresql://").await.unwrap(); | ||
let mut db = db.begin().await.unwrap(); | ||
crate::clear_DANGER_(&mut db).await.unwrap(); | ||
|
||
let auction = vec![ByteArray([1; 56]), ByteArray([2; 56])]; | ||
|
||
insert(&mut db, 1, &auction).await.unwrap(); | ||
|
||
let output = fetch(&mut db, 1).await.unwrap(); | ||
assert_eq!(output, Some(auction)); | ||
|
||
// non-existent auction | ||
let output = fetch(&mut db, 2).await.unwrap(); | ||
assert!(output.is_none()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- All orders that were part of an auction. An order can appear in multiple auctions. | ||
CREATE TABLE auction_orders ( | ||
auction_id bigint PRIMARY KEY, | ||
order_uids bytea[] NOT NULL | ||
); |