aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TestUtils.cpp6
-rw-r--r--TestUtils.h2
-rw-r--r--contracts/AuctionRegistrar.cpp85
-rw-r--r--libsolidity/solidityExecutionFramework.h10
4 files changed, 91 insertions, 12 deletions
diff --git a/TestUtils.cpp b/TestUtils.cpp
index 053ffa21..0ec76386 100644
--- a/TestUtils.cpp
+++ b/TestUtils.cpp
@@ -122,10 +122,6 @@ void ParallelClientBaseFixture::enumerateClients(std::function<void(Json::Value
MoveNonceToTempDir::MoveNonceToTempDir()
{
- crypto::Nonce::setSeedFilePath(m_dir.path() + "/seed");
+ crypto::Nonce::seedFilePath(m_dir.path() + "/seed");
}
-MoveNonceToTempDir::~MoveNonceToTempDir()
-{
- crypto::Nonce::reset();
-}
diff --git a/TestUtils.h b/TestUtils.h
index 94558635..f0c8e50f 100644
--- a/TestUtils.h
+++ b/TestUtils.h
@@ -82,7 +82,7 @@ struct JsonRpcFixture: public ClientBaseFixture
struct MoveNonceToTempDir
{
MoveNonceToTempDir();
- ~MoveNonceToTempDir();
+ ~MoveNonceToTempDir() {}
private:
TransientDirectory m_dir;
};
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)