Repository: public-awesome/launchpad
Pull request #432 (2022-10-12 04:52:37)

add airdrop price query


Patch:
diff --git a/contracts/vending-minter/src/contract.rs b/contracts/vending-minter/src/contract.rs
index 1359e28d..ac1ff07a 100644
--- a/contracts/vending-minter/src/contract.rs
+++ b/contracts/vending-minter/src/contract.rs
@@ -121,12 +121,21 @@ pub fn instantiate(
     // Use default start trading time if not provided
     let mut collection_info = msg.collection_params.info.clone();
     let offset = factory_params.max_trading_offset_secs;
-    let start_time = msg.init_msg.start_time;
+    let default_start_time_with_offset = msg.init_msg.start_time.plus_seconds(offset);
+    if let Some(trading_start_time) = msg.collection_params.info.trading_start_time {
+        // If trading start time > start_time + offset, return error
+        if trading_start_time > default_start_time_with_offset {
+            return Err(ContractError::InvalidTradingStartTime(
+                trading_start_time,
+                default_start_time_with_offset,
+            ));
+        }
+    }
     let trading_start_time = msg
         .collection_params
         .info
         .trading_start_time
-        .or_else(|| Some(start_time.plus_seconds(offset)));
+        .or(Some(default_start_time_with_offset));
     collection_info.trading_start_time = trading_start_time;
 
     let config = Config {
@@ -734,18 +743,18 @@ pub fn execute_update_trading_start_time(
         .start_time
         .plus_seconds(factory_params.params.max_trading_offset_secs);
 
-    if let Some(start_time) = start_time {
-        if env.block.time > start_time {
+    if let Some(trading_start_time) = start_time {
+        if env.block.time > trading_start_time {
             return Err(ContractError::InvalidTradingStartTime(
                 env.block.time,
-                start_time,
+                trading_start_time,
             ));
         }
-        // If old start time + offset > new start_time, return error
-        if default_start_time_with_offset > start_time {
+        // If new trading_start_time > old start time + offset , return error
+        if trading_start_time > default_start_time_with_offset {
             return Err(ContractError::InvalidTradingStartTime(
+                trading_start_time,
                 default_start_time_with_offset,
-                start_time,
             ));
         }
     }


Test patch:
diff --git a/contracts/vending-minter/src/integration_tests.rs b/contracts/vending-minter/src/integration_tests.rs
index ffdcc0f6..74651960 100644
--- a/contracts/vending-minter/src/integration_tests.rs
+++ b/contracts/vending-minter/src/integration_tests.rs
@@ -1638,6 +1638,64 @@ fn test_invalid_start_time() {
     assert_eq!(err.source().unwrap().to_string(), "AlreadyStarted");
 }
 
+#[test]
+fn invalid_trading_time_during_init() {
+    let num_tokens = 10;
+    let mut router = custom_mock_app();
+    let (creator, _) = setup_accounts(&mut router);
+
+    let minter_code_id = router.store_code(contract_minter());
+    println!("minter_code_id: {}", minter_code_id);
+    let creation_fee = coins(CREATION_FEE, NATIVE_DENOM);
+
+    let factory_code_id = router.store_code(contract_factory());
+    println!("factory_code_id: {}", factory_code_id);
+
+    // set up minter contract
+    let mut params = mock_params();
+    params.code_id = minter_code_id;
+    let factory_addr = router
+        .instantiate_contract(
+            factory_code_id,
+            creator.clone(),
+            &vending_factory::msg::InstantiateMsg {
+                params: params.clone(),
+            },
+            &[],
+            "factory",
+            None,
+        )
+        .unwrap();
+
+    let sg721_code_id = router.store_code(contract_sg721());
+    println!("sg721_code_id: {}", sg721_code_id);
+
+    let mut msg = mock_create_minter(None);
+    msg.init_msg.mint_price = coin(MINT_PRICE, NATIVE_DENOM);
+    msg.init_msg.num_tokens = num_tokens;
+    msg.collection_params.code_id = sg721_code_id;
+    msg.collection_params.info.creator = creator.to_string();
+    // make trading time beyond factory max trading start time offset
+    msg.collection_params.info.trading_start_time = Some(
+        msg.init_msg
+            .start_time
+            .plus_seconds(params.max_trading_offset_secs + 1),
+    );
+
+    let msg = Sg2ExecuteMsg::CreateMinter(msg);
+
+    let err = router
+        .execute_contract(creator, factory_addr, &msg, &creation_fee)
+        .unwrap_err();
+    assert!(err
+        .source()
+        .unwrap()
+        .source()
+        .unwrap()
+        .to_string()
+        .contains("InvalidTradingStartTime"));
+}
+
 #[test]
 fn update_trading_start_time() {
     let mut router = custom_mock_app();
@@ -1664,8 +1722,20 @@ fn update_trading_start_time() {
     );
     assert!(res.is_err());
 
-    // succeeds
+    // invalid start trading time, over offset
     let params = mock_params();
+    let res = router.execute_contract(
+        Addr::unchecked(creator.clone()),
+        Addr::unchecked(minter_addr.clone()),
+        &ExecuteMsg::UpdateTradingStartTime(Some(
+            Timestamp::from_nanos(GENESIS_MINT_START_TIME)
+                .plus_seconds(params.max_trading_offset_secs + 100),
+        )),
+        &[],
+    );
+    assert!(res.is_err());
+
+    // succeeds
     let res = router.execute_contract(
         Addr::unchecked(creator.clone()),
         Addr::unchecked(minter_addr),