Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 0.2.0 deveop #143

Merged
merged 38 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1312997
--showhash show full hash
winsvega Aug 11, 2021
936bfb2
spDataObject move requester
winsvega Aug 12, 2021
2bb26a6
support difficulty from tool. swithc to rlp when sending transactions…
winsvega Aug 19, 2021
6a025f8
less memory copy. move to smart pointers WIP
winsvega Aug 19, 2021
ce83692
state test fillers parsing memory WIP
winsvega Aug 20, 2021
c73fa86
remove oldStyle account export
winsvega Aug 20, 2021
2cb650d
StateTestFillerTransaction spPointerMove
winsvega Aug 20, 2021
9246869
do not build error strings for warnings before the flag
winsvega Aug 20, 2021
ad910c5
cache hash as string calculation in FH types
winsvega Aug 21, 2021
6926c17
cache value asString convertion
winsvega Aug 21, 2021
c3d2f67
State and Account on smartPointers WIP
winsvega Aug 21, 2021
0d21d16
Account on spDataObject
winsvega Aug 21, 2021
4fb8cde
test x of y debug log
winsvega Aug 22, 2021
7dd3eb0
RUNNING AND FILLING ALL TESTS WORKS
winsvega Aug 22, 2021
225b07b
sort data only on export
winsvega Aug 22, 2021
b96307e
fix LegacyTests run on old sorted hash calculation
winsvega Aug 22, 2021
5242549
fix test x out of y calculation using boost
winsvega Aug 23, 2021
a2f3786
skip legacy tests hash verification bacause of sorting
winsvega Aug 23, 2021
615b333
fix calculate filler hash on threads issue
winsvega Aug 23, 2021
f6d3589
fix boost test cases calculation
winsvega Aug 23, 2021
cf02184
thread join time WIP
winsvega Aug 25, 2021
88e34b6
print warning on old test verion or retesteth version vs tests
winsvega Aug 29, 2021
a7a9787
test_rawTransaction
winsvega Aug 31, 2021
449e958
ttTransaction test suite WIP
winsvega Aug 31, 2021
235bd26
ttTransaction Test suite
winsvega Sep 1, 2021
01dae6a
make json verifications maps static so not to construct it every time
winsvega Sep 1, 2021
99e2183
prioritize structure check before throwing any exceptions
winsvega Sep 1, 2021
9679751
version 0.2.0
winsvega Sep 2, 2021
ca97d3f
50 ms thread wait
winsvega Sep 2, 2021
3fe832c
thread protect spPointers
winsvega Sep 2, 2021
06c64b5
fix initializers
winsvega Sep 3, 2021
7c39217
t9n tool support
winsvega Sep 4, 2021
6b5946b
--forceupdate option
winsvega Sep 5, 2021
09f9745
export test only if there were changes
winsvega Sep 5, 2021
db66e36
move thread logic to ThreadManager
winsvega Sep 5, 2021
5ccafb6
macOS Mutex
winsvega Sep 6, 2021
f368575
t9n return hash
winsvega Sep 8, 2021
71e9f78
try 25ms thread wait
winsvega Sep 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
State and Account on smartPointers WIP
  • Loading branch information
winsvega committed Aug 21, 2021
commit c3d2f6707d6fd1b52c35e6b8b7e32480edcadcd4
21 changes: 11 additions & 10 deletions retesteth/session/RPCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ FH32 RPCImpl::eth_sendRawTransaction(BYTES const& _rlp, VALUE const& _secret)
return FH32(result.getCContent());
}

VALUE RPCImpl::eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber)
spVALUE RPCImpl::eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber)
{
try
{
spDataObject response = rpcCall("eth_getTransactionCount", {quote(_address.asString()), quote(_blockNumber.asString())});
(*response).performModifier(mod_valueToCompactEvenHexPrefixed);
if (response->type() == DataType::String)
return VALUE(response);
return VALUE(response->asInt());
return spVALUE(new VALUE(response));
return spVALUE(new VALUE(response->asInt()));
}
catch(std::exception const& _ex)
{
ETH_FAIL_MESSAGE(string("RPC eth_getTransactionCount Exception: ") + _ex.what());
}
return VALUE(0);
return spVALUE(0);
}

VALUE RPCImpl::eth_blockNumber()
Expand All @@ -65,20 +65,21 @@ EthGetBlockBy RPCImpl::eth_getBlockByNumber(VALUE const& _blockNumber, Request _
return EthGetBlockBy(response);
}

BYTES RPCImpl::eth_getCode(FH20 const& _address, VALUE const& _blockNumber)
spBYTES RPCImpl::eth_getCode(FH20 const& _address, VALUE const& _blockNumber)
{
spDataObject const res(rpcCall("eth_getCode", {quote(_address.asString()), quote(_blockNumber.asString())}));
spDataObject res = rpcCall("eth_getCode", {quote(_address.asString()), quote(_blockNumber.asString())});
if (res->asString().empty())
{
ETH_WARNING_TEST("eth_getCode return `` empty string, correct to `0x` empty bytes ", 6);
return BYTES(DataObject("0x"));
return spBYTES(new BYTES(DataObject("0x")));
}
return BYTES(res);
return spBYTES(new BYTES(res));
}

VALUE RPCImpl::eth_getBalance(FH20 const& _address, VALUE const& _blockNumber)
spVALUE RPCImpl::eth_getBalance(FH20 const& _address, VALUE const& _blockNumber)
{
return VALUE(rpcCall("eth_getBalance", {quote(_address.asString()), quote(_blockNumber.asString())}));
auto ret = rpcCall("eth_getBalance", {quote(_address.asString()), quote(_blockNumber.asString())});
return spVALUE(new VALUE(ret));
}


Expand Down
7 changes: 4 additions & 3 deletions retesteth/session/RPCImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class RPCImpl : public SessionInterface

// ETH Methods
FH32 eth_sendRawTransaction(BYTES const& _rlp, VALUE const& _secret) override;
VALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) override;
VALUE eth_blockNumber() override;
EthGetBlockBy eth_getBlockByHash(FH32 const& _hash, Request _fullObjects) override;
EthGetBlockBy eth_getBlockByNumber(VALUE const& _blockNumber, Request _fullObjects) override;

BYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) override;
VALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) override;
// Account functions
spVALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) override;
spBYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) override;
spVALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) override;

// Debug
DebugAccountRange debug_accountRange(
Expand Down
8 changes: 5 additions & 3 deletions retesteth/session/SessionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class SessionInterface

// ETH Methods
virtual FH32 eth_sendRawTransaction(BYTES const& _rlp, VALUE const& _secret) = 0;
virtual VALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) = 0;

virtual VALUE eth_blockNumber() = 0;
virtual EthGetBlockBy eth_getBlockByHash(FH32 const& _blockHash, Request _fullObjects) = 0;
virtual EthGetBlockBy eth_getBlockByNumber(VALUE const& _blockNumber, Request _fullObjects) = 0;
virtual BYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) = 0;
virtual VALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) = 0;

// Account functions
virtual spBYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) = 0;
virtual spVALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) = 0;
virtual spVALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) = 0;

// Debug
virtual DebugAccountRange debug_accountRange(
Expand Down
25 changes: 13 additions & 12 deletions retesteth/session/ToolImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ FH32 ToolImpl::eth_sendRawTransaction(BYTES const& _rlp, VALUE const& _secret)
return FH32::zero();
}

VALUE ToolImpl::eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber)
spVALUE ToolImpl::eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber)
{
rpcCall("", {});
ETH_TEST_MESSAGE("\nRequest: eth_getTransactionCount " + _blockNumber.asString() + " " + _address.asString());
TRYCATCHCALL(
VALUE const& nonce = blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).nonce();
ETH_TEST_MESSAGE("Response: eth_getTransactionCount " + nonce.asDecString());
spVALUE nonce (blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).nonce().copy());
ETH_TEST_MESSAGE("Response: eth_getTransactionCount " + nonce->asDecString());
return nonce;
, "eth_getTransactionCount", CallType::FAILEVERYTHING)
return VALUE(0);
return spVALUE(0);
}

VALUE ToolImpl::eth_blockNumber()
Expand Down Expand Up @@ -125,28 +125,29 @@ EthGetBlockBy ToolImpl::eth_getBlockByNumber(VALUE const& _blockNumber, Request
return EthGetBlockBy(DataObject());
}

BYTES ToolImpl::eth_getCode(FH20 const& _address, VALUE const& _blockNumber)
spBYTES ToolImpl::eth_getCode(FH20 const& _address, VALUE const& _blockNumber)
{
rpcCall("", {});
ETH_TEST_MESSAGE("\nRequest: eth_getCode " + _blockNumber.asString() + " " + _address.asString());
TRYCATCHCALL(
BYTES const& code = blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).code();
ETH_TEST_MESSAGE("Response: eth_getCode " + code.asString());
spBYTES code(blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).code().copy());
ETH_TEST_MESSAGE("Response: eth_getCode " + code->asString());
return code;
, "eth_getCode", CallType::FAILEVERYTHING)
return BYTES(DataObject());
return spBYTES(0);
}

VALUE ToolImpl::eth_getBalance(FH20 const& _address, VALUE const& _blockNumber)
spVALUE ToolImpl::eth_getBalance(FH20 const& _address, VALUE const& _blockNumber)
{
rpcCall("", {});
ETH_TEST_MESSAGE("\nRequest: eth_getBalance " + _blockNumber.asString() + " " + _address.asString());
TRYCATCHCALL(
VALUE const& balance = blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).balance();
ETH_TEST_MESSAGE("Response: eth_getBalance " + balance.asDecString());
// Make a copy here because we do not expose the memory of the tool backend
spVALUE balance(blockchain().blockByNumber(_blockNumber).state()->getAccount(_address).balance().copy());
ETH_TEST_MESSAGE("Response: eth_getBalance " + balance->asDecString());
return balance;
, "eth_getBalance", CallType::FAILEVERYTHING)
return VALUE(0);
return spVALUE(0);
}

// Debug
Expand Down
7 changes: 4 additions & 3 deletions retesteth/session/ToolImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class ToolImpl : public SessionInterface

// ETH Methods
FH32 eth_sendRawTransaction(BYTES const& _rlp, VALUE const& _secret) override;
VALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) override;
VALUE eth_blockNumber() override;
EthGetBlockBy eth_getBlockByHash(FH32 const& _hash, Request _fullObjects) override;
EthGetBlockBy eth_getBlockByNumber(VALUE const& _blockNumber, Request _fullObjects) override;

BYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) override;
VALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) override;
// Account functions
spVALUE eth_getTransactionCount(FH20 const& _address, VALUE const& _blockNumber) override;
spBYTES eth_getCode(FH20 const& _address, VALUE const& _blockNumber) override;
spVALUE eth_getBalance(FH20 const& _address, VALUE const& _blockNumber) override;

// Debug
DebugAccountRange debug_accountRange(
Expand Down
2 changes: 1 addition & 1 deletion retesteth/testStructures/basetypes/FH.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct FH : GCP_SPointerBase
{
FH(dev::RLP const& _rlp, size_t _scale);
FH(string const&, size_t _scale);
FH(DataObject const&, size_t _scale);
FH(DataObject const&, size_t _scale); // Does not require to move smart pointer here as this structure changes a lot
FH(dev::bigint const&, size_t _scale);

bool isBigInt() const { return m_bigint; }
Expand Down
2 changes: 1 addition & 1 deletion retesteth/testStructures/basetypes/VALUE.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct VALUE : GCP_SPointerBase
VALUE(dev::RLP const& _rlp);
VALUE(dev::bigint const&);
VALUE(int);
VALUE(DataObject const&);
VALUE(DataObject const&); // Does not require to move smart pointer here as this structure changes a lot
VALUE* copy() const { return new VALUE(m_data); }

bool operator<(int _rhs) const { return m_data < _rhs; }
Expand Down
51 changes: 25 additions & 26 deletions retesteth/testStructures/types/Ethereum/Account.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
#include "Account.h"
#include "State.h"
#include <retesteth/TestHelper.h>
#include <retesteth/testStructures/Common.h>

namespace test
{
namespace teststruct
{
Account::Account(FH20 const& _addr, VALUE const& _balance, VALUE const& _nonce, BYTES const& _code, Storage const& _storage)

// The Account is a part of State class and manages it's data
State::Account::Account(FH20 const& _addr, spVALUE& _balance, spVALUE& _nonce, spBYTES& _code, Storage const& _storage)
{
m_address = spFH20(_addr.copy());
m_balance = spVALUE(_balance.copy());
m_nonce = spVALUE(_nonce.copy());
m_code = spBYTES(_code.copy());
m_balance = _balance;
m_nonce = _nonce;
m_code = _code;
m_storage = spStorage(new Storage(_storage));
if (m_nonce.getCContent() > c_maxNonce)
ETH_ERROR_MESSAGE("Account `" + m_address->asString() + "` requires nonce <= (2**64)-1");
}

Account::Account(DataObject const& _data)
State::Account::Account(spDataObject& _data)
{
m_address = spFH20(new FH20(_data.getKey()));
m_balance = spVALUE(new VALUE(_data.atKey("balance")));
m_nonce = spVALUE(new VALUE(_data.atKey("nonce")));
m_code = spBYTES(new BYTES(_data.atKey("code")));
m_storage = spStorage(new Storage(_data.atKey("storage")));
m_rawData = _data;
m_address = spFH20(new FH20(_data->getKey()));
m_balance = spVALUE(new VALUE(_data->atKey("balance")));
m_nonce = spVALUE(new VALUE(_data->atKey("nonce")));
m_code = spBYTES(new BYTES(_data->atKey("code")));
m_storage = spStorage(new Storage(_data->atKey("storage")));
if (m_nonce.getCContent() > c_maxNonce)
ETH_ERROR_MESSAGE("Account `" + m_address->asString() + "` requires nonce <= (2**64)-1");
requireJsonFields(_data, "Account " + _data.getKey(),
requireJsonFields(_data, "Account " + _data->getKey(),
{{"balance", {{DataType::String}, jsonField::Required}},
{"code", {{DataType::String}, jsonField::Required}},
{"nonce", {{DataType::String}, jsonField::Required}},
{"storage", {{DataType::Object}, jsonField::Required}}});
}

spDataObject Account::asDataObject(ExportOrder _order) const
spDataObject const& State::Account::asDataObject() const
{
spDataObject out(new DataObject());
string const& addr = m_address->asString();
(*out)["balance"] = m_balance->asString();
(*out)["code"] = m_code->asString();
(*out)["nonce"] = m_nonce->asString();
(*out).atKeyPointer("storage") = m_storage->asDataObject();
(*out).setKey(addr);

if (_order == ExportOrder::OldStyle)
if (m_rawData.isEmpty())
{
(*out).setKeyPos("code", 0);
(*out).setKeyPos("nonce", 1);
(*out).setKeyPos("balance", 2);
// Prepare output data TODO make mutable and generate on request
m_rawData = spDataObject(new DataObject());
(*m_rawData).setKey(m_address->asString());
(*m_rawData)["code"] = m_code->asString();
(*m_rawData)["nonce"] = m_nonce->asString();
(*m_rawData)["balance"] = m_balance->asString();
(*m_rawData).atKeyPointer("storage") = m_storage->asDataObject();
}
return out;
return m_rawData;
}

} // namespace teststruct
Expand Down
29 changes: 0 additions & 29 deletions retesteth/testStructures/types/Ethereum/Account.h

This file was deleted.

45 changes: 16 additions & 29 deletions retesteth/testStructures/types/Ethereum/AccountIncomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,35 @@ namespace test
{
namespace teststruct
{
AccountIncomplete::AccountIncomplete(DataObject const& _data)
AccountIncomplete::AccountIncomplete(spDataObject& _data)
{
m_address = spFH20(new FH20(_data.getKey()));
m_shouldNotExist = _data.count("shouldnotexist");
if (_data.count("storage"))
m_storage = spStorage(new Storage(_data.atKey("storage")));
if (_data.count("balance"))
m_balance = spVALUE(new VALUE(_data.atKey("balance")));
if (_data.count("nonce"))
m_rawData = _data;
m_address = spFH20(new FH20(_data->getKey()));
m_shouldNotExist = _data->count("shouldnotexist");
if (_data->count("storage"))
m_storage = spStorage(new Storage(_data->atKey("storage")));
if (_data->count("balance"))
m_balance = spVALUE(new VALUE(_data->atKey("balance")));
if (_data->count("nonce"))
{
m_nonce = spVALUE(new VALUE(_data.atKey("nonce")));
m_nonce = spVALUE(new VALUE(_data->atKey("nonce")));
if (m_nonce.getCContent() > c_maxNonce)
ETH_ERROR_MESSAGE("AccountIncomplete `" + m_address->asString() + "` requires nonce <= (2**64)-1");
}
if (_data.count("code"))
m_code = spBYTES(new BYTES(_data.atKey("code")));
requireJsonFields(_data, "AccountIncomplete " + _data.getKey(),
if (_data->count("code"))
m_code = spBYTES(new BYTES(_data->atKey("code")));
requireJsonFields(_data, "AccountIncomplete " + _data->getKey(),
{{"shouldnotexist", {{DataType::String}, jsonField::Optional}},
{"storage", {{DataType::Object}, jsonField::Optional}},
{"balance", {{DataType::String}, jsonField::Optional}},
{"nonce", {{DataType::String}, jsonField::Optional}},
{"code", {{DataType::String}, jsonField::Optional}}});
ETH_ERROR_REQUIRE_MESSAGE(_data.getSubObjects().size() > 0, "AccountIncomplete must have at least one object!");
ETH_ERROR_REQUIRE_MESSAGE(_data->getSubObjects().size() > 0, "AccountIncomplete must have at least one object!");
}

spDataObject AccountIncomplete::asDataObject(ExportOrder) const
spDataObject const& AccountIncomplete::asDataObject() const
{
spDataObject _out(new DataObject());
DataObject& out = _out.getContent();
string const& addr = m_address->asString();
if (!m_balance.isEmpty())
out["balance"] = m_balance->asString();
if (!m_nonce.isEmpty())
out["nonce"] = m_nonce->asString();
if (!m_code.isEmpty())
out["code"] = m_code->asString();
if (!m_storage.isEmpty())
out.atKeyPointer("storage") = m_storage->asDataObject();
if (m_shouldNotExist)
out["shouldnotexist"] = "1";
out.setKey(addr);
return _out;
return m_rawData;
}


Expand Down
5 changes: 3 additions & 2 deletions retesteth/testStructures/types/Ethereum/AccountIncomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ namespace teststruct
// It can be missing some of the fields defined
struct AccountIncomplete : AccountBase
{
AccountIncomplete(DataObject const&);
AccountIncomplete(spDataObject&);
void setBalance(VALUE const& _balance) { m_balance = spVALUE(new VALUE(_balance)); }
spDataObject asDataObject(ExportOrder) const override;
spDataObject const& asDataObject() const override;
AccountType type() const override { return AccountType::Incomplete; }
};

typedef GCP_SPointer<AccountIncomplete> spAccountIncomplete;
Expand Down
Loading