diff options
author | chriseth <c@ethdev.com> | 2015-08-06 17:01:59 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-08-06 23:48:27 +0800 |
commit | 5aec9fba478e57e2173f596eed3868743c3d8a7d (patch) | |
tree | fc966a3a262c574471bf8bd6bafa70cb0dbab637 | |
parent | e24d24b34bb05fcf3ed9413f426fcfad9c618809 (diff) | |
download | dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar.gz dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar.bz2 dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar.lz dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar.xz dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.tar.zst dexon-solidity-5aec9fba478e57e2173f596eed3868743c3d8a7d.zip |
Actual auction tests.
-rw-r--r-- | contracts/AuctionRegistrar.cpp | 85 | ||||
-rw-r--r-- | libsolidity/solidityExecutionFramework.h | 10 |
2 files changed, 89 insertions, 6 deletions
diff --git a/contracts/AuctionRegistrar.cpp b/contracts/AuctionRegistrar.cpp index 3832e8e0..7c5d9fa3 100644 --- a/contracts/AuctionRegistrar.cpp +++ b/contracts/AuctionRegistrar.cpp @@ -289,6 +289,9 @@ protected: return callString("disown", _name); } }; + + u256 const m_biddingTime = u256(7 * 24 * 3600); + u256 const m_renewalInterval = u256(365 * 24 * 3600); }; } @@ -393,6 +396,7 @@ BOOST_AUTO_TEST_CASE(disown) registrar.setContent(name, h256(u256(123))); registrar.setAddress(name, u160(124), true); registrar.setSubRegistrar(name, u160(125)); + BOOST_CHECK_EQUAL(registrar.name(u160(124)), name); // someone else tries disowning m_sender = Address(0x128); @@ -405,11 +409,86 @@ BOOST_AUTO_TEST_CASE(disown) BOOST_CHECK_EQUAL(registrar.addr(name), 0); BOOST_CHECK_EQUAL(registrar.subRegistrar(name), 0); BOOST_CHECK_EQUAL(registrar.content(name), h256()); + BOOST_CHECK_EQUAL(registrar.name(u160(124)), ""); +} + +BOOST_AUTO_TEST_CASE(auction_simple) +{ + deployRegistrar(); + string name = "x"; + m_sender = Address(0x123); + RegistrarInterface registrar(*this); + // initiate auction + registrar.setNextValue(8); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0); + // "wait" until auction end + m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime + 10); + // trigger auction again + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x123); } -//@todo: -// - reverse lookup -// - actual auction +BOOST_AUTO_TEST_CASE(auction_bidding) +{ + deployRegistrar(); + string name = "x"; + m_sender = Address(0x123); + RegistrarInterface registrar(*this); + // initiate auction + registrar.setNextValue(8); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0); + // overbid self + m_envInfo.setTimestamp(m_biddingTime - 10); + registrar.setNextValue(12); + registrar.reserve(name); + // another bid by someone else + m_sender = Address(0x124); + m_envInfo.setTimestamp(2 * m_biddingTime - 50); + registrar.setNextValue(13); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0); + // end auction by first bidder (which is not highest) trying to overbid again (too late) + m_sender = Address(0x123); + m_envInfo.setTimestamp(4 * m_biddingTime); + registrar.setNextValue(20); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x124); +} + +BOOST_AUTO_TEST_CASE(auction_renewal) +{ + deployRegistrar(); + string name = "x"; + RegistrarInterface registrar(*this); + // register name by auction + m_sender = Address(0x123); + registrar.setNextValue(8); + registrar.reserve(name); + m_envInfo.setTimestamp(4 * m_biddingTime); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x123); + + // try to re-register before interval end + m_sender = Address(0x222); + registrar.setNextValue(80); + m_envInfo.setTimestamp(m_envInfo.timestamp() + m_renewalInterval - 1); + registrar.reserve(name); + m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime); + // if there is a bug in the renewal logic, this would transfer the ownership to 0x222, + // but if there is no bug, this will initiate the auction, albeit with a zero bid + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x123); + + m_envInfo.setTimestamp(m_envInfo.timestamp() + 2); + registrar.setNextValue(80); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x123); + m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime + 2); + registrar.reserve(name); + BOOST_CHECK_EQUAL(registrar.owner(name), 0x222); +} BOOST_AUTO_TEST_SUITE_END() diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index 3f443720..98241b2f 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -171,6 +171,8 @@ public: public: ContractInterface(ExecutionFramework& _framework): m_framework(_framework) {} + void setNextValue(u256 const& _value) { m_nextValue = _value; } + protected: template <class... Args> bytes const& call(std::string const& _sig, Args const&... _arguments) @@ -210,11 +212,13 @@ public: std::string callAddressReturnsString(std::string const& _name, u160 const& _arg) { - bytes const& ret = call(_name + "(address)", _arg); + bytesConstRef ret = ref(call(_name + "(address)", _arg)); BOOST_REQUIRE(ret.size() >= 0x20); + u256 offset = eth::abiOut<u256>(ret); + BOOST_REQUIRE_EQUAL(offset, 0x20); u256 len = eth::abiOut<u256>(ret); - BOOST_REQUIRE(ret.size() == (0x20 + len) / 32 * 32); - return std::string(ret.begin() + 0x20, ret.begin() + 0x20 + size_t(len)); + BOOST_REQUIRE_EQUAL(ret.size(), ((len + 0x1f) / 0x20) * 0x20); + return ret.cropped(0, size_t(len)).toString(); } h256 callStringReturnsBytes32(std::string const& _name, std::string const& _arg) |