Skip to content

Commit 8edae85

Browse files
committed
unit test
1 parent ab13dce commit 8edae85

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

cmd/ulxly/ulxly.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func logAndReturnJsonError(ctx context.Context, client *ethclient.Client, tx *ty
600600
return err
601601
}
602602

603-
reason, decodeErr := smcerror.DecodeInterfaceSmcErrorCode(jsonError.Data)
603+
reason, decodeErr := smcerror.DecodeSmcErrorCode(jsonError.Data)
604604
if decodeErr != nil {
605605
log.Error().Err(err).Msg("unable to decode smart contract error")
606606
return err

errors/smc.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ var ErrorMessages = map[string]string{
233233
"0x3a64d973":"OnlyChainsWithPessimisticProofsError",
234234
}
235235

236-
func DecodeInterfaceSmcErrorCode(errorCode interface{}) (string, error) {
236+
func DecodeSmcErrorCode(errorCode interface{}) (string, error) {
237237
codeStr, ok := errorCode.(string)
238238
if !ok {
239239
return "", errors.New("jsonError.Data is not a string, unable to decode smart contract error")
@@ -243,10 +243,3 @@ func DecodeInterfaceSmcErrorCode(errorCode interface{}) (string, error) {
243243
}
244244
return codeStr + " (unknown selector)", nil
245245
}
246-
247-
func DecodeStringSmcErrorCode(errorCode string) string {
248-
if msg, exists := ErrorMessages[errorCode]; exists {
249-
return msg
250-
}
251-
return errorCode + " (unknown selector)"
252-
}

errors/smc_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package errors_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/0xPolygon/polygon-cli/errors"
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestDecodeSmcErrorCode (t *testing.T) {
12+
reason, err := errors.DecodeSmcErrorCode("0x1a070d9a")
13+
require.NoError(t, err)
14+
assert.Equal(t, "InitSequencedBatchDoesNotMatchError", reason)
15+
16+
reason, err = errors.DecodeSmcErrorCode("0x52ad525a")
17+
require.NoError(t, err)
18+
assert.Equal(t, "InvalidPessimisticProofError", reason)
19+
20+
reason, err = errors.DecodeSmcErrorCode("0x9aad315a")
21+
require.NoError(t, err)
22+
assert.Equal(t, "0x9aad315a (unknown selector)", reason)
23+
24+
var emptyInterface interface{}
25+
reason, err = errors.DecodeSmcErrorCode(emptyInterface)
26+
require.Error(t, err)
27+
28+
code := "0x3bbd317c"
29+
reason, err = errors.DecodeSmcErrorCode(code)
30+
require.NoError(t, err)
31+
assert.Equal(t, "0x3bbd317c (unknown selector)", reason)
32+
}
33+

0 commit comments

Comments
 (0)