From 0bdd3914a4dfef7dc5d95ff6104f6a281482d157 Mon Sep 17 00:00:00 2001 From: Artem Date: Sun, 15 Oct 2023 20:14:33 +0200 Subject: [PATCH] Fix: errors scan --- internal/bcd/encoding/base58_test.go | 4 ++++ internal/bcd/tezerrors/error.go | 5 ++--- internal/bcd/tezerrors/error_test.go | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/bcd/encoding/base58_test.go b/internal/bcd/encoding/base58_test.go index 577147fb4..ad3801433 100644 --- a/internal/bcd/encoding/base58_test.go +++ b/internal/bcd/encoding/base58_test.go @@ -52,6 +52,10 @@ func TestDecodeBase58String(t *testing.T) { name: "smart rollup commitment hash", data: "src13MtM1eBzxCH1FBhLAkAiWGW6JbjvycLeH6vuz5k9GSiTYTCTja", want: "751b92ce705ebc551917bb488310498e969d7a1261fda86b509e7da2c780ec8d", + }, { + name: "operation", + data: "opMhUv6wNFN1k5DofyPonyts1mSo4cTjCsk19i4Li7reT1oAQ1K", + want: "e1e56182ae0a8738f804ac7edfd199a6ce617a6ee6751a0c69a4ad972098ebc7", }, } for _, tt := range tests { diff --git a/internal/bcd/tezerrors/error.go b/internal/bcd/tezerrors/error.go index ab4b0f58e..d335b4ba9 100644 --- a/internal/bcd/tezerrors/error.go +++ b/internal/bcd/tezerrors/error.go @@ -39,10 +39,9 @@ func (e *Errors) Scan(value interface{}) error { return fmt.Errorf("pg: can't parse bytea: %q", tmp) } - if tmp[0] != '\\' || tmp[1] != 'x' { - return fmt.Errorf("pg: can't parse bytea: %q", tmp) + if tmp[0] == '\\' && tmp[1] == 'x' { + tmp = tmp[2:] } - tmp = tmp[2:] b := make([]byte, len(tmp)) if _, err := hex.Decode(b, tmp); err != nil { diff --git a/internal/bcd/tezerrors/error_test.go b/internal/bcd/tezerrors/error_test.go index 877da51b9..b05a14215 100644 --- a/internal/bcd/tezerrors/error_test.go +++ b/internal/bcd/tezerrors/error_test.go @@ -286,3 +286,23 @@ func TestInvalidSyntacticConstantError_Parse(t *testing.T) { }) } } + +func TestErrors_Scan(t *testing.T) { + tests := []struct { + name string + e Errors + value interface{} + }{ + { + name: "Test 1", + e: make(Errors, 0), + value: []byte(`5b7b226964223a2270726f746f2e3031322d50736974686163612e6d696368656c736f6e5f76312e72756e74696d655f6572726f72222c226b696e64223a2274656d706f72617279222c227469746c65223a225363726970742072756e74696d65206572726f72222c226465736372223a22546f706c6576656c206572726f7220666f7220616c6c2072756e74696d6520736372697074206572726f7273227d2c7b226964223a2270726f746f2e3031322d50736974686163612e6d696368656c736f6e5f76312e696e76616c69645f636f6e7374616e74222c226b696e64223a227065726d616e656e74222c227469746c65223a22496e76616c696420636f6e7374616e74222c226465736372223a224120646174612065787072657373696f6e2077617320696e76616c696420666f722069747320657870656374656420747970652e227d2c7b226964223a2270726f746f2e3031322d50736974686163612e6d696368656c736f6e5f76312e696e76616c69645f636f6e7374616e74222c226b696e64223a227065726d616e656e74222c227469746c65223a22496e76616c696420636f6e7374616e74222c226465736372223a224120646174612065787072657373696f6e2077617320696e76616c696420666f722069747320657870656374656420747970652e222c20226c6f636174696f6e223a317d2c7b226964223a2270726f746f2e3031322d50736974686163612e6d696368656c736f6e5f76312e696e76616c69645f636f6e7374616e74222c226b696e64223a227065726d616e656e74222c227469746c65223a22496e76616c696420636f6e7374616e74222c226465736372223a224120646174612065787072657373696f6e2077617320696e76616c696420666f722069747320657870656374656420747970652e222c20226c6f636174696f6e223a397d2c7b226964223a2270726f746f2e3031322d50736974686163612e6761735f6578686175737465642e6f7065726174696f6e222c226b696e64223a2274656d706f72617279222c227469746c65223a224761732071756f746120657863656564656420666f7220746865206f7065726174696f6e222c226465736372223a224120736372697074206f72206f6e65206f66206974732063616c6c656520746f6f6b206d6f72652074696d65207468616e20746865206f7065726174696f6e207361696420697420776f756c64227d5d`), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.e.Scan(tt.value) + require.NoError(t, err) + }) + } +}