Skip to content

Commit

Permalink
Fix: errors scan
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 15, 2023
1 parent f76ef45 commit 0bdd391
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/bcd/encoding/base58_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions internal/bcd/tezerrors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions internal/bcd/tezerrors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit 0bdd391

Please sign in to comment.