2015-08-04 14:31:27 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2015-08-04 14:31:27 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2015-08-04 14:31:27 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2015-08-04 14:31:27 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2015-08-04 14:31:27 +00:00
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2015
|
|
|
|
* Tests for a fixed fee registrar contract.
|
|
|
|
*/
|
|
|
|
|
2016-06-09 16:54:29 +00:00
|
|
|
#include <test/libsolidity/SolidityExecutionFramework.h>
|
2017-10-18 23:12:32 +00:00
|
|
|
#include <test/contracts/ContractInterface.h>
|
2019-06-26 16:42:24 +00:00
|
|
|
#include <test/EVMHost.h>
|
|
|
|
|
2020-05-12 14:04:13 +00:00
|
|
|
#include <libsolutil/LazyInit.h>
|
|
|
|
|
2019-06-26 16:42:24 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
2020-05-12 14:04:13 +00:00
|
|
|
#include <optional>
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::test;
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::frontend::test
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static char const* registrarCode = R"DELIMITER(
|
2020-12-03 22:05:05 +00:00
|
|
|
pragma solidity >=0.7.0 <0.9.0;
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2019-09-19 19:31:42 +00:00
|
|
|
abstract contract NameRegister {
|
2019-11-05 17:25:34 +00:00
|
|
|
function addr(string memory _name) public virtual view returns (address o_owner);
|
|
|
|
function name(address _owner) public view virtual returns (string memory o_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 19:31:42 +00:00
|
|
|
abstract contract Registrar is NameRegister {
|
2015-08-04 14:31:27 +00:00
|
|
|
event Changed(string indexed name);
|
|
|
|
event PrimaryChanged(string indexed name, address indexed addr);
|
|
|
|
|
2019-11-05 17:25:34 +00:00
|
|
|
function owner(string memory _name) public view virtual returns (address o_owner);
|
|
|
|
function addr(string memory _name) public virtual override view returns (address o_address);
|
|
|
|
function subRegistrar(string memory _name) public virtual view returns (address o_subRegistrar);
|
|
|
|
function content(string memory _name) public virtual view returns (bytes32 o_content);
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2019-11-05 17:25:34 +00:00
|
|
|
function name(address _owner) public virtual override view returns (string memory o_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 19:31:42 +00:00
|
|
|
abstract contract AuctionSystem {
|
2015-08-04 14:31:27 +00:00
|
|
|
event AuctionEnded(string indexed _name, address _winner);
|
|
|
|
event NewBid(string indexed _name, address _bidder, uint _value);
|
|
|
|
|
|
|
|
/// Function that is called once an auction ends.
|
2019-11-05 17:25:34 +00:00
|
|
|
function onAuctionEnd(string memory _name) internal virtual;
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2018-09-12 14:21:43 +00:00
|
|
|
function bid(string memory _name, address payable _bidder, uint _value) internal {
|
2018-06-28 13:19:53 +00:00
|
|
|
Auction storage auction = m_auctions[_name];
|
2020-05-05 11:33:28 +00:00
|
|
|
if (auction.endDate > 0 && block.timestamp > auction.endDate)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
2018-06-26 18:09:54 +00:00
|
|
|
emit AuctionEnded(_name, auction.highestBidder);
|
2015-08-04 14:31:27 +00:00
|
|
|
onAuctionEnd(_name);
|
|
|
|
delete m_auctions[_name];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (msg.value > auction.highestBid)
|
|
|
|
{
|
|
|
|
// new bid on auction
|
|
|
|
auction.secondHighestBid = auction.highestBid;
|
|
|
|
auction.sumOfBids += _value;
|
|
|
|
auction.highestBid = _value;
|
|
|
|
auction.highestBidder = _bidder;
|
2020-05-05 11:33:28 +00:00
|
|
|
auction.endDate = block.timestamp + c_biddingTime;
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2018-06-26 18:09:54 +00:00
|
|
|
emit NewBid(_name, _bidder, _value);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint constant c_biddingTime = 7 days;
|
|
|
|
|
|
|
|
struct Auction {
|
2018-09-12 14:21:43 +00:00
|
|
|
address payable highestBidder;
|
2015-08-04 14:31:27 +00:00
|
|
|
uint highestBid;
|
|
|
|
uint secondHighestBid;
|
|
|
|
uint sumOfBids;
|
|
|
|
uint endDate;
|
|
|
|
}
|
|
|
|
mapping(string => Auction) m_auctions;
|
|
|
|
}
|
|
|
|
|
|
|
|
contract GlobalRegistrar is Registrar, AuctionSystem {
|
|
|
|
struct Record {
|
2018-09-12 14:21:43 +00:00
|
|
|
address payable owner;
|
2015-08-04 14:31:27 +00:00
|
|
|
address primary;
|
|
|
|
address subRegistrar;
|
|
|
|
bytes32 content;
|
|
|
|
uint renewalDate;
|
|
|
|
}
|
|
|
|
|
2018-06-20 22:01:40 +00:00
|
|
|
uint constant c_renewalInterval = 365 days;
|
2015-08-04 14:31:27 +00:00
|
|
|
uint constant c_freeBytes = 12;
|
|
|
|
|
2020-06-23 12:14:24 +00:00
|
|
|
constructor() {
|
2015-08-04 14:31:27 +00:00
|
|
|
// TODO: Populate with hall-of-fame.
|
|
|
|
}
|
|
|
|
|
2019-09-16 12:33:43 +00:00
|
|
|
function onAuctionEnd(string memory _name) internal override {
|
2018-06-28 13:19:53 +00:00
|
|
|
Auction storage auction = m_auctions[_name];
|
|
|
|
Record storage record = m_toRecord[_name];
|
|
|
|
address previousOwner = record.owner;
|
2020-05-05 11:33:28 +00:00
|
|
|
record.renewalDate = block.timestamp + c_renewalInterval;
|
2015-08-04 14:31:27 +00:00
|
|
|
record.owner = auction.highestBidder;
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2018-05-30 21:02:47 +00:00
|
|
|
if (previousOwner != 0x0000000000000000000000000000000000000000) {
|
2016-06-28 22:14:22 +00:00
|
|
|
if (!record.owner.send(auction.sumOfBids - auction.highestBid / 100))
|
2018-07-11 23:43:19 +00:00
|
|
|
revert();
|
2016-08-24 19:31:59 +00:00
|
|
|
} else {
|
2016-06-28 22:14:22 +00:00
|
|
|
if (!auction.highestBidder.send(auction.highestBid - auction.secondHighestBid))
|
2018-07-11 23:43:19 +00:00
|
|
|
revert();
|
2016-06-28 22:14:22 +00:00
|
|
|
}
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 13:19:50 +00:00
|
|
|
function reserve(string calldata _name) external payable {
|
2015-08-04 14:31:27 +00:00
|
|
|
if (bytes(_name).length == 0)
|
2018-07-11 23:43:19 +00:00
|
|
|
revert();
|
2015-08-04 14:31:27 +00:00
|
|
|
bool needAuction = requiresAuction(_name);
|
|
|
|
if (needAuction)
|
|
|
|
{
|
2020-05-05 11:33:28 +00:00
|
|
|
if (block.timestamp < m_toRecord[_name].renewalDate)
|
2018-07-11 23:43:19 +00:00
|
|
|
revert();
|
2020-12-03 22:05:05 +00:00
|
|
|
bid(_name, payable(msg.sender), msg.value);
|
2016-08-24 19:31:59 +00:00
|
|
|
} else {
|
2018-07-11 11:23:33 +00:00
|
|
|
Record storage record = m_toRecord[_name];
|
2018-05-30 21:02:47 +00:00
|
|
|
if (record.owner != 0x0000000000000000000000000000000000000000)
|
2018-07-11 23:43:19 +00:00
|
|
|
revert();
|
2020-12-03 22:05:05 +00:00
|
|
|
m_toRecord[_name].owner = payable(msg.sender);
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 04:18:50 +00:00
|
|
|
function requiresAuction(string memory _name) internal returns (bool) {
|
2015-08-04 14:31:27 +00:00
|
|
|
return bytes(_name).length < c_freeBytes;
|
|
|
|
}
|
|
|
|
|
2018-07-12 04:18:50 +00:00
|
|
|
modifier onlyrecordowner(string memory _name) { if (m_toRecord[_name].owner == msg.sender) _; }
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2018-09-12 14:21:43 +00:00
|
|
|
function transfer(string memory _name, address payable _newOwner) onlyrecordowner(_name) public {
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toRecord[_name].owner = _newOwner;
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 14:17:01 +00:00
|
|
|
function disown(string memory _name) onlyrecordowner(_name) public {
|
2015-08-04 14:31:27 +00:00
|
|
|
if (stringsEqual(m_toName[m_toRecord[_name].primary], _name))
|
|
|
|
{
|
2018-06-26 18:09:54 +00:00
|
|
|
emit PrimaryChanged(_name, m_toRecord[_name].primary);
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toName[m_toRecord[_name].primary] = "";
|
|
|
|
}
|
|
|
|
delete m_toRecord[_name];
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 14:17:01 +00:00
|
|
|
function setAddress(string memory _name, address _a, bool _primary) onlyrecordowner(_name) public {
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toRecord[_name].primary = _a;
|
|
|
|
if (_primary)
|
|
|
|
{
|
2018-06-27 08:48:03 +00:00
|
|
|
emit PrimaryChanged(_name, _a);
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toName[_a] = _name;
|
|
|
|
}
|
2018-06-27 08:48:03 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
2018-07-11 14:17:01 +00:00
|
|
|
function setSubRegistrar(string memory _name, address _registrar) onlyrecordowner(_name) public {
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toRecord[_name].subRegistrar = _registrar;
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
2018-07-11 14:17:01 +00:00
|
|
|
function setContent(string memory _name, bytes32 _content) onlyrecordowner(_name) public {
|
2015-08-04 14:31:27 +00:00
|
|
|
m_toRecord[_name].content = _content;
|
2018-06-26 18:09:54 +00:00
|
|
|
emit Changed(_name);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stringsEqual(string storage _a, string memory _b) internal returns (bool) {
|
|
|
|
bytes storage a = bytes(_a);
|
|
|
|
bytes memory b = bytes(_b);
|
|
|
|
if (a.length != b.length)
|
|
|
|
return false;
|
|
|
|
// @todo unroll this loop
|
|
|
|
for (uint i = 0; i < a.length; i ++)
|
|
|
|
if (a[i] != b[i])
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-16 12:33:43 +00:00
|
|
|
function owner(string memory _name) public override view returns (address) { return m_toRecord[_name].owner; }
|
|
|
|
function addr(string memory _name) public override view returns (address) { return m_toRecord[_name].primary; }
|
|
|
|
function subRegistrar(string memory _name) public override view returns (address) { return m_toRecord[_name].subRegistrar; }
|
|
|
|
function content(string memory _name) public override view returns (bytes32) { return m_toRecord[_name].content; }
|
|
|
|
function name(address _addr) public override view returns (string memory o_name) { return m_toName[_addr]; }
|
2015-08-04 14:31:27 +00:00
|
|
|
|
|
|
|
mapping (address => string) m_toName;
|
|
|
|
mapping (string => Record) m_toRecord;
|
|
|
|
}
|
|
|
|
)DELIMITER";
|
|
|
|
|
2020-05-12 14:04:13 +00:00
|
|
|
static LazyInit<bytes> s_compiledRegistrar;
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2016-11-28 00:21:01 +00:00
|
|
|
class AuctionRegistrarTestFramework: public SolidityExecutionFramework
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void deployRegistrar()
|
|
|
|
{
|
2020-05-12 14:04:13 +00:00
|
|
|
bytes const& compiled = s_compiledRegistrar.init([&]{
|
|
|
|
return compileContract(registrarCode, "GlobalRegistrar");
|
|
|
|
});
|
2018-02-27 18:32:05 +00:00
|
|
|
|
2020-05-12 14:04:13 +00:00
|
|
|
sendMessage(compiled, true);
|
2018-06-15 10:18:00 +00:00
|
|
|
BOOST_REQUIRE(m_transactionSuccessful);
|
2015-08-04 14:31:27 +00:00
|
|
|
BOOST_REQUIRE(!m_output.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
class RegistrarInterface: public ContractInterface
|
|
|
|
{
|
|
|
|
public:
|
2016-11-28 00:21:01 +00:00
|
|
|
RegistrarInterface(SolidityExecutionFramework& _framework): ContractInterface(_framework) {}
|
2023-08-30 00:08:06 +00:00
|
|
|
void reserve(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
callString("reserve", _name);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
h160 owner(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callStringReturnsAddress("owner", _name);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
void setAddress(std::string const& _name, h160 const& _address, bool _primary)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
callStringAddressBool("setAddress", _name, _address, _primary);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
h160 addr(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callStringReturnsAddress("addr", _name);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name(h160 const& _addr)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callAddressReturnsString("name", _addr);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
void setSubRegistrar(std::string const& _name, h160 const& _address)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
callStringAddress("setSubRegistrar", _name, _address);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
h160 subRegistrar(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callStringReturnsAddress("subRegistrar", _name);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
void setContent(std::string const& _name, h256 const& _content)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
callStringBytes32("setContent", _name, _content);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
h256 content(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callStringReturnsBytes32("content", _name);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
void transfer(std::string const& _name, h160 const& _target)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callStringAddress("transfer", _name, _target);
|
|
|
|
}
|
2023-08-30 00:08:06 +00:00
|
|
|
void disown(std::string const& _name)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
|
|
|
return callString("disown", _name);
|
|
|
|
}
|
|
|
|
};
|
2015-08-06 09:01:59 +00:00
|
|
|
|
2019-11-28 10:54:57 +00:00
|
|
|
int64_t const m_biddingTime = 7 * 24 * 3600;
|
2015-08-04 14:31:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a test suite that tests optimised code!
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(SolidityAuctionRegistrar, AuctionRegistrarTestFramework)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(creation)
|
|
|
|
{
|
|
|
|
deployRegistrar();
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(reserve)
|
|
|
|
{
|
|
|
|
// Test that reserving works for long strings
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::vector<std::string> names{"abcabcabcabcabc", "defdefdefdefdef", "ghighighighighighighighighighighighighighighi"};
|
2015-08-04 14:31:27 +00:00
|
|
|
|
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
|
|
|
|
// should not work
|
|
|
|
registrar.reserve("");
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(""), h160{});
|
2015-08-04 14:31:27 +00:00
|
|
|
|
|
|
|
for (auto const& name: names)
|
|
|
|
{
|
|
|
|
registrar.reserve(name);
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(double_reserve_long)
|
|
|
|
{
|
|
|
|
// Test that it is not possible to re-reserve from a different address.
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name = "abcabcabcabcabcabcabcabcabcabca";
|
2015-08-04 14:31:27 +00:00
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
registrar.reserve(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2016-08-01 05:25:37 +00:00
|
|
|
sendEther(account(1), u256(10) * ether);
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(1);
|
2015-08-04 14:31:27 +00:00
|
|
|
registrar.reserve(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), account(0));
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(properties)
|
|
|
|
{
|
|
|
|
// Test setting and retrieving the various properties works.
|
|
|
|
deployRegistrar();
|
|
|
|
RegistrarInterface registrar(*this);
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string names[] = {"abcaeouoeuaoeuaoeu", "defncboagufra,fui", "ghagpyajfbcuajouhaeoi"};
|
2015-08-04 14:31:27 +00:00
|
|
|
size_t addr = 0x9872543;
|
2016-06-18 00:08:20 +00:00
|
|
|
size_t count = 1;
|
2023-08-30 00:08:06 +00:00
|
|
|
for (std::string const& name: names)
|
2015-08-04 14:31:27 +00:00
|
|
|
{
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(0);
|
2016-08-01 05:25:37 +00:00
|
|
|
sendEther(account(count), u256(20) * ether);
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(count);
|
|
|
|
auto sender = m_sender;
|
|
|
|
addr += count;
|
2015-08-04 14:31:27 +00:00
|
|
|
// setting by sender works
|
|
|
|
registrar.reserve(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), sender);
|
2020-11-13 16:03:49 +00:00
|
|
|
registrar.setAddress(name, h160(addr), true);
|
|
|
|
BOOST_CHECK_EQUAL(registrar.addr(name), h160(addr));
|
|
|
|
registrar.setSubRegistrar(name, h160(addr + 20));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.subRegistrar(name), h160(addr + 20));
|
2015-08-04 14:31:27 +00:00
|
|
|
registrar.setContent(name, h256(u256(addr + 90)));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.content(name), h256(u256(addr + 90)));
|
|
|
|
|
|
|
|
// but not by someone else
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(count - 1);
|
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), sender);
|
2020-11-13 16:03:49 +00:00
|
|
|
registrar.setAddress(name, h160(addr + 1), true);
|
|
|
|
BOOST_CHECK_EQUAL(registrar.addr(name), h160(addr));
|
|
|
|
registrar.setSubRegistrar(name, h160(addr + 20 + 1));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.subRegistrar(name), h160(addr + 20));
|
2015-08-04 14:31:27 +00:00
|
|
|
registrar.setContent(name, h256(u256(addr + 90 + 1)));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.content(name), h256(u256(addr + 90)));
|
2016-06-18 00:08:20 +00:00
|
|
|
count++;
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(transfer)
|
|
|
|
{
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name = "abcaoeguaoucaeoduceo";
|
2015-08-04 14:31:27 +00:00
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
registrar.reserve(name);
|
|
|
|
registrar.setContent(name, h256(u256(123)));
|
2020-11-13 16:03:49 +00:00
|
|
|
registrar.transfer(name, h160(555));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), h160(555));
|
2015-08-04 14:31:27 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.content(name), h256(u256(123)));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(disown)
|
|
|
|
{
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name = "abcaoeguaoucaeoduceo";
|
2016-06-18 00:08:20 +00:00
|
|
|
|
2015-08-04 14:31:27 +00:00
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
registrar.reserve(name);
|
|
|
|
registrar.setContent(name, h256(u256(123)));
|
2020-11-13 16:03:49 +00:00
|
|
|
registrar.setAddress(name, h160(124), true);
|
|
|
|
registrar.setSubRegistrar(name, h160(125));
|
|
|
|
BOOST_CHECK_EQUAL(registrar.name(h160(124)), name);
|
2015-08-04 14:31:27 +00:00
|
|
|
|
|
|
|
// someone else tries disowning
|
2016-08-01 05:25:37 +00:00
|
|
|
sendEther(account(1), u256(10) * ether);
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(1);
|
2015-08-04 14:31:27 +00:00
|
|
|
registrar.disown(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), account(0));
|
2015-08-04 14:31:27 +00:00
|
|
|
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(0);
|
2015-08-04 14:31:27 +00:00
|
|
|
registrar.disown(name);
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), h160());
|
|
|
|
BOOST_CHECK_EQUAL(registrar.addr(name), h160());
|
|
|
|
BOOST_CHECK_EQUAL(registrar.subRegistrar(name), h160());
|
2015-08-04 14:31:27 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.content(name), h256());
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.name(h160(124)), "");
|
2015-08-06 09:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(auction_simple)
|
|
|
|
{
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name = "x";
|
2016-06-18 00:08:20 +00:00
|
|
|
|
2015-08-06 09:01:59 +00:00
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
// initiate auction
|
|
|
|
registrar.setNextValue(8);
|
|
|
|
registrar.reserve(name);
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), h160());
|
2015-08-06 09:01:59 +00:00
|
|
|
// "wait" until auction end
|
2019-06-26 16:42:24 +00:00
|
|
|
|
2020-06-05 23:10:48 +00:00
|
|
|
m_evmcHost->tx_context.block_timestamp += m_biddingTime + 10;
|
2015-08-06 09:01:59 +00:00
|
|
|
// trigger auction again
|
|
|
|
registrar.reserve(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
2015-08-04 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 09:01:59 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(auction_bidding)
|
|
|
|
{
|
|
|
|
deployRegistrar();
|
2023-08-30 00:08:06 +00:00
|
|
|
std::string name = "x";
|
2016-06-18 00:08:20 +00:00
|
|
|
|
|
|
|
unsigned startTime = 0x776347e2;
|
2020-06-05 23:10:48 +00:00
|
|
|
m_evmcHost->tx_context.block_timestamp = startTime;
|
2016-06-18 00:08:20 +00:00
|
|
|
|
2015-08-06 09:01:59 +00:00
|
|
|
RegistrarInterface registrar(*this);
|
|
|
|
// initiate auction
|
|
|
|
registrar.setNextValue(8);
|
|
|
|
registrar.reserve(name);
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), h160());
|
2015-08-06 09:01:59 +00:00
|
|
|
// overbid self
|
2020-06-05 23:10:48 +00:00
|
|
|
m_evmcHost->tx_context.block_timestamp = startTime + m_biddingTime - 10;
|
2015-08-06 09:01:59 +00:00
|
|
|
registrar.setNextValue(12);
|
|
|
|
registrar.reserve(name);
|
|
|
|
// another bid by someone else
|
2016-08-01 05:25:37 +00:00
|
|
|
sendEther(account(1), 10 * ether);
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(1);
|
2020-06-05 23:10:48 +00:00
|
|
|
m_evmcHost->tx_context.block_timestamp = startTime + 2 * m_biddingTime - 50;
|
2015-08-06 09:01:59 +00:00
|
|
|
registrar.setNextValue(13);
|
|
|
|
registrar.reserve(name);
|
2020-11-13 16:03:49 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), h160());
|
2015-08-06 09:01:59 +00:00
|
|
|
// end auction by first bidder (which is not highest) trying to overbid again (too late)
|
2016-06-18 00:08:20 +00:00
|
|
|
m_sender = account(0);
|
2020-06-05 23:10:48 +00:00
|
|
|
m_evmcHost->tx_context.block_timestamp = startTime + 4 * m_biddingTime;
|
2015-08-06 09:01:59 +00:00
|
|
|
registrar.setNextValue(20);
|
|
|
|
registrar.reserve(name);
|
2016-06-18 00:08:20 +00:00
|
|
|
BOOST_CHECK_EQUAL(registrar.owner(name), account(1));
|
2015-08-06 09:01:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:31:27 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|
|
|
|
} // end namespaces
|