Use LazyInit for cached contract compilations

This commit is contained in:
Jason Cobb
2020-05-14 10:36:58 -04:00
parent cffd1eaff1
commit 24dfa89ee7
3 changed files with 24 additions and 12 deletions
+8 -4
View File
@@ -20,8 +20,11 @@
* Tests for a (comparatively) complex multisig wallet contract.
*/
#include <libsolutil/LazyInit.h>
#include <string>
#include <tuple>
#include <optional>
#if defined(_MSC_VER)
#pragma warning(push)
@@ -435,7 +438,7 @@ contract Wallet is multisig, multiowned, daylimit {
}
)DELIMITER";
static unique_ptr<bytes> s_compiledWallet;
static LazyInit<bytes> s_compiledWallet;
class WalletTestFramework: public SolidityExecutionFramework
{
@@ -447,11 +450,12 @@ protected:
u256 _dailyLimit = 0
)
{
if (!s_compiledWallet)
s_compiledWallet = make_unique<bytes>(compileContract(walletCode, "Wallet"));
bytes const& compiled = s_compiledWallet.init([&]{
return compileContract(walletCode, "Wallet");
});
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
sendMessage(*s_compiledWallet + args, true, _value);
sendMessage(compiled + args, true, _value);
BOOST_REQUIRE(m_transactionSuccessful);
BOOST_REQUIRE(!m_output.empty());
}