-
Notifications
You must be signed in to change notification settings - Fork 41
fix: validate tron address checksum #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5b65880
66be504
01a31e1
c6f5bac
8836fcc
0caba94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package types_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
@@ -9,6 +10,10 @@ | |
| ) | ||
|
|
||
| func TestValidateTronAddress(t *testing.T) { | ||
| nonTronPrefix := byte(0x00) | ||
| nonTronPayload := append([]byte{nonTronPrefix}, bytes.Repeat([]byte{0x11}, tronaddress.AddressLength-1)...) | ||
|
Check failure on line 14 in x/tron/types/address_test.go
|
||
| shortTronPayload := append([]byte{tronaddress.TronBytePrefix}, bytes.Repeat([]byte{0x11}, tronaddress.AddressLength-2)...) | ||
|
Check failure on line 15 in x/tron/types/address_test.go
|
||
|
|
||
| testCases := []struct { | ||
| testName string | ||
| value string | ||
|
|
@@ -25,13 +30,13 @@ | |
| testName: "address length not match", | ||
| value: "abcdddddd", | ||
| expectPass: false, | ||
| errStr: "wrong length", | ||
| errStr: "invalid address length", | ||
| }, | ||
| { | ||
| testName: "address length great than tron address", | ||
| value: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t6666", | ||
| expectPass: false, | ||
| errStr: "wrong length", | ||
| errStr: "invalid address length", | ||
| }, | ||
| { | ||
| testName: "lowercase address", | ||
|
|
@@ -45,6 +50,18 @@ | |
| expectPass: false, | ||
| errStr: "doesn't pass format validation", | ||
| }, | ||
| { | ||
| testName: "base58check address with non-tron prefix", | ||
| value: troncommon.EncodeCheck(nonTronPayload), | ||
|
Check failure on line 55 in x/tron/types/address_test.go
|
||
| expectPass: false, | ||
| errStr: "invalid tron prefix", | ||
| }, | ||
|
NikYak228 marked this conversation as resolved.
|
||
| { | ||
| testName: "base58check address with invalid decoded length", | ||
| value: troncommon.EncodeCheck(shortTronPayload), | ||
|
Check failure on line 61 in x/tron/types/address_test.go
|
||
| expectPass: false, | ||
| errStr: "invalid address length", | ||
| }, | ||
|
Comment on lines
+62
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Make the decoded-length regression case branch-specific. Line 63 ( Suggested patch@@
{
testName: "base58check address with invalid decoded length",
value: troncommon.EncodeCheck(shortTronPayload),
expectPass: false,
- errStr: "invalid address length",
+ errStr: "expected decoded",
},
@@
- require.Contains(t, err.Error(), testCase.errStr, testCase.value)
+ require.Error(t, err)
+ require.Contains(t, err.Error(), testCase.errStr, testCase.value)As per path instructions, "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request". Also applies to: 79-79 🤖 Prompt for AI AgentsSource: Path instructions |
||
| { | ||
| testName: "normal address", | ||
| value: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", | ||
|
|
@@ -59,7 +76,7 @@ | |
| require.NoError(t, err) | ||
| return | ||
| } | ||
| require.EqualValues(t, testCase.errStr, err.Error(), testCase.value) | ||
| require.Contains(t, err.Error(), testCase.errStr, testCase.value) | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.