nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mailru/go-clickhouse
Pull request #180 (2024-05-13 17:26:38)

Add transport response callback


Patch:
diff --git a/conn.go b/conn.go
index 6358e64..ca6d772 100644
--- a/conn.go
+++ b/conn.go
@@ -277,6 +277,12 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) (io.ReadCloser,
 		c.cancel = nil
 		return nil, fmt.Errorf("doRequest: transport failed to send a request to ClickHouse: %w", err)
 	}
+
+        if err = callCtxTransportCallback(ctx, req, resp); err != nil {
+                c.cancel = nil
+                return nil, fmt.Errorf("doRequest: transport callback: %w", err)
+        }
+
 	if resp.StatusCode != 200 {
 		msg, err := readResponse(resp)
 		c.cancel = nil
@@ -287,6 +293,7 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) (io.ReadCloser,
 		// response
 		return nil, newError(string(msg))
 	}
+
 	return resp.Body, nil
 }
 
diff --git a/ctx.go b/ctx.go
new file mode 100644
index 0000000..638d84b
--- /dev/null
+++ b/ctx.go
@@ -0,0 +1,28 @@
+package clickhouse
+
+import (
+	"context"
+	"net/http"
+)
+
+type ctxKey uint8
+
+const (
+	ctxTransportCallbackKey ctxKey = iota + 1
+)
+
+// TransportCallback is a transport response callback. Called before processing the http response.
+type TransportCallback func(*http.Request, *http.Response) error
+
+// CtxAddTransportCallback adds callback to work with transport response.
+func CtxAddTransportCallback(ctx context.Context, f TransportCallback) context.Context {
+	return context.WithValue(ctx, ctxTransportCallbackKey, f)
+}
+
+func callCtxTransportCallback(ctx context.Context, req *http.Request, resp *http.Response) error {
+	if f, ok := ctx.Value(ctxTransportCallbackKey).(TransportCallback); ok && f != nil {
+		return f(req, resp)
+	}
+
+	return nil
+}


Test patch:
diff --git a/ctx_test.go b/ctx_test.go
new file mode 100644
index 0000000..9f79bab
--- /dev/null
+++ b/ctx_test.go
@@ -0,0 +1,41 @@
+package clickhouse
+
+import (
+	"context"
+	"errors"
+	"net/http"
+	"net/http/httptest"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func Test_CtxAddTransportCallback(t *testing.T) {
+	var flag bool
+	ctx := context.Background()
+
+	ctx = CtxAddTransportCallback(ctx, func(_ *http.Request, _ *http.Response) error {
+		flag = true
+		return nil
+	})
+
+	assert.NoError(t, callCtxTransportCallback(ctx,
+		httptest.NewRequest(http.MethodGet, "http://localhost", nil), httptest.NewRecorder().Result(),
+	))
+	assert.True(t, flag)
+}
+
+func Test_CtxAddTransportCallback_err(t *testing.T) {
+	var flag bool
+	ctx := context.Background()
+
+	ctx = CtxAddTransportCallback(ctx, func(_ *http.Request, _ *http.Response) error {
+		flag = true
+		return errors.New("some error")
+	})
+
+	assert.EqualError(t, callCtxTransportCallback(ctx,
+		httptest.NewRequest(http.MethodGet, "http://localhost", nil), httptest.NewRecorder().Result(),
+	), "some error")
+	assert.True(t, flag)
+}
Repository: algorand/js-algorand-sdk
Pull request #387 (2021-06-22 19:40:10)

Dynamic opcode
SDK Updates for dynamic opcode accounting, backward jumps, loops, callsub, retsub

shiqizng: Can you please also add the new unit tests for these op codes,  callsub, retsub, loop? like what you had in java sdk. 

Patch:
diff --git a/src/logic/logic.ts b/src/logic/logic.ts
index a23c559..35bda56 100644
--- a/src/logic/logic.ts
+++ b/src/logic/logic.ts
@@ -245,11 +245,12 @@ export function readProgram(
     }
     pc += size;
   }
-
-  if (cost > maxCost) {
-    throw new Error('program too costly to run');
+  // costs calculated dynamically starting in v4
+  if (version < 4 && cost > maxCost) {
+    throw new Error(
+      'program too costly for Teal version < 4. consider using v4.'
+    );
   }
-
   return [ints, byteArrays, true];
 }
 


Test patch:
diff --git a/tests/8.LogicSig.js b/tests/8.LogicSig.js
index eb114ad..e34ae23 100644
--- a/tests/8.LogicSig.js
+++ b/tests/8.LogicSig.js
@@ -321,12 +321,26 @@ describe('Logic validation', () => {
       result = logic.checkProgram(program);
       assert.equal(result, true);
 
-      // 800x keccak256 more is to costly
+      // 800x keccak256 more is too costly
       program = utils.concatArrays(program, new Uint8Array(800).fill(2));
-      assert.throws(
-        () => logic.checkProgram(program),
-        new Error('program too costly to run')
-      );
+      //  old versions
+      const oldVersions = [0x1, 0x2, 0x3];
+      let i;
+      for (i = 0; i < oldVersions.length; i++) {
+        program[0] = oldVersions[i];
+        assert.throws(
+          () => logic.checkProgram(program),
+          new Error(
+            'program too costly for Teal version < 4. consider using v4.'
+          )
+        );
+      }
+      //  new versions
+      const newVersions = [0x4];
+      for (i = 0; i < newVersions.length; i++) {
+        program[0] = newVersions[i];
+        assert.ok(logic.checkProgram(program));
+      }
     });
     it('should support TEAL v2 opcodes', () => {
       assert.ok(logic.langspecEvalMaxVersion >= 2);
@@ -473,6 +487,49 @@ describe('Logic validation', () => {
         0x12,
       ]); // byte 0x11; byte 0x10; b>=
       assert.ok(logic.checkProgram(program));
+
+      // callsub, retsub
+      program = Uint8Array.from([
+        0x04,
+        0x20,
+        0x02,
+        0x01,
+        0x02,
+        0x22,
+        0x88,
+        0x00,
+        0x03,
+        0x23,
+        0x12,
+        0x43,
+        0x49,
+        0x08,
+        0x89,
+      ]); // int 1; callsub double; int 2; ==; return; double: dup; +; retsub;
+      assert.ok(logic.checkProgram(program));
+
+      // loop
+      program = Uint8Array.from([
+        0x04,
+        0x20,
+        0x04,
+        0x01,
+        0x02,
+        0x0a,
+        0x10,
+        0x22,
+        0x23,
+        0x0b,
+        0x49,
+        0x24,
+        0x0c,
+        0x40,
+        0xff,
+        0xf8,
+        0x25,
+        0x12,
+      ]); // int 1; loop: int 2; *; dup; int 10; <; bnz loop; int 16; ==
+      assert.ok(logic.checkProgram(program));
     });
   });
 });
Repository: algorand/js-algorand-sdk
Pull request #501 (2022-01-18 12:32:55)

adding note to use bigint
Adding message to help debug when amount/assetAmount is large as in #500 


Patch:
diff --git a/src/transaction.ts b/src/transaction.ts
index 55e4f16..37035a3 100644
--- a/src/transaction.ts
+++ b/src/transaction.ts
@@ -251,7 +251,9 @@ export class Transaction implements TransactionStorageStructure {
       ) ||
         txn.amount < 0)
     )
-      throw Error('Amount must be a positive number and smaller than 2^64-1');
+      throw Error(
+        'Amount must be a positive number and smaller than 2^64-1. If the number is larger than 2^53-1, use bigint.'
+      );
     if (!Number.isSafeInteger(txn.fee) || txn.fee < 0)
       throw Error('fee must be a positive number and smaller than 2^53-1');
     if (!Number.isSafeInteger(txn.firstRound) || txn.firstRound < 0)
@@ -275,7 +277,7 @@ export class Transaction implements TransactionStorageStructure {
         txn.assetTotal < 0)
     )
       throw Error(
-        'Total asset issuance must be a positive number and smaller than 2^64-1'
+        'Total asset issuance must be a positive number and smaller than 2^64-1. If the number is larger than 2^53-1, use bigint.'
       );
     if (
       txn.assetDecimals !== undefined &&


Test patch:
diff --git a/tests/5.Transaction.js b/tests/5.Transaction.js
index 48ceecb..710d16e 100644
--- a/tests/5.Transaction.js
+++ b/tests/5.Transaction.js
@@ -785,7 +785,9 @@ describe('Sign', () => {
       };
       assert.throws(
         () => new algosdk.Transaction(o),
-        new Error('Amount must be a positive number and smaller than 2^64-1')
+        new Error(
+          'Amount must be a positive number and smaller than 2^64-1. If the number is larger than 2^53-1, use bigint.'
+        )
       );
     });
 
@@ -1152,7 +1154,7 @@ describe('Sign', () => {
       assert.throws(
         () => new algosdk.Transaction(o),
         new Error(
-          'Total asset issuance must be a positive number and smaller than 2^64-1'
+          'Total asset issuance must be a positive number and smaller than 2^64-1. If the number is larger than 2^53-1, use bigint.'
         )
       );
     });