From 5a83f73da203e2d57dcef0f0b8bce5672c4a0ce5 Mon Sep 17 00:00:00 2001 From: JimmyShi22 <417711026@qq.com> Date: Mon, 6 Nov 2023 13:02:20 +0800 Subject: [PATCH] fix unittest --- bcos-crypto/bcos-crypto/ChecksumAddress.h | 3 ++- .../test/unittests/interfaces/FeaturesTest.cpp | 11 ++++------- bcos-scheduler/src/DmcExecutor.h | 2 ++ bcos-scheduler/test/testDmcExecutor.cpp | 9 +++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bcos-crypto/bcos-crypto/ChecksumAddress.h b/bcos-crypto/bcos-crypto/ChecksumAddress.h index 3d9402cdad..dcf3cff11f 100644 --- a/bcos-crypto/bcos-crypto/ChecksumAddress.h +++ b/bcos-crypto/bcos-crypto/ChecksumAddress.h @@ -101,7 +101,8 @@ inline std::string newEVMAddress(bcos::crypto::Hash::Ptr _hashImpl, const std::s bytesConstRef _init, u256 const& _salt) { auto hash = _hashImpl->hash( - bytes{0xff} + fromHex(_sender) + toBigEndian(_salt) + _hashImpl->hash(_init)); + bytes{0xff} + (_sender.starts_with("0x") ? fromHexWithPrefix(_sender) : fromHex(_sender)) + + toBigEndian(_salt) + _hashImpl->hash(_init)); std::string hexAddress; hexAddress.reserve(40); diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index 3cbf1bf894..ce1272e5e1 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -41,12 +41,9 @@ BOOST_AUTO_TEST_CASE(feature) features3.setToDefault(bcos::protocol::BlockVersion::V3_2_3_VERSION); flags = features3.flags(); // std::tie(flag, name, value) = flags[0]; - flag = std::get<0>(flags[0]); - name = std::get<1>(flags[0]); - value = std::get<2>(flags[0]); - BOOST_CHECK_EQUAL(flag, Features::Flag::bugfix_revert); - BOOST_CHECK_EQUAL(name, "bugfix_revert"); - BOOST_CHECK_EQUAL(value, true); + BOOST_CHECK_EQUAL(std::get<0>(flags[0]), Features::Flag::bugfix_revert); + BOOST_CHECK_EQUAL(std::get<1>(flags[0]), "bugfix_revert"); + BOOST_CHECK_EQUAL(std::get<2>(flags[0]), true); BOOST_CHECK_EQUAL(features3.get(Features::Flag::feature_dmc2serial), false); BOOST_CHECK_EQUAL(features3.get("feature_dmc2serial"), false); @@ -68,7 +65,7 @@ BOOST_AUTO_TEST_CASE(feature) BOOST_CHECK_EQUAL(features5.get("feature_dmc2serial"), true); auto keys = Features::featureKeys(); - BOOST_CHECK_EQUAL(keys.size(), 3); + BOOST_CHECK_EQUAL(keys.size(), 4); BOOST_CHECK_EQUAL(keys[0], "bugfix_revert"); BOOST_CHECK_EQUAL(keys[1], "bugfix_statestorage_hash"); BOOST_CHECK_EQUAL(keys[2], "bugfix_evm_create2_delegatecall_staticcall_codecopy"); diff --git a/bcos-scheduler/src/DmcExecutor.h b/bcos-scheduler/src/DmcExecutor.h index 4571efd165..6e7a9e959d 100644 --- a/bcos-scheduler/src/DmcExecutor.h +++ b/bcos-scheduler/src/DmcExecutor.h @@ -114,6 +114,8 @@ class DmcExecutor }); } + void setIsCall(bool isCall) { m_isCall = isCall; } + private: MessageHint handleExecutiveMessage(ExecutiveState::Ptr executive); void handleExecutiveOutputs(std::vector outputs); diff --git a/bcos-scheduler/test/testDmcExecutor.cpp b/bcos-scheduler/test/testDmcExecutor.cpp index 4fd0e41008..dff0192c12 100644 --- a/bcos-scheduler/test/testDmcExecutor.cpp +++ b/bcos-scheduler/test/testDmcExecutor.cpp @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(stateSwitchTest) block->setBlockHeader(blockHeader); // block = fakeBlock(cryptoSuite, blockFactory, 1, 1, 1); auto dmcExecutor = std::make_shared( - "DmcExecutor1", "0xaabbccdd", block, executor1, keyLocks, hashImpl, dmcRecorder); + "DmcExecutor1", "0xaabbccdd", block, executor1, keyLocks, hashImpl, dmcRecorder, false); dmcExecutor->setSchedulerOutHandler( [this, &dmcFlagStruct](bcos::scheduler::ExecutiveState::Ptr executiveState) { @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(stateSwitchTest) blockHeader->calculateHash(*hashImpl); block->setBlockHeader(blockHeader); auto dmcExecutor2 = std::make_shared( - "DmcExecutor2", to, block, executor1, keyLocks, hashImpl, dmcRecorder); + "DmcExecutor2", to, block, executor1, keyLocks, hashImpl, dmcRecorder, false); dmcExecutor2->scheduleIn(executiveState); }); @@ -226,6 +226,7 @@ BOOST_AUTO_TEST_CASE(stateSwitchTest) // call + dmcExecutor->setIsCall(true); auto callMessage = createMessage(4, 0, 1, "0xaabbccdd", true); dmcExecutor->submit(std::move(callMessage), false); dmcExecutor->prepare(); @@ -253,7 +254,7 @@ BOOST_AUTO_TEST_CASE(keyLocksTest) block->setBlockHeader(blockHeader); // block = fakeBlock(cryptoSuite, blockFactory, 1, 1, 1); auto dmcExecutor = std::make_shared( - "DmcExecutor1", "0xaabbccdd", block, executor1, keyLocks, hashImpl, dmcRecorder); + "DmcExecutor1", "0xaabbccdd", block, executor1, keyLocks, hashImpl, dmcRecorder, false); dmcExecutor->setSchedulerOutHandler( [this, &dmcFlagStruct](bcos::scheduler::ExecutiveState::Ptr executiveState) { @@ -266,7 +267,7 @@ BOOST_AUTO_TEST_CASE(keyLocksTest) blockHeader->calculateHash(*blockFactory->cryptoSuite()->hashImpl()); block->setBlockHeader(blockHeader); auto dmcExecutor2 = std::make_shared( - "DmcExecutor2", to, block, executor1, keyLocks, hashImpl, dmcRecorder); + "DmcExecutor2", to, block, executor1, keyLocks, hashImpl, dmcRecorder, false); dmcExecutor2->scheduleIn(executiveState); });