diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-17 08:40:50 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-17 08:46:45 +0800 |
commit | 53796c0fe8bfd6ff2707bd12dd3141169489f763 (patch) | |
tree | 092a1703bf0d44b6eb7af6282b213c098f65ab84 /test/libdevcore/Checksum.cpp | |
parent | f7249abe284b5f29996621f2e19cab7f09f51785 (diff) | |
download | dexon-solidity-53796c0fe8bfd6ff2707bd12dd3141169489f763.tar.gz dexon-solidity-53796c0fe8bfd6ff2707bd12dd3141169489f763.tar.zst dexon-solidity-53796c0fe8bfd6ff2707bd12dd3141169489f763.zip |
Add tests for getChecksummedAddress
Diffstat (limited to 'test/libdevcore/Checksum.cpp')
-rw-r--r-- | test/libdevcore/Checksum.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/libdevcore/Checksum.cpp b/test/libdevcore/Checksum.cpp index 17a17d22..4eedbd99 100644 --- a/test/libdevcore/Checksum.cpp +++ b/test/libdevcore/Checksum.cpp @@ -19,6 +19,8 @@ */ #include <libdevcore/CommonData.h> +#include <libdevcore/Exceptions.h> + #include "../TestHelper.h" @@ -31,6 +33,38 @@ namespace test BOOST_AUTO_TEST_SUITE(Checksum) +BOOST_AUTO_TEST_CASE(calculate) +{ + BOOST_CHECK(!getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed").empty()); + BOOST_CHECK(!getChecksummedAddress("0x0123456789abcdefABCDEF0123456789abcdefAB").empty()); + // too short + BOOST_CHECK_THROW(getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beae"), InvalidAddress); + BOOST_CHECK_THROW(getChecksummedAddress("5aaeb6053f3e94c9b9a09f33669435e7ef1beae"), InvalidAddress); + // too long + BOOST_CHECK_THROW(getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1"), InvalidAddress); + BOOST_CHECK_THROW(getChecksummedAddress("5aaeb6053f3e94c9b9a09f33669435e7ef1beaed1"), InvalidAddress); + // non-hex character + BOOST_CHECK_THROW(getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaeK"), InvalidAddress); + + // the official test suite from EIP-55 + vector<string> cases { + // all upper case + "0x52908400098527886E0F7030069857D2E4169EE7", + "0x8617E340B3D01FA5F11F306F4090FD50E238070D", + // all lower case + "0xde709f2102306220921060314715629080e2fb77", + "0x27b1fdb04752bbc536007a920d24acb045561c26", + // regular + "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", + "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", + "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB", + "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb" + }; + + for (size_t i = 0; i < cases.size(); i++) + BOOST_REQUIRE_MESSAGE(getChecksummedAddress(cases[i]) == cases[i], cases[i]); +} + BOOST_AUTO_TEST_CASE(regular) { BOOST_CHECK(passesAddressChecksum("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", true)); |