Skip to content

Commit

Permalink
feat(smart-contracts): add test for try bid works
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Mar 8, 2024
1 parent d2fcc4e commit 60ac8c1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 3 additions & 1 deletion contracts/injective-auction-pool/src/executions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ pub(crate) fn try_bid(
auction_round: u64,
basket_value: Uint128,
) -> Result<Response, ContractError> {
cw_utils::nonpayable(&info)?;

// only whitelist addresses or the contract itself can bid on the auction
let config = CONFIG.load(deps.storage)?;
if info.sender != env.contract.address || !config.whitelisted_addresses.contains(&info.sender) {
if info.sender != env.contract.address && !config.whitelisted_addresses.contains(&info.sender) {
return Err(ContractError::Unauthorized {});
}
let current_auction_round_response = query_current_auction(deps.as_ref())?;
Expand Down
45 changes: 44 additions & 1 deletion contracts/injective-auction-pool/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use cosmwasm_std::{
ContractResult as CwContractResult, CosmosMsg, Decimal, Empty, Env, MemoryStorage, MessageInfo,
OwnedDeps, Querier, QuerierResult, QueryRequest, Uint128, WasmMsg,
};
use injective_auction::auction::{Coin, QueryCurrentAuctionBasketResponse};
use injective_auction::auction::{Coin, MsgBid, QueryCurrentAuctionBasketResponse};
use injective_auction::auction_pool::{ExecuteMsg, InstantiateMsg};
use prost::Message;
use treasurechest::tf::tokenfactory::TokenFactoryType;

use crate::contract::{execute, instantiate};
Expand Down Expand Up @@ -304,3 +305,45 @@ fn exit_pool_fails() {
);
assert_eq!(res.attributes, vec![attr("action", "exit_pool")]);
}

#[test]
fn try_bid_works() {
let (mut deps, env) = init();

// join pool with one user & enough funds to be able to outbid default highest bid (20000)
let info = mock_info("robinho", &coins(30_000, "native_denom"));
let msg = ExecuteMsg::JoinPool {
auction_round: 1,
basket_value: Uint128::from(10_000u128),
};
let _ = execute(deps.as_mut().branch(), env.clone(), info, msg).unwrap();

let info = mock_info("bot", &[]);
let msg = ExecuteMsg::TryBid {
auction_round: 1,
basket_value: Uint128::from(10_000u128),
};
let res = execute(deps.as_mut().branch(), env.clone(), info, msg).unwrap();

// check the stargate bid message is correct, should only bid minimum allowed bid amount
assert_eq!(
res.messages[0].msg,
CosmosMsg::Stargate {
type_url: "/injective.auction.v1beta1.MsgBid".to_string(),
value: {
let msg = MsgBid {
sender: env.contract.address.to_string(),
bid_amount: Some(injective_auction::auction::Coin {
denom: "native_denom".to_string(),
amount: "20051".to_string(),
}),
round: 1,
};
Binary(msg.encode_to_vec())
},
}
);

// checking attributes are fine
assert_eq!(res.attributes, vec![attr("action", "try_bid"), attr("amount", "20051"),]);
}

0 comments on commit 60ac8c1

Please sign in to comment.