Browse Source

Fix for tests.

cl-refactor
Gav Wood 11 years ago
parent
commit
9b78189310
  1. 2
      libethereum/RLP.h
  2. 7
      libethereum/VirtualMachine.cpp
  3. 7
      libethereum/VirtualMachine.h
  4. 1
      test/CMakeLists.txt
  5. 7
      test/main.cpp

2
libethereum/RLP.h

@ -89,7 +89,7 @@ public:
if (_i < m_lastIndex)
{
m_lastEnd = RLP(payload()).actualSize();
m_lastItem = payload().cropped(m_lastEnd);
m_lastItem = payload().cropped(0, m_lastEnd);
m_lastIndex = 0;
}
for (; m_lastIndex < _i; ++m_lastIndex)

7
libethereum/VirtualMachine.cpp

@ -41,12 +41,6 @@ bytes Transaction::rlp() const
return rlp.out();
}
// Entry point for a user-originated transaction.
bool State::execute(Transaction const& _t)
{
return execute(_t, _t.vrs.address());
}
bool State::execute(Transaction const& _t, u160 _sender)
{
// Entry point for a contract-originated transaction.
@ -339,6 +333,7 @@ void State::execute(u160 _myAddress, u160 _txSender, u256 _txValue, u256 _txFee,
break;
}
case Instruction::ECMUL:
case Instruction::ECADD:
case Instruction::ECSIGN:
case Instruction::ECRECOVER:

7
libethereum/VirtualMachine.h

@ -187,7 +187,10 @@ struct Signature
u256 r;
u256 s;
u160 address() const { return as160(s); } // TODO!
u160 address(bytesConstRef _tx) const
{
return as160(s);
}
};
@ -214,7 +217,7 @@ public:
explicit State(u256 _minerAddress): m_minerAddress(_minerAddress) {}
bool verify(bytes const& _block);
bool execute(bytes const& _rlp) { try { Transaction t(_rlp); return execute(t); } catch (...) { return false; } }
bool execute(bytes const& _rlp) { try { Transaction t(_rlp); u160 sender = t.vrs.address(bytesConstRef(const_cast<bytes*>(&_rlp))); return execute(t, sender); } catch (...) { return false; } } // remove const_cast once vector_ref can handle const vector* properly.
private:
bool execute(Transaction const& _t);

1
test/CMakeLists.txt

@ -1,6 +1,7 @@
cmake_policy(SET CMP0015 NEW)
aux_source_directory(. SRC_LIST)
include_directories(../../secp256k1/include)
include_directories(../libethereum)
link_directories(../libethereum)
link_directories(../../secp256k1)

7
test/main.cpp

@ -1,5 +1,6 @@
#include <random>
#include <Common.h>
#include <secp256k1.h>
#include "RLP.h"
#include "Trie.h"
#include "VirtualMachine.h"
@ -19,6 +20,8 @@ std::string randomWord()
int main()
{
{
Trie t;
t.insert("dog", "puppy");
@ -85,7 +88,9 @@ int main()
// 2-item list
RLP twoItemList("\x82\x0f\x43""dog");
assert(twoItemList.itemCount() == 2 && twoItemList[0] == 15 && twoItemList[1] == "dog");
assert(twoItemList.itemCount() == 2);
assert(twoItemList[0] == 15);
assert(twoItemList[1] == "dog");
assert(rlpList(15, "dog") == "\x82\x0f\x43""dog");
// 1-byte (8-bit) int

Loading…
Cancel
Save