diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 1383b84b8..9af1e8d5e 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -52,7 +52,10 @@ class PrecompiledContract { u256 const& _blockNumber ) const { return m_cost( _in, _chainParams, _blockNumber ); } - std::pair< bool, bytes > execute( bytesConstRef _in ) const { return m_execute( _in ); } + std::pair< bool, bytes > execute( + bytesConstRef _in, skale::OverlayFS* _overlayFS = nullptr ) const { + return m_execute( _in, _overlayFS ); + } u256 const& startingBlock() const { return m_startingBlock; } @@ -270,9 +273,9 @@ struct ChainOperationParams { Address const& _a, bytesConstRef _in, u256 const& _blockNumber ) const { return precompiled.at( _a ).cost( _in, *this, _blockNumber ); } - std::pair< bool, bytes > executePrecompiled( - Address const& _a, bytesConstRef _in, u256 const& ) const { - return precompiled.at( _a ).execute( _in ); + std::pair< bool, bytes > executePrecompiled( Address const& _a, bytesConstRef _in, u256 const&, + skale::OverlayFS* _overlayFS = nullptr ) const { + return precompiled.at( _a ).execute( _in, _overlayFS ); } bool precompiledExecutionAllowedFrom( Address const& _a, Address const& _from, bool _readOnly ) const { diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 242245ba7..4de49515d 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -331,11 +331,8 @@ bool Executive::call( CallParameters const& _p, u256 const& _gasPrice, Address c m_gas = ( u256 )( _p.gas - g ); bytes output; bool success; - // dev::eth::g_state = m_s.delegateWrite(); - dev::eth::g_overlayFS = m_s.fs(); - tie( success, output ) = - m_chainParams.executePrecompiled( _p.codeAddress, _p.data, m_envInfo.number() ); - // m_s = dev::eth::g_state.delegateWrite(); + tie( success, output ) = m_chainParams.executePrecompiled( + _p.codeAddress, _p.data, m_envInfo.number(), m_s.fs().get() ); size_t outputSize = output.size(); m_output = owning_bytes_ref{ std::move( output ), 0, outputSize }; if ( !success ) { diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index ecbf7f770..bfcff6b7c 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -60,7 +60,6 @@ namespace eth { std::shared_ptr< skutils::json_config_file_accessor > g_configAccesssor; std::shared_ptr< SkaleHost > g_skaleHost; -std::shared_ptr< skale::OverlayFS > g_overlayFS; }; // namespace eth }; // namespace dev @@ -281,7 +280,10 @@ boost::filesystem::path getFileStorageDir( const Address& _address ) { } // TODO: check file name and file existance -ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( createFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -297,14 +299,14 @@ ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { const fs::path filePath( rawFilename ); const fs::path fsDirectoryPath = getFileStorageDir( Address( address ) ); if ( !fs::exists( fsDirectoryPath ) ) { - g_overlayFS->createDirectory( fsDirectoryPath.string() ); + _overlayFS->createDirectory( fsDirectoryPath.string() ); } const fs::path fsFilePath = fsDirectoryPath / filePath.parent_path(); if ( filePath.filename().extension() == "._hash" ) { throw std::runtime_error( "createFile() failed because _hash extension is not allowed" ); } - g_overlayFS->createFile( ( fsFilePath / filePath.filename() ).string(), fileSize ); + _overlayFS->createFile( ( fsFilePath / filePath.filename() ).string(), fileSize ); u256 code = 1; bytes response = toBigEndian( code ); @@ -322,7 +324,10 @@ ETH_REGISTER_PRECOMPILED( createFile )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( uploadChunk )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -349,7 +354,7 @@ ETH_REGISTER_PRECOMPILED( uploadChunk )( bytesConstRef _in ) { const _byte_* data = _in.cropped( 128 + filenameBlocksCount * UINT256_SIZE, dataLength ).data(); - g_overlayFS->writeChunk( filePath.string(), position, dataLength, data ); + _overlayFS->writeChunk( filePath.string(), position, dataLength, data ); u256 code = 1; bytes response = toBigEndian( code ); @@ -451,7 +456,10 @@ ETH_REGISTER_PRECOMPILED( getFileSize )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( deleteFile )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -462,8 +470,8 @@ ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { const fs::path filePath = getFileStorageDir( Address( address ) ) / filename; - g_overlayFS->deleteFile( filePath.string() ); - g_overlayFS->deleteFile( filePath.string() + "._hash" ); + _overlayFS->deleteFile( filePath.string() ); + _overlayFS->deleteFile( filePath.string() + "._hash" ); u256 code = 1; bytes response = toBigEndian( code ); @@ -481,7 +489,10 @@ ETH_REGISTER_PRECOMPILED( deleteFile )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( createDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -491,7 +502,7 @@ ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { convertBytesToString( _in, 32, directoryPath, directoryPathLength ); const fs::path absolutePath = getFileStorageDir( Address( address ) ) / directoryPath; - g_overlayFS->createDirectory( absolutePath.string() ); + _overlayFS->createDirectory( absolutePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -509,7 +520,10 @@ ETH_REGISTER_PRECOMPILED( createDirectory )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( deleteDirectory )( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { + if ( !_overlayFS ) + throw runtime_error( "_overlayFS is nullptr " ); + try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -525,8 +539,8 @@ ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { const std::string absolutePathStr = absolutePath.string(); - g_overlayFS->deleteFile( absolutePathStr + "._hash" ); - g_overlayFS->deleteDirectory( absolutePath.string() ); + _overlayFS->deleteFile( absolutePathStr + "._hash" ); + _overlayFS->deleteDirectory( absolutePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -544,7 +558,8 @@ ETH_REGISTER_PRECOMPILED( deleteDirectory )( bytesConstRef _in ) { return { false, response }; } -ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in ) { +ETH_REGISTER_FS_PRECOMPILED( calculateFileHash ) +( bytesConstRef _in, skale::OverlayFS* _overlayFS ) { try { auto rawAddress = _in.cropped( 12, 20 ).toBytes(); std::string address; @@ -560,7 +575,7 @@ ETH_REGISTER_PRECOMPILED( calculateFileHash )( bytesConstRef _in ) { throw std::runtime_error( "calculateFileHash() failed because file does not exist" ); } - g_overlayFS->calculateFileHash( filePath.string() ); + _overlayFS->calculateFileHash( filePath.string() ); u256 code = 1; bytes response = toBigEndian( code ); @@ -1057,30 +1072,6 @@ ETH_REGISTER_PRECOMPILED( getBlockRandom )( bytesConstRef ) { } ETH_REGISTER_PRECOMPILED( addBalance )( [[maybe_unused]] bytesConstRef _in ) { - /* - try { - auto rawAddress = _in.cropped( 0, 20 ).toBytes(); - std::string address; - boost::algorithm::hex( rawAddress.begin(), rawAddress.end(), back_inserter( address ) ); - auto add = parseBigEndianRightPadded( _in, 20, 32 ); - - auto value = u256( add ); - - g_state.addBalance( Address( address ), value ); - - dev::u256 code = 1; - bytes response = toBigEndian( code ); - return {true, response}; - } catch ( std::exception& ex ) { - std::string strError = ex.what(); - if ( strError.empty() ) - strError = "exception without description"; - LOG( getLogger( VerbosityError ) ) - << "Exception in precompiled/addBalance(): " << strError << "\n"; - } catch ( ... ) { - LOG( getLogger( VerbosityError ) ) << "Unknown exception in precompiled/addBalance()\n"; - } - */ dev::u256 code = 0; bytes response = toBigEndian( code ); return { false, response }; // 1st false - means bad error occur @@ -1111,47 +1102,4 @@ ETH_REGISTER_PRECOMPILED( getIMABLSPublicKey )( bytesConstRef ) { return { false, response }; // 1st false - means bad error occur } -// ETH_REGISTER_PRECOMPILED( convertUint256ToString )( bytesConstRef _in ) { -// try { -// auto rawValue = _in.cropped( 0, 32 ).toBytes(); -// std::string strValue = ""; -// boost::algorithm::hex( rawValue.begin(), rawValue.end(), back_inserter( strValue ) ); -// bytes response = stat_string_to_bytes_with_length( strValue ); -// return {true, response}; -// } catch ( std::exception& ex ) { -// std::string strError = ex.what(); -// if ( strError.empty() ) -// strError = "exception without description"; -// LOG( getLogger( VerbosityError ) ) -// << "Exception in precompiled/convertUint256ToString(): " << strError << "\n"; -// } catch ( ... ) { -// LOG( getLogger( VerbosityError ) ) -// << "Unknown exception in precompiled/convertUint256ToString()\n"; -// } -// u256 code = 0; -// bytes response = toBigEndian( code ); -// return {false, response}; // 1st false - means bad error occur -//} -// ETH_REGISTER_PRECOMPILED( convertAddressToString )( bytesConstRef _in ) { -// try { -// auto rawAddress = _in.cropped( 12, 20 ).toBytes(); -// std::string strValue = ""; -// boost::algorithm::hex( rawAddress.begin(), rawAddress.end(), back_inserter( strValue ) ); -// bytes response = stat_string_to_bytes_with_length( strValue ); -// return {true, response}; -// } catch ( std::exception& ex ) { -// std::string strError = ex.what(); -// if ( strError.empty() ) -// strError = "exception without description"; -// LOG( getLogger( VerbosityError ) ) -// << "Exception in precompiled/convertAddressToString(): " << strError << "\n"; -// } catch ( ... ) { -// LOG( getLogger( VerbosityError ) ) -// << "Unknown exception in precompiled/convertAddressToString()\n"; -// } -// u256 code = 0; -// bytes response = toBigEndian( code ); -// return {false, response}; // 1st false - means bad error occur -//} - } // namespace diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index cab79e312..cc0219dc3 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -51,11 +51,26 @@ namespace eth { extern std::shared_ptr< skutils::json_config_file_accessor > g_configAccesssor; extern std::shared_ptr< SkaleHost > g_skaleHost; extern skale::State g_state; -extern std::shared_ptr< skale::OverlayFS > g_overlayFS; struct ChainOperationParams; -using PrecompiledExecutor = std::function< std::pair< bool, bytes >( bytesConstRef _in ) >; +// allow call both with overlayFS and without it +class PrecompiledExecutor { +public: + std::pair< bool, bytes > operator()( + bytesConstRef _in, skale::OverlayFS* _overlayFS = nullptr ) const { + return proxy( _in, _overlayFS ); + } + PrecompiledExecutor() {} + PrecompiledExecutor( const std::function< std::pair< bool, bytes >( + bytesConstRef _in, skale::OverlayFS* _overlayFS ) >& _func ) + : proxy( _func ) {} + +private: + std::function< std::pair< bool, bytes >( bytesConstRef _in, skale::OverlayFS* _overlayFS ) > + proxy; +}; + using PrecompiledPricer = std::function< bigint( bytesConstRef _in, ChainOperationParams const& _chainParams, u256 const& _blockNumber ) >; @@ -98,13 +113,26 @@ class PrecompiledRegistrar { static PrecompiledRegistrar* s_this; }; +// ignore _overlayFS param and call registered function with 1 parameter // TODO: unregister on unload with a static object. #define ETH_REGISTER_PRECOMPILED( Name ) \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( bytesConstRef _in ); \ static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ ::dev::eth::PrecompiledRegistrar::registerExecutor( \ - #Name, &__eth_registerPrecompiledFunction##Name ); \ + #Name, PrecompiledExecutor( \ + []( bytesConstRef _in, skale::OverlayFS* ) -> std::pair< bool, bytes > { \ + return __eth_registerPrecompiledFunction##Name( _in ); \ + } ) ); \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name + +#define ETH_REGISTER_FS_PRECOMPILED( Name ) \ + static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name( \ + bytesConstRef _in, skale::OverlayFS* _overlayFS ); \ + static PrecompiledExecutor __eth_registerPrecompiledFactory##Name = \ + ::dev::eth::PrecompiledRegistrar::registerExecutor( \ + #Name, PrecompiledExecutor( &__eth_registerPrecompiledFunction##Name ) ); \ static std::pair< bool, bytes > __eth_registerPrecompiledFunction##Name + #define ETH_REGISTER_PRECOMPILED_PRICER( Name ) \ static bigint __eth_registerPricerFunction##Name( \ bytesConstRef _in, ChainOperationParams const& _chainParams, u256 const& _blockNumber ); \ diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 7be67c511..3483a4699 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1796,66 +1796,6 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( !res.first ); } -// temporary merge tests for getConfigVariable -// because of the specifics in test design -//BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { -// ChainParams chainParams; -// chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); -// chainParams.sealEngineName = NoProof::name(); -// chainParams.allowFutureBlocks = true; - -// dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); - -// std::unique_ptr client; -// dev::TransientDirectory m_tmpDir; -// auto monitor = make_shared< InstanceMonitor >("test"); -// setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); -// client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, -// shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); - -// client->injectSkaleHost(); -// client->startWorking(); - -// client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); - -// ClientTest* testClient = asClientTest( client.get() ); - -// testClient->mineBlocks( 1 ); -// testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); -// dev::eth::g_skaleHost = testClient->skaleHost(); - -// PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - -// std::string input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); -// bytes in = fromHex( numberToHex( 32 ) + input ); -// auto res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( res.first ); -// BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); -// input = input.substr(0, 58); // remove 0s in the end - -// in = fromHex( numberToHex( 29 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); -// input = input.substr(0, 76); // remove 0s in the end -// in = fromHex( numberToHex( 38 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); - -// input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); -// input = input.substr(0, 78); // remove 0s in the end -// in = fromHex( numberToHex( 39 ) + input ); -// res = exec( bytesConstRef( in.data(), in.size() ) ); - -// BOOST_REQUIRE( !res.first ); -//} - struct FilestorageFixture : public TestOutputHelperFixture { FilestorageFixture() { ownerAddress = Address( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ); @@ -1875,7 +1815,7 @@ struct FilestorageFixture : public TestOutputHelperFixture { file.seekp( static_cast< long >( fileSize ) - 1 ); file.write( "0", 1 ); - dev::eth::g_overlayFS = std::make_shared< skale::OverlayFS >( true ); + m_overlayFS = std::make_shared< skale::OverlayFS >( true ); } ~FilestorageFixture() override { @@ -1889,6 +1829,7 @@ struct FilestorageFixture : public TestOutputHelperFixture { std::string fileName; std::size_t fileSize; boost::filesystem::path pathToFile; + std::shared_ptr< skale::OverlayFS > m_overlayFS; }; BOOST_FIXTURE_TEST_SUITE( FilestoragePrecompiledTests, FilestorageFixture ) @@ -1901,11 +1842,11 @@ BOOST_AUTO_TEST_CASE( createFile ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( path ) ); BOOST_REQUIRE( boost::filesystem::file_size( path ) == fileSize ); remove( path.c_str() ); @@ -1919,10 +1860,10 @@ BOOST_AUTO_TEST_CASE( fileWithHashExtension ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first == false); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( path ) ); } @@ -1932,10 +1873,10 @@ BOOST_AUTO_TEST_CASE( uploadChunk ) { std::string data = "random_data"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( data.length() ) + stringToHex( data ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); std::ifstream ifs( pathToFile.string() ); std::string content; std::copy_n( std::istreambuf_iterator< char >( ifs.rdbuf() ), data.length(), @@ -1948,7 +1889,7 @@ BOOST_AUTO_TEST_CASE( readChunk ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); std::ifstream file( pathToFile.c_str(), std::ios_base::binary ); @@ -1965,7 +1906,7 @@ BOOST_AUTO_TEST_CASE( readMaliciousChunk ) { fileName = "../../test"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( 0 ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first == false); } @@ -1973,7 +1914,7 @@ BOOST_AUTO_TEST_CASE( getFileSize ) { PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getFileSize" ); bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == toBigEndian( static_cast< u256 >( fileSize ) ) ); } @@ -1984,7 +1925,7 @@ BOOST_AUTO_TEST_CASE( getMaliciousFileSize ) { fileName = "../../test"; bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( !res.first ); } @@ -1992,23 +1933,23 @@ BOOST_AUTO_TEST_CASE( deleteFile ) { PrecompiledExecutor execCreate = PrecompiledRegistrar::executor( "createFile" ); bytes inCreate = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - execCreate( bytesConstRef( inCreate.data(), inCreate.size() ) ); - dev::eth::g_overlayFS->commit(); + execCreate( bytesConstRef( inCreate.data(), inCreate.size() ), m_overlayFS.get() ); + m_overlayFS->commit(); PrecompiledExecutor execHash = PrecompiledRegistrar::executor( "calculateFileHash" ); bytes inHash = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - execHash( bytesConstRef( inHash.data(), inHash.size() ) ); - dev::eth::g_overlayFS->commit(); + execHash( bytesConstRef( inHash.data(), inHash.size() ), m_overlayFS.get() ); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( pathToFile.string() + "._hash" ) ); PrecompiledExecutor exec = PrecompiledRegistrar::executor( "deleteFile" ); bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( pathToFile ) ); BOOST_REQUIRE( !boost::filesystem::exists( pathToFile.string() + "._hash" ) ); } @@ -2021,10 +1962,10 @@ BOOST_AUTO_TEST_CASE( createDirectory ) { dev::getDataDir() / "filestorage" / ownerAddress.hex() / dirName; bytes in = fromHex( hexAddress + numberToHex( dirName.length() ) + stringToHex( dirName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( pathToDir ) ); remove( pathToDir.c_str() ); } @@ -2038,11 +1979,11 @@ BOOST_AUTO_TEST_CASE( deleteDirectory ) { boost::filesystem::create_directories( pathToDir ); bytes in = fromHex( hexAddress + numberToHex( dirName.length() ) + stringToHex( dirName ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( !boost::filesystem::exists( pathToDir ) ); } @@ -2060,11 +2001,11 @@ BOOST_AUTO_TEST_CASE( calculateFileHash ) { bytes in = fromHex( hexAddress + numberToHex( fileName.length() ) + stringToHex( fileName ) + numberToHex( fileSize ) ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ), m_overlayFS.get() ); BOOST_REQUIRE( res.first ); - dev::eth::g_overlayFS->commit(); + m_overlayFS->commit(); BOOST_REQUIRE( boost::filesystem::exists( fileHashName ) ); std::ifstream resultFile( fileHashName ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index cd2de8781..86945f627 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -37,7 +37,6 @@ #include #include #include "genesisGeneration2Config.h" -// SKALE#include #include #include #include @@ -195,15 +194,15 @@ static std::string const c_genesisConfigString = "balance": "0", "code": "0x6080604052348015600f57600080fd5b506004361060325760003560e01c80639b063104146037578063cd16ecbf146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050608d565b005b608b60048036036020811015607657600080fd5b81019080803590602001909291905050506097565b005b8060018190555050565b806000819055505056fea265627a7a7231582029df540a7555533ef4b3f66bc4f9abe138b00117d1496efbfd9d035a48cd595e64736f6c634300050d0032", "storage": { - "0x0": "0x01" - }, + "0x0": "0x01" + }, "nonce": "0" }, "0xD2002000000000000000000000000000000000D2": { "balance": "0", "code": "0x608060405234801561001057600080fd5b50600436106100455760003560e01c806313f44d101461005557806338eada1c146100af5780634ba79dfe146100f357610046565b5b6002801461005357600080fd5b005b6100976004803603602081101561006b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610137565b60405180821515815260200191505060405180910390f35b6100f1600480360360208110156100c557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506101f4565b005b6101356004803603602081101561010957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061030f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16148061019957506101988261042b565b5b806101ed5750600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b9050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102b5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b60018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f43616c6c6572206973206e6f7420746865206f776e657200000000000000000081525060200191505060405180910390fd5b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600080823b90506000811191505091905056fea26469706673582212202aca1f7abb7d02061b58de9b559eabe1607c880fda3932bbdb2b74fa553e537c64736f6c634300060c0033", "storage": { - }, + }, "nonce": "0" }, "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { @@ -213,10 +212,10 @@ static std::string const c_genesisConfigString = "storage" : { } }, - "0xD2001300000000000000000000000000000000D4": { - "balance": "0", - "nonce": "0", - "storage": {}, + "0xD2001300000000000000000000000000000000D4": { + "balance": "0", + "nonce": "0", + "storage": {}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80632098776714610051578063b8bd717f1461007f578063d37165fa146100ad578063fdde8d66146100db575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610109565b005b6100ab6004803603602081101561009557600080fd5b8101908080359060200190929190505050610136565b005b6100d9600480360360208110156100c357600080fd5b8101908080359060200190929190505050610170565b005b610107600480360360208110156100f157600080fd5b8101908080359060200190929190505050610191565b005b60005a90505b815a8203101561011e5761010f565b600080fd5b815a8203101561013257610123565b5050565b60005a90505b815a8203101561014b5761013c565b600060011461015957600080fd5b5a90505b815a8203101561016c5761015d565b5050565b60005a9050600081830390505b805a8303101561018c5761017d565b505050565b60005a90505b815a820310156101a657610197565b60016101b157600080fd5b5a90505b815a820310156101c4576101b5565b505056fea264697066735822122089b72532621e7d1849e444ee6efaad4fb8771258e6f79755083dce434e5ac94c64736f6c63430006000033" } } @@ -316,22 +315,12 @@ JsonRpcFixture( const std::string& _config = "", bool _owner = true, chainParams.sChain.multiTransactionMode = _mtmEnabled; chainParams.nodeInfo.syncNode = _isSyncNode; - // web3.reset( new WebThreeDirect( - // "eth tests", tempDir.path(), "", chainParams, WithExisting::Kill, {"eth"}, - // true ) ); - auto monitor = make_shared< InstanceMonitor >("test"); setenv("DATA_DIR", tempDir.path().c_str(), 1); client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, tempDir.path(), WithExisting::Kill ) ); - // client.reset( - // new eth::Client( chainParams, ( int ) chainParams.networkID, shared_ptr< - // GasPricer >(), - // tempDir.path(), "", WithExisting::Kill, TransactionQueue::Limits{100000, - // 1024} ) ); - client->setAuthor( coinbase.address() ); // wait for 1st block - because it's always empty @@ -478,18 +467,6 @@ BOOST_AUTO_TEST_CASE( jsonrpc_gasPrice ) { BOOST_CHECK_EQUAL( gasPrice, toJS( 20 * dev::eth::shannon ) ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(jsonrpc_isListening) -//{ -// web3->startNetwork(); -// bool listeningOn = rpcClient->net_listening(); -// BOOST_CHECK_EQUAL(listeningOn, web3->isNetworkStarted()); -// -// web3->stopNetwork(); -// bool listeningOff = rpcClient->net_listening(); -// BOOST_CHECK_EQUAL(listeningOff, web3->isNetworkStarted()); -//} - BOOST_AUTO_TEST_CASE( jsonrpc_accounts, *boost::unit_test::precondition( dev::test::run_not_express ) ) { JsonRpcFixture fixture; @@ -517,22 +494,6 @@ BOOST_AUTO_TEST_CASE( jsonrpc_number ) { BOOST_CHECK_EQUAL( numberAfter, fixture.client->number() ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(jsonrpc_peerCount) -//{ -// auto peerCount = jsToU256(rpcClient->net_peerCount()); -// BOOST_CHECK_EQUAL(web3->peerCount(), peerCount); -//} - -// BOOST_AUTO_TEST_CASE(jsonrpc_setListening) -//{ -// rpcClient->admin_net_start(adminSession); -// BOOST_CHECK_EQUAL(web3->isNetworkStarted(), true); -// -// rpcClient->admin_net_stop(adminSession); -// BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false); -//} - BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) { std::string _config = c_genesisConfigString; @@ -540,12 +501,12 @@ BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) Json::Reader().parse( _config, ret ); // Set chainID = 65535 - ret["params"]["chainID"] = "0xffff"; + ret["params"]["chainID"] = "0xffff"; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); JsonRpcFixture fixture( config ); - + auto version = fixture.rpcClient->net_version(); BOOST_CHECK_EQUAL( version, "65535" ); } @@ -588,7 +549,6 @@ BOOST_AUTO_TEST_CASE( eth_sendTransaction ) { BOOST_CHECK_EQUAL( jsToDecimal( balanceString ), "0" ); dev::eth::simulateMining( *( fixture.client ), 1 ); - // BOOST_CHECK_EQUAL(client->blockByNumber(LatestBlock).author(), address); balance = fixture.client->balanceAt( address ); balanceString = fixture.rpcClient->eth_getBalance( toJS( address ), "latest" ); @@ -839,8 +799,8 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { // pragma solidity 0.8.4; // contract test { // uint value; - // function f(uint a) public pure returns(uint d) { - // return a * 7; + // function f(uint a) public pure returns(uint d) { + // return a * 7; // } // function setValue(uint _value) external { // value = _value; @@ -908,191 +868,18 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { transact["to"] = contractAddress; transact["data"] = "0x552410770000000000000000000000000000000000000000000000000000000000000001"; txHash = fixture.rpcClient->eth_sendTransaction( transact ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); auto res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); Json::Value inputTx; inputTx["to"] = contractAddress; inputTx["input"] = "0x552410770000000000000000000000000000000000000000000000000000000000000002"; txHash = fixture.rpcClient->eth_sendTransaction( inputTx ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); -} - -/* -// As block rotation is not exact now - let's use approximate comparisons -#define REQUIRE_APPROX_EQUAL(a, b) BOOST_REQUIRE(4*(a) > 3*(b) && 4*(a) < 5*(b)) - -BOOST_AUTO_TEST_CASE( logs_range, *boost::unit_test::disabled() ) { - JsonRpcFixture fixture; - dev::eth::simulateMining( *( fixture.client ), 1 ); - - -//pragma solidity >=0.4.10 <0.7.0; - -//contract Logger{ -// fallback() external payable { -// log2(bytes32(block.number+1), bytes32(block.number), "dimalit"); -// } -//} - - string bytecode = - "6080604052348015600f57600080fd5b50607d80601d6000396000f3fe60806040527f64696d616c69740000000000000000000000000000000000000000000000000043600102600143016001026040518082815260200191505060405180910390a200fea2646970667358221220ecafb98cd573366a37976cb7a4489abe5389d1b5989cd7b7136c8eb0c5ba0b5664736f6c63430006000033"; - - Json::Value create; - create["code"] = bytecode; - create["gas"] = "180000"; // TODO or change global default of 90000? - - string deployHash = fixture.rpcClient->eth_sendTransaction( create ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - - // -> blockNumber = 2 (1 for bootstrapAll, 1 for deploy) - - Json::Value deployReceipt = fixture.rpcClient->eth_getTransactionReceipt( deployHash ); - string contractAddress = deployReceipt["contractAddress"].asString(); - - Json::Value filterObj; - filterObj["address"] = contractAddress; - filterObj["fromBlock"] = "0x1"; - string filterId = fixture.rpcClient->eth_newFilter( filterObj ); - - Json::Value res = fixture.rpcClient->eth_getFilterLogs(filterId); - BOOST_REQUIRE(res.isArray()); - BOOST_REQUIRE_EQUAL(res.size(), 0); - res = fixture.rpcClient->eth_getFilterChanges(filterId); - BOOST_REQUIRE(res.isArray()); - BOOST_REQUIRE_EQUAL(res.size(), 0); - - // need blockNumber==2+255 afterwards - for(int i=0; i<255; ++i){ - Json::Value t; - t["from"] = toJS( fixture.coinbase.address() ); - t["value"] = jsToDecimal( "0" ); - t["to"] = contractAddress; - t["gas"] = "99000"; - - std::string txHash = fixture.rpcClient->eth_sendTransaction( t ); - BOOST_REQUIRE( !txHash.empty() ); - - dev::eth::mineTransaction( *( fixture.client ), 1 ); - } - BOOST_REQUIRE_EQUAL(fixture.client->number(), 2 + 255); - - // ask for logs - Json::Value t; - t["fromBlock"] = 0; // really 3 - t["toBlock"] = 251; - t["address"] = contractAddress; - Json::Value logs = fixture.rpcClient->eth_getLogs(t); - BOOST_REQUIRE(logs.isArray()); - BOOST_REQUIRE_EQUAL(logs.size(), 249); - - // check logs - for(size_t i=0; ieth_sendTransaction( t ); - BOOST_REQUIRE( !lastHash.empty() ); - - dev::eth::mineTransaction( *( fixture.client ), 1 ); - } - BOOST_REQUIRE_EQUAL(fixture.client->number(), 512); - - // ask for logs - t["toBlock"] = 512; - logs = fixture.rpcClient->eth_getLogs(t); - BOOST_REQUIRE(logs.isArray()); - REQUIRE_APPROX_EQUAL(logs.size(), 256+64); - - // and filter - res = fixture.rpcClient->eth_getFilterChanges(filterId); - BOOST_REQUIRE_EQUAL(res.size(), 255+255); // NB!! we had pending here, but then they disappeared! - res = fixture.rpcClient->eth_getFilterLogs(filterId); - REQUIRE_APPROX_EQUAL(res.size(), 256+64); - - ///////////////// OTHER CALLS ////////////////// - // HACK this may return DIFFERENT block! because of undeterministic block rotation! - string existing = "0x1df"; string existing_hash = logs[256+64-1-1-32]["blockHash"].asString(); - //cerr << logs << endl; - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByNumber(existing, true)); - BOOST_REQUIRE_EQUAL(res["number"], existing); - BOOST_REQUIRE(res["transactions"].isArray() && res["transactions"].size() == 1); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByNumber(nonexisting, true), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockByHash(existing_hash, false)); - REQUIRE_APPROX_EQUAL(dev::eth::jsToBlockNumber(res["number"].asCString()), dev::eth::jsToBlockNumber(existing)); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockByHash(nonexisting_hash, true), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByNumber(existing)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByNumber(nonexisting), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getBlockTransactionCountByHash(existing_hash)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x1"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBlockTransactionCountByHash(nonexisting_hash), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockNumber(existing)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockNumber(nonexisting), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getUncleCountByBlockHash(existing_hash)); - BOOST_REQUIRE_EQUAL(res.asString(), "0x0"); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleCountByBlockHash(nonexisting_hash), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(existing, "0x0")); - BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); - // HACK disabled for undeterminism BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); - - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(existing_hash, "0x0")); - // HACK disabled for undeterminism BOOST_REQUIRE_EQUAL(res["blockNumber"], existing); - BOOST_REQUIRE_EQUAL(res["blockHash"], existing_hash); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(existing, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockNumberAndIndex(nonexisting, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(existing_hash, "0x0"), jsonrpc::JsonRpcException); - BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getUncleByBlockHashAndIndex(nonexisting_hash, "0x0"), jsonrpc::JsonRpcException); - - // - - BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionByHash(deployHash), jsonrpc::JsonRpcException); - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionByHash(lastHash)); - BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); - - BOOST_REQUIRE_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(deployHash), jsonrpc::JsonRpcException); - BOOST_REQUIRE_NO_THROW(res = fixture.rpcClient->eth_getTransactionReceipt(lastHash)); - BOOST_REQUIRE_EQUAL(res["transactionHash"], lastHash); - BOOST_REQUIRE_EQUAL(res["blockNumber"], "0x200"); - BOOST_REQUIRE_EQUAL(res["to"], contractAddress); + res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); } -*/ BOOST_AUTO_TEST_CASE( deploy_contract_from_owner ) { JsonRpcFixture fixture( c_genesisConfigString ); @@ -1606,76 +1393,6 @@ BOOST_AUTO_TEST_CASE( web3_sha3, "0xc6888fa159d67f77c2f3d7a402e199802766bd7e8d4d1ecd2274fc920265d56a", result ); } -// SKALE disabled -// BOOST_AUTO_TEST_CASE(debugAccountRangeAtFinalBlockState) -//{ -// // mine to get some balance at coinbase -// dev::eth::mine(*(client), 1); - -// // send transaction to have non-emtpy block -// Address receiver = Address::random(); -// Json::Value tx; -// tx["from"] = toJS(coinbase.address()); -// tx["value"] = toJS(10); -// tx["to"] = toJS(receiver); -// tx["gas"] = toJS(EVMSchedule().txGas); -// tx["gasPrice"] = toJS(10 * dev::eth::szabo); -// string txHash = rpcClient->eth_sendTransaction(tx); -// BOOST_REQUIRE(!txHash.empty()); - -// dev::eth::mineTransaction(*(client), 1); - -// string receiverHash = toString(sha3(receiver)); - -// // receiver doesn't exist in the beginning of the 2nd block -// Json::Value result = rpcClient->debug_accountRangeAt("2", 0, "0", 100); -// BOOST_CHECK(!result["addressMap"].isMember(receiverHash)); - -// // receiver exists in the end of the 2nd block -// result = rpcClient->debug_accountRangeAt("2", 1, "0", 100); -// BOOST_CHECK(result["addressMap"].isMember(receiverHash)); -// BOOST_CHECK_EQUAL(result["addressMap"][receiverHash], toString(receiver)); -//} - -// SKALE disabled -// BOOST_AUTO_TEST_CASE(debugStorageRangeAtFinalBlockState) -//{ -// // mine to get some balance at coinbase -// dev::eth::mine(*(client), 1); - -// // pragma solidity ^0.4.22; -// // contract test -// //{ -// // uint hello = 7; -// //} -// string initCode = -// "608060405260076000553415601357600080fd5b60358060206000396000" -// "f3006080604052600080fd00a165627a7a7230582006db0551577963b544" -// "3e9501b4b10880e186cff876cd360e9ad6e4181731fcdd0029"; - -// Json::Value tx; -// tx["code"] = initCode; -// tx["from"] = toJS(coinbase.address()); -// string txHash = rpcClient->eth_sendTransaction(tx); - -// dev::eth::mineTransaction(*(client), 1); - -// Json::Value receipt = rpcClient->eth_getTransactionReceipt(txHash); -// string contractAddress = receipt["contractAddress"].asString(); - -// // contract doesn't exist in the beginning of the 2nd block -// Json::Value result = rpcClient->debug_storageRangeAt("2", 0, contractAddress, "0", 100); -// BOOST_CHECK(result["storage"].empty()); - -// // contracts exists in the end of the 2nd block -// result = rpcClient->debug_storageRangeAt("2", 1, contractAddress, "0", 100); -// BOOST_CHECK(!result["storage"].empty()); -// string keyHash = toJS(sha3(u256{0})); -// BOOST_CHECK(!result["storage"][keyHash].empty()); -// BOOST_CHECK_EQUAL(result["storage"][keyHash]["key"].asString(), "0x00"); -// BOOST_CHECK_EQUAL(result["storage"][keyHash]["value"].asString(), "0x07"); -//} - BOOST_AUTO_TEST_CASE( test_importRawBlock ) { JsonRpcFixture fixture( c_genesisConfigString ); string blockHash = fixture.rpcClient->test_importRawBlock( @@ -1868,7 +1585,7 @@ BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { "0200191505060405180910390f35b600081600081905550600190509190" "505600a165627a7a72305820d8407d9cdaaf82966f3fa7a3e665b8cf4e6" "5ee8909b83094a3f856b9051274500029"; - + auto senderAddress = fixture.coinbase.address(); Json::Value create; @@ -1977,7 +1694,7 @@ contract Logger{ }// j overflow } } -*/ +*/ string bytecode = "6080604052348015600f57600080fd5b50609b8061001e6000396000f3fe608060405260015460001b60005460001b4360001b4360001b6040518082815260200191505060405180910390a3600160008154809291906001019190505550600a6001541415606357600060018190555060008081548092919060010191905055505b00fea2646970667358221220fdf2f98961b803b6b32dfc9be766990cbdb17559d9a03724d12fc672e33804b164736f6c634300060c0033"; @@ -2296,7 +2013,7 @@ contract TestEstimateGas { BOOST_AUTO_TEST_CASE( storage_limit_contract ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 10 ); - + // pragma solidity 0.4.25; // contract TestStorageLimit { @@ -2324,18 +2041,18 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { // function zero(uint256 index) public { // storageArray[index] = 0; // } - + // function strangeFunction(uint256 index) public { // storageArray[index] = 1; // storageArray[index] = 0; // storageArray[index] = 2; // } // } - + std::string bytecode = "0x608060405234801561001057600080fd5b5061034f806100206000396000f300608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630e031ab1146100885780631007f753146100c95780636057361d146100f6578063c298557814610123578063c67cd8841461013a578063d269ad4e14610167578063e0353e5914610194575b600080fd5b34801561009457600080fd5b506100b3600480360381019080803590602001909291905050506101c1565b6040518082815260200191505060405180910390f35b3480156100d557600080fd5b506100f4600480360381019080803590602001909291905050506101e4565b005b34801561010257600080fd5b5061012160048036038101908080359060200190929190505050610204565b005b34801561012f57600080fd5b50610138610233565b005b34801561014657600080fd5b506101656004803603810190808035906020019092919050505061026c565b005b34801561017357600080fd5b50610192600480360381019080803590602001909291905050506102a3565b005b3480156101a057600080fd5b506101bf60048036038101908080359060200190929190505050610302565b005b6000818154811015156101d057fe5b906000526020600020016000915090505481565b6000818154811015156101f357fe5b906000526020600020016000905550565b600081908060018154018082558091505090600182039060005260206000200160009091929091909150555050565b60008080549050905060006001908060018154018082558091505090600182039060005260206000200160009091929091909150555050565b60008190806001815401808255809150509060018203906000526020600020016000909192909190915055506102a0610233565b50565b60016000828154811015156102b457fe5b9060005260206000200181905550600080828154811015156102d257fe5b906000526020600020018190555060026000828154811015156102f157fe5b906000526020600020018190555050565b6000808281548110151561031257fe5b9060005260206000200181905550505600a165627a7a723058201ed095336772c55688864a6b45ca6ab89311c5533f8d38cdf931f1ce38be78080029"; - + auto senderAddress = fixture.coinbase.address(); - + Json::Value create; create["from"] = toJS( senderAddress ); create["data"] = bytecode; @@ -2363,7 +2080,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txPushValueAndCall ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); - + Json::Value txPushValue; // call store(2) txPushValue["to"] = contractAddress; txPushValue["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000002"; @@ -2372,7 +2089,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txPushValue ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); - + Json::Value txThrow; // trying to call store(3) txThrow["to"] = contractAddress; txThrow["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000003"; @@ -2381,7 +2098,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txHash = fixture.rpcClient->eth_sendTransaction( txThrow ); dev::eth::mineTransaction( *( fixture.client ), 1 ); BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); - + Json::Value txEraseValue; // call erase(2) txEraseValue["to"] = contractAddress; txEraseValue["data"] = "0x1007f7530000000000000000000000000000000000000000000000000000000000000002"; @@ -2585,7 +2302,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_predeployed ) { JsonRpcFixture fixture( c_genesisConfigString ); dev::eth::simulateMining( *( fixture.client ), 20 ); BOOST_REQUIRE( fixture.client->state().storageUsedTotal() == 64 ); - + string contractAddress = "0xC2002000000000000000000000000000000000C2"; string senderAddress = toJS(fixture.coinbase.address()); @@ -2813,7 +2530,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { Json::Value eip1898BadFormed3; eip1898BadFormed3["blockHash"] = dev::h256::random().hex(); eip1898BadFormed3["requireCanonical"] = 228; - + Json::Value eip1898BadFormed4; eip1898BadFormed4["blockNumber"] = dev::h256::random().hex(); eip1898BadFormed4["requireCanonical"] = true; @@ -2824,7 +2541,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { std::array wellFormedCalls = { eip1898WellFormed, eip1898WellFormed1, eip1898WellFormed2, eip1898WellFormed3 }; std::array badFormedCalls = { eip1898BadFormed, eip1898BadFormed1, eip1898BadFormed2, eip1898BadFormed3, eip1898BadFormed4, eip1898BadFormed5 }; - + auto address = fixture.coinbase.address(); std::string response; @@ -2835,7 +2552,7 @@ BOOST_AUTO_TEST_CASE( EIP1898Calls ) { for (const auto& call: badFormedCalls) { BOOST_REQUIRE_THROW(fixture.rpcClient->eth_getBalanceEIP1898( toJS( address ), call ), jsonrpc::JsonRpcException); } - + for (const auto& call: wellFormedCalls) { Json::Value transactionCallObject; transactionCallObject["to"] = "0x0000000000000000000000000000000000000005"; @@ -3366,15 +3083,15 @@ BOOST_AUTO_TEST_CASE( deploy_controller_generation2 ) { BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // Inserting ConfigController mockup into config and enabling flexibleDeploymentPatch. - // ConfigController mockup contract: - + // ConfigController mockup contract: + // pragma solidity ^0.8.9; // contract ConfigController { // bool public freeContractDeployment = false; // function isAddressWhitelisted(address addr) external view returns (bool) { // return false; // } - // function isDeploymentAllowed(address origin, address sender) + // function isDeploymentAllowed(address origin, address sender) // external view returns (bool) { // return freeContractDeployment; // } @@ -3383,7 +3100,7 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // } // } - string configControllerV2 = + string configControllerV2 = "0x608060405234801561001057600080fd5b506004361061004c576000" "3560e01c806313f44d1014610051578063a2306c4f14610081578063d0" "f557f41461009f578063f7e2a91b146100cf575b600080fd5b61006b60" @@ -3564,7 +3281,7 @@ BOOST_AUTO_TEST_CASE( PrecompiledPrintFakeEth, *boost::unit_test::precondition( balance = fixture.client->balanceAt( jsToAddress( "0x5C4e11842E8Be09264DC1976943571D7AF6d00f8" ) ); BOOST_REQUIRE_EQUAL( balance, 16 ); - Json::Value printFakeEthCall; + Json::Value printFakeEthCall; printFakeEthCall["data"] = "0x5C4e11842E8Be09264DC1976943571D7AF6d00f80000000000000000000000000000000000000000000000000000000000000010"; printFakeEthCall["from"] = "0x5C4e11842E8be09264dc1976943571d7Af6d00F9"; printFakeEthCall["to"] = "0000000000000000000000000000000000000006"; @@ -3575,7 +3292,7 @@ BOOST_AUTO_TEST_CASE( PrecompiledPrintFakeEth, *boost::unit_test::precondition( BOOST_REQUIRE_EQUAL( balance, 16 ); // pragma solidity ^0.4.25; - + // contract Caller { // function call() public view { // bool status; @@ -3735,52 +3452,6 @@ BOOST_AUTO_TEST_CASE( mtm_import_future_txs ) { // TODO: Enable for multitransaction mode checking -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode ) { -// auto _config = c_genesisConfigString; -// Json::Value ret; -// Json::Reader().parse( _config, ret ); -// /* Test contract -// pragma solidity ^0.8.9; -// contract Test { -// function isMTMEnabled() external pure returns (bool) { -// return true; -// } -// } -// */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906069565b60405180910390f35b60006001905090565b60008115159050919050565b6063816050565b82525050565b6000602082019050607c6000830184605c565b9291505056fea26469706673582212208d89ce57f69b9b53e8f0808cbaa6fa8fd21a495ab92d0b48b6e47d903989835464736f6c63430008090033"; -// Json::FastWriter fastWriter; -// std::string config = fastWriter.write( ret ); -// JsonRpcFixture fixture( config ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( mtm ); -// } - -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode_false ) { -// auto _config = c_genesisConfigString; -// Json::Value ret; -// Json::Reader().parse( _config, ret ); -// /* Test contract -// pragma solidity ^0.8.9; -// contract Test { -// function isMTMEnabled() external pure returns (bool) { -// return false; -// } -// } -// */ -// ret["accounts"]["0xD2002000000000000000000000000000000000D2"]["code"] = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063bad0396e14602d575b600080fd5b60336047565b604051603e91906065565b60405180910390f35b600090565b60008115159050919050565b605f81604c565b82525050565b6000602082019050607860008301846058565b9291505056fea2646970667358221220c88541a65627d63d4b0cc04094bc5b2154a2700c97677dcd5de2ee2a27bed58564736f6c63430008090033"; -// Json::FastWriter fastWriter; -// std::string config = fastWriter.write( ret ); -// JsonRpcFixture fixture( config ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( !mtm ); -// } - -// BOOST_AUTO_TEST_CASE( check_multitransaction_mode_empty ) { -// JsonRpcFixture fixture( c_genesisConfigString ); -// bool mtm = fixture.client->checkMultitransactionMode(fixture.client->state(), fixture.client->gasBidPrice()); -// BOOST_REQUIRE( !mtm ); -// } - // historic node shall ignore invalid transactions in block BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { JsonRpcFixture fixture( c_genesisConfigString, true, true, false, true ); @@ -4076,11 +3747,11 @@ BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE( FilestorageCacheSuite ) BOOST_AUTO_TEST_CASE( cached_filestorage ) { - + auto _config = c_genesisConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); RestrictedAddressFixture fixture( config ); @@ -4110,7 +3781,7 @@ BOOST_AUTO_TEST_CASE( uncached_filestorage ) { auto _config = c_genesisConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 9999999999999; + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 9999999999999; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); RestrictedAddressFixture fixture( config );