diff options
author | RJ <rj@erisindustries.com> | 2016-10-14 04:18:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-14 04:18:45 +0800 |
commit | d9af51be51f98c652e262444dc9e4ad2b5110cc8 (patch) | |
tree | f640c5284781c2230a2e5903107e91df894d8f96 /test | |
parent | 5e75cae28abd79c499aa8ba4b567efdf801ed735 (diff) | |
parent | 5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2 (diff) | |
download | dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar.gz dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar.bz2 dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar.lz dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar.xz dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.tar.zst dexon-solidity-d9af51be51f98c652e262444dc9e4ad2b5110cc8.zip |
Merge pull request #1079 from VoR0220/fixedTypeTestFramework
Solidity helper function for testing fixed points
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 10 |
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: |