Skip to content

Commit

Permalink
Merge pull request #2097 from skalenetwork/bug/2031-fix-unit-tests
Browse files Browse the repository at this point in the history
Bug/2031 fix unit tests
  • Loading branch information
DmytroNazarenko authored Feb 7, 2025
2 parents 21834e1 + bd06b85 commit c27e6c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/unittests/libethereum/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ BOOST_AUTO_TEST_CASE( ClientSnapshotsTest, *boost::unit_test::disabled() ) {

BOOST_REQUIRE( testClient->latestBlock().info().stateRoot() == empty_state_root_hash );

std::this_thread::sleep_for( 1000ms );
std::this_thread::sleep_for( 3000ms );

BOOST_REQUIRE( fs::exists( fs::path( fixture.getTmpDataDir() ) / "snapshots" / "2" / "snapshot_hash.txt" ) );

Expand Down
6 changes: 3 additions & 3 deletions test/unittests/libskutils/test_skutils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,9 @@ void test_print_header_name( const char* s ) {
cc::_on_ = bPrev;
}


int g_nDefaultPort = 9696;
int g_nDefaultPortProxygen = 8686;
int randomOffset = std::rand() % 50000;
int g_nDefaultPort = 9696 + randomOffset;
int g_nDefaultPortProxygen = 8686 + randomOffset;

std::vector< std::string > g_vecTestClientNamesA = {"Frodo", "Bilbo", "Sam", "Elrond", "Galadriel",
"Celeborn", "Balrog", "Anduin", "Samwise", "Gandalf", "Legolas", "Aragorn", "Gimli", "Faramir",
Expand Down
38 changes: 20 additions & 18 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ struct JsonRpcFixture : public TestOutputHelperFixture {
client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID,
shared_ptr< GasPricer >(), NULL, monitor, tempDir.path(), WithExisting::Kill ) );

client->setAuthor( coinbase.address() );
if ( !_generation2 )
client->setAuthor( coinbase.address() );
else
client->setAuthor( chainParams.sChain.blockAuthor );

// wait for 1st block - because it's always empty
std::promise< void > blockPromise;
Expand All @@ -352,11 +355,6 @@ struct JsonRpcFixture : public TestOutputHelperFixture {
if ( !_isSyncNode )
blockPromise.get_future().wait();

if ( !_generation2 )
client->setAuthor( coinbase.address() );
else
client->setAuthor( chainParams.sChain.blockAuthor );

using FullServer = ModularServer< rpc::EthFace, rpc::NetFace, rpc::Web3Face,
rpc::AdminEthFace /*, rpc::AdminNetFace*/, rpc::DebugFace, rpc::TestFace >;

Expand Down Expand Up @@ -396,7 +394,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture {

sleep( 1 );

auto httpClient = new jsonrpc::HttpClient(
httpClient = new jsonrpc::HttpClient(
"http://" + chainParams.nodeInfo.ip + ":" +
std::to_string( serverOpts.netOpts_.bindOptsStandard_.nBasePortHTTP4_ ) );
httpClient->SetTimeout( 1000000000 );
Expand All @@ -410,6 +408,9 @@ struct JsonRpcFixture : public TestOutputHelperFixture {
~JsonRpcFixture() {
if ( skale_server_connector )
skale_server_connector->StopListening();

if ( httpClient )
delete httpClient;
BOOST_TEST_MESSAGE( "Destructed JsonRpcFixture" );
}

Expand Down Expand Up @@ -447,6 +448,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture {
unique_ptr< WebThreeStubClient > rpcClient;
std::string adminSession;
SkaleServerOverride* skale_server_connector;
jsonrpc::HttpClient* httpClient;
time_t powPatchActivationTimestamp;
time_t push0PatchActivationTimestamp;
};
Expand Down Expand Up @@ -2510,7 +2512,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txCall["from"] = toJS( senderAddress );
txCall["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_call( txCall, "latest" );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 0 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 0 );

Json::Value txPushValueAndCall; // call storeAndCall(1)
txPushValueAndCall["to"] = contractAddress;
Expand All @@ -2520,7 +2522,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txPushValueAndCall["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txPushValueAndCall );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 );

Json::Value txPushValue; // call store(2)
txPushValue["to"] = contractAddress;
Expand All @@ -2530,7 +2532,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txPushValue["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txPushValue );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 );

Json::Value txThrow; // trying to call store(3)
txThrow["to"] = contractAddress;
Expand All @@ -2539,7 +2541,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txThrow["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txThrow );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 );

Json::Value txEraseValue; // call erase(2)
txEraseValue["to"] = contractAddress;
Expand All @@ -2549,7 +2551,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txEraseValue["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txEraseValue );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 );

Json::Value txZeroValue; // call zero(1)
txZeroValue["to"] = contractAddress;
Expand All @@ -2559,7 +2561,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txZeroValue["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txZeroValue );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 64 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 64 );

Json::Value txZeroValue1; // call zero(1)
txZeroValue1["to"] = contractAddress;
Expand All @@ -2569,7 +2571,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txZeroValue1["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txZeroValue1 );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 64 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 64 );

Json::Value txValueChanged; // call strangeFunction(1)
txValueChanged["to"] = contractAddress;
Expand All @@ -2579,7 +2581,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txValueChanged["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 );

Json::Value txValueChanged1; // call strangeFunction(0)
txValueChanged1["to"] = contractAddress;
Expand All @@ -2589,7 +2591,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txValueChanged1["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged1 );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 );

Json::Value txValueChanged2; // call strangeFunction(2)
txValueChanged2["to"] = contractAddress;
Expand All @@ -2599,7 +2601,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txValueChanged2["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged2 );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 );

Json::Value txValueChanged3; // try call strangeFunction(3)
txValueChanged3["to"] = contractAddress;
Expand All @@ -2609,7 +2611,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) {
txValueChanged3["gasPrice"] = fixture.rpcClient->eth_gasPrice();
txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged3 );
dev::eth::mineTransaction( *( fixture.client ), 1 );
BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 );
BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 );
}

BOOST_AUTO_TEST_CASE( storage_limit_chain ) {
Expand Down

0 comments on commit c27e6c6

Please sign in to comment.