use super::*; #[tokio::test] async fn test_edit_order() -> Result<(), TransportError> { let TestInitialize { context, collect_fee_admin, owner, owner_token_0, owner_token_1, market, market_base_vault, market_quote_vault, price_lots, tokens, account_1, account_2, .. } = TestContext::new_with_market(TestNewMarketInitialize { maker_fee: -100, taker_fee: 200, ..TestNewMarketInitialize::default() }) .await?; let solana = &context.solana.clone(); // Set the initial oracle price set_stub_oracle_price(solana, &tokens[1], collect_fee_admin, 1000.0).await; send_tx( solana, PlaceOrderInstruction { open_orders_account: account_1, open_orders_admin: None, market, signer: owner, user_token_account: owner_token_1, market_vault: market_quote_vault, side: Side::Bid, price_lots, max_base_lots: 2, max_quote_lots_including_fees: 20004, client_order_id: 12, expiry_timestamp: 0, order_type: PlaceOrderType::Limit, self_trade_behavior: SelfTradeBehavior::default(), remainings: vec![], }, ) .await .unwrap(); { let open_orders_account_1 = solana.get_account::(account_1).await; assert_eq!(open_orders_account_1.position.bids_base_lots, 2); assert_eq!(open_orders_account_1.position.asks_base_lots, 0); } // No client Id found, is treated as if order was fully filled send_tx( solana, EditOrderInstruction { open_orders_account: account_1, open_orders_admin: None, market, signer: owner, user_token_account: owner_token_1, market_vault: market_quote_vault, side: Side::Bid, price_lots, max_base_lots: 1, max_quote_lots_including_fees: 10002, client_order_id: 11, expiry_timestamp: 0, order_type: PlaceOrderType::Limit, self_trade_behavior: SelfTradeBehavior::default(), remainings: vec![], expected_cancel_size: 1, }, ) .await .unwrap(); // take 1. send remaining to crank and remove 1 bids_base_lots send_tx( solana, PlaceOrderInstruction { open_orders_account: account_2, open_orders_admin: None, market, signer: owner, user_token_account: owner_token_0, market_vault: market_base_vault, side: Side::Ask, price_lots, max_base_lots: 1, max_quote_lots_including_fees: 10000, client_order_id: 12, expiry_timestamp: 0, order_type: PlaceOrderType::Limit, self_trade_behavior: SelfTradeBehavior::default(), remainings: vec![account_1], }, ) .await .unwrap(); // 1 base_lot has been taken, post only 1 send_tx( solana, EditOrderInstruction { open_orders_account: account_1, open_orders_admin: None, market, signer: owner, user_token_account: owner_token_1, market_vault: market_quote_vault, side: Side::Bid, price_lots, max_base_lots: 2, max_quote_lots_including_fees: 20004, client_order_id: 12, expiry_timestamp: 0, order_type: PlaceOrderType::Limit, self_trade_behavior: SelfTradeBehavior::default(), remainings: vec![], expected_cancel_size: 2, }, ) .await .unwrap(); { let open_orders_account_1 = solana.get_account::(account_1).await; assert_eq!(open_orders_account_1.position.bids_base_lots, 1); assert_eq!(open_orders_account_1.position.asks_base_lots, 0); } Ok(()) }