nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: public-awesome/launchpad
Pull request #450 (2022-10-25 15:13:31)

add transaction index to the seed
Previous version of CosmWasm was not providing the right tx index from the environment, this has been fixed in 0.29 and cosmwasm 1.1.

This PRs adds back the tx index which will depend on how many txs land on the same block.


Patch:
diff --git a/contracts/vending-minter/src/contract.rs b/contracts/vending-minter/src/contract.rs
index 0b5df18f..9aca4663 100644
--- a/contracts/vending-minter/src/contract.rs
+++ b/contracts/vending-minter/src/contract.rs
@@ -601,8 +601,14 @@ fn random_token_list(
     sender: Addr,
     mut tokens: Vec<u32>,
 ) -> Result<Vec<u32>, ContractError> {
-    let sha256 =
-        Sha256::digest(format!("{}{}{}", sender, env.block.height, tokens.len()).into_bytes());
+    let tx_index = if let Some(tx) = &env.transaction {
+        tx.index
+    } else {
+        0
+    };
+    let sha256 = Sha256::digest(
+        format!("{}{}{}{}", sender, env.block.height, tokens.len(), tx_index).into_bytes(),
+    );
     // Cut first 16 bytes from 32 byte value
     let randomness: [u8; 16] = sha256.to_vec()[0..16].try_into().unwrap();
     let mut rng = Xoshiro128PlusPlus::from_seed(randomness);
@@ -620,8 +626,14 @@ fn random_mintable_token_mapping(
     sender: Addr,
 ) -> Result<TokenPositionMapping, ContractError> {
     let num_tokens = MINTABLE_NUM_TOKENS.load(deps.storage)?;
-    let sha256 =
-        Sha256::digest(format!("{}{}{}", sender, num_tokens, env.block.height).into_bytes());
+    let tx_index = if let Some(tx) = &env.transaction {
+        tx.index
+    } else {
+        0
+    };
+    let sha256 = Sha256::digest(
+        format!("{}{}{}{}", sender, num_tokens, env.block.height, tx_index).into_bytes(),
+    );
     // Cut first 16 bytes from 32 byte value
     let randomness: [u8; 16] = sha256.to_vec()[0..16].try_into().unwrap();
 


Test patch:
diff --git a/contracts/vending-minter/src/integration_tests.rs b/contracts/vending-minter/src/integration_tests.rs
index 7b1f858d..3ef1f7f9 100644
--- a/contracts/vending-minter/src/integration_tests.rs
+++ b/contracts/vending-minter/src/integration_tests.rs
@@ -509,7 +509,7 @@ fn happy_path() {
     // Check NFT owned by buyer
     // Random mint token_id 1
     let query_owner_msg = Cw721QueryMsg::OwnerOf {
-        token_id: String::from("1"),
+        token_id: String::from("2"),
         include_expired: None,
     };
Repository: public-awesome/launchpad
Pull request #523 (2023-03-10 18:23:27)

whitelist allow decreasing end time after started


Patch:
diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs
index 6685c844..20785174 100644
--- a/contracts/whitelist/src/contract.rs
+++ b/contracts/whitelist/src/contract.rs
@@ -219,8 +219,9 @@ pub fn execute_update_end_time(
     let mut config = CONFIG.load(deps.storage)?;
     can_execute(&deps, info.sender.clone())?;
 
-    // don't allow updating end time if whitelist is active
-    if env.block.time >= config.start_time {
+    // if whitelist already started don't allow updating end_time unless
+    // it is to reduce it
+    if env.block.time >= config.start_time && end_time > config.end_time {
         return Err(ContractError::AlreadyStarted {});
     }
 


Test patch:
diff --git a/test-suite/src/whitelist/tests/unit_tests.rs b/test-suite/src/whitelist/tests/unit_tests.rs
index 00504f60..3631cfda 100644
--- a/test-suite/src/whitelist/tests/unit_tests.rs
+++ b/test-suite/src/whitelist/tests/unit_tests.rs
@@ -168,6 +168,42 @@ fn update_end_time() {
     execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
 }
 
+#[test]
+fn update_end_time_after() {
+    let mut deps = mock_dependencies();
+    setup_contract(deps.as_mut());
+
+    let msg = ExecuteMsg::UpdateEndTime(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 100));
+    let info = mock_info(ADMIN, &[]);
+    let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap();
+    assert_eq!(res.attributes.len(), 3);
+
+    let mut env = mock_env();
+    env.block.time = Timestamp::from_nanos(GENESIS_MINT_START_TIME + 1);
+
+    // after time started should not let increase it
+    let msg = ExecuteMsg::UpdateEndTime(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 500));
+    let info = mock_info(ADMIN, &[]);
+    assert_eq!(
+        execute(deps.as_mut(), env.clone(), info, msg)
+            .unwrap_err()
+            .to_string(),
+        "AlreadyStarted"
+    );
+
+    // after time started should let decrease the end time
+    let msg = ExecuteMsg::UpdateEndTime(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 50));
+    let info = mock_info(ADMIN, &[]);
+
+    assert!(execute(deps.as_mut(), env.clone(), info, msg).is_ok());
+
+    // after time started should not let decrease before start_time
+    let msg = ExecuteMsg::UpdateEndTime(Timestamp::from_nanos(GENESIS_MINT_START_TIME - 50));
+    let info = mock_info(ADMIN, &[]);
+
+    assert!(execute(deps.as_mut(), env, info, msg).is_err());
+}
+
 #[test]
 fn update_members() {
     let mut deps = mock_dependencies();
Repository: prql/prql
Pull request #902 (2022-08-02 13:33:48)

fix(parser): fix parse error when new lines are present in `table`
Resolves https://github.com/prql/prql/issues/901


Patch:
diff --git a/prql-compiler/src/parser.rs b/prql-compiler/src/parser.rs
index 6cea4a75..c9886902 100644
--- a/prql-compiler/src/parser.rs
+++ b/prql-compiler/src/parser.rs
@@ -1374,6 +1374,45 @@ take 20
         Ok(())
     }
 
+    #[test]
+    fn test_parse_table_with_newlines() -> Result<()> {
+        assert_yaml_snapshot!(ast_of_string(
+          "table x = (
+
+            from x_table
+
+            select only_in_x = foo
+
+          )
+
+          from x",
+          Rule::table
+        )?, @r###"
+        ---
+        Table:
+          name: x
+          pipeline:
+            Pipeline:
+              nodes:
+                - FuncCall:
+                    name: from
+                    args:
+                      - Ident: x_table
+                    named_args: {}
+                - FuncCall:
+                    name: select
+                    args:
+                      - Assign:
+                          name: only_in_x
+                          expr:
+                            Ident: foo
+                    named_args: {}
+          id: ~
+        "###);
+
+        Ok(())
+    }
+
     #[test]
     fn test_inline_pipeline() {
         assert_yaml_snapshot!(ast_of_string("(salary | percentile 50)", Rule::nested_pipeline).unwrap(), @r###"
diff --git a/prql-compiler/src/prql.pest b/prql-compiler/src/prql.pest
index e3c48c3d..d11d56b8 100644
--- a/prql-compiler/src/prql.pest
+++ b/prql-compiler/src/prql.pest
@@ -25,7 +25,7 @@ type_term = { ident ~ type_def? }
 
 table = { "table" ~ ident ~ "=" ~ nested_pipeline }
 
-pipe = _{ NEWLINE | "|" }
+pipe = _{ NEWLINE+ | "|" }
 pipeline = { WHITESPACE* ~ expr_call ~ (pipe ~ expr_call)* }
 
 // See parser.rs for why this is so complicated to parse


Test patch:
diff --git a/book/tests/snapshots/snapshot__run_display_reference_prql@misc-1.prql.snap b/book/tests/snapshots/snapshot__run_display_reference_prql@misc-1.prql.snap
index fa7fc8f8..caca95da 100644
--- a/book/tests/snapshots/snapshot__run_display_reference_prql@misc-1.prql.snap
+++ b/book/tests/snapshots/snapshot__run_display_reference_prql@misc-1.prql.snap
@@ -7,7 +7,6 @@ prql dialect:generic
 
 from `club_ratings`
 filter `rating` != null
-
 group `year` (
   derive [rating_norm = `rating` - ( average `rating` ) / ( stddev `rating` )]
 )
diff --git a/book/tests/snapshots/snapshot__run_display_reference_prql@syntax-6.prql.snap b/book/tests/snapshots/snapshot__run_display_reference_prql@syntax-6.prql.snap
index 2ed1e5ca..87dbf47c 100644
--- a/book/tests/snapshots/snapshot__run_display_reference_prql@syntax-6.prql.snap
+++ b/book/tests/snapshots/snapshot__run_display_reference_prql@syntax-6.prql.snap
@@ -6,7 +6,6 @@ input_file: book/tests/prql/queries/syntax-6.prql
 prql dialect:generic
 
 from `employees`
-
 aggregate [average `salary`]