subtly
10 years ago
65 changed files with 2924 additions and 2100 deletions
File diff suppressed because it is too large
@ -0,0 +1,95 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BasicGasPricer.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <boost/math/distributions/normal.hpp> |
|||
#include "BasicGasPricer.h" |
|||
#include "BlockChain.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
void BasicGasPricer::update(BlockChain const& _bc) |
|||
{ |
|||
unsigned c = 0; |
|||
h256 p = _bc.currentHash(); |
|||
m_gasPerBlock = _bc.info(p).gasLimit; |
|||
|
|||
map<u256, u256> dist; |
|||
u256 total = 0; |
|||
|
|||
// make gasPrice versus gasUsed distribution for the last 1000 blocks
|
|||
while (c < 1000 && p) |
|||
{ |
|||
BlockInfo bi = _bc.info(p); |
|||
if (bi.transactionsRoot != EmptyTrie) |
|||
{ |
|||
auto bb = _bc.block(p); |
|||
RLP r(bb); |
|||
BlockReceipts brs(_bc.receipts(bi.hash())); |
|||
size_t i = 0; |
|||
for (auto const& tr: r[1]) |
|||
{ |
|||
Transaction tx(tr.data(), CheckTransaction::None); |
|||
u256 gu = brs.receipts[i].gasUsed(); |
|||
dist[tx.gasPrice()] += gu; |
|||
total += gu; |
|||
i++; |
|||
} |
|||
} |
|||
p = bi.parentHash; |
|||
++c; |
|||
} |
|||
|
|||
// fill m_octiles with weighted gasPrices
|
|||
if (total > 0) |
|||
{ |
|||
m_octiles[0] = dist.begin()->first; |
|||
|
|||
// calc mean
|
|||
u256 mean = 0; |
|||
for (auto const& i: dist) |
|||
mean += i.first * i.second; |
|||
mean /= total; |
|||
|
|||
// calc standard deviation
|
|||
u256 sdSquared = 0; |
|||
for (auto const& i: dist) |
|||
sdSquared += i.second * (i.first - mean) * (i.first - mean); |
|||
sdSquared /= total; |
|||
|
|||
if (sdSquared) |
|||
{ |
|||
long double sd = sqrt(sdSquared.convert_to<long double>()); |
|||
long double normalizedSd = sd / mean.convert_to<long double>(); |
|||
|
|||
// calc octiles normalized to gaussian distribution
|
|||
boost::math::normal gauss(1.0, (normalizedSd > 0.01) ? normalizedSd : 0.01); |
|||
for (size_t i = 1; i < 8; i++) |
|||
m_octiles[i] = u256(mean.convert_to<long double>() * boost::math::quantile(gauss, i / 8.0)); |
|||
m_octiles[8] = dist.rbegin()->first; |
|||
} |
|||
else |
|||
{ |
|||
for (size_t i = 0; i < 9; i++) |
|||
m_octiles[i] = (i + 1) * mean / 5; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,53 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BasicGasPricer.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <array> |
|||
#include "GasPricer.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class BasicGasPricer: public GasPricer |
|||
{ |
|||
public: |
|||
explicit BasicGasPricer(u256 _weiPerRef, u256 _refsPerBlock): m_weiPerRef(_weiPerRef), m_refsPerBlock(_refsPerBlock) {} |
|||
|
|||
void setRefPrice(u256 _weiPerRef) { if ((bigint)m_refsPerBlock * _weiPerRef > std::numeric_limits<u256>::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_weiPerRef = _weiPerRef; } |
|||
void setRefBlockFees(u256 _refsPerBlock) { if ((bigint)m_weiPerRef * _refsPerBlock > std::numeric_limits<u256>::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_refsPerBlock = _refsPerBlock; } |
|||
|
|||
u256 ask(State const&) const override { return m_weiPerRef * m_refsPerBlock / m_gasPerBlock; } |
|||
u256 bid(TransactionPriority _p = TransactionPriority::Medium) const override { return m_octiles[(int)_p] > 0 ? m_octiles[(int)_p] : (m_weiPerRef * m_refsPerBlock / m_gasPerBlock); } |
|||
|
|||
void update(BlockChain const& _bc) override; |
|||
|
|||
private: |
|||
u256 m_weiPerRef; |
|||
u256 m_refsPerBlock; |
|||
u256 m_gasPerBlock = 3141592; |
|||
std::array<u256, 9> m_octiles; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file GasPricer.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "GasPricer.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
@ -0,0 +1,74 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file GasPricer.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <libethcore/Common.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class State; |
|||
class BlockChain; |
|||
|
|||
enum class TransactionPriority |
|||
{ |
|||
Lowest = 0, |
|||
Low = 2, |
|||
Medium = 4, |
|||
High = 6, |
|||
Highest = 8 |
|||
}; |
|||
|
|||
class GasPricer |
|||
{ |
|||
public: |
|||
GasPricer() = default; |
|||
virtual ~GasPricer() = default; |
|||
|
|||
virtual u256 ask(State const&) const = 0; |
|||
virtual u256 bid(TransactionPriority _p = TransactionPriority::Medium) const = 0; |
|||
|
|||
virtual void update(BlockChain const&) {} |
|||
}; |
|||
|
|||
class TrivialGasPricer: public GasPricer |
|||
{ |
|||
public: |
|||
TrivialGasPricer() = default; |
|||
TrivialGasPricer(u256 const& _ask, u256 const& _bid): m_ask(_ask), m_bid(_bid) {} |
|||
|
|||
void setAsk(u256 const& _ask) { m_ask = _ask; } |
|||
void setBid(u256 const& _bid) { m_bid = _bid; } |
|||
|
|||
u256 ask() const { return m_ask; } |
|||
u256 ask(State const&) const override { return m_ask; } |
|||
u256 bid(TransactionPriority = TransactionPriority::Medium) const override { return m_bid; } |
|||
|
|||
private: |
|||
u256 m_ask = 10 * szabo; |
|||
u256 m_bid = 10 * szabo; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,28 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BloomFilter.cpp
|
|||
* @author Vladislav Gluhovsky <vlad@ethdev.com> |
|||
* @date June 2015 |
|||
*/ |
|||
|
|||
#include "BloomFilter.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::shh; |
|||
|
|||
|
@ -0,0 +1,134 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
import QtQuick.Dialogs 1.1 |
|||
import QtQuick.Layouts 1.1 |
|||
import Qt.labs.settings 1.0 |
|||
import org.ethereum.qml.QEther 1.0 |
|||
import "js/Debugger.js" as Debugger |
|||
import "js/ErrorLocationFormater.js" as ErrorLocationFormater |
|||
import "js/TransactionHelper.js" as TransactionHelper |
|||
import "js/QEtherHelper.js" as QEtherHelper |
|||
import "." |
|||
|
|||
ColumnLayout { |
|||
id: root |
|||
property alias title: titleLabel.text |
|||
property variant _data |
|||
property string role |
|||
property alias model: modelKeyValue |
|||
|
|||
function add(key, value) |
|||
{ |
|||
modelKeyValue.append({ "key": key, "value": value }) |
|||
} |
|||
|
|||
function clear() |
|||
{ |
|||
modelKeyValue.clear() |
|||
} |
|||
|
|||
function init() |
|||
{ |
|||
modelKeyValue.clear() |
|||
if (typeof(computeData) !== "undefined" && computeData instanceof Function) |
|||
computeData() |
|||
else |
|||
{ |
|||
if (_data !== undefined && _data[role] !== undefined) |
|||
{ |
|||
var keys = Object.keys(_data[role]) |
|||
for (var k in keys) |
|||
{ |
|||
modelKeyValue.append({ "key": keys[k] === "" ? "undefined" : keys[k], "value": _data[role][keys[k]] }) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
RowLayout |
|||
{ |
|||
Layout.preferredHeight: 20 |
|||
Layout.fillWidth: true |
|||
Label |
|||
{ |
|||
id: titleLabel |
|||
anchors.left: parent.left |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
color: "white" |
|||
} |
|||
} |
|||
|
|||
RowLayout |
|||
{ |
|||
Layout.fillWidth: true |
|||
Layout.preferredHeight: 100 |
|||
ListModel |
|||
{ |
|||
id: modelKeyValue |
|||
} |
|||
|
|||
Rectangle |
|||
{ |
|||
Layout.fillWidth: true |
|||
Layout.fillHeight: true |
|||
color: "white" |
|||
radius: 2 |
|||
ScrollView |
|||
{ |
|||
id: columnValues |
|||
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff |
|||
anchors.fill: parent |
|||
clip: true |
|||
ColumnLayout |
|||
{ |
|||
anchors.margins: 10 |
|||
Repeater |
|||
{ |
|||
id: repeaterKeyValue |
|||
model: modelKeyValue |
|||
RowLayout |
|||
{ |
|||
Layout.fillWidth: true |
|||
Layout.preferredHeight: 30 |
|||
spacing: 0 |
|||
Rectangle |
|||
{ |
|||
Layout.preferredWidth: columnValues.width / 2 |
|||
Label |
|||
{ |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: 10 |
|||
text: { |
|||
if (index >= 0 && repeaterKeyValue.model.get(index).key !== undefined) |
|||
return repeaterKeyValue.model.get(index).key |
|||
else |
|||
return "" |
|||
} |
|||
} |
|||
} |
|||
|
|||
Rectangle |
|||
{ |
|||
Layout.preferredWidth: columnValues.width / 2 - 10 |
|||
Label |
|||
{ |
|||
anchors.right: parent.right |
|||
anchors.rightMargin: 10 |
|||
text: { |
|||
if (index >= 0 && repeaterKeyValue.model.get(index).value !== undefined) |
|||
return repeaterKeyValue.model.get(index).value |
|||
else |
|||
return "" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,203 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
import QtQuick.Dialogs 1.1 |
|||
import QtQuick.Layouts 1.1 |
|||
import Qt.labs.settings 1.0 |
|||
import org.ethereum.qml.QEther 1.0 |
|||
import "js/Debugger.js" as Debugger |
|||
import "js/ErrorLocationFormater.js" as ErrorLocationFormater |
|||
import "js/TransactionHelper.js" as TransactionHelper |
|||
import "js/QEtherHelper.js" as QEtherHelper |
|||
import "." |
|||
|
|||
Rectangle { |
|||
color: "#4F4F4F" |
|||
radius: 4 |
|||
property variant tx |
|||
property variant currentState |
|||
property variant bc |
|||
property var blockIndex |
|||
property var txIndex |
|||
|
|||
function clear() |
|||
{ |
|||
from.text = "" |
|||
to.text = "" |
|||
value.text = "" |
|||
inputParams.clear() |
|||
returnParams.clear() |
|||
accounts.clear() |
|||
events.clear() |
|||
} |
|||
|
|||
function addAccount(address, amount) |
|||
{ |
|||
accounts.add(address, amount) |
|||
} |
|||
|
|||
function updateWidthTx(_tx, _state, _blockIndex, _txIndex) |
|||
{ |
|||
from.text = clientModel.resolveAddress(_tx.sender) |
|||
to.text = _tx.label |
|||
value.text = _tx.value.format() |
|||
tx = _tx |
|||
blockIndex = _blockIndex |
|||
txIndex = _txIndex |
|||
currentState = _state |
|||
inputParams.init() |
|||
if (_tx.isContractCreation) |
|||
{ |
|||
returnParams.role = "creationAddr" |
|||
returnParams._data = { |
|||
creationAddr : { |
|||
} |
|||
} |
|||
returnParams._data.creationAddr[qsTr("contract address")] = _tx.returned |
|||
} |
|||
else |
|||
{ |
|||
returnParams.role = "returnParameters" |
|||
returnParams._data = tx |
|||
} |
|||
returnParams.init() |
|||
accounts.init() |
|||
events.init() |
|||
} |
|||
|
|||
Column { |
|||
anchors.fill: parent |
|||
spacing: 15 |
|||
Rectangle |
|||
{ |
|||
height: 15 |
|||
width: parent.width - 30 |
|||
color: "transparent" |
|||
Row |
|||
{ |
|||
id: rowHeader |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
anchors.top: rowHeader.parent.top |
|||
anchors.topMargin: 6 |
|||
spacing: 5 |
|||
Label { |
|||
id: fromLabel |
|||
text: qsTr("from") |
|||
visible: from.text !== "" |
|||
color: "#EAB920" |
|||
} |
|||
Label { |
|||
id: from |
|||
color: "#EAB920" |
|||
elide: Text.ElideRight |
|||
maximumLineCount: 1 |
|||
clip: true |
|||
width: 200 |
|||
} |
|||
Label { |
|||
id: toLabel |
|||
text: qsTr("to") |
|||
visible: from.text !== "" |
|||
color: "#EAB920" |
|||
} |
|||
Label { |
|||
id: to |
|||
color: "#EAB920" |
|||
elide: Text.ElideRight |
|||
maximumLineCount: 1 |
|||
clip: true |
|||
width: 100 |
|||
} |
|||
Label { |
|||
id: value |
|||
color: "#EAB920" |
|||
font.italic: true |
|||
clip: true |
|||
} |
|||
} |
|||
|
|||
Image { |
|||
anchors.right: rowHeader.parent.right |
|||
anchors.top: rowHeader.parent.top |
|||
anchors.topMargin: -3 |
|||
source: "qrc:/qml/img/edittransaction2.png" |
|||
height: 30 |
|||
fillMode: Image.PreserveAspectFit |
|||
visible: from.text !== "" |
|||
MouseArea |
|||
{ |
|||
anchors.fill: parent |
|||
onClicked: |
|||
{ |
|||
bc.blockChainRepeater.editTx(blockIndex, txIndex) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
Rectangle { |
|||
height: 1 |
|||
width: parent.width - 30 |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
border.color: "#cccccc" |
|||
border.width: 1 |
|||
} |
|||
|
|||
KeyValuePanel |
|||
{ |
|||
height: 150 |
|||
width: parent.width - 30 |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
id: inputParams |
|||
title: qsTr("INPUT PARAMETERS") |
|||
role: "parameters" |
|||
_data: tx |
|||
} |
|||
|
|||
KeyValuePanel |
|||
{ |
|||
height: 150 |
|||
width: parent.width - 30 |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
id: returnParams |
|||
title: qsTr("RETURN PARAMETERS") |
|||
role: "returnParameters" |
|||
_data: tx |
|||
} |
|||
|
|||
KeyValuePanel |
|||
{ |
|||
height: 150 |
|||
width: parent.width - 30 |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
id: accounts |
|||
title: qsTr("ACCOUNTS") |
|||
role: "accounts" |
|||
_data: currentState |
|||
} |
|||
|
|||
KeyValuePanel |
|||
{ |
|||
height: 150 |
|||
width: parent.width - 30 |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
id: events |
|||
title: qsTr("EVENTS") |
|||
function computeData() |
|||
{ |
|||
model.clear() |
|||
var ret = [] |
|||
for (var k in tx.logs) |
|||
{ |
|||
var param = "" |
|||
for (var p in tx.logs[k].param) |
|||
{ |
|||
param += " " + tx.logs[k].param[p].value + " " |
|||
} |
|||
param = "(" + param + ")" |
|||
model.append({ "key": tx.logs[k].name, "value": param }) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,148 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file RangeMask.cpp
|
|||
* @author Christian <c@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <libdevcore/RangeMask.h> |
|||
#include "../TestHelper.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace test |
|||
{ |
|||
|
|||
BOOST_AUTO_TEST_SUITE(RangeMaskTest) |
|||
|
|||
BOOST_AUTO_TEST_CASE(constructor) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
for (RM r: {RM(), RM(1, 10), RM(Range(2, 10))}) |
|||
{ |
|||
BOOST_CHECK(r.empty()); |
|||
BOOST_CHECK(!r.contains(0)); |
|||
BOOST_CHECK(!r.contains(1)); |
|||
BOOST_CHECK_EQUAL(0, r.size()); |
|||
} |
|||
BOOST_CHECK(RM().full()); |
|||
BOOST_CHECK(!RM(1, 10).full()); |
|||
BOOST_CHECK(!RM(Range(2, 10)).full()); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(simple_unions) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
RM m(Range(0, 2000)); |
|||
m.unionWith(Range(1, 2)); |
|||
BOOST_CHECK_EQUAL(m.size(), 1); |
|||
m.unionWith(Range(50, 250)); |
|||
BOOST_CHECK_EQUAL(m.size(), 201); |
|||
m.unionWith(Range(10, 16)); |
|||
BOOST_CHECK_EQUAL(m.size(), 207); |
|||
BOOST_CHECK(m.contains(1)); |
|||
BOOST_CHECK(m.contains(11)); |
|||
BOOST_CHECK(m.contains(51)); |
|||
BOOST_CHECK(m.contains(200)); |
|||
BOOST_CHECK(!m.contains(2)); |
|||
BOOST_CHECK(!m.contains(7)); |
|||
BOOST_CHECK(!m.contains(17)); |
|||
BOOST_CHECK(!m.contains(258)); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(empty_union) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
RM m(Range(0, 2000)); |
|||
m.unionWith(Range(3, 6)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
m.unionWith(Range(50, 50)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
m.unionWith(Range(0, 0)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
m.unionWith(Range(1, 1)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
m.unionWith(Range(2, 2)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
m.unionWith(Range(3, 3)); |
|||
BOOST_CHECK_EQUAL(m.size(), 3); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(overlapping_unions) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
RM m(Range(0, 2000)); |
|||
m.unionWith(Range(10, 20)); |
|||
BOOST_CHECK_EQUAL(10, m.size()); |
|||
m.unionWith(Range(30, 40)); |
|||
BOOST_CHECK_EQUAL(20, m.size()); |
|||
m.unionWith(Range(15, 30)); |
|||
BOOST_CHECK_EQUAL(40 - 10, m.size()); |
|||
m.unionWith(Range(50, 60)); |
|||
m.unionWith(Range(45, 55)); |
|||
// [40, 45) still missing here
|
|||
BOOST_CHECK_EQUAL(60 - 10 - 5, m.size()); |
|||
m.unionWith(Range(15, 56)); |
|||
BOOST_CHECK_EQUAL(60 - 10, m.size()); |
|||
m.unionWith(Range(15, 65)); |
|||
BOOST_CHECK_EQUAL(65 - 10, m.size()); |
|||
m.unionWith(Range(5, 70)); |
|||
BOOST_CHECK_EQUAL(70 - 5, m.size()); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(complement) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
RM m(Range(0, 2000)); |
|||
m.unionWith(7).unionWith(9); |
|||
m = ~m; |
|||
m.unionWith(7).unionWith(9); |
|||
m = ~m; |
|||
BOOST_CHECK(m.empty()); |
|||
|
|||
m += Range(0, 10); |
|||
m += Range(1000, 2000); |
|||
m.invert(); |
|||
BOOST_CHECK_EQUAL(m.size(), 1000 - 10); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(iterator) |
|||
{ |
|||
using RM = RangeMask<unsigned>; |
|||
using Range = pair<unsigned, unsigned>; |
|||
RM m(Range(0, 2000)); |
|||
m.unionWith(Range(7, 9)); |
|||
m.unionWith(11); |
|||
m.unionWith(Range(200, 205)); |
|||
|
|||
vector<unsigned> elements; |
|||
copy(m.begin(), m.end(), back_inserter(elements)); |
|||
BOOST_CHECK(elements == (vector<unsigned>{7, 8, 11, 200, 201, 202, 203, 204})); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
|||
|
|||
} |
|||
} |
@ -0,0 +1,64 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
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. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
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 |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file transactionqueue.cpp
|
|||
* @author Christoph Jentzsch <cj@ethdev.com> |
|||
* @date 2015 |
|||
* TransactionQueue test functions. |
|||
*/ |
|||
|
|||
#include <libethereum/TransactionQueue.h> |
|||
#include "../TestHelper.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
BOOST_AUTO_TEST_SUITE(TransactionQueue) |
|||
|
|||
BOOST_AUTO_TEST_CASE(maxNonce) |
|||
{ |
|||
|
|||
dev::eth::TransactionQueue txq; |
|||
|
|||
// from a94f5374fce5edbc8e2a8697c15331677e6ebf0b
|
|||
const u256 gasCost = 10 * szabo; |
|||
const u256 gas = 25000; |
|||
Address dest = Address("0x095e7baea6a6c7c4c2dfeb977efac326af552d87"); |
|||
Address to = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"); |
|||
Secret sec = Secret("0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"); |
|||
Transaction tx0(0, gasCost, gas, dest, bytes(), 0, sec ); |
|||
Transaction tx0_1(1, gasCost, gas, dest, bytes(), 0, sec ); |
|||
Transaction tx1(0, gasCost, gas, dest, bytes(), 1, sec ); |
|||
Transaction tx2(0, gasCost, gas, dest, bytes(), 2, sec ); |
|||
Transaction tx9(0, gasCost, gas, dest, bytes(), 9, sec ); |
|||
|
|||
txq.import(tx0); |
|||
BOOST_CHECK(1 == txq.maxNonce(to)); |
|||
txq.import(tx0); |
|||
BOOST_CHECK(1 == txq.maxNonce(to)); |
|||
txq.import(tx0_1); |
|||
BOOST_CHECK(1 == txq.maxNonce(to)); |
|||
txq.import(tx1); |
|||
BOOST_CHECK(2 == txq.maxNonce(to)); |
|||
txq.import(tx9); |
|||
BOOST_CHECK(10 == txq.maxNonce(to)); |
|||
txq.import(tx2); |
|||
BOOST_CHECK(10 == txq.maxNonce(to)); |
|||
|
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
Loading…
Reference in new issue