diff options
author | chriseth <chris@ethereum.org> | 2016-10-12 23:28:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 23:28:47 +0800 |
commit | 5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2 (patch) | |
tree | 1976579193413d73cd7166200d4a4489ece829d3 /test | |
parent | cbd933ceedc9d38df356856eec7bfca07d440523 (diff) | |
download | dexon-solidity-5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2.tar.gz dexon-solidity-5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2.tar.zst dexon-solidity-5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2.zip |
Replace `fixed` by standard `encode` function.
This way, we can use
```
BOOST_CHECK(callContractFunction("t(fixed8x128)", make_pair(rational(2, 3), 128)) == encodeArgs(u256(9)));
```
which is a bit more self-explanatory, I would say.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index a4181dfe..bfd87c2b 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -156,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) { @@ -187,12 +195,6 @@ public: { return encodeArgs(u256(0x20), u256(_arg.size()), _arg); } - static u256 fixed(dev::bigint _numerator, dev::bigint _denominator, int _fixedBits) - { - rational _value = rational(dev::bigint(_numerator), dev::bigint(_denominator)); - rational value = _value * boost::multiprecision::pow(bigint(2), _fixedBits); - return u256(value.numerator()/value.denominator()); - } class ContractInterface { public: |