aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityExecutionFramework.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h
index 1cd45603..7d44edaf 100644
--- a/test/libsolidity/SolidityExecutionFramework.h
+++ b/test/libsolidity/SolidityExecutionFramework.h
@@ -39,6 +39,7 @@ namespace dev
{
namespace solidity
{
+ using rational = boost::rational<dev::bigint>;
/// An Ethereum address: 20 bytes.
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
using Address = h160;
@@ -155,6 +156,14 @@ public:
static bytes encode(char const* _value) { return encode(std::string(_value)); }
static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; }
static bytes encode(u256 const& _value) { return toBigEndian(_value); }
+ /// @returns the fixed-point encoding of a rational number with a given
+ /// number of fractional bits.
+ static bytes encode(std::pair<rational, int> const& _valueAndPrecision)
+ {
+ rational const& value = _valueAndPrecision.first;
+ int fractionalBits = _valueAndPrecision.second;
+ return encode(u256((value.numerator() << fractionalBits) / value.denominator()));
+ }
static bytes encode(h256 const& _value) { return _value.asBytes(); }
static bytes encode(bytes const& _value, bool _padLeft = true)
{
@@ -186,7 +195,6 @@ public:
{
return encodeArgs(u256(0x20), u256(_arg.size()), _arg);
}
-
class ContractInterface
{
public: