Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
common: tests for EIP55-compliant Address.Hex()
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jul 16, 2017
1 parent 9e80d9b commit ad8d519
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions common/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit ad8d519

Please sign in to comment.