aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJim McDonald <Jim@mcdee.net>2017-07-16 20:28:22 +0800
committerJim McDonald <Jim@mcdee.net>2017-07-16 20:28:22 +0800
commitad8d519eb5dbf7852737f827c563c70287a4dfa8 (patch)
tree14b54663d25d4f97fbb7baa9c310cbeb8a6965b6 /common
parent9e80d9bee1363520f4868bd63e42dea79ada24e5 (diff)
downloadgo-tangerine-ad8d519eb5dbf7852737f827c563c70287a4dfa8.tar.gz
go-tangerine-ad8d519eb5dbf7852737f827c563c70287a4dfa8.tar.zst
go-tangerine-ad8d519eb5dbf7852737f827c563c70287a4dfa8.zip
common: tests for EIP55-compliant Address.Hex()
Diffstat (limited to 'common')
-rw-r--r--common/types_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/common/types_test.go b/common/types_test.go
index 154c33063..6f3b31576 100644
--- a/common/types_test.go
+++ b/common/types_test.go
@@ -94,3 +94,34 @@ func TestAddressUnmarshalJSON(t *testing.T) {
}
}
}
+
+func TestAddressHexChecksum(t *testing.T) {
+ var tests = []struct {
+ Input string
+ Output string
+ }{
+ // Test cases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md#specification
+ {"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"},
+ {"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359", "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"},
+ {"0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb", "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"},
+ {"0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"},
+ // Ensure that non-standard length input values are handled correctly
+ {"0xa", "0x000000000000000000000000000000000000000A"},
+ {"0x0a", "0x000000000000000000000000000000000000000A"},
+ {"0x00a", "0x000000000000000000000000000000000000000A"},
+ {"0x000000000000000000000000000000000000000a", "0x000000000000000000000000000000000000000A"},
+ }
+ for i, test := range tests {
+ output := HexToAddress(test.Input).Hex()
+ if output != test.Output {
+ t.Errorf("test #%d: failed to match when it should (%s != %s)", i, output, test.Output)
+ }
+ }
+}
+
+func BenchmarkAddressHex(b *testing.B) {
+ testAddr := HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
+ for n := 0; n < b.N; n++ {
+ testAddr.Hex()
+ }
+}