mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
deprecate using namespace std
test: updat filereader test deprecate namespace std deprecate namespace std deprecate namespace std deprecate namespace std deprecate namespace std deprecate namespace std deprecate namespace std deprecate namespace std deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace deprecated std namespace depecrate namespace std deprecated namespace std check ci clean line Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> purge line pure line deprecate std deprecate std deprecate std deprecate std deprecate std deprecate deprecate std bye namespace
This commit is contained in:
parent
df03f1412d
commit
b3230b0bdc
@ -38,6 +38,13 @@ NAMESPACE_STD_FREE_FILES=(
|
|||||||
libyul/backends/evm/*
|
libyul/backends/evm/*
|
||||||
libyul/optimiser/*
|
libyul/optimiser/*
|
||||||
solc/*
|
solc/*
|
||||||
|
test/contracts/*
|
||||||
|
test/libevmasm/*
|
||||||
|
test/liblangutil/*
|
||||||
|
test/libsolutil/*
|
||||||
|
test/libsolidity/*
|
||||||
|
test/libsolidity/analysis/*
|
||||||
|
test/libsolidity/interface/*
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
@ -235,47 +234,47 @@ protected:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RegistrarInterface(SolidityExecutionFramework& _framework): ContractInterface(_framework) {}
|
RegistrarInterface(SolidityExecutionFramework& _framework): ContractInterface(_framework) {}
|
||||||
void reserve(string const& _name)
|
void reserve(std::string const& _name)
|
||||||
{
|
{
|
||||||
callString("reserve", _name);
|
callString("reserve", _name);
|
||||||
}
|
}
|
||||||
h160 owner(string const& _name)
|
h160 owner(std::string const& _name)
|
||||||
{
|
{
|
||||||
return callStringReturnsAddress("owner", _name);
|
return callStringReturnsAddress("owner", _name);
|
||||||
}
|
}
|
||||||
void setAddress(string const& _name, h160 const& _address, bool _primary)
|
void setAddress(std::string const& _name, h160 const& _address, bool _primary)
|
||||||
{
|
{
|
||||||
callStringAddressBool("setAddress", _name, _address, _primary);
|
callStringAddressBool("setAddress", _name, _address, _primary);
|
||||||
}
|
}
|
||||||
h160 addr(string const& _name)
|
h160 addr(std::string const& _name)
|
||||||
{
|
{
|
||||||
return callStringReturnsAddress("addr", _name);
|
return callStringReturnsAddress("addr", _name);
|
||||||
}
|
}
|
||||||
string name(h160 const& _addr)
|
std::string name(h160 const& _addr)
|
||||||
{
|
{
|
||||||
return callAddressReturnsString("name", _addr);
|
return callAddressReturnsString("name", _addr);
|
||||||
}
|
}
|
||||||
void setSubRegistrar(string const& _name, h160 const& _address)
|
void setSubRegistrar(std::string const& _name, h160 const& _address)
|
||||||
{
|
{
|
||||||
callStringAddress("setSubRegistrar", _name, _address);
|
callStringAddress("setSubRegistrar", _name, _address);
|
||||||
}
|
}
|
||||||
h160 subRegistrar(string const& _name)
|
h160 subRegistrar(std::string const& _name)
|
||||||
{
|
{
|
||||||
return callStringReturnsAddress("subRegistrar", _name);
|
return callStringReturnsAddress("subRegistrar", _name);
|
||||||
}
|
}
|
||||||
void setContent(string const& _name, h256 const& _content)
|
void setContent(std::string const& _name, h256 const& _content)
|
||||||
{
|
{
|
||||||
callStringBytes32("setContent", _name, _content);
|
callStringBytes32("setContent", _name, _content);
|
||||||
}
|
}
|
||||||
h256 content(string const& _name)
|
h256 content(std::string const& _name)
|
||||||
{
|
{
|
||||||
return callStringReturnsBytes32("content", _name);
|
return callStringReturnsBytes32("content", _name);
|
||||||
}
|
}
|
||||||
void transfer(string const& _name, h160 const& _target)
|
void transfer(std::string const& _name, h160 const& _target)
|
||||||
{
|
{
|
||||||
return callStringAddress("transfer", _name, _target);
|
return callStringAddress("transfer", _name, _target);
|
||||||
}
|
}
|
||||||
void disown(string const& _name)
|
void disown(std::string const& _name)
|
||||||
{
|
{
|
||||||
return callString("disown", _name);
|
return callString("disown", _name);
|
||||||
}
|
}
|
||||||
@ -298,7 +297,7 @@ BOOST_AUTO_TEST_CASE(reserve)
|
|||||||
{
|
{
|
||||||
// Test that reserving works for long strings
|
// Test that reserving works for long strings
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
vector<string> names{"abcabcabcabcabc", "defdefdefdefdef", "ghighighighighighighighighighighighighighighi"};
|
std::vector<std::string> names{"abcabcabcabcabc", "defdefdefdefdef", "ghighighighighighighighighighighighighighighi"};
|
||||||
|
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
|
|
||||||
@ -317,7 +316,7 @@ BOOST_AUTO_TEST_CASE(double_reserve_long)
|
|||||||
{
|
{
|
||||||
// Test that it is not possible to re-reserve from a different address.
|
// Test that it is not possible to re-reserve from a different address.
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
string name = "abcabcabcabcabcabcabcabcabcabca";
|
std::string name = "abcabcabcabcabcabcabcabcabcabca";
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
registrar.reserve(name);
|
registrar.reserve(name);
|
||||||
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
||||||
@ -333,10 +332,10 @@ BOOST_AUTO_TEST_CASE(properties)
|
|||||||
// Test setting and retrieving the various properties works.
|
// Test setting and retrieving the various properties works.
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
string names[] = {"abcaeouoeuaoeuaoeu", "defncboagufra,fui", "ghagpyajfbcuajouhaeoi"};
|
std::string names[] = {"abcaeouoeuaoeuaoeu", "defncboagufra,fui", "ghagpyajfbcuajouhaeoi"};
|
||||||
size_t addr = 0x9872543;
|
size_t addr = 0x9872543;
|
||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
for (string const& name: names)
|
for (std::string const& name: names)
|
||||||
{
|
{
|
||||||
m_sender = account(0);
|
m_sender = account(0);
|
||||||
sendEther(account(count), u256(20) * ether);
|
sendEther(account(count), u256(20) * ether);
|
||||||
@ -369,7 +368,7 @@ BOOST_AUTO_TEST_CASE(properties)
|
|||||||
BOOST_AUTO_TEST_CASE(transfer)
|
BOOST_AUTO_TEST_CASE(transfer)
|
||||||
{
|
{
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
string name = "abcaoeguaoucaeoduceo";
|
std::string name = "abcaoeguaoucaeoduceo";
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
registrar.reserve(name);
|
registrar.reserve(name);
|
||||||
registrar.setContent(name, h256(u256(123)));
|
registrar.setContent(name, h256(u256(123)));
|
||||||
@ -381,7 +380,7 @@ BOOST_AUTO_TEST_CASE(transfer)
|
|||||||
BOOST_AUTO_TEST_CASE(disown)
|
BOOST_AUTO_TEST_CASE(disown)
|
||||||
{
|
{
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
string name = "abcaoeguaoucaeoduceo";
|
std::string name = "abcaoeguaoucaeoduceo";
|
||||||
|
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
registrar.reserve(name);
|
registrar.reserve(name);
|
||||||
@ -408,7 +407,7 @@ BOOST_AUTO_TEST_CASE(disown)
|
|||||||
BOOST_AUTO_TEST_CASE(auction_simple)
|
BOOST_AUTO_TEST_CASE(auction_simple)
|
||||||
{
|
{
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
string name = "x";
|
std::string name = "x";
|
||||||
|
|
||||||
RegistrarInterface registrar(*this);
|
RegistrarInterface registrar(*this);
|
||||||
// initiate auction
|
// initiate auction
|
||||||
@ -426,7 +425,7 @@ BOOST_AUTO_TEST_CASE(auction_simple)
|
|||||||
BOOST_AUTO_TEST_CASE(auction_bidding)
|
BOOST_AUTO_TEST_CASE(auction_bidding)
|
||||||
{
|
{
|
||||||
deployRegistrar();
|
deployRegistrar();
|
||||||
string name = "x";
|
std::string name = "x";
|
||||||
|
|
||||||
unsigned startTime = 0x776347e2;
|
unsigned startTime = 0x776347e2;
|
||||||
m_evmcHost->tx_context.block_timestamp = startTime;
|
m_evmcHost->tx_context.block_timestamp = startTime;
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
#include <test/libsolidity/SolidityExecutionFramework.h>
|
#include <test/libsolidity/SolidityExecutionFramework.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
|
|
||||||
@ -445,7 +444,7 @@ class WalletTestFramework: public SolidityExecutionFramework
|
|||||||
protected:
|
protected:
|
||||||
void deployWallet(
|
void deployWallet(
|
||||||
u256 const& _value = 0,
|
u256 const& _value = 0,
|
||||||
vector<h160> const& _owners = vector<h160>{},
|
std::vector<h160> const& _owners = std::vector<h160>{},
|
||||||
u256 _required = 1,
|
u256 _required = 1,
|
||||||
u256 _dailyLimit = 0
|
u256 _dailyLimit = 0
|
||||||
)
|
)
|
||||||
@ -535,7 +534,7 @@ BOOST_AUTO_TEST_CASE(remove_owner)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(initial_owners)
|
BOOST_AUTO_TEST_CASE(initial_owners)
|
||||||
{
|
{
|
||||||
vector<h160> owners{
|
std::vector<h160> owners{
|
||||||
h160("0x42c56279432962a17176998a4747d1b4d6ed4367"),
|
h160("0x42c56279432962a17176998a4747d1b4d6ed4367"),
|
||||||
h160("0xd4d4669f5ba9f4c27d38ef02a358c339b5560c47"),
|
h160("0xd4d4669f5ba9f4c27d38ef02a358c339b5560c47"),
|
||||||
h160("0xe6716f9544a56c530d868e4bfbacb172315bdead"),
|
h160("0xe6716f9544a56c530d868e4bfbacb172315bdead"),
|
||||||
|
@ -34,9 +34,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
@ -55,34 +55,34 @@ BOOST_AUTO_TEST_SUITE(Assembler)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(all_assembly_items)
|
BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||||
{
|
{
|
||||||
map<string, unsigned> indices = {
|
std::map<std::string, unsigned> indices = {
|
||||||
{ "root.asm", 0 },
|
{ "root.asm", 0 },
|
||||||
{ "sub.asm", 1 },
|
{ "sub.asm", 1 },
|
||||||
{ "verbatim.asm", 2 }
|
{ "verbatim.asm", 2 }
|
||||||
};
|
};
|
||||||
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
||||||
Assembly _assembly{evmVersion, false, {}};
|
Assembly _assembly{evmVersion, false, {}};
|
||||||
auto root_asm = make_shared<string>("root.asm");
|
auto root_asm = std::make_shared<std::string>("root.asm");
|
||||||
_assembly.setSourceLocation({1, 3, root_asm});
|
_assembly.setSourceLocation({1, 3, root_asm});
|
||||||
|
|
||||||
Assembly _subAsm{evmVersion, false, {}};
|
Assembly _subAsm{evmVersion, false, {}};
|
||||||
auto sub_asm = make_shared<string>("sub.asm");
|
auto sub_asm = std::make_shared<std::string>("sub.asm");
|
||||||
_subAsm.setSourceLocation({6, 8, sub_asm});
|
_subAsm.setSourceLocation({6, 8, sub_asm});
|
||||||
|
|
||||||
Assembly _verbatimAsm(evmVersion, true, "");
|
Assembly _verbatimAsm(evmVersion, true, "");
|
||||||
auto verbatim_asm = make_shared<string>("verbatim.asm");
|
auto verbatim_asm = std::make_shared<std::string>("verbatim.asm");
|
||||||
_verbatimAsm.setSourceLocation({8, 18, verbatim_asm});
|
_verbatimAsm.setSourceLocation({8, 18, verbatim_asm});
|
||||||
|
|
||||||
// PushImmutable
|
// PushImmutable
|
||||||
_subAsm.appendImmutable("someImmutable");
|
_subAsm.appendImmutable("someImmutable");
|
||||||
_subAsm.append(AssemblyItem(PushTag, 0));
|
_subAsm.append(AssemblyItem(PushTag, 0));
|
||||||
_subAsm.append(Instruction::INVALID);
|
_subAsm.append(Instruction::INVALID);
|
||||||
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);
|
std::shared_ptr<Assembly> _subAsmPtr = std::make_shared<Assembly>(_subAsm);
|
||||||
|
|
||||||
_verbatimAsm.appendVerbatim({0xff,0xff}, 0, 0);
|
_verbatimAsm.appendVerbatim({0xff,0xff}, 0, 0);
|
||||||
_verbatimAsm.appendVerbatim({0x74, 0x65, 0x73, 0x74}, 0, 1);
|
_verbatimAsm.appendVerbatim({0x74, 0x65, 0x73, 0x74}, 0, 1);
|
||||||
_verbatimAsm.append(Instruction::MSTORE);
|
_verbatimAsm.append(Instruction::MSTORE);
|
||||||
shared_ptr<Assembly> _verbatimAsmPtr = make_shared<Assembly>(_verbatimAsm);
|
std::shared_ptr<Assembly> _verbatimAsmPtr = std::make_shared<Assembly>(_verbatimAsm);
|
||||||
|
|
||||||
// Tag
|
// Tag
|
||||||
auto tag = _assembly.newTag();
|
auto tag = _assembly.newTag();
|
||||||
@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
|||||||
"\n"
|
"\n"
|
||||||
"auxdata: 0x4266eeaa\n"
|
"auxdata: 0x4266eeaa\n"
|
||||||
);
|
);
|
||||||
string json{
|
std::string json{
|
||||||
"{\".auxdata\":\"4266eeaa\",\".code\":["
|
"{\".auxdata\":\"4266eeaa\",\".code\":["
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"tag\",\"source\":0,\"value\":\"1\"},"
|
"{\"begin\":1,\"end\":3,\"name\":\"tag\",\"source\":0,\"value\":\"1\"},"
|
||||||
"{\"begin\":1,\"end\":3,\"name\":\"JUMPDEST\",\"source\":0},"
|
"{\"begin\":1,\"end\":3,\"name\":\"JUMPDEST\",\"source\":0},"
|
||||||
@ -221,11 +221,11 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
|
|||||||
// Tests for 1, 2, 3 number of immutables.
|
// Tests for 1, 2, 3 number of immutables.
|
||||||
for (int numImmutables = 1; numImmutables <= 3; ++numImmutables)
|
for (int numImmutables = 1; numImmutables <= 3; ++numImmutables)
|
||||||
{
|
{
|
||||||
BOOST_TEST_MESSAGE("NumImmutables: "s + to_string(numImmutables));
|
BOOST_TEST_MESSAGE("NumImmutables: "s + std::to_string(numImmutables));
|
||||||
// Tests for the cases 1, 2, 3 occurrences of an immutable reference.
|
// Tests for the cases 1, 2, 3 occurrences of an immutable reference.
|
||||||
for (int numActualRefs = 1; numActualRefs <= 3; ++numActualRefs)
|
for (int numActualRefs = 1; numActualRefs <= 3; ++numActualRefs)
|
||||||
{
|
{
|
||||||
BOOST_TEST_MESSAGE("NumActualRefs: "s + to_string(numActualRefs));
|
BOOST_TEST_MESSAGE("NumActualRefs: "s + std::to_string(numActualRefs));
|
||||||
auto const NumExpectedMappings =
|
auto const NumExpectedMappings =
|
||||||
(
|
(
|
||||||
2 + // PUSH <a> PUSH <b>
|
2 + // PUSH <a> PUSH <b>
|
||||||
@ -238,21 +238,21 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
|
|||||||
NumSubs + // PUSH <addr> for every sub assembly
|
NumSubs + // PUSH <addr> for every sub assembly
|
||||||
1; // INVALID
|
1; // INVALID
|
||||||
|
|
||||||
auto assemblyName = make_shared<string>("root.asm");
|
auto assemblyName = std::make_shared<std::string>("root.asm");
|
||||||
auto subName = make_shared<string>("sub.asm");
|
auto subName = std::make_shared<std::string>("sub.asm");
|
||||||
|
|
||||||
map<string, unsigned> indices = {
|
std::map<std::string, unsigned> indices = {
|
||||||
{ *assemblyName, 0 },
|
{ *assemblyName, 0 },
|
||||||
{ *subName, 1 }
|
{ *subName, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
auto subAsm = make_shared<Assembly>(evmVersion, false, string{});
|
auto subAsm = std::make_shared<Assembly>(evmVersion, false, std::string{});
|
||||||
for (char i = 0; i < numImmutables; ++i)
|
for (char i = 0; i < numImmutables; ++i)
|
||||||
{
|
{
|
||||||
for (int r = 0; r < numActualRefs; ++r)
|
for (int r = 0; r < numActualRefs; ++r)
|
||||||
{
|
{
|
||||||
subAsm->setSourceLocation(SourceLocation{10*i, 10*i + 6 + r, subName});
|
subAsm->setSourceLocation(SourceLocation{10*i, 10*i + 6 + r, subName});
|
||||||
subAsm->appendImmutable(string(1, char('a' + i))); // "a", "b", ...
|
subAsm->appendImmutable(std::string(1, char('a' + i))); // "a", "b", ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,34 +262,34 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
|
|||||||
assembly.setSourceLocation({10*i, 10*i + 3+i, assemblyName});
|
assembly.setSourceLocation({10*i, 10*i + 3+i, assemblyName});
|
||||||
assembly.append(u256(0x71)); // immutble value
|
assembly.append(u256(0x71)); // immutble value
|
||||||
assembly.append(u256(0)); // target... modules?
|
assembly.append(u256(0)); // target... modules?
|
||||||
assembly.appendImmutableAssignment(string(1, char('a' + i - 1)));
|
assembly.appendImmutableAssignment(std::string(1, char('a' + i - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assembly.appendSubroutine(subAsm);
|
assembly.appendSubroutine(subAsm);
|
||||||
|
|
||||||
checkCompilation(assembly);
|
checkCompilation(assembly);
|
||||||
|
|
||||||
string const sourceMappings = AssemblyItem::computeSourceMapping(assembly.items(), indices);
|
std::string const sourceMappings = AssemblyItem::computeSourceMapping(assembly.items(), indices);
|
||||||
auto const numberOfMappings = std::count(sourceMappings.begin(), sourceMappings.end(), ';');
|
auto const numberOfMappings = std::count(sourceMappings.begin(), sourceMappings.end(), ';');
|
||||||
|
|
||||||
LinkerObject const& obj = assembly.assemble();
|
LinkerObject const& obj = assembly.assemble();
|
||||||
string const disassembly = disassemble(obj.bytecode, evmVersion, "\n");
|
std::string const disassembly = disassemble(obj.bytecode, evmVersion, "\n");
|
||||||
auto const numberOfOpcodes = std::count(disassembly.begin(), disassembly.end(), '\n');
|
auto const numberOfOpcodes = std::count(disassembly.begin(), disassembly.end(), '\n');
|
||||||
|
|
||||||
#if 0 // {{{ debug prints
|
#if 0 // {{{ debug prints
|
||||||
{
|
{
|
||||||
LinkerObject const& subObj = assembly.sub(0).assemble();
|
LinkerObject const& subObj = assembly.sub(0).assemble();
|
||||||
string const subDisassembly = disassemble(subObj.bytecode, "\n");
|
std::string const subDisassembly = disassemble(subObj.bytecode, "\n");
|
||||||
cout << '\n';
|
std::cout << '\n';
|
||||||
cout << "### immutables: " << numImmutables << ", refs: " << numActualRefs << '\n';
|
std::cout << "### immutables: " << numImmutables << ", refs: " << numActualRefs << '\n';
|
||||||
cout << " - srcmap: \"" << sourceMappings << "\"\n";
|
std::cout << " - srcmap: \"" << sourceMappings << "\"\n";
|
||||||
cout << " - src mappings: " << numberOfMappings << '\n';
|
std::cout << " - src mappings: " << numberOfMappings << '\n';
|
||||||
cout << " - opcodes: " << numberOfOpcodes << '\n';
|
std::cout << " - opcodes: " << numberOfOpcodes << '\n';
|
||||||
cout << " - subs: " << assembly.numSubs() << '\n';
|
std::cout << " - subs: " << assembly.numSubs() << '\n';
|
||||||
cout << " - sub opcodes " << std::count(subDisassembly.begin(), subDisassembly.end(), '\n') << '\n';
|
std::cout << " - sub opcodes " << std::count(subDisassembly.begin(), subDisassembly.end(), '\n') << '\n';
|
||||||
cout << " - sub srcmaps " << AssemblyItem::computeSourceMapping(subAsm->items(), indices) << '\n';
|
std::cout << " - sub srcmaps " << AssemblyItem::computeSourceMapping(subAsm->items(), indices) << '\n';
|
||||||
cout << " - main bytecode:\n\t" << disassemble(obj.bytecode, "\n\t");
|
std::cout << " - main bytecode:\n\t" << disassemble(obj.bytecode, "\n\t");
|
||||||
cout << "\r - sub bytecode:\n\t" << disassemble(subObj.bytecode, "\n\t");
|
std::cout << "\r - sub bytecode:\n\t" << disassemble(subObj.bytecode, "\n\t");
|
||||||
}
|
}
|
||||||
#endif // }}}
|
#endif // }}}
|
||||||
|
|
||||||
@ -301,22 +301,22 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(immutable)
|
BOOST_AUTO_TEST_CASE(immutable)
|
||||||
{
|
{
|
||||||
map<string, unsigned> indices = {
|
std::map<std::string, unsigned> indices = {
|
||||||
{ "root.asm", 0 },
|
{ "root.asm", 0 },
|
||||||
{ "sub.asm", 1 }
|
{ "sub.asm", 1 }
|
||||||
};
|
};
|
||||||
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
||||||
Assembly _assembly{evmVersion, true, {}};
|
Assembly _assembly{evmVersion, true, {}};
|
||||||
auto root_asm = make_shared<string>("root.asm");
|
auto root_asm = std::make_shared<std::string>("root.asm");
|
||||||
_assembly.setSourceLocation({1, 3, root_asm});
|
_assembly.setSourceLocation({1, 3, root_asm});
|
||||||
|
|
||||||
Assembly _subAsm{evmVersion, false, {}};
|
Assembly _subAsm{evmVersion, false, {}};
|
||||||
auto sub_asm = make_shared<string>("sub.asm");
|
auto sub_asm = std::make_shared<std::string>("sub.asm");
|
||||||
_subAsm.setSourceLocation({6, 8, sub_asm});
|
_subAsm.setSourceLocation({6, 8, sub_asm});
|
||||||
_subAsm.appendImmutable("someImmutable");
|
_subAsm.appendImmutable("someImmutable");
|
||||||
_subAsm.appendImmutable("someOtherImmutable");
|
_subAsm.appendImmutable("someOtherImmutable");
|
||||||
_subAsm.appendImmutable("someImmutable");
|
_subAsm.appendImmutable("someImmutable");
|
||||||
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);
|
std::shared_ptr<Assembly> _subAsmPtr = std::make_shared<Assembly>(_subAsm);
|
||||||
|
|
||||||
_assembly.append(u256(42));
|
_assembly.append(u256(42));
|
||||||
_assembly.append(u256(0));
|
_assembly.append(u256(0));
|
||||||
@ -330,9 +330,9 @@ BOOST_AUTO_TEST_CASE(immutable)
|
|||||||
|
|
||||||
checkCompilation(_assembly);
|
checkCompilation(_assembly);
|
||||||
|
|
||||||
string genericPush0 = evmVersion.hasPush0() ? "5f" : "6000";
|
std::string genericPush0 = evmVersion.hasPush0() ? "5f" : "6000";
|
||||||
// PUSH1 0x1b v/s PUSH1 0x19
|
// PUSH1 0x1b v/s PUSH1 0x19
|
||||||
string dataOffset = evmVersion.hasPush0() ? "6019" : "601b" ;
|
std::string dataOffset = evmVersion.hasPush0() ? "6019" : "601b" ;
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
_assembly.assemble().toHex(),
|
_assembly.assemble().toHex(),
|
||||||
@ -406,8 +406,8 @@ BOOST_AUTO_TEST_CASE(subobject_encode_decode)
|
|||||||
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
||||||
Assembly assembly{evmVersion, true, {}};
|
Assembly assembly{evmVersion, true, {}};
|
||||||
|
|
||||||
shared_ptr<Assembly> subAsmPtr = make_shared<Assembly>(evmVersion, false, string{});
|
std::shared_ptr<Assembly> subAsmPtr = std::make_shared<Assembly>(evmVersion, false, std::string{});
|
||||||
shared_ptr<Assembly> subSubAsmPtr = make_shared<Assembly>(evmVersion, false, string{});
|
std::shared_ptr<Assembly> subSubAsmPtr = std::make_shared<Assembly>(evmVersion, false, std::string{});
|
||||||
|
|
||||||
assembly.appendSubroutine(subAsmPtr);
|
assembly.appendSubroutine(subAsmPtr);
|
||||||
subAsmPtr->appendSubroutine(subSubAsmPtr);
|
subAsmPtr->appendSubroutine(subSubAsmPtr);
|
||||||
@ -416,7 +416,7 @@ BOOST_AUTO_TEST_CASE(subobject_encode_decode)
|
|||||||
BOOST_REQUIRE_THROW(assembly.encodeSubPath({1}), solidity::evmasm::AssemblyException);
|
BOOST_REQUIRE_THROW(assembly.encodeSubPath({1}), solidity::evmasm::AssemblyException);
|
||||||
BOOST_REQUIRE_THROW(assembly.decodeSubPath(1), solidity::evmasm::AssemblyException);
|
BOOST_REQUIRE_THROW(assembly.decodeSubPath(1), solidity::evmasm::AssemblyException);
|
||||||
|
|
||||||
vector<size_t> subPath{0, 0};
|
std::vector<size_t> subPath{0, 0};
|
||||||
BOOST_CHECK(assembly.decodeSubPath(assembly.encodeSubPath(subPath)) == subPath);
|
BOOST_CHECK(assembly.decodeSubPath(assembly.encodeSubPath(subPath)) == subPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
|
|
||||||
@ -874,7 +873,7 @@ BOOST_AUTO_TEST_CASE(block_deduplicator)
|
|||||||
BlockDeduplicator deduplicator(input);
|
BlockDeduplicator deduplicator(input);
|
||||||
deduplicator.deduplicate();
|
deduplicator.deduplicate();
|
||||||
|
|
||||||
set<u256> pushTags;
|
std::set<u256> pushTags;
|
||||||
for (AssemblyItem const& item: input)
|
for (AssemblyItem const& item: input)
|
||||||
if (item.type() == PushTag)
|
if (item.type() == PushTag)
|
||||||
pushTags.insert(item.data());
|
pushTags.insert(item.data());
|
||||||
@ -968,7 +967,7 @@ BOOST_AUTO_TEST_CASE(block_deduplicator_loops)
|
|||||||
BlockDeduplicator deduplicator(input);
|
BlockDeduplicator deduplicator(input);
|
||||||
deduplicator.deduplicate();
|
deduplicator.deduplicate();
|
||||||
|
|
||||||
set<u256> pushTags;
|
std::set<u256> pushTags;
|
||||||
for (AssemblyItem const& item: input)
|
for (AssemblyItem const& item: input)
|
||||||
if (item.type() == PushTag)
|
if (item.type() == PushTag)
|
||||||
pushTags.insert(item.data());
|
pushTags.insert(item.data());
|
||||||
@ -1051,7 +1050,7 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
||||||
{
|
{
|
||||||
vector<Instruction> ops{
|
std::vector<Instruction> ops{
|
||||||
Instruction::ADD,
|
Instruction::ADD,
|
||||||
Instruction::MUL,
|
Instruction::MUL,
|
||||||
Instruction::EQ,
|
Instruction::EQ,
|
||||||
@ -1088,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
|
|||||||
BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
||||||
{
|
{
|
||||||
// NOTE: not comprehensive
|
// NOTE: not comprehensive
|
||||||
vector<Instruction> ops{
|
std::vector<Instruction> ops{
|
||||||
Instruction::SUB,
|
Instruction::SUB,
|
||||||
Instruction::DIV,
|
Instruction::DIV,
|
||||||
Instruction::SDIV,
|
Instruction::SDIV,
|
||||||
@ -1125,7 +1124,7 @@ BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(peephole_swap_comparison)
|
BOOST_AUTO_TEST_CASE(peephole_swap_comparison)
|
||||||
{
|
{
|
||||||
map<Instruction, Instruction> swappableOps{
|
std::map<Instruction, Instruction> swappableOps{
|
||||||
{ Instruction::LT, Instruction::GT },
|
{ Instruction::LT, Instruction::GT },
|
||||||
{ Instruction::GT, Instruction::LT },
|
{ Instruction::GT, Instruction::LT },
|
||||||
{ Instruction::SLT, Instruction::SGT },
|
{ Instruction::SLT, Instruction::SGT },
|
||||||
@ -1261,7 +1260,7 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
|
|||||||
settings.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment;
|
settings.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment;
|
||||||
|
|
||||||
Assembly main{settings.evmVersion, false, {}};
|
Assembly main{settings.evmVersion, false, {}};
|
||||||
AssemblyPointer sub = make_shared<Assembly>(settings.evmVersion, true, string{});
|
AssemblyPointer sub = std::make_shared<Assembly>(settings.evmVersion, true, std::string{});
|
||||||
|
|
||||||
sub->append(u256(1));
|
sub->append(u256(1));
|
||||||
auto t1 = sub->newTag();
|
auto t1 = sub->newTag();
|
||||||
@ -1428,7 +1427,7 @@ BOOST_AUTO_TEST_CASE(verbatim_knownstate)
|
|||||||
Instruction::DUP3,
|
Instruction::DUP3,
|
||||||
Instruction::DUP4
|
Instruction::DUP4
|
||||||
});
|
});
|
||||||
map<int, unsigned> const& stackElements = state.stackElements();
|
std::map<int, unsigned> const& stackElements = state.stackElements();
|
||||||
|
|
||||||
BOOST_CHECK(state.stackHeight() == 4);
|
BOOST_CHECK(state.stackHeight() == 4);
|
||||||
// One more than stack height because of the initial unknown element.
|
// One more than stack height because of the initial unknown element.
|
||||||
@ -1540,7 +1539,7 @@ BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cse_remove_unwanted_masking_of_address)
|
BOOST_AUTO_TEST_CASE(cse_remove_unwanted_masking_of_address)
|
||||||
{
|
{
|
||||||
vector<Instruction> ops{
|
std::vector<Instruction> ops{
|
||||||
Instruction::ADDRESS,
|
Instruction::ADDRESS,
|
||||||
Instruction::CALLER,
|
Instruction::CALLER,
|
||||||
Instruction::ORIGIN,
|
Instruction::ORIGIN,
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
|
|
||||||
namespace boost::test_tools::tt_detail
|
namespace boost::test_tools::tt_detail
|
||||||
@ -39,16 +38,16 @@ struct print_log_value<std::optional<int>>
|
|||||||
{
|
{
|
||||||
void operator()(std::ostream& _out, std::optional<int> const& _value) const
|
void operator()(std::ostream& _out, std::optional<int> const& _value) const
|
||||||
{
|
{
|
||||||
_out << (_value ? to_string(*_value) : "[nullopt]");
|
_out << (_value ? to_string(*_value) : "[std::nullopt]");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct print_log_value<nullopt_t>
|
struct print_log_value<std::nullopt_t>
|
||||||
{
|
{
|
||||||
void operator()(std::ostream& _out, nullopt_t const&) const
|
void operator()(std::ostream& _out, std::nullopt_t const&) const
|
||||||
{
|
{
|
||||||
_out << "[nullopt]";
|
_out << "[std::nullopt]";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ BOOST_AUTO_TEST_CASE(test_fail)
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::optional<int> toPosition(int _line, int _column, string const& _text)
|
std::optional<int> toPosition(int _line, int _column, std::string const& _text)
|
||||||
{
|
{
|
||||||
return CharStream{_text, "source"}.translateLineColumnToPosition(
|
return CharStream{_text, "source"}.translateLineColumnToPosition(
|
||||||
LineColumn{_line, _column}
|
LineColumn{_line, _column}
|
||||||
@ -88,30 +87,30 @@ std::optional<int> toPosition(int _line, int _column, string const& _text)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(translateLineColumnToPosition)
|
BOOST_AUTO_TEST_CASE(translateLineColumnToPosition)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(toPosition(-1, 0, "ABC"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(-1, 0, "ABC"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, -1, "ABC"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(0, -1, "ABC"), std::nullopt);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 0, ""), 0);
|
BOOST_CHECK_EQUAL(toPosition(0, 0, ""), 0);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 0, ""), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(1, 0, ""), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 1, ""), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(0, 1, ""), std::nullopt);
|
||||||
|
|
||||||
// With last line containing no LF
|
// With last line containing no LF
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 0, "ABC"), 0);
|
BOOST_CHECK_EQUAL(toPosition(0, 0, "ABC"), 0);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 1, "ABC"), 1);
|
BOOST_CHECK_EQUAL(toPosition(0, 1, "ABC"), 1);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 2, "ABC"), 2);
|
BOOST_CHECK_EQUAL(toPosition(0, 2, "ABC"), 2);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 3, "ABC"), 3);
|
BOOST_CHECK_EQUAL(toPosition(0, 3, "ABC"), 3);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 4, "ABC"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(0, 4, "ABC"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 0, "ABC"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(1, 0, "ABC"), std::nullopt);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 3, "ABC\nDEF"), 3);
|
BOOST_CHECK_EQUAL(toPosition(0, 3, "ABC\nDEF"), 3);
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 4, "ABC\nDEF"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(0, 4, "ABC\nDEF"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 0, "ABC\nDEF"), 4);
|
BOOST_CHECK_EQUAL(toPosition(1, 0, "ABC\nDEF"), 4);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 1, "ABC\nDEF"), 5);
|
BOOST_CHECK_EQUAL(toPosition(1, 1, "ABC\nDEF"), 5);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 2, "ABC\nDEF"), 6);
|
BOOST_CHECK_EQUAL(toPosition(1, 2, "ABC\nDEF"), 6);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 3, "ABC\nDEF"), 7);
|
BOOST_CHECK_EQUAL(toPosition(1, 3, "ABC\nDEF"), 7);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 4, "ABC\nDEF"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(1, 4, "ABC\nDEF"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF"), std::nullopt);
|
||||||
|
|
||||||
// With last line containing LF
|
// With last line containing LF
|
||||||
BOOST_CHECK_EQUAL(toPosition(0, 0, "ABC\nDEF\n"), 0);
|
BOOST_CHECK_EQUAL(toPosition(0, 0, "ABC\nDEF\n"), 0);
|
||||||
@ -122,9 +121,9 @@ BOOST_AUTO_TEST_CASE(translateLineColumnToPosition)
|
|||||||
BOOST_CHECK_EQUAL(toPosition(1, 1, "ABC\nDEF\n"), 5);
|
BOOST_CHECK_EQUAL(toPosition(1, 1, "ABC\nDEF\n"), 5);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 2, "ABC\nDEF\n"), 6);
|
BOOST_CHECK_EQUAL(toPosition(1, 2, "ABC\nDEF\n"), 6);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 3, "ABC\nDEF\n"), 7);
|
BOOST_CHECK_EQUAL(toPosition(1, 3, "ABC\nDEF\n"), 7);
|
||||||
BOOST_CHECK_EQUAL(toPosition(1, 4, "ABC\nDEF\n"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(1, 4, "ABC\nDEF\n"), std::nullopt);
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF\n"), 8);
|
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF\n"), 8);
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF\n"), nullopt);
|
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF\n"), std::nullopt);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF\nGHI\n"), 8);
|
BOOST_CHECK_EQUAL(toPosition(2, 0, "ABC\nDEF\nGHI\n"), 8);
|
||||||
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF\nGHI\n"), 9);
|
BOOST_CHECK_EQUAL(toPosition(2, 1, "ABC\nDEF\nGHI\n"), 9);
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
namespace solidity::langutil::test
|
namespace solidity::langutil::test
|
||||||
{
|
{
|
||||||
@ -89,15 +89,15 @@ BOOST_AUTO_TEST_CASE(assembly_multiple_assign)
|
|||||||
BOOST_AUTO_TEST_CASE(string_printable)
|
BOOST_AUTO_TEST_CASE(string_printable)
|
||||||
{
|
{
|
||||||
for (unsigned v = 0x20; v < 0x7e; v++) {
|
for (unsigned v = 0x20; v < 0x7e; v++) {
|
||||||
string lit{static_cast<char>(v)};
|
std::string lit{static_cast<char>(v)};
|
||||||
// Escape \ and " (since we are quoting with ")
|
// Escape \ and " (since we are quoting with ")
|
||||||
if (v == '\\' || v == '"')
|
if (v == '\\' || v == '"')
|
||||||
lit = string{'\\'} + lit;
|
lit = std::string{'\\'} + lit;
|
||||||
CharStream stream(" { \"" + lit + "\"", "");
|
CharStream stream(" { \"" + lit + "\"", "");
|
||||||
Scanner scanner(stream);
|
Scanner scanner(stream);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), string{static_cast<char>(v)});
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), std::string{static_cast<char>(v)});
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
||||||
}
|
}
|
||||||
// Special case of unescaped " for strings quoted with '
|
// Special case of unescaped " for strings quoted with '
|
||||||
@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(string_nonprintable)
|
|||||||
// Skip the valid ones
|
// Skip the valid ones
|
||||||
if (v >= 0x20 && v <= 0x7e)
|
if (v >= 0x20 && v <= 0x7e)
|
||||||
continue;
|
continue;
|
||||||
string lit{static_cast<char>(v)};
|
std::string lit{static_cast<char>(v)};
|
||||||
CharStream stream(" { \"" + lit + "\"", "");
|
CharStream stream(" { \"" + lit + "\"", "");
|
||||||
Scanner scanner(stream);
|
Scanner scanner(stream);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
@ -148,14 +148,14 @@ BOOST_AUTO_TEST_CASE(string_escapes_all)
|
|||||||
|
|
||||||
struct TestScanner
|
struct TestScanner
|
||||||
{
|
{
|
||||||
unique_ptr<CharStream> stream;
|
std::unique_ptr<CharStream> stream;
|
||||||
unique_ptr<Scanner> scanner;
|
std::unique_ptr<Scanner> scanner;
|
||||||
explicit TestScanner(string _text) { reset(std::move(_text)); }
|
explicit TestScanner(std::string _text) { reset(std::move(_text)); }
|
||||||
|
|
||||||
void reset(std::string _text)
|
void reset(std::string _text)
|
||||||
{
|
{
|
||||||
stream = make_unique<CharStream>(std::move(_text), "");
|
stream = std::make_unique<CharStream>(std::move(_text), "");
|
||||||
scanner = make_unique<Scanner>(*stream);
|
scanner = std::make_unique<Scanner>(*stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
decltype(auto) currentToken() { return scanner->currentToken(); }
|
decltype(auto) currentToken() { return scanner->currentToken(); }
|
||||||
@ -801,7 +801,7 @@ BOOST_AUTO_TEST_CASE(regular_line_break_in_single_line_comment)
|
|||||||
{
|
{
|
||||||
for (auto const& nl: {"\r", "\n", "\r\n"})
|
for (auto const& nl: {"\r", "\n", "\r\n"})
|
||||||
{
|
{
|
||||||
TestScanner scanner("// abc " + string(nl) + " def ");
|
TestScanner scanner("// abc " + std::string(nl) + " def ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
|
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
||||||
@ -813,10 +813,10 @@ BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_single_line_comment)
|
|||||||
{
|
{
|
||||||
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
||||||
{
|
{
|
||||||
TestScanner scanner("// abc " + string(nl) + " def ");
|
TestScanner scanner("// abc " + std::string(nl) + " def ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
|
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
||||||
for (size_t i = 0; i < string(nl).size() - 1; i++)
|
for (size_t i = 0; i < std::string(nl).size() - 1; i++)
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
||||||
@ -828,7 +828,7 @@ BOOST_AUTO_TEST_CASE(regular_line_breaks_in_single_line_doc_comment)
|
|||||||
{
|
{
|
||||||
for (auto const& nl: {"\r", "\n", "\r\n"})
|
for (auto const& nl: {"\r", "\n", "\r\n"})
|
||||||
{
|
{
|
||||||
TestScanner scanner("/// abc " + string(nl) + " def ");
|
TestScanner scanner("/// abc " + std::string(nl) + " def ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
|
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
||||||
@ -856,10 +856,10 @@ BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_single_line_doc_comment)
|
|||||||
{
|
{
|
||||||
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
||||||
{
|
{
|
||||||
TestScanner scanner("/// abc " + string(nl) + " def ");
|
TestScanner scanner("/// abc " + std::string(nl) + " def ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
|
BOOST_CHECK_EQUAL(scanner.currentCommentLiteral(), "abc ");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
||||||
for (size_t i = 0; i < string(nl).size() - 1; i++)
|
for (size_t i = 0; i < std::string(nl).size() - 1; i++)
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
||||||
@ -884,9 +884,9 @@ BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_strings)
|
|||||||
{
|
{
|
||||||
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
for (auto const& nl: {"\v", "\f", "\xE2\x80\xA8", "\xE2\x80\xA9"})
|
||||||
{
|
{
|
||||||
TestScanner scanner("\"abc " + string(nl) + " def\"");
|
TestScanner scanner("\"abc " + std::string(nl) + " def\"");
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
||||||
for (size_t i = 0; i < string(nl).size(); i++)
|
for (size_t i = 0; i < std::string(nl).size(); i++)
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "def");
|
||||||
@ -898,7 +898,7 @@ BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_strings)
|
|||||||
BOOST_AUTO_TEST_CASE(solidity_keywords)
|
BOOST_AUTO_TEST_CASE(solidity_keywords)
|
||||||
{
|
{
|
||||||
// These are tokens which have a different meaning in Yul.
|
// These are tokens which have a different meaning in Yul.
|
||||||
string keywords = "return byte bool address var in true false leave switch case default";
|
std::string keywords = "return byte bool address var in true false leave switch case default";
|
||||||
TestScanner scanner(keywords);
|
TestScanner scanner(keywords);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Return);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Return);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Byte);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Byte);
|
||||||
@ -962,7 +962,7 @@ BOOST_AUTO_TEST_CASE(yul_identifier_with_dots)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(yul_function)
|
BOOST_AUTO_TEST_CASE(yul_function)
|
||||||
{
|
{
|
||||||
string sig = "function f(a, b) -> x, y";
|
std::string sig = "function f(a, b) -> x, y";
|
||||||
TestScanner scanner(sig);
|
TestScanner scanner(sig);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Function);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Function);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||||
@ -994,7 +994,7 @@ BOOST_AUTO_TEST_CASE(yul_function)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(yul_function_with_whitespace)
|
BOOST_AUTO_TEST_CASE(yul_function_with_whitespace)
|
||||||
{
|
{
|
||||||
string sig = "function f (a, b) - > x, y";
|
std::string sig = "function f (a, b) - > x, y";
|
||||||
TestScanner scanner(sig);
|
TestScanner scanner(sig);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Function);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Function);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <test/libsolidity/ABITestsCommon.h>
|
#include <test/libsolidity/ABITestsCommon.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ BOOST_FIXTURE_TEST_SUITE(ABIDecoderTest, SolidityExecutionFramework)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(value_types)
|
BOOST_AUTO_TEST_CASE(value_types)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint16 b, uint24 c, int24 d, bytes3 x, bool e, C g) public returns (uint) {
|
function f(uint a, uint16 b, uint24 c, int24 d, bytes3 x, bool e, C g) public returns (uint) {
|
||||||
if (a != 1) return 1;
|
if (a != 1) return 1;
|
||||||
@ -57,14 +56,14 @@ BOOST_AUTO_TEST_CASE(value_types)
|
|||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
ABI_CHECK(callContractFunction(
|
ABI_CHECK(callContractFunction(
|
||||||
"f(uint256,uint16,uint24,int24,bytes3,bool,address)",
|
"f(uint256,uint16,uint24,int24,bytes3,bool,address)",
|
||||||
1, 2, 3, 4, string("abc"), true, m_contractAddress
|
1, 2, 3, 4, std::string("abc"), true, m_contractAddress
|
||||||
), encodeArgs(u256(20)));
|
), encodeArgs(u256(20)));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
|
BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
uint public _a;
|
uint public _a;
|
||||||
uint[] public _b;
|
uint[] public _b;
|
||||||
@ -90,7 +89,7 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(decode_function_type)
|
BOOST_AUTO_TEST_CASE(decode_function_type)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract D {
|
contract D {
|
||||||
function () external returns (uint) public _a;
|
function () external returns (uint) public _a;
|
||||||
constructor(function () external returns (uint) a) {
|
constructor(function () external returns (uint) a) {
|
||||||
@ -124,7 +123,7 @@ BOOST_AUTO_TEST_CASE(decode_function_type)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(decode_function_type_array)
|
BOOST_AUTO_TEST_CASE(decode_function_type_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract D {
|
contract D {
|
||||||
function () external returns (uint)[] public _a;
|
function () external returns (uint)[] public _a;
|
||||||
constructor(function () external returns (uint)[] memory a) {
|
constructor(function () external returns (uint)[] memory a) {
|
||||||
@ -190,7 +189,7 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(decode_from_memory_complex)
|
BOOST_AUTO_TEST_CASE(decode_from_memory_complex)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
uint public _a;
|
uint public _a;
|
||||||
uint[] public _b;
|
uint[] public _b;
|
||||||
@ -209,23 +208,23 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_complex)
|
|||||||
3, 0x21, 0x22, 0x23,
|
3, 0x21, 0x22, 0x23,
|
||||||
// c
|
// c
|
||||||
0x40, 0x80,
|
0x40, 0x80,
|
||||||
8, string("abcdefgh"),
|
8, std::string("abcdefgh"),
|
||||||
52, string("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
52, std::string("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
));
|
));
|
||||||
ABI_CHECK(callContractFunction("_a()"), encodeArgs(7));
|
ABI_CHECK(callContractFunction("_a()"), encodeArgs(7));
|
||||||
ABI_CHECK(callContractFunction("_b(uint256)", 0), encodeArgs(0x21));
|
ABI_CHECK(callContractFunction("_b(uint256)", 0), encodeArgs(0x21));
|
||||||
ABI_CHECK(callContractFunction("_b(uint256)", 1), encodeArgs(0x22));
|
ABI_CHECK(callContractFunction("_b(uint256)", 1), encodeArgs(0x22));
|
||||||
ABI_CHECK(callContractFunction("_b(uint256)", 2), encodeArgs(0x23));
|
ABI_CHECK(callContractFunction("_b(uint256)", 2), encodeArgs(0x23));
|
||||||
ABI_CHECK(callContractFunction("_b(uint256)", 3), encodeArgs());
|
ABI_CHECK(callContractFunction("_b(uint256)", 3), encodeArgs());
|
||||||
ABI_CHECK(callContractFunction("_c(uint256)", 0), encodeArgs(0x20, 8, string("abcdefgh")));
|
ABI_CHECK(callContractFunction("_c(uint256)", 0), encodeArgs(0x20, 8, std::string("abcdefgh")));
|
||||||
ABI_CHECK(callContractFunction("_c(uint256)", 1), encodeArgs(0x20, 52, string("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")));
|
ABI_CHECK(callContractFunction("_c(uint256)", 1), encodeArgs(0x20, 52, std::string("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")));
|
||||||
ABI_CHECK(callContractFunction("_c(uint256)", 2), encodeArgs());
|
ABI_CHECK(callContractFunction("_c(uint256)", 2), encodeArgs());
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(short_input_value_type)
|
BOOST_AUTO_TEST_CASE(short_input_value_type)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint b) public pure returns (uint) { return a; }
|
function f(uint a, uint b) public pure returns (uint) { return a; }
|
||||||
}
|
}
|
||||||
@ -240,7 +239,7 @@ BOOST_AUTO_TEST_CASE(short_input_value_type)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(short_input_array)
|
BOOST_AUTO_TEST_CASE(short_input_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint[] memory a) public pure returns (uint) { return 7; }
|
function f(uint[] memory a) public pure returns (uint) { return 7; }
|
||||||
}
|
}
|
||||||
@ -257,7 +256,7 @@ BOOST_AUTO_TEST_CASE(short_input_array)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(short_dynamic_input_array)
|
BOOST_AUTO_TEST_CASE(short_dynamic_input_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(bytes[1] memory a) public pure returns (uint) { return 7; }
|
function f(bytes[1] memory a) public pure returns (uint) { return 7; }
|
||||||
}
|
}
|
||||||
@ -270,7 +269,7 @@ BOOST_AUTO_TEST_CASE(short_dynamic_input_array)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(short_input_bytes)
|
BOOST_AUTO_TEST_CASE(short_input_bytes)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function e(bytes memory a) public pure returns (uint) { return 7; }
|
function e(bytes memory a) public pure returns (uint) { return 7; }
|
||||||
function f(bytes[] memory a) public pure returns (uint) { return 7; }
|
function f(bytes[] memory a) public pure returns (uint) { return 7; }
|
||||||
@ -291,7 +290,7 @@ BOOST_AUTO_TEST_CASE(short_input_bytes)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(validation_int_inside_arrays)
|
BOOST_AUTO_TEST_CASE(validation_int_inside_arrays)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
enum E { A, B }
|
enum E { A, B }
|
||||||
function f(uint16[] memory a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
|
function f(uint16[] memory a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
|
||||||
@ -315,7 +314,7 @@ BOOST_AUTO_TEST_CASE(validation_int_inside_arrays)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(validation_function_type)
|
BOOST_AUTO_TEST_CASE(validation_function_type)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(function () external) public pure returns (uint r) { r = 1; }
|
function f(function () external) public pure returns (uint r) { r = 1; }
|
||||||
function g(function () external[] memory) public pure returns (uint r) { r = 2; }
|
function g(function () external[] memory) public pure returns (uint r) { r = 2; }
|
||||||
@ -324,8 +323,8 @@ BOOST_AUTO_TEST_CASE(validation_function_type)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
bool newDecoder = false;
|
bool newDecoder = false;
|
||||||
string validFun{"01234567890123456789abcd"};
|
std::string validFun{"01234567890123456789abcd"};
|
||||||
string invalidFun{"01234567890123456789abcdX"};
|
std::string invalidFun{"01234567890123456789abcdX"};
|
||||||
BOTH_ENCODERS(
|
BOTH_ENCODERS(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
ABI_CHECK(callContractFunction("f(function)", validFun), encodeArgs(1));
|
ABI_CHECK(callContractFunction("f(function)", validFun), encodeArgs(1));
|
||||||
@ -343,7 +342,7 @@ BOOST_AUTO_TEST_CASE(validation_function_type)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_short)
|
BOOST_AUTO_TEST_CASE(struct_short)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S { int a; uint b; bytes16 c; }
|
struct S { int a; uint b; bytes16 c; }
|
||||||
function f(S memory s) public pure returns (S memory q) {
|
function f(S memory s) public pure returns (S memory q) {
|
||||||
@ -370,7 +369,7 @@ BOOST_AUTO_TEST_CASE(struct_short)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(complex_struct)
|
BOOST_AUTO_TEST_CASE(complex_struct)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
enum E {A, B, C}
|
enum E {A, B, C}
|
||||||
struct T { uint x; E e; uint8 y; }
|
struct T { uint x; E e; uint8 y; }
|
||||||
@ -390,7 +389,7 @@ BOOST_AUTO_TEST_CASE(complex_struct)
|
|||||||
)";
|
)";
|
||||||
NEW_ENCODER(
|
NEW_ENCODER(
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
string sig = "f(uint256,(address,(uint256,uint8,uint8)[])[2],(address,(uint256,uint8,uint8)[])[],uint256)";
|
std::string sig = "f(uint256,(address,(uint256,uint8,uint8)[])[2],(address,(uint256,uint8,uint8)[])[],uint256)";
|
||||||
bytes args = encodeArgs(
|
bytes args = encodeArgs(
|
||||||
7, 0x80, 0x1e0, 8,
|
7, 0x80, 0x1e0, 8,
|
||||||
// S[2] s1
|
// S[2] s1
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
@ -50,7 +49,7 @@ BOOST_FIXTURE_TEST_SUITE(ABIEncoderTest, SolidityExecutionFramework)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(value_types)
|
BOOST_AUTO_TEST_CASE(value_types)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(uint a, uint16 b, uint24 c, int24 d, bytes3 x, bool, C);
|
event E(uint a, uint16 b, uint24 c, int24 d, bytes3 x, bool, C);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -67,14 +66,14 @@ BOOST_AUTO_TEST_CASE(value_types)
|
|||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
REQUIRE_LOG_DATA(encodeArgs(
|
REQUIRE_LOG_DATA(encodeArgs(
|
||||||
10, u256(65534), u256(0x121212), u256(-1), string("\x1b\xab\xab"), true, h160("fffffffffffffffffffffffffffffffffffffffb")
|
10, u256(65534), u256(0x121212), u256(-1), std::string("\x1b\xab\xab"), true, h160("fffffffffffffffffffffffffffffffffffffffb")
|
||||||
));
|
));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(string_literal)
|
BOOST_AUTO_TEST_CASE(string_literal)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(string, bytes20, string);
|
event E(string, bytes20, string);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -86,9 +85,9 @@ BOOST_AUTO_TEST_CASE(string_literal)
|
|||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
REQUIRE_LOG_DATA(encodeArgs(
|
REQUIRE_LOG_DATA(encodeArgs(
|
||||||
0x60, string("abcde"), 0xa0,
|
0x60, std::string("abcde"), 0xa0,
|
||||||
6, string("abcdef"),
|
6, std::string("abcdef"),
|
||||||
0x8b, string("abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl")
|
0x8b, std::string("abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl")
|
||||||
));
|
));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -96,7 +95,7 @@ BOOST_AUTO_TEST_CASE(string_literal)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(enum_type_cleanup)
|
BOOST_AUTO_TEST_CASE(enum_type_cleanup)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
enum E { A, B }
|
enum E { A, B }
|
||||||
function f(uint x) public returns (E en) {
|
function f(uint x) public returns (E en) {
|
||||||
@ -114,7 +113,7 @@ BOOST_AUTO_TEST_CASE(enum_type_cleanup)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(conversion)
|
BOOST_AUTO_TEST_CASE(conversion)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(bytes4, bytes4, uint16, uint8, int16, int8);
|
event E(bytes4, bytes4, uint16, uint8, int16, int8);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -132,7 +131,7 @@ BOOST_AUTO_TEST_CASE(conversion)
|
|||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
REQUIRE_LOG_DATA(encodeArgs(
|
REQUIRE_LOG_DATA(encodeArgs(
|
||||||
string(3, 0) + string("\x0a"), string("\xf1\xf2"),
|
std::string(3, 0) + std::string("\x0a"), std::string("\xf1\xf2"),
|
||||||
0xff, 0xff, u256(-1), u256(1)
|
0xff, 0xff, u256(-1), u256(1)
|
||||||
));
|
));
|
||||||
)
|
)
|
||||||
@ -140,7 +139,7 @@ BOOST_AUTO_TEST_CASE(conversion)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(memory_array_one_dim)
|
BOOST_AUTO_TEST_CASE(memory_array_one_dim)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(uint a, int16[] b, uint c);
|
event E(uint a, int16[] b, uint c);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(memory_array_two_dim)
|
BOOST_AUTO_TEST_CASE(memory_array_two_dim)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(uint a, int16[][2] b, uint c);
|
event E(uint a, int16[][2] b, uint c);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -197,7 +196,7 @@ BOOST_AUTO_TEST_CASE(memory_array_two_dim)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(memory_byte_array)
|
BOOST_AUTO_TEST_CASE(memory_byte_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(uint a, bytes[] b, uint c);
|
event E(uint a, bytes[] b, uint c);
|
||||||
function f() public {
|
function f() public {
|
||||||
@ -214,15 +213,15 @@ BOOST_AUTO_TEST_CASE(memory_byte_array)
|
|||||||
REQUIRE_LOG_DATA(encodeArgs(
|
REQUIRE_LOG_DATA(encodeArgs(
|
||||||
10, 0x60, 11,
|
10, 0x60, 11,
|
||||||
2, 0x40, 0xc0,
|
2, 0x40, 0xc0,
|
||||||
66, string("abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw"),
|
66, std::string("abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw"),
|
||||||
63, string("abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw")
|
63, std::string("abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw")
|
||||||
));
|
));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(storage_byte_array)
|
BOOST_AUTO_TEST_CASE(storage_byte_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
bytes short;
|
bytes short;
|
||||||
bytes long;
|
bytes long;
|
||||||
@ -239,15 +238,15 @@ BOOST_AUTO_TEST_CASE(storage_byte_array)
|
|||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
REQUIRE_LOG_DATA(encodeArgs(
|
REQUIRE_LOG_DATA(encodeArgs(
|
||||||
0x40, 0x80,
|
0x40, 0x80,
|
||||||
31, string("123456789012345678901234567890a"),
|
31, std::string("123456789012345678901234567890a"),
|
||||||
75, string("ffff123456789012345678901234567890afffffffff123456789012345678901234567890a")
|
75, std::string("ffff123456789012345678901234567890afffffffff123456789012345678901234567890a")
|
||||||
));
|
));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(storage_array)
|
BOOST_AUTO_TEST_CASE(storage_array)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
address[3] addr;
|
address[3] addr;
|
||||||
event E(address[3] a);
|
event E(address[3] a);
|
||||||
@ -274,7 +273,7 @@ BOOST_AUTO_TEST_CASE(storage_array)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(storage_array_dyn)
|
BOOST_AUTO_TEST_CASE(storage_array_dyn)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
address[] addr;
|
address[] addr;
|
||||||
event E(address[] a);
|
event E(address[] a);
|
||||||
@ -301,7 +300,7 @@ BOOST_AUTO_TEST_CASE(storage_array_dyn)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(storage_array_compact)
|
BOOST_AUTO_TEST_CASE(storage_array_compact)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
int72[] x;
|
int72[] x;
|
||||||
event E(int72[]);
|
event E(int72[]);
|
||||||
@ -329,7 +328,7 @@ BOOST_AUTO_TEST_CASE(storage_array_compact)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(external_function)
|
BOOST_AUTO_TEST_CASE(external_function)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(function(uint) external returns (uint), function(uint) external returns (uint));
|
event E(function(uint) external returns (uint), function(uint) external returns (uint));
|
||||||
function(uint) external returns (uint) g;
|
function(uint) external returns (uint) g;
|
||||||
@ -342,14 +341,14 @@ BOOST_AUTO_TEST_CASE(external_function)
|
|||||||
BOTH_ENCODERS(
|
BOTH_ENCODERS(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f(uint256)", u256(0));
|
callContractFunction("f(uint256)", u256(0));
|
||||||
string functionIdF = asString(m_contractAddress.ref()) + asString(util::selectorFromSignatureH32("f(uint256)").ref());
|
std::string functionIdF = asString(m_contractAddress.ref()) + asString(util::selectorFromSignatureH32("f(uint256)").ref());
|
||||||
REQUIRE_LOG_DATA(encodeArgs(functionIdF, functionIdF));
|
REQUIRE_LOG_DATA(encodeArgs(functionIdF, functionIdF));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(external_function_cleanup)
|
BOOST_AUTO_TEST_CASE(external_function_cleanup)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(function(uint) external returns (uint), function(uint) external returns (uint));
|
event E(function(uint) external returns (uint), function(uint) external returns (uint));
|
||||||
// This test relies on the fact that g is stored in slot zero.
|
// This test relies on the fact that g is stored in slot zero.
|
||||||
@ -364,13 +363,13 @@ BOOST_AUTO_TEST_CASE(external_function_cleanup)
|
|||||||
BOTH_ENCODERS(
|
BOTH_ENCODERS(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f(uint256)", u256(0));
|
callContractFunction("f(uint256)", u256(0));
|
||||||
REQUIRE_LOG_DATA(encodeArgs(string(24, char(-1)), string(24, char(-1))));
|
REQUIRE_LOG_DATA(encodeArgs(std::string(24, char(-1)), std::string(24, char(-1))));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(calldata)
|
BOOST_AUTO_TEST_CASE(calldata)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
event E(bytes);
|
event E(bytes);
|
||||||
function f(bytes calldata a) external {
|
function f(bytes calldata a) external {
|
||||||
@ -378,8 +377,8 @@ BOOST_AUTO_TEST_CASE(calldata)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
string s("abcdef");
|
std::string s("abcdef");
|
||||||
string t("abcdefgggggggggggggggggggggggggggggggggggggggghhheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeggg");
|
std::string t("abcdefgggggggggggggggggggggggggggggggggggggggghhheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeggg");
|
||||||
BOTH_ENCODERS(
|
BOTH_ENCODERS(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
callContractFunction("f(bytes)", 0x20, s.size(), s);
|
callContractFunction("f(bytes)", 0x20, s.size(), s);
|
||||||
@ -393,7 +392,7 @@ BOOST_AUTO_TEST_CASE(function_name_collision)
|
|||||||
{
|
{
|
||||||
// This tests a collision between a function name used by inline assembly
|
// This tests a collision between a function name used by inline assembly
|
||||||
// and by the ABI encoder
|
// and by the ABI encoder
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint x) public returns (uint) {
|
function f(uint x) public returns (uint) {
|
||||||
assembly {
|
assembly {
|
||||||
@ -417,7 +416,7 @@ BOOST_AUTO_TEST_CASE(function_name_collision)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(structs)
|
BOOST_AUTO_TEST_CASE(structs)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S { uint16 a; uint16 b; T[] sub; uint16 c; }
|
struct S { uint16 a; uint16 b; T[] sub; uint16 c; }
|
||||||
struct T { uint64[2] x; }
|
struct T { uint64[2] x; }
|
||||||
@ -452,13 +451,13 @@ BOOST_AUTO_TEST_CASE(structs)
|
|||||||
);
|
);
|
||||||
BOOST_CHECK(callContractFunction("f()") == encoded);
|
BOOST_CHECK(callContractFunction("f()") == encoded);
|
||||||
REQUIRE_LOG_DATA(encoded);
|
REQUIRE_LOG_DATA(encoded);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), keccak256(string("e(uint16,(uint16,uint16,(uint64[2])[],uint16))")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), keccak256(std::string("e(uint16,(uint16,uint16,(uint64[2])[],uint16))")));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(structs2)
|
BOOST_AUTO_TEST_CASE(structs2)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
enum E {A, B, C}
|
enum E {A, B, C}
|
||||||
struct T { uint x; E e; uint8 y; }
|
struct T { uint x; E e; uint8 y; }
|
||||||
@ -517,7 +516,7 @@ BOOST_AUTO_TEST_CASE(structs2)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(bool_arrays)
|
BOOST_AUTO_TEST_CASE(bool_arrays)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
bool[] x;
|
bool[] x;
|
||||||
bool[4] y;
|
bool[4] y;
|
||||||
@ -550,7 +549,7 @@ BOOST_AUTO_TEST_CASE(bool_arrays)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(bool_arrays_split)
|
BOOST_AUTO_TEST_CASE(bool_arrays_split)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
bool[] x;
|
bool[] x;
|
||||||
bool[4] y;
|
bool[4] y;
|
||||||
@ -587,7 +586,7 @@ BOOST_AUTO_TEST_CASE(bool_arrays_split)
|
|||||||
BOOST_AUTO_TEST_CASE(bytesNN_arrays)
|
BOOST_AUTO_TEST_CASE(bytesNN_arrays)
|
||||||
{
|
{
|
||||||
// This tests that encoding packed arrays from storage work correctly.
|
// This tests that encoding packed arrays from storage work correctly.
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
bytes8[] x;
|
bytes8[] x;
|
||||||
bytesWIDTH[SIZE] y;
|
bytesWIDTH[SIZE] y;
|
||||||
@ -610,12 +609,12 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays)
|
|||||||
{
|
{
|
||||||
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
|
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
|
||||||
{
|
{
|
||||||
string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size));
|
std::string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", std::to_string(size));
|
||||||
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8));
|
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", std::to_string(width * 8));
|
||||||
source = boost::algorithm::replace_all_copy(source, "WIDTH", to_string(width));
|
source = boost::algorithm::replace_all_copy(source, "WIDTH", std::to_string(width));
|
||||||
compileAndRun(source, 0, "C");
|
compileAndRun(source, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("store()"), bytes{});
|
ABI_CHECK(callContractFunction("store()"), bytes{});
|
||||||
vector<u256> arr;
|
std::vector<u256> arr;
|
||||||
for (size_t i = 0; i < size; i ++)
|
for (size_t i = 0; i < size; i ++)
|
||||||
arr.emplace_back(u256(i + 1) << (8 * (32 - width)));
|
arr.emplace_back(u256(i + 1) << (8 * (32 - width)));
|
||||||
bytes encoded = encodeArgs(
|
bytes encoded = encodeArgs(
|
||||||
@ -632,7 +631,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays)
|
|||||||
BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn)
|
BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn)
|
||||||
{
|
{
|
||||||
// This tests that encoding packed arrays from storage work correctly.
|
// This tests that encoding packed arrays from storage work correctly.
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
bytes8[] x;
|
bytes8[] x;
|
||||||
bytesWIDTH[] y;
|
bytesWIDTH[] y;
|
||||||
@ -655,12 +654,12 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn)
|
|||||||
{
|
{
|
||||||
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
|
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
|
||||||
{
|
{
|
||||||
string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size));
|
std::string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", std::to_string(size));
|
||||||
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8));
|
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", std::to_string(width * 8));
|
||||||
source = boost::algorithm::replace_all_copy(source, "WIDTH", to_string(width));
|
source = boost::algorithm::replace_all_copy(source, "WIDTH", std::to_string(width));
|
||||||
compileAndRun(source, 0, "C");
|
compileAndRun(source, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("store()"), bytes{});
|
ABI_CHECK(callContractFunction("store()"), bytes{});
|
||||||
vector<u256> arr;
|
std::vector<u256> arr;
|
||||||
for (size_t i = 0; i < size; i ++)
|
for (size_t i = 0; i < size; i ++)
|
||||||
arr.emplace_back(u256(i + 1) << (8 * (32 - width)));
|
arr.emplace_back(u256(i + 1) << (8 * (32 - width)));
|
||||||
bytes encoded = encodeArgs(
|
bytes encoded = encodeArgs(
|
||||||
@ -677,7 +676,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(packed_structs)
|
BOOST_AUTO_TEST_CASE(packed_structs)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S { bool a; int8 b; function() external g; bytes3 d; int8 e; }
|
struct S { bool a; int8 b; function() external g; bytes3 d; int8 e; }
|
||||||
S s;
|
S s;
|
||||||
@ -712,7 +711,7 @@ BOOST_AUTO_TEST_CASE(packed_structs)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_in_constructor)
|
BOOST_AUTO_TEST_CASE(struct_in_constructor)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S {
|
struct S {
|
||||||
string a;
|
string a;
|
||||||
@ -732,7 +731,7 @@ BOOST_AUTO_TEST_CASE(struct_in_constructor)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_in_constructor_indirect)
|
BOOST_AUTO_TEST_CASE(struct_in_constructor_indirect)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S {
|
struct S {
|
||||||
string a;
|
string a;
|
||||||
@ -765,7 +764,7 @@ BOOST_AUTO_TEST_CASE(struct_in_constructor_indirect)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_in_constructor_data_short)
|
BOOST_AUTO_TEST_CASE(struct_in_constructor_data_short)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
struct S {
|
struct S {
|
||||||
string a;
|
string a;
|
||||||
|
@ -28,20 +28,19 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
|
|
||||||
ABIJsonTest::ABIJsonTest(string const& _filename):
|
ABIJsonTest::ABIJsonTest(std::string const& _filename):
|
||||||
TestCase(_filename)
|
TestCase(_filename)
|
||||||
{
|
{
|
||||||
m_source = m_reader.source();
|
m_source = m_reader.source();
|
||||||
m_expectation = m_reader.simpleExpectations();
|
m_expectation = m_reader.simpleExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult ABIJsonTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
TestCase::TestResult ABIJsonTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
|
||||||
{
|
{
|
||||||
CompilerStack compiler;
|
CompilerStack compiler;
|
||||||
|
|
||||||
@ -52,11 +51,11 @@ TestCase::TestResult ABIJsonTest::run(ostream& _stream, string const& _linePrefi
|
|||||||
compiler.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
compiler.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||||
compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
if (!compiler.parseAndAnalyze())
|
if (!compiler.parseAndAnalyze())
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Parsing contract failed"));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Parsing contract failed"));
|
||||||
|
|
||||||
m_obtainedResult.clear();
|
m_obtainedResult.clear();
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (string const& contractName: compiler.contractNames())
|
for (std::string const& contractName: compiler.contractNames())
|
||||||
{
|
{
|
||||||
if (!first)
|
if (!first)
|
||||||
m_obtainedResult += "\n\n";
|
m_obtainedResult += "\n\n";
|
||||||
|
@ -23,7 +23,7 @@ namespace solidity::frontend::test
|
|||||||
|
|
||||||
#define NEW_ENCODER(CODE) \
|
#define NEW_ENCODER(CODE) \
|
||||||
{ \
|
{ \
|
||||||
string sourceCodeTmp = sourceCode; \
|
std::string sourceCodeTmp = sourceCode; \
|
||||||
sourceCode = "pragma abicoder v2;\n" + sourceCode; \
|
sourceCode = "pragma abicoder v2;\n" + sourceCode; \
|
||||||
{ CODE } \
|
{ CODE } \
|
||||||
sourceCode = sourceCodeTmp; \
|
sourceCode = sourceCodeTmp; \
|
||||||
@ -31,7 +31,7 @@ namespace solidity::frontend::test
|
|||||||
|
|
||||||
#define OLD_ENCODER(CODE) \
|
#define OLD_ENCODER(CODE) \
|
||||||
{ \
|
{ \
|
||||||
string sourceCodeTmp = sourceCode; \
|
std::string sourceCodeTmp = sourceCode; \
|
||||||
sourceCode = "pragma abicoder v1;\n" + sourceCode; \
|
sourceCode = "pragma abicoder v1;\n" + sourceCode; \
|
||||||
{ CODE } \
|
{ CODE } \
|
||||||
sourceCode = sourceCodeTmp; \
|
sourceCode = sourceCodeTmp; \
|
||||||
|
@ -36,22 +36,22 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace solidity;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace solidity::util::formatting;
|
using namespace solidity::util::formatting;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity;
|
|
||||||
using namespace std;
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
string const sourceDelimiter("==== Source: ");
|
std::string const sourceDelimiter("==== Source: ");
|
||||||
|
|
||||||
string compilerStateToString(CompilerStack::State _state)
|
std::string compilerStateToString(CompilerStack::State _state)
|
||||||
{
|
{
|
||||||
switch (_state)
|
switch (_state)
|
||||||
{
|
{
|
||||||
@ -65,17 +65,17 @@ string compilerStateToString(CompilerStack::State _state)
|
|||||||
soltestAssert(false, "Unexpected value of state parameter");
|
soltestAssert(false, "Unexpected value of state parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerStack::State stringToCompilerState(const string& _state)
|
CompilerStack::State stringToCompilerState(const std::string& _state)
|
||||||
{
|
{
|
||||||
for (unsigned int i = CompilerStack::State::Empty; i <= CompilerStack::State::CompilationSuccessful; ++i)
|
for (unsigned int i = CompilerStack::State::Empty; i <= CompilerStack::State::CompilationSuccessful; ++i)
|
||||||
{
|
{
|
||||||
if (_state == compilerStateToString(CompilerStack::State(i)))
|
if (_state == compilerStateToString(CompilerStack::State(i)))
|
||||||
return CompilerStack::State(i);
|
return CompilerStack::State(i);
|
||||||
}
|
}
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Unsupported compiler state (" + _state + ") in test contract file"));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Unsupported compiler state (" + _state + ") in test contract file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceVersionWithTag(string& _input)
|
void replaceVersionWithTag(std::string& _input)
|
||||||
{
|
{
|
||||||
boost::algorithm::replace_all(
|
boost::algorithm::replace_all(
|
||||||
_input,
|
_input,
|
||||||
@ -84,7 +84,7 @@ void replaceVersionWithTag(string& _input)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceTagWithVersion(string& _input)
|
void replaceTagWithVersion(std::string& _input)
|
||||||
{
|
{
|
||||||
boost::algorithm::replace_all(
|
boost::algorithm::replace_all(
|
||||||
_input,
|
_input,
|
||||||
@ -95,9 +95,9 @@ void replaceTagWithVersion(string& _input)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTJSONTest::generateTestVariants(string const& _filename)
|
void ASTJSONTest::generateTestVariants(std::string const& _filename)
|
||||||
{
|
{
|
||||||
string_view baseName = _filename;
|
std::string_view baseName = _filename;
|
||||||
baseName.remove_suffix(4);
|
baseName.remove_suffix(4);
|
||||||
|
|
||||||
const std::vector<CompilerStack::State> variantCompileStates = {
|
const std::vector<CompilerStack::State> variantCompileStates = {
|
||||||
@ -117,18 +117,18 @@ void ASTJSONTest::generateTestVariants(string const& _filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTJSONTest::fillSources(string const& _filename)
|
void ASTJSONTest::fillSources(std::string const& _filename)
|
||||||
{
|
{
|
||||||
ifstream file(_filename);
|
std::ifstream file(_filename);
|
||||||
if (!file)
|
if (!file)
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test contract: \"" + _filename + "\"."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot open test contract: \"" + _filename + "\"."));
|
||||||
file.exceptions(ios::badbit);
|
file.exceptions(std::ios::badbit);
|
||||||
|
|
||||||
string sourceName;
|
std::string sourceName;
|
||||||
string source;
|
std::string source;
|
||||||
string line;
|
std::string line;
|
||||||
string const delimiter("// ----");
|
std::string const delimiter("// ----");
|
||||||
string const failMarker("// failAfter:");
|
std::string const failMarker("// failAfter:");
|
||||||
while (getline(file, line))
|
while (getline(file, line))
|
||||||
{
|
{
|
||||||
if (boost::algorithm::starts_with(line, sourceDelimiter))
|
if (boost::algorithm::starts_with(line, sourceDelimiter))
|
||||||
@ -140,14 +140,14 @@ void ASTJSONTest::fillSources(string const& _filename)
|
|||||||
sourceDelimiter.size(),
|
sourceDelimiter.size(),
|
||||||
line.size() - " ===="s.size() - sourceDelimiter.size()
|
line.size() - " ===="s.size() - sourceDelimiter.size()
|
||||||
);
|
);
|
||||||
source = string();
|
source = std::string();
|
||||||
}
|
}
|
||||||
else if (boost::algorithm::starts_with(line, failMarker))
|
else if (boost::algorithm::starts_with(line, failMarker))
|
||||||
{
|
{
|
||||||
string state = line.substr(failMarker.size());
|
std::string state = line.substr(failMarker.size());
|
||||||
boost::algorithm::trim(state);
|
boost::algorithm::trim(state);
|
||||||
if (m_expectedFailAfter.has_value())
|
if (m_expectedFailAfter.has_value())
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Duplicated \"failAfter\" directive"));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Duplicated \"failAfter\" directive"));
|
||||||
m_expectedFailAfter = stringToCompilerState(state);
|
m_expectedFailAfter = stringToCompilerState(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ void ASTJSONTest::fillSources(string const& _filename)
|
|||||||
void ASTJSONTest::validateTestConfiguration() const
|
void ASTJSONTest::validateTestConfiguration() const
|
||||||
{
|
{
|
||||||
if (m_variants.empty())
|
if (m_variants.empty())
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("No file with expected result found."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("No file with expected result found."));
|
||||||
|
|
||||||
if (m_expectedFailAfter.has_value())
|
if (m_expectedFailAfter.has_value())
|
||||||
{
|
{
|
||||||
@ -172,8 +172,8 @@ void ASTJSONTest::validateTestConfiguration() const
|
|||||||
|
|
||||||
if (unexpectedTestVariant != m_variants.end())
|
if (unexpectedTestVariant != m_variants.end())
|
||||||
BOOST_THROW_EXCEPTION(
|
BOOST_THROW_EXCEPTION(
|
||||||
runtime_error(
|
std::runtime_error(
|
||||||
string("Unexpected JSON file: ") + unexpectedTestVariant->astFilename() +
|
std::string("Unexpected JSON file: ") + unexpectedTestVariant->astFilename() +
|
||||||
" in \"failAfter: " +
|
" in \"failAfter: " +
|
||||||
compilerStateToString(m_expectedFailAfter.value()) + "\" scenario."
|
compilerStateToString(m_expectedFailAfter.value()) + "\" scenario."
|
||||||
)
|
)
|
||||||
@ -181,23 +181,23 @@ void ASTJSONTest::validateTestConfiguration() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTJSONTest::ASTJSONTest(string const& _filename):
|
ASTJSONTest::ASTJSONTest(std::string const& _filename):
|
||||||
EVMVersionRestrictedTestCase(_filename)
|
EVMVersionRestrictedTestCase(_filename)
|
||||||
{
|
{
|
||||||
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
|
||||||
|
|
||||||
generateTestVariants(_filename);
|
generateTestVariants(_filename);
|
||||||
fillSources(_filename);
|
fillSources(_filename);
|
||||||
validateTestConfiguration();
|
validateTestConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
TestCase::TestResult ASTJSONTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
|
|
||||||
StringMap sources;
|
StringMap sources;
|
||||||
map<string, unsigned> sourceIndices;
|
std::map<std::string, unsigned> sourceIndices;
|
||||||
for (size_t i = 0; i < m_sources.size(); i++)
|
for (size_t i = 0; i < m_sources.size(); i++)
|
||||||
{
|
{
|
||||||
sources[m_sources[i].first] = m_sources[i].second;
|
sources[m_sources[i].first] = m_sources[i].second;
|
||||||
@ -237,10 +237,10 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
|||||||
|
|
||||||
bool ASTJSONTest::runTest(
|
bool ASTJSONTest::runTest(
|
||||||
TestVariant& _variant,
|
TestVariant& _variant,
|
||||||
map<string, unsigned> const& _sourceIndices,
|
std::map<std::string, unsigned> const& _sourceIndices,
|
||||||
CompilerStack& _compiler,
|
CompilerStack& _compiler,
|
||||||
ostream& _stream,
|
std::ostream& _stream,
|
||||||
string const& _linePrefix,
|
std::string const& _linePrefix,
|
||||||
bool const _formatted
|
bool const _formatted
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -249,7 +249,7 @@ bool ASTJSONTest::runTest(
|
|||||||
|
|
||||||
for (size_t i = 0; i < m_sources.size(); i++)
|
for (size_t i = 0; i < m_sources.size(); i++)
|
||||||
{
|
{
|
||||||
ostringstream result;
|
std::ostringstream result;
|
||||||
ASTJsonExporter(_compiler.state(), _sourceIndices).print(result, _compiler.ast(m_sources[i].first), JsonFormat{ JsonFormat::Pretty });
|
ASTJsonExporter(_compiler.state(), _sourceIndices).print(result, _compiler.ast(m_sources[i].first), JsonFormat{ JsonFormat::Pretty });
|
||||||
_variant.result += result.str();
|
_variant.result += result.str();
|
||||||
if (i != m_sources.size() - 1)
|
if (i != m_sources.size() - 1)
|
||||||
@ -264,49 +264,49 @@ bool ASTJSONTest::runTest(
|
|||||||
|
|
||||||
if (_variant.expectation != _variant.result)
|
if (_variant.expectation != _variant.result)
|
||||||
{
|
{
|
||||||
string nextIndentLevel = _linePrefix + " ";
|
std::string nextIndentLevel = _linePrefix + " ";
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) <<
|
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) <<
|
||||||
_linePrefix <<
|
_linePrefix <<
|
||||||
"Expected result" <<
|
"Expected result" <<
|
||||||
(!_variant.name().empty() ? " (" + _variant.name() + "):" : ":") <<
|
(!_variant.name().empty() ? " (" + _variant.name() + "):" : ":") <<
|
||||||
endl;
|
std::endl;
|
||||||
{
|
{
|
||||||
istringstream stream(_variant.expectation);
|
std::istringstream stream(_variant.expectation);
|
||||||
string line;
|
std::string line;
|
||||||
while (getline(stream, line))
|
while (getline(stream, line))
|
||||||
_stream << nextIndentLevel << line << endl;
|
_stream << nextIndentLevel << line << std::endl;
|
||||||
}
|
}
|
||||||
_stream << endl;
|
_stream << std::endl;
|
||||||
|
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) <<
|
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) <<
|
||||||
_linePrefix <<
|
_linePrefix <<
|
||||||
"Obtained result" <<
|
"Obtained result" <<
|
||||||
(!_variant.name().empty() ? " (" + _variant.name() + "):" : ":") <<
|
(!_variant.name().empty() ? " (" + _variant.name() + "):" : ":") <<
|
||||||
endl;
|
std::endl;
|
||||||
{
|
{
|
||||||
istringstream stream(_variant.result);
|
std::istringstream stream(_variant.result);
|
||||||
string line;
|
std::string line;
|
||||||
while (getline(stream, line))
|
while (getline(stream, line))
|
||||||
_stream << nextIndentLevel << line << endl;
|
_stream << nextIndentLevel << line << std::endl;
|
||||||
}
|
}
|
||||||
_stream << endl;
|
_stream << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTJSONTest::printSource(ostream& _stream, string const& _linePrefix, bool const) const
|
void ASTJSONTest::printSource(std::ostream& _stream, std::string const& _linePrefix, bool const) const
|
||||||
{
|
{
|
||||||
for (auto const& source: m_sources)
|
for (auto const& source: m_sources)
|
||||||
{
|
{
|
||||||
if (m_sources.size() > 1 || source.first != "a")
|
if (m_sources.size() > 1 || source.first != "a")
|
||||||
_stream << _linePrefix << sourceDelimiter << source.first << " ====" << endl << endl;
|
_stream << _linePrefix << sourceDelimiter << source.first << " ====" << std::endl << std::endl;
|
||||||
stringstream stream(source.second);
|
std::stringstream stream(source.second);
|
||||||
string line;
|
std::string line;
|
||||||
while (getline(stream, line))
|
while (getline(stream, line))
|
||||||
_stream << _linePrefix << line << endl;
|
_stream << _linePrefix << line << std::endl;
|
||||||
_stream << endl;
|
_stream << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,13 +320,13 @@ void ASTJSONTest::printUpdatedExpectations(std::ostream&, std::string const&) co
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTJSONTest::updateExpectation(string const& _filename, string const& _expectation, string const& _variant) const
|
void ASTJSONTest::updateExpectation(std::string const& _filename, std::string const& _expectation, std::string const& _variant) const
|
||||||
{
|
{
|
||||||
ofstream file(_filename.c_str());
|
std::ofstream file(_filename.c_str());
|
||||||
if (!file) BOOST_THROW_EXCEPTION(runtime_error("Cannot write " + _variant + "AST expectation to \"" + _filename + "\"."));
|
if (!file) BOOST_THROW_EXCEPTION(std::runtime_error("Cannot write " + _variant + "AST expectation to \"" + _filename + "\"."));
|
||||||
file.exceptions(ios::badbit);
|
file.exceptions(std::ios::badbit);
|
||||||
|
|
||||||
string replacedResult = _expectation;
|
std::string replacedResult = _expectation;
|
||||||
replaceVersionWithTag(replacedResult);
|
replaceVersionWithTag(replacedResult);
|
||||||
|
|
||||||
file << replacedResult;
|
file << replacedResult;
|
||||||
|
@ -40,23 +40,23 @@ using namespace solidity::langutil;
|
|||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace std;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
ASTPropertyTest::ASTPropertyTest(string const& _filename):
|
ASTPropertyTest::ASTPropertyTest(std::string const& _filename):
|
||||||
TestCase(_filename)
|
TestCase(_filename)
|
||||||
{
|
{
|
||||||
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Not a Solidity file: \"" + _filename + "\"."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Not a Solidity file: \"" + _filename + "\"."));
|
||||||
|
|
||||||
m_source = m_reader.source();
|
m_source = m_reader.source();
|
||||||
readExpectations();
|
readExpectations();
|
||||||
soltestAssert(m_tests.size() > 0, "No tests specified in " + _filename);
|
soltestAssert(m_tests.size() > 0, "No tests specified in " + _filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
string ASTPropertyTest::formatExpectations(bool _obtainedResult)
|
std::string ASTPropertyTest::formatExpectations(bool _obtainedResult)
|
||||||
{
|
{
|
||||||
string expectations;
|
std::string expectations;
|
||||||
for (string const& testId: m_testOrder)
|
for (std::string const& testId: m_testOrder)
|
||||||
{
|
{
|
||||||
soltestAssert(m_tests.count(testId) > 0);
|
soltestAssert(m_tests.count(testId) > 0);
|
||||||
expectations +=
|
expectations +=
|
||||||
@ -68,10 +68,10 @@ string ASTPropertyTest::formatExpectations(bool _obtainedResult)
|
|||||||
return expectations;
|
return expectations;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<StringPair> ASTPropertyTest::readKeyValuePairs(string const& _input)
|
std::vector<StringPair> ASTPropertyTest::readKeyValuePairs(std::string const& _input)
|
||||||
{
|
{
|
||||||
vector<StringPair> result;
|
std::vector<StringPair> result;
|
||||||
for (string line: _input | ranges::views::split('\n') | ranges::to<vector<string>>)
|
for (std::string line: _input | ranges::views::split('\n') | ranges::to<std::vector<std::string>>)
|
||||||
{
|
{
|
||||||
boost::trim(line);
|
boost::trim(line);
|
||||||
if (line.empty())
|
if (line.empty())
|
||||||
@ -83,14 +83,14 @@ vector<StringPair> ASTPropertyTest::readKeyValuePairs(string const& _input)
|
|||||||
);
|
);
|
||||||
|
|
||||||
auto colonPosition = line.find_first_of(':');
|
auto colonPosition = line.find_first_of(':');
|
||||||
soltestAssert(colonPosition != string::npos, "Property test is missing a colon: " + line);
|
soltestAssert(colonPosition != std::string::npos, "Property test is missing a colon: " + line);
|
||||||
|
|
||||||
StringPair pair{
|
StringPair pair{
|
||||||
boost::trim_copy(line.substr(0, colonPosition)),
|
boost::trim_copy(line.substr(0, colonPosition)),
|
||||||
boost::trim_copy(line.substr(colonPosition + 1))
|
boost::trim_copy(line.substr(colonPosition + 1))
|
||||||
};
|
};
|
||||||
soltestAssert(!get<0>(pair).empty() != false, "Empty key in property test: " + line);
|
soltestAssert(!std::get<0>(pair).empty() != false, "Empty key in property test: " + line);
|
||||||
soltestAssert(!get<1>(pair).empty() != false, "Empty value in property test: " + line);
|
soltestAssert(!std::get<1>(pair).empty() != false, "Empty value in property test: " + line);
|
||||||
|
|
||||||
result.push_back(pair);
|
result.push_back(pair);
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ void ASTPropertyTest::readExpectations()
|
|||||||
|
|
||||||
void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
||||||
{
|
{
|
||||||
queue<Json::Value> nodesToVisit;
|
std::queue<Json::Value> nodesToVisit;
|
||||||
nodesToVisit.push(_astJson);
|
nodesToVisit.push(_astJson);
|
||||||
|
|
||||||
while (!nodesToVisit.empty())
|
while (!nodesToVisit.empty())
|
||||||
@ -121,7 +121,7 @@ void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
|||||||
for (auto&& member: node)
|
for (auto&& member: node)
|
||||||
nodesToVisit.push(member);
|
nodesToVisit.push(member);
|
||||||
else if (node.isObject())
|
else if (node.isObject())
|
||||||
for (string const& memberName: node.getMemberNames())
|
for (std::string const& memberName: node.getMemberNames())
|
||||||
{
|
{
|
||||||
if (memberName != "documentation")
|
if (memberName != "documentation")
|
||||||
{
|
{
|
||||||
@ -129,12 +129,12 @@ void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string nodeDocstring = node["documentation"].isObject() ?
|
std::string nodeDocstring = node["documentation"].isObject() ?
|
||||||
node["documentation"]["text"].asString() :
|
node["documentation"]["text"].asString() :
|
||||||
node["documentation"].asString();
|
node["documentation"].asString();
|
||||||
soltestAssert(!nodeDocstring.empty());
|
soltestAssert(!nodeDocstring.empty());
|
||||||
|
|
||||||
vector<StringPair> pairs = readKeyValuePairs(nodeDocstring);
|
std::vector<StringPair> pairs = readKeyValuePairs(nodeDocstring);
|
||||||
if (pairs.empty())
|
if (pairs.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
|||||||
m_tests[testId].property = testedProperty;
|
m_tests[testId].property = testedProperty;
|
||||||
|
|
||||||
soltestAssert(node.isMember("nodeType"));
|
soltestAssert(node.isMember("nodeType"));
|
||||||
optional<Json::Value> propertyNode = jsonValueByPath(node, testedProperty);
|
std::optional<Json::Value> propertyNode = jsonValueByPath(node, testedProperty);
|
||||||
soltestAssert(
|
soltestAssert(
|
||||||
propertyNode.has_value(),
|
propertyNode.has_value(),
|
||||||
node["nodeType"].asString() + " node does not have a property named \""s + testedProperty + "\""
|
node["nodeType"].asString() + " node does not have a property named \""s + testedProperty + "\""
|
||||||
@ -179,7 +179,7 @@ void ASTPropertyTest::extractTestsFromAST(Json::Value const& _astJson)
|
|||||||
m_obtainedResult = formatExpectations(true /* _obtainedResult */);
|
m_obtainedResult = formatExpectations(true /* _obtainedResult */);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult ASTPropertyTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
TestCase::TestResult ASTPropertyTest::run(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted)
|
||||||
{
|
{
|
||||||
CompilerStack compiler;
|
CompilerStack compiler;
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ TestCase::TestResult ASTPropertyTest::run(ostream& _stream, string const& _lineP
|
|||||||
compiler.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
compiler.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||||
compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compiler.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
if (!compiler.parseAndAnalyze())
|
if (!compiler.parseAndAnalyze())
|
||||||
BOOST_THROW_EXCEPTION(runtime_error(
|
BOOST_THROW_EXCEPTION(std::runtime_error(
|
||||||
"Parsing contract failed" +
|
"Parsing contract failed" +
|
||||||
SourceReferenceFormatter::formatErrorInformation(compiler.errors(), compiler, _formatted)
|
SourceReferenceFormatter::formatErrorInformation(compiler.errors(), compiler, _formatted)
|
||||||
));
|
));
|
||||||
|
@ -35,16 +35,15 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
|
|
||||||
pair<SourceUnit const*, ErrorList>
|
std::pair<SourceUnit const*, ErrorList>
|
||||||
AnalysisFramework::parseAnalyseAndReturnError(
|
AnalysisFramework::parseAnalyseAndReturnError(
|
||||||
string const& _source,
|
std::string const& _source,
|
||||||
bool _reportWarnings,
|
bool _reportWarnings,
|
||||||
bool _insertLicenseAndVersionPragma,
|
bool _insertLicenseAndVersionPragma,
|
||||||
bool _allowMultipleErrors
|
bool _allowMultipleErrors
|
||||||
@ -99,7 +98,7 @@ ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _inc
|
|||||||
{
|
{
|
||||||
SourceLocation const* location = currentError->sourceLocation();
|
SourceLocation const* location = currentError->sourceLocation();
|
||||||
// sufficient for now, but in future we might clone the error completely, including the secondary location
|
// sufficient for now, but in future we might clone the error completely, including the secondary location
|
||||||
newError = make_shared<Error>(
|
newError = std::make_shared<Error>(
|
||||||
currentError->errorId(),
|
currentError->errorId(),
|
||||||
currentError->type(),
|
currentError->type(),
|
||||||
messagePrefix + " ....",
|
messagePrefix + " ....",
|
||||||
@ -114,18 +113,18 @@ ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _inc
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
|
SourceUnit const* AnalysisFramework::parseAndAnalyse(std::string const& _source)
|
||||||
{
|
{
|
||||||
auto sourceAndError = parseAnalyseAndReturnError(_source);
|
auto sourceAndError = parseAnalyseAndReturnError(_source);
|
||||||
BOOST_REQUIRE(!!sourceAndError.first);
|
BOOST_REQUIRE(!!sourceAndError.first);
|
||||||
string message;
|
std::string message;
|
||||||
if (!sourceAndError.second.empty())
|
if (!sourceAndError.second.empty())
|
||||||
message = "Unexpected error: " + formatErrors(compiler().errors());
|
message = "Unexpected error: " + formatErrors(compiler().errors());
|
||||||
BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message);
|
BOOST_REQUIRE_MESSAGE(sourceAndError.second.empty(), message);
|
||||||
return sourceAndError.first;
|
return sourceAndError.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnalysisFramework::success(string const& _source)
|
bool AnalysisFramework::success(std::string const& _source)
|
||||||
{
|
{
|
||||||
return parseAnalyseAndReturnError(_source).second.empty();
|
return parseAnalyseAndReturnError(_source).second.empty();
|
||||||
}
|
}
|
||||||
@ -138,7 +137,7 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni
|
|||||||
return sourceAndErrors.second;
|
return sourceAndErrors.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
string AnalysisFramework::formatErrors(
|
std::string AnalysisFramework::formatErrors(
|
||||||
langutil::ErrorList const& _errors,
|
langutil::ErrorList const& _errors,
|
||||||
bool _colored,
|
bool _colored,
|
||||||
bool _withErrorIds
|
bool _withErrorIds
|
||||||
@ -152,7 +151,7 @@ string AnalysisFramework::formatErrors(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AnalysisFramework::formatError(
|
std::string AnalysisFramework::formatError(
|
||||||
Error const& _error,
|
Error const& _error,
|
||||||
bool _colored,
|
bool _colored,
|
||||||
bool _withErrorIds
|
bool _withErrorIds
|
||||||
@ -166,11 +165,11 @@ string AnalysisFramework::formatError(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContractDefinition const* AnalysisFramework::retrieveContractByName(SourceUnit const& _source, string const& _name)
|
ContractDefinition const* AnalysisFramework::retrieveContractByName(SourceUnit const& _source, std::string const& _name)
|
||||||
{
|
{
|
||||||
ContractDefinition* contract = nullptr;
|
ContractDefinition* contract = nullptr;
|
||||||
|
|
||||||
for (shared_ptr<ASTNode> const& node: _source.nodes())
|
for (std::shared_ptr<ASTNode> const& node: _source.nodes())
|
||||||
if ((contract = dynamic_cast<ContractDefinition*>(node.get())) && contract->name() == _name)
|
if ((contract = dynamic_cast<ContractDefinition*>(node.get())) && contract->name() == _name)
|
||||||
return contract;
|
return contract;
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
|||||||
RevertStrings::Default,
|
RevertStrings::Default,
|
||||||
solidity::test::CommonOptions::get().optimize ? OptimiserSettings::standard() : OptimiserSettings::minimal()
|
solidity::test::CommonOptions::get().optimize ? OptimiserSettings::standard() : OptimiserSettings::minimal()
|
||||||
);
|
);
|
||||||
compiler.compileContract(*contract, map<ContractDefinition const*, shared_ptr<Compiler const>>{}, bytes());
|
compiler.compileContract(*contract, std::map<ContractDefinition const*, std::shared_ptr<Compiler const>>{}, bytes());
|
||||||
|
|
||||||
return compiler.runtimeAssembly().items();
|
return compiler.runtimeAssembly().items();
|
||||||
}
|
}
|
||||||
@ -102,7 +101,7 @@ void printAssemblyLocations(AssemblyItems const& _items)
|
|||||||
{
|
{
|
||||||
auto printRepeated = [](SourceLocation const& _loc, size_t _repetitions)
|
auto printRepeated = [](SourceLocation const& _loc, size_t _repetitions)
|
||||||
{
|
{
|
||||||
cout <<
|
std::cout <<
|
||||||
"\t\tvector<SourceLocation>(" <<
|
"\t\tvector<SourceLocation>(" <<
|
||||||
_repetitions <<
|
_repetitions <<
|
||||||
", SourceLocation{" <<
|
", SourceLocation{" <<
|
||||||
@ -111,10 +110,10 @@ void printAssemblyLocations(AssemblyItems const& _items)
|
|||||||
_loc.end <<
|
_loc.end <<
|
||||||
", make_shared<string>(\"" <<
|
", make_shared<string>(\"" <<
|
||||||
*_loc.sourceName <<
|
*_loc.sourceName <<
|
||||||
"\")}) +" << endl;
|
"\")}) +" << std::endl;
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<SourceLocation> locations;
|
std::vector<SourceLocation> locations;
|
||||||
for (auto const& item: _items)
|
for (auto const& item: _items)
|
||||||
locations.push_back(item.location());
|
locations.push_back(item.location());
|
||||||
size_t repetitions = 0;
|
size_t repetitions = 0;
|
||||||
@ -136,15 +135,15 @@ void printAssemblyLocations(AssemblyItems const& _items)
|
|||||||
printRepeated(*previousLoc, repetitions);
|
printRepeated(*previousLoc, repetitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations)
|
void checkAssemblyLocations(AssemblyItems const& _items, std::vector<SourceLocation> const& _locations)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
|
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
|
||||||
for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i)
|
for (size_t i = 0; i < std::min(_items.size(), _locations.size()); ++i)
|
||||||
{
|
{
|
||||||
if (_items[i].location().start != _locations[i].start ||
|
if (_items[i].location().start != _locations[i].start ||
|
||||||
_items[i].location().end != _locations[i].end)
|
_items[i].location().end != _locations[i].end)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_MESSAGE(false, "Location mismatch for item " + to_string(i) + ". Found the following locations:");
|
BOOST_CHECK_MESSAGE(false, "Location mismatch for item " + std::to_string(i) + ". Found the following locations:");
|
||||||
printAssemblyLocations(_items);
|
printAssemblyLocations(_items);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,7 +157,7 @@ BOOST_AUTO_TEST_SUITE(Assembly)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(location_test)
|
BOOST_AUTO_TEST_CASE(location_test)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
pragma abicoder v1;
|
pragma abicoder v1;
|
||||||
contract test {
|
contract test {
|
||||||
function f() public returns (uint256 a) {
|
function f() public returns (uint256 a) {
|
||||||
@ -166,34 +165,34 @@ BOOST_AUTO_TEST_CASE(location_test)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
AssemblyItems items = compileContract(make_shared<CharStream>(sourceCode, ""));
|
AssemblyItems items = compileContract(std::make_shared<CharStream>(sourceCode, ""));
|
||||||
shared_ptr<string> sourceName = make_shared<string>();
|
std::shared_ptr<std::string> sourceName = std::make_shared<std::string>();
|
||||||
bool hasShifts = solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting();
|
bool hasShifts = solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting();
|
||||||
|
|
||||||
auto codegenCharStream = make_shared<CharStream>("", "--CODEGEN--");
|
auto codegenCharStream = std::make_shared<CharStream>("", "--CODEGEN--");
|
||||||
|
|
||||||
vector<SourceLocation> locations;
|
std::vector<SourceLocation> locations;
|
||||||
if (solidity::test::CommonOptions::get().optimize)
|
if (solidity::test::CommonOptions::get().optimize)
|
||||||
locations =
|
locations =
|
||||||
vector<SourceLocation>(31, SourceLocation{23, 103, sourceName}) +
|
std::vector<SourceLocation>(31, SourceLocation{23, 103, sourceName}) +
|
||||||
vector<SourceLocation>(1, SourceLocation{41, 100, sourceName}) +
|
std::vector<SourceLocation>(1, SourceLocation{41, 100, sourceName}) +
|
||||||
vector<SourceLocation>(1, SourceLocation{93, 95, sourceName}) +
|
std::vector<SourceLocation>(1, SourceLocation{93, 95, sourceName}) +
|
||||||
vector<SourceLocation>(15, SourceLocation{41, 100, sourceName});
|
std::vector<SourceLocation>(15, SourceLocation{41, 100, sourceName});
|
||||||
else
|
else
|
||||||
locations =
|
locations =
|
||||||
vector<SourceLocation>(hasShifts ? 31 : 32, SourceLocation{23, 103, sourceName}) +
|
std::vector<SourceLocation>(hasShifts ? 31 : 32, SourceLocation{23, 103, sourceName}) +
|
||||||
vector<SourceLocation>(24, SourceLocation{41, 100, sourceName}) +
|
std::vector<SourceLocation>(24, SourceLocation{41, 100, sourceName}) +
|
||||||
vector<SourceLocation>(1, SourceLocation{70, 79, sourceName}) +
|
std::vector<SourceLocation>(1, SourceLocation{70, 79, sourceName}) +
|
||||||
vector<SourceLocation>(1, SourceLocation{93, 95, sourceName}) +
|
std::vector<SourceLocation>(1, SourceLocation{93, 95, sourceName}) +
|
||||||
vector<SourceLocation>(2, SourceLocation{86, 95, sourceName}) +
|
std::vector<SourceLocation>(2, SourceLocation{86, 95, sourceName}) +
|
||||||
vector<SourceLocation>(2, SourceLocation{41, 100, sourceName});
|
std::vector<SourceLocation>(2, SourceLocation{41, 100, sourceName});
|
||||||
checkAssemblyLocations(items, locations);
|
checkAssemblyLocations(items, locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(jump_type)
|
BOOST_AUTO_TEST_CASE(jump_type)
|
||||||
{
|
{
|
||||||
auto sourceCode = make_shared<CharStream>(R"(
|
auto sourceCode = std::make_shared<CharStream>(R"(
|
||||||
pragma abicoder v1;
|
pragma abicoder v1;
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a) public pure returns (uint t) {
|
function f(uint a) public pure returns (uint t) {
|
||||||
@ -206,7 +205,7 @@ BOOST_AUTO_TEST_CASE(jump_type)
|
|||||||
)", "");
|
)", "");
|
||||||
AssemblyItems items = compileContract(sourceCode);
|
AssemblyItems items = compileContract(sourceCode);
|
||||||
|
|
||||||
string jumpTypes;
|
std::string jumpTypes;
|
||||||
for (AssemblyItem const& item: items)
|
for (AssemblyItem const& item: items)
|
||||||
if (item.getJumpType() != AssemblyItem::JumpType::Ordinary)
|
if (item.getJumpType() != AssemblyItem::JumpType::Ordinary)
|
||||||
jumpTypes += item.getJumpTypeAsString() + "\n";
|
jumpTypes += item.getJumpTypeAsString() + "\n";
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
@ -42,29 +41,29 @@ std::string errorMessage(Error const& _e)
|
|||||||
|
|
||||||
bool solidity::frontend::test::searchErrorMessage(Error const& _err, std::string const& _substr)
|
bool solidity::frontend::test::searchErrorMessage(Error const& _err, std::string const& _substr)
|
||||||
{
|
{
|
||||||
if (string const* errorMessage = _err.comment())
|
if (std::string const* errorMessage = _err.comment())
|
||||||
{
|
{
|
||||||
if (errorMessage->find(_substr) == std::string::npos)
|
if (errorMessage->find(_substr) == std::string::npos)
|
||||||
{
|
{
|
||||||
cout << "Expected message \"" << _substr << "\" but found \"" << *errorMessage << "\".\n";
|
std::cout << "Expected message \"" << _substr << "\" but found \"" << *errorMessage << "\".\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "Expected error message but found none." << endl;
|
std::cout << "Expected error message but found none." << std::endl;
|
||||||
return _substr.empty();
|
return _substr.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
string solidity::frontend::test::searchErrors(ErrorList const& _errors, vector<pair<Error::Type, string>> const& _expectations)
|
std::string solidity::frontend::test::searchErrors(ErrorList const& _errors, std::vector<std::pair<Error::Type, std::string>> const& _expectations)
|
||||||
{
|
{
|
||||||
auto expectations = _expectations;
|
auto expectations = _expectations;
|
||||||
for (auto const& error: _errors)
|
for (auto const& error: _errors)
|
||||||
{
|
{
|
||||||
string msg = errorMessage(*error);
|
std::string msg = errorMessage(*error);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto it = expectations.begin(); it != expectations.end(); ++it)
|
for (auto it = expectations.begin(); it != expectations.end(); ++it)
|
||||||
if (msg.find(it->second) != string::npos && error->type() == it->first)
|
if (msg.find(it->second) != std::string::npos && error->type() == it->first)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
expectations.erase(it);
|
expectations.erase(it);
|
||||||
@ -75,7 +74,7 @@ string solidity::frontend::test::searchErrors(ErrorList const& _errors, vector<p
|
|||||||
}
|
}
|
||||||
if (!expectations.empty())
|
if (!expectations.empty())
|
||||||
{
|
{
|
||||||
string msg = "Expected error(s) not present:\n";
|
std::string msg = "Expected error(s) not present:\n";
|
||||||
for (auto const& expectation: expectations)
|
for (auto const& expectation: expectations)
|
||||||
msg += expectation.second + "\n";
|
msg += expectation.second + "\n";
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
@ -168,7 +167,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(single_callvaluecheck)
|
BOOST_AUTO_TEST_CASE(single_callvaluecheck)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
// All functions nonpayable, we can check callvalue at the beginning
|
// All functions nonpayable, we can check callvalue at the beginning
|
||||||
contract Nonpayable {
|
contract Nonpayable {
|
||||||
address a;
|
address a;
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
#include <libsolidity/interface/GasEstimator.h>
|
#include <libsolidity/interface/GasEstimator.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
@ -40,7 +39,7 @@ namespace solidity::frontend::test
|
|||||||
class GasMeterTestFramework: public SolidityExecutionFramework
|
class GasMeterTestFramework: public SolidityExecutionFramework
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void compile(string const& _sourceCode)
|
void compile(std::string const& _sourceCode)
|
||||||
{
|
{
|
||||||
m_compiler.reset();
|
m_compiler.reset();
|
||||||
m_compiler.setSources({{"", "pragma solidity >=0.0;\n"
|
m_compiler.setSources({{"", "pragma solidity >=0.0;\n"
|
||||||
@ -50,10 +49,10 @@ public:
|
|||||||
BOOST_REQUIRE_MESSAGE(m_compiler.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(m_compiler.compile(), "Compiling contract failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCreationTimeGas(string const& _sourceCode, u256 const& _tolerance = u256(0))
|
void testCreationTimeGas(std::string const& _sourceCode, u256 const& _tolerance = u256(0))
|
||||||
{
|
{
|
||||||
compileAndRun(_sourceCode);
|
compileAndRun(_sourceCode);
|
||||||
auto state = make_shared<KnownState>();
|
auto state = std::make_shared<KnownState>();
|
||||||
PathGasMeter meter(*m_compiler.assemblyItems(m_compiler.lastContractName()), solidity::test::CommonOptions::get().evmVersion());
|
PathGasMeter meter(*m_compiler.assemblyItems(m_compiler.lastContractName()), solidity::test::CommonOptions::get().evmVersion());
|
||||||
GasMeter::GasConsumption gas = meter.estimateMax(0, state);
|
GasMeter::GasConsumption gas = meter.estimateMax(0, state);
|
||||||
u256 bytecodeSize(m_compiler.runtimeObject(m_compiler.lastContractName()).bytecode.size());
|
u256 bytecodeSize(m_compiler.runtimeObject(m_compiler.lastContractName()).bytecode.size());
|
||||||
@ -74,7 +73,7 @@ public:
|
|||||||
|
|
||||||
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
|
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
|
||||||
/// against the actual gas usage computed by the VM on the given set of argument variants.
|
/// against the actual gas usage computed by the VM on the given set of argument variants.
|
||||||
void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants, u256 const& _tolerance = u256(0))
|
void testRunTimeGas(std::string const& _sig, std::vector<bytes> _argumentVariants, u256 const& _tolerance = u256(0))
|
||||||
{
|
{
|
||||||
u256 gasUsed = 0;
|
u256 gasUsed = 0;
|
||||||
GasMeter::GasConsumption gas;
|
GasMeter::GasConsumption gas;
|
||||||
@ -83,8 +82,8 @@ public:
|
|||||||
{
|
{
|
||||||
sendMessage(hash.asBytes() + arguments, false, 0);
|
sendMessage(hash.asBytes() + arguments, false, 0);
|
||||||
BOOST_CHECK(m_transactionSuccessful);
|
BOOST_CHECK(m_transactionSuccessful);
|
||||||
gasUsed = max(gasUsed, m_gasUsed);
|
gasUsed = std::max(gasUsed, m_gasUsed);
|
||||||
gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false));
|
gas = std::max(gas, gasForTransaction(hash.asBytes() + arguments, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
gas += GasEstimator(solidity::test::CommonOptions::get().evmVersion()).functionalEstimation(
|
gas += GasEstimator(solidity::test::CommonOptions::get().evmVersion()).functionalEstimation(
|
||||||
@ -171,7 +170,7 @@ BOOST_AUTO_TEST_CASE(branches)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode, 1);
|
testCreationTimeGas(sourceCode, 1);
|
||||||
testRunTimeGas("f(uint256)", vector<bytes>{encodeArgs(2), encodeArgs(8)}, 1);
|
testRunTimeGas("f(uint256)", std::vector<bytes>{encodeArgs(2), encodeArgs(8)}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_calls)
|
BOOST_AUTO_TEST_CASE(function_calls)
|
||||||
@ -196,7 +195,7 @@ BOOST_AUTO_TEST_CASE(function_calls)
|
|||||||
// However, GasMeter always assumes cold costs.
|
// However, GasMeter always assumes cold costs.
|
||||||
testRunTimeGas(
|
testRunTimeGas(
|
||||||
"f(uint256)",
|
"f(uint256)",
|
||||||
vector<bytes>{encodeArgs(2), encodeArgs(8)},
|
std::vector<bytes>{encodeArgs(2), encodeArgs(8)},
|
||||||
m_evmVersion < EVMVersion::berlin() ?
|
m_evmVersion < EVMVersion::berlin() ?
|
||||||
u256(0) :
|
u256(0) :
|
||||||
u256(2100)
|
u256(2100)
|
||||||
@ -225,13 +224,13 @@ BOOST_AUTO_TEST_CASE(multiple_external_functions)
|
|||||||
// However, GasMeter always assumes cold costs.
|
// However, GasMeter always assumes cold costs.
|
||||||
testRunTimeGas(
|
testRunTimeGas(
|
||||||
"f(uint256)",
|
"f(uint256)",
|
||||||
vector<bytes>{encodeArgs(2), encodeArgs(8)},
|
std::vector<bytes>{encodeArgs(2), encodeArgs(8)},
|
||||||
m_evmVersion < EVMVersion::berlin() ?
|
m_evmVersion < EVMVersion::berlin() ?
|
||||||
u256(0) :
|
u256(0) :
|
||||||
u256(2100)
|
u256(2100)
|
||||||
);
|
);
|
||||||
|
|
||||||
testRunTimeGas("g(uint256)", vector<bytes>{encodeArgs(2)});
|
testRunTimeGas("g(uint256)", std::vector<bytes>{encodeArgs(2)});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(exponent_size)
|
BOOST_AUTO_TEST_CASE(exponent_size)
|
||||||
@ -250,9 +249,9 @@ BOOST_AUTO_TEST_CASE(exponent_size)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode);
|
testCreationTimeGas(sourceCode);
|
||||||
testRunTimeGas("f(uint256)", vector<bytes>{encodeArgs(2)});
|
testRunTimeGas("f(uint256)", std::vector<bytes>{encodeArgs(2)});
|
||||||
testRunTimeGas("g(uint256)", vector<bytes>{encodeArgs(2)});
|
testRunTimeGas("g(uint256)", std::vector<bytes>{encodeArgs(2)});
|
||||||
testRunTimeGas("h(uint256)", vector<bytes>{encodeArgs(2)});
|
testRunTimeGas("h(uint256)", std::vector<bytes>{encodeArgs(2)});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(balance_gas)
|
BOOST_AUTO_TEST_CASE(balance_gas)
|
||||||
@ -265,7 +264,7 @@ BOOST_AUTO_TEST_CASE(balance_gas)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode);
|
testCreationTimeGas(sourceCode);
|
||||||
testRunTimeGas("lookup_balance(address)", vector<bytes>{encodeArgs(2), encodeArgs(100)});
|
testRunTimeGas("lookup_balance(address)", std::vector<bytes>{encodeArgs(2), encodeArgs(100)});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(extcodesize_gas)
|
BOOST_AUTO_TEST_CASE(extcodesize_gas)
|
||||||
@ -280,7 +279,7 @@ BOOST_AUTO_TEST_CASE(extcodesize_gas)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode);
|
testCreationTimeGas(sourceCode);
|
||||||
testRunTimeGas("f()", vector<bytes>{encodeArgs()});
|
testRunTimeGas("f()", std::vector<bytes>{encodeArgs()});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
|
BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
|
||||||
@ -294,7 +293,7 @@ BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode);
|
testCreationTimeGas(sourceCode);
|
||||||
testRunTimeGas("x()", vector<bytes>{encodeArgs()});
|
testRunTimeGas("x()", std::vector<bytes>{encodeArgs()});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(complex_control_flow)
|
BOOST_AUTO_TEST_CASE(complex_control_flow)
|
||||||
@ -335,7 +334,7 @@ BOOST_AUTO_TEST_CASE(complex_control_flow)
|
|||||||
)";
|
)";
|
||||||
testCreationTimeGas(sourceCode);
|
testCreationTimeGas(sourceCode);
|
||||||
// max gas is used for small x
|
// max gas is used for small x
|
||||||
testRunTimeGas("ln(int128)", vector<bytes>{encodeArgs(0), encodeArgs(10), encodeArgs(105), encodeArgs(30000)});
|
testRunTimeGas("ln(int128)", std::vector<bytes>{encodeArgs(0), encodeArgs(10), encodeArgs(105), encodeArgs(30000)});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -33,10 +33,9 @@ using namespace solidity::langutil;
|
|||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace std;
|
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
|
||||||
GasTest::GasTest(string const& _filename):
|
GasTest::GasTest(std::string const& _filename):
|
||||||
TestCase(_filename)
|
TestCase(_filename)
|
||||||
{
|
{
|
||||||
m_source = m_reader.source();
|
m_source = m_reader.source();
|
||||||
@ -48,20 +47,20 @@ GasTest::GasTest(string const& _filename):
|
|||||||
|
|
||||||
void GasTest::parseExpectations(std::istream& _stream)
|
void GasTest::parseExpectations(std::istream& _stream)
|
||||||
{
|
{
|
||||||
map<std::string, std::string>* currentKind = nullptr;
|
std::map<std::string, std::string>* currentKind = nullptr;
|
||||||
string line;
|
std::string line;
|
||||||
|
|
||||||
while (getline(_stream, line))
|
while (getline(_stream, line))
|
||||||
if (!boost::starts_with(line, "// "))
|
if (!boost::starts_with(line, "// "))
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid expectation: expected \"// \"."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid expectation: expected \"// \"."));
|
||||||
else if (boost::ends_with(line, ":"))
|
else if (boost::ends_with(line, ":"))
|
||||||
{
|
{
|
||||||
string kind = line.substr(3, line.length() - 4);
|
std::string kind = line.substr(3, line.length() - 4);
|
||||||
boost::trim(kind);
|
boost::trim(kind);
|
||||||
currentKind = &m_expectations[std::move(kind)];
|
currentKind = &m_expectations[std::move(kind)];
|
||||||
}
|
}
|
||||||
else if (!currentKind)
|
else if (!currentKind)
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("No function kind specified. Expected \"creation:\", \"external:\" or \"internal:\"."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("No function kind specified. Expected \"creation:\", \"external:\" or \"internal:\"."));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto it = line.begin() + 3;
|
auto it = line.begin() + 3;
|
||||||
@ -69,18 +68,18 @@ void GasTest::parseExpectations(std::istream& _stream)
|
|||||||
auto functionNameBegin = it;
|
auto functionNameBegin = it;
|
||||||
while (it != line.end() && *it != ':')
|
while (it != line.end() && *it != ':')
|
||||||
++it;
|
++it;
|
||||||
string functionName(functionNameBegin, it);
|
std::string functionName(functionNameBegin, it);
|
||||||
if (functionName == "fallback")
|
if (functionName == "fallback")
|
||||||
functionName.clear();
|
functionName.clear();
|
||||||
expect(it, line.end(), ':');
|
expect(it, line.end(), ':');
|
||||||
skipWhitespace(it, line.end());
|
skipWhitespace(it, line.end());
|
||||||
if (it == line.end())
|
if (it == line.end())
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid expectation: expected gas cost."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid expectation: expected gas cost."));
|
||||||
(*currentKind)[functionName] = std::string(it, line.end());
|
(*currentKind)[functionName] = std::string(it, line.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GasTest::printUpdatedExpectations(ostream& _stream, string const& _linePrefix) const
|
void GasTest::printUpdatedExpectations(std::ostream& _stream, std::string const& _linePrefix) const
|
||||||
{
|
{
|
||||||
Json::Value estimates = compiler().gasEstimates(compiler().lastContractName());
|
Json::Value estimates = compiler().gasEstimates(compiler().lastContractName());
|
||||||
for (auto groupIt = estimates.begin(); groupIt != estimates.end(); ++groupIt)
|
for (auto groupIt = estimates.begin(); groupIt != estimates.end(); ++groupIt)
|
||||||
@ -98,7 +97,7 @@ void GasTest::printUpdatedExpectations(ostream& _stream, string const& _linePref
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
TestCase::TestResult GasTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
|
||||||
{
|
{
|
||||||
compiler().reset();
|
compiler().reset();
|
||||||
// Prerelease CBOR metadata varies in size due to changing version numbers and build dates.
|
// Prerelease CBOR metadata varies in size due to changing version numbers and build dates.
|
||||||
@ -153,10 +152,10 @@ TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GasTest::printSource(ostream& _stream, string const& _linePrefix, bool) const
|
void GasTest::printSource(std::ostream& _stream, std::string const& _linePrefix, bool) const
|
||||||
{
|
{
|
||||||
string line;
|
std::string line;
|
||||||
istringstream input(m_source);
|
std::istringstream input(m_source);
|
||||||
while (getline(input, line))
|
while (getline(input, line))
|
||||||
_stream << _linePrefix << line << std::endl;
|
_stream << _linePrefix << line << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
@ -42,7 +41,7 @@ BOOST_AUTO_TEST_SUITE(SolidityImports)
|
|||||||
BOOST_AUTO_TEST_CASE(remappings)
|
BOOST_AUTO_TEST_CASE(remappings)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
c.setRemappings(vector<ImportRemapper::Remapping>{{"", "s", "s_1.4.6"},{"", "t", "Tee"}});
|
c.setRemappings(std::vector<ImportRemapper::Remapping>{{"", "s", "s_1.4.6"},{"", "t", "Tee"}});
|
||||||
c.setSources({
|
c.setSources({
|
||||||
{"a", "import \"s/s.sol\"; contract A is S {} pragma solidity >=0.0;"},
|
{"a", "import \"s/s.sol\"; contract A is S {} pragma solidity >=0.0;"},
|
||||||
{"b", "import \"t/tee.sol\"; contract A is Tee {} pragma solidity >=0.0;"},
|
{"b", "import \"t/tee.sol\"; contract A is Tee {} pragma solidity >=0.0;"},
|
||||||
@ -56,7 +55,7 @@ BOOST_AUTO_TEST_CASE(remappings)
|
|||||||
BOOST_AUTO_TEST_CASE(context_dependent_remappings)
|
BOOST_AUTO_TEST_CASE(context_dependent_remappings)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
c.setRemappings(vector<ImportRemapper::Remapping>{{"a", "s", "s_1.4.6"}, {"b", "s", "s_1.4.7"}});
|
c.setRemappings(std::vector<ImportRemapper::Remapping>{{"a", "s", "s_1.4.6"}, {"b", "s", "s_1.4.7"}});
|
||||||
c.setSources({
|
c.setSources({
|
||||||
{"a/a.sol", "import \"s/s.sol\"; contract A is SSix {} pragma solidity >=0.0;"},
|
{"a/a.sol", "import \"s/s.sol\"; contract A is SSix {} pragma solidity >=0.0;"},
|
||||||
{"b/b.sol", "import \"s/s.sol\"; contract B is SSeven {} pragma solidity >=0.0;"},
|
{"b/b.sol", "import \"s/s.sol\"; contract B is SSeven {} pragma solidity >=0.0;"},
|
||||||
@ -70,7 +69,7 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings)
|
|||||||
BOOST_AUTO_TEST_CASE(context_dependent_remappings_ensure_default_and_module_preserved)
|
BOOST_AUTO_TEST_CASE(context_dependent_remappings_ensure_default_and_module_preserved)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
c.setRemappings(vector<ImportRemapper::Remapping>{
|
c.setRemappings(std::vector<ImportRemapper::Remapping>{
|
||||||
{"", "foo", "vendor/foo_2.0.0"},
|
{"", "foo", "vendor/foo_2.0.0"},
|
||||||
{"vendor/bar", "foo", "vendor/foo_1.0.0"},
|
{"vendor/bar", "foo", "vendor/foo_1.0.0"},
|
||||||
{"", "bar", "vendor/bar"}
|
{"", "bar", "vendor/bar"}
|
||||||
@ -88,7 +87,7 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings_ensure_default_and_module_pres
|
|||||||
BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent_1)
|
BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent_1)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
c.setRemappings(vector<ImportRemapper::Remapping>{{"a", "x/y/z", "d"}, {"a/b", "x", "e"}});
|
c.setRemappings(std::vector<ImportRemapper::Remapping>{{"a", "x/y/z", "d"}, {"a/b", "x", "e"}});
|
||||||
c.setSources({
|
c.setSources({
|
||||||
{"a/main.sol", "import \"x/y/z/z.sol\"; contract Main is D {} pragma solidity >=0.0;"},
|
{"a/main.sol", "import \"x/y/z/z.sol\"; contract Main is D {} pragma solidity >=0.0;"},
|
||||||
{"a/b/main.sol", "import \"x/y/z/z.sol\"; contract Main is E {} pragma solidity >=0.0;"},
|
{"a/b/main.sol", "import \"x/y/z/z.sol\"; contract Main is E {} pragma solidity >=0.0;"},
|
||||||
@ -102,7 +101,7 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent_1)
|
|||||||
BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent_2)
|
BOOST_AUTO_TEST_CASE(context_dependent_remappings_order_independent_2)
|
||||||
{
|
{
|
||||||
CompilerStack c;
|
CompilerStack c;
|
||||||
c.setRemappings(vector<ImportRemapper::Remapping>{{"a/b", "x", "e"}, {"a", "x/y/z", "d"}});
|
c.setRemappings(std::vector<ImportRemapper::Remapping>{{"a/b", "x", "e"}, {"a", "x/y/z", "d"}});
|
||||||
c.setSources({
|
c.setSources({
|
||||||
{"a/main.sol", "import \"x/y/z/z.sol\"; contract Main is D {} pragma solidity >=0.0;"},
|
{"a/main.sol", "import \"x/y/z/z.sol\"; contract Main is D {} pragma solidity >=0.0;"},
|
||||||
{"a/b/main.sol", "import \"x/y/z/z.sol\"; contract Main is E {} pragma solidity >=0.0;"},
|
{"a/b/main.sol", "import \"x/y/z/z.sol\"; contract Main is E {} pragma solidity >=0.0;"},
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::yul;
|
using namespace solidity::yul;
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ namespace
|
|||||||
{
|
{
|
||||||
|
|
||||||
std::optional<Error> parseAndReturnFirstError(
|
std::optional<Error> parseAndReturnFirstError(
|
||||||
string const& _source,
|
std::string const& _source,
|
||||||
bool _assemble = false,
|
bool _assemble = false,
|
||||||
bool _allowWarnings = true,
|
bool _allowWarnings = true,
|
||||||
YulStack::Language _language = YulStack::Language::Assembly,
|
YulStack::Language _language = YulStack::Language::Assembly,
|
||||||
@ -79,7 +78,7 @@ std::optional<Error> parseAndReturnFirstError(
|
|||||||
BOOST_FAIL("Fatal error leaked.");
|
BOOST_FAIL("Fatal error leaked.");
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
shared_ptr<Error const> error;
|
std::shared_ptr<Error const> error;
|
||||||
for (auto const& e: stack.errors())
|
for (auto const& e: stack.errors())
|
||||||
{
|
{
|
||||||
if (_allowWarnings && e->type() == Error::Type::Warning)
|
if (_allowWarnings && e->type() == Error::Type::Warning)
|
||||||
@ -99,7 +98,7 @@ std::optional<Error> parseAndReturnFirstError(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool successParse(
|
bool successParse(
|
||||||
string const& _source,
|
std::string const& _source,
|
||||||
bool _assemble = false,
|
bool _assemble = false,
|
||||||
bool _allowWarnings = true,
|
bool _allowWarnings = true,
|
||||||
YulStack::Language _language = YulStack::Language::Assembly,
|
YulStack::Language _language = YulStack::Language::Assembly,
|
||||||
@ -109,7 +108,7 @@ bool successParse(
|
|||||||
return !parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language, _machine);
|
return !parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language, _machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool successAssemble(string const& _source, bool _allowWarnings = true, YulStack::Language _language = YulStack::Language::Assembly)
|
bool successAssemble(std::string const& _source, bool _allowWarnings = true, YulStack::Language _language = YulStack::Language::Assembly)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
successParse(_source, true, _allowWarnings, _language, YulStack::Machine::EVM);
|
successParse(_source, true, _allowWarnings, _language, YulStack::Machine::EVM);
|
||||||
@ -128,7 +127,7 @@ Error expectError(
|
|||||||
return *error;
|
return *error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parsePrintCompare(string const& _source, bool _canWarn = false)
|
void parsePrintCompare(std::string const& _source, bool _canWarn = false)
|
||||||
{
|
{
|
||||||
YulStack stack(
|
YulStack stack(
|
||||||
solidity::test::CommonOptions::get().evmVersion(),
|
solidity::test::CommonOptions::get().evmVersion(),
|
||||||
@ -142,7 +141,7 @@ void parsePrintCompare(string const& _source, bool _canWarn = false)
|
|||||||
BOOST_REQUIRE(!Error::containsErrors(stack.errors()));
|
BOOST_REQUIRE(!Error::containsErrors(stack.errors()));
|
||||||
else
|
else
|
||||||
BOOST_REQUIRE(stack.errors().empty());
|
BOOST_REQUIRE(stack.errors().empty());
|
||||||
string expectation = "object \"object\" {\n code " + boost::replace_all_copy(_source, "\n", "\n ") + "\n}\n";
|
std::string expectation = "object \"object\" {\n code " + boost::replace_all_copy(_source, "\n", "\n ") + "\n}\n";
|
||||||
BOOST_CHECK_EQUAL(stack.print(), expectation);
|
BOOST_CHECK_EQUAL(stack.print(), expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,8 +218,8 @@ BOOST_AUTO_TEST_CASE(print_string_literals)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
|
BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
|
||||||
{
|
{
|
||||||
string source = "{ let x := \"\\u1bac\" }";
|
std::string source = "{ let x := \"\\u1bac\" }";
|
||||||
string parsed = "object \"object\" {\n code { let x := \"\\xe1\\xae\\xac\" }\n}\n";
|
std::string parsed = "object \"object\" {\n code { let x := \"\\xe1\\xae\\xac\" }\n}\n";
|
||||||
YulStack stack(
|
YulStack stack(
|
||||||
solidity::test::CommonOptions::get().evmVersion(),
|
solidity::test::CommonOptions::get().evmVersion(),
|
||||||
solidity::test::CommonOptions::get().eofVersion(),
|
solidity::test::CommonOptions::get().eofVersion(),
|
||||||
@ -232,7 +231,7 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
|
|||||||
BOOST_REQUIRE(stack.errors().empty());
|
BOOST_REQUIRE(stack.errors().empty());
|
||||||
BOOST_CHECK_EQUAL(stack.print(), parsed);
|
BOOST_CHECK_EQUAL(stack.print(), parsed);
|
||||||
|
|
||||||
string parsedInner = "{ let x := \"\\xe1\\xae\\xac\" }";
|
std::string parsedInner = "{ let x := \"\\xe1\\xae\\xac\" }";
|
||||||
parsePrintCompare(parsedInner);
|
parsePrintCompare(parsedInner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +257,7 @@ BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_calls)
|
BOOST_AUTO_TEST_CASE(function_calls)
|
||||||
{
|
{
|
||||||
string source = R"({
|
std::string source = R"({
|
||||||
function y()
|
function y()
|
||||||
{ }
|
{ }
|
||||||
function f(a) -> b
|
function f(a) -> b
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <libsolidity/interface/Version.h>
|
#include <libsolidity/interface/Version.h>
|
||||||
#include <libsolc/libsolc.h>
|
#include <libsolc/libsolc.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
@ -37,7 +36,7 @@ namespace
|
|||||||
|
|
||||||
/// TODO: share this between StandardCompiler.cpp
|
/// TODO: share this between StandardCompiler.cpp
|
||||||
/// Helper to match a specific error type and message
|
/// Helper to match a specific error type and message
|
||||||
bool containsError(Json::Value const& _compilerResult, string const& _type, string const& _message)
|
bool containsError(Json::Value const& _compilerResult, std::string const& _type, std::string const& _message)
|
||||||
{
|
{
|
||||||
if (!_compilerResult.isMember("errors"))
|
if (!_compilerResult.isMember("errors"))
|
||||||
return false;
|
return false;
|
||||||
@ -54,10 +53,10 @@ bool containsError(Json::Value const& _compilerResult, string const& _type, stri
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value compile(string const& _input, CStyleReadFileCallback _callback = nullptr)
|
Json::Value compile(std::string const& _input, CStyleReadFileCallback _callback = nullptr)
|
||||||
{
|
{
|
||||||
char* output_ptr = solidity_compile(_input.c_str(), _callback, nullptr);
|
char* output_ptr = solidity_compile(_input.c_str(), _callback, nullptr);
|
||||||
string output(output_ptr);
|
std::string output(output_ptr);
|
||||||
solidity_free(output_ptr);
|
solidity_free(output_ptr);
|
||||||
solidity_reset();
|
solidity_reset();
|
||||||
Json::Value ret;
|
Json::Value ret;
|
||||||
@ -65,7 +64,7 @@ Json::Value compile(string const& _input, CStyleReadFileCallback _callback = nul
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* stringToSolidity(string const& _input)
|
char* stringToSolidity(std::string const& _input)
|
||||||
{
|
{
|
||||||
char* ptr = solidity_alloc(_input.length());
|
char* ptr = solidity_alloc(_input.length());
|
||||||
BOOST_REQUIRE(ptr != nullptr);
|
BOOST_REQUIRE(ptr != nullptr);
|
||||||
@ -79,14 +78,14 @@ BOOST_AUTO_TEST_SUITE(LibSolc)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(read_version)
|
BOOST_AUTO_TEST_CASE(read_version)
|
||||||
{
|
{
|
||||||
string output(solidity_version());
|
std::string output(solidity_version());
|
||||||
BOOST_CHECK(output.find(VersionString) == 0);
|
BOOST_CHECK(output.find(VersionString) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(read_license)
|
BOOST_AUTO_TEST_CASE(read_license)
|
||||||
{
|
{
|
||||||
string output(solidity_license());
|
std::string output(solidity_license());
|
||||||
BOOST_CHECK(output.find("GNU GENERAL PUBLIC LICENSE") != string::npos);
|
BOOST_CHECK(output.find("GNU GENERAL PUBLIC LICENSE") != std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(standard_compilation)
|
BOOST_AUTO_TEST_CASE(standard_compilation)
|
||||||
@ -148,16 +147,16 @@ BOOST_AUTO_TEST_CASE(with_callback)
|
|||||||
// Passed in a nullptr in the compile() helper above.
|
// Passed in a nullptr in the compile() helper above.
|
||||||
BOOST_REQUIRE(_context == nullptr);
|
BOOST_REQUIRE(_context == nullptr);
|
||||||
// Caller frees the pointers.
|
// Caller frees the pointers.
|
||||||
BOOST_REQUIRE(string(_kind) == ReadCallback::kindString(ReadCallback::Kind::ReadFile));
|
BOOST_REQUIRE(std::string(_kind) == ReadCallback::kindString(ReadCallback::Kind::ReadFile));
|
||||||
if (string(_path) == "found.sol")
|
if (std::string(_path) == "found.sol")
|
||||||
{
|
{
|
||||||
static string content{"import \"missing.sol\"; contract B {}"};
|
static std::string content{"import \"missing.sol\"; contract B {}"};
|
||||||
*o_contents = stringToSolidity(content);
|
*o_contents = stringToSolidity(content);
|
||||||
*o_error = nullptr;
|
*o_error = nullptr;
|
||||||
}
|
}
|
||||||
else if (string(_path) == "missing.sol")
|
else if (std::string(_path) == "missing.sol")
|
||||||
{
|
{
|
||||||
static string errorMsg{"Missing file."};
|
static std::string errorMsg{"Missing file."};
|
||||||
*o_error = stringToSolidity(errorMsg);
|
*o_error = stringToSolidity(errorMsg);
|
||||||
*o_contents = nullptr;
|
*o_contents = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::util::formatting;
|
using namespace solidity::util::formatting;
|
||||||
@ -37,7 +36,7 @@ using namespace solidity::frontend;
|
|||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace yul;
|
using namespace yul;
|
||||||
|
|
||||||
TestCase::TestResult MemoryGuardTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
TestCase::TestResult MemoryGuardTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
|
||||||
{
|
{
|
||||||
compiler().reset();
|
compiler().reset();
|
||||||
compiler().setSources(StringMap{{"", m_source}});
|
compiler().setSources(StringMap{{"", m_source}});
|
||||||
@ -50,7 +49,7 @@ TestCase::TestResult MemoryGuardTest::run(ostream& _stream, string const& _lineP
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_obtainedResult.clear();
|
m_obtainedResult.clear();
|
||||||
for (string contractName: compiler().contractNames())
|
for (std::string contractName: compiler().contractNames())
|
||||||
{
|
{
|
||||||
ErrorList errors;
|
ErrorList errors;
|
||||||
auto [object, analysisInfo] = yul::test::parse(
|
auto [object, analysisInfo] = yul::test::parse(
|
||||||
@ -61,7 +60,7 @@ TestCase::TestResult MemoryGuardTest::run(ostream& _stream, string const& _lineP
|
|||||||
|
|
||||||
if (!object || !analysisInfo || Error::containsErrors(errors))
|
if (!object || !analysisInfo || Error::containsErrors(errors))
|
||||||
{
|
{
|
||||||
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing IR." << endl;
|
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing IR." << std::endl;
|
||||||
return TestResult::FatalError;
|
return TestResult::FatalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
@ -37,13 +36,13 @@ namespace solidity::frontend::test
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
map<string, string> requireParsedCBORMetadata(bytes const& _bytecode, CompilerStack::MetadataFormat _metadataFormat)
|
std::map<std::string, std::string> requireParsedCBORMetadata(bytes const& _bytecode, CompilerStack::MetadataFormat _metadataFormat)
|
||||||
{
|
{
|
||||||
bytes cborMetadata = solidity::test::onlyMetadata(_bytecode);
|
bytes cborMetadata = solidity::test::onlyMetadata(_bytecode);
|
||||||
if (_metadataFormat != CompilerStack::MetadataFormat::NoMetadata)
|
if (_metadataFormat != CompilerStack::MetadataFormat::NoMetadata)
|
||||||
{
|
{
|
||||||
BOOST_REQUIRE(!cborMetadata.empty());
|
BOOST_REQUIRE(!cborMetadata.empty());
|
||||||
std::optional<map<string, string>> tmp = solidity::test::parseCBORMetadata(cborMetadata);
|
std::optional<std::map<std::string, std::string>> tmp = solidity::test::parseCBORMetadata(cborMetadata);
|
||||||
BOOST_REQUIRE(tmp);
|
BOOST_REQUIRE(tmp);
|
||||||
return *tmp;
|
return *tmp;
|
||||||
}
|
}
|
||||||
@ -51,13 +50,13 @@ map<string, string> requireParsedCBORMetadata(bytes const& _bytecode, CompilerSt
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<string> compileAndCheckLicenseMetadata(string const& _contractName, char const* _sourceCode)
|
std::optional<std::string> compileAndCheckLicenseMetadata(std::string const& _contractName, char const* _sourceCode)
|
||||||
{
|
{
|
||||||
CompilerStack compilerStack;
|
CompilerStack compilerStack;
|
||||||
compilerStack.setSources({{"A.sol", _sourceCode}});
|
compilerStack.setSources({{"A.sol", _sourceCode}});
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
string const& serialisedMetadata = compilerStack.metadata(_contractName);
|
std::string const& serialisedMetadata = compilerStack.metadata(_contractName);
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -71,7 +70,7 @@ optional<string> compileAndCheckLicenseMetadata(string const& _contractName, cha
|
|||||||
return metadata["sources"]["A.sol"]["license"].asString();
|
return metadata["sources"]["A.sol"]["license"].asString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -93,7 +92,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
||||||
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
||||||
})
|
})
|
||||||
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
for (auto metadataHash: std::set<CompilerStack::MetadataHash>{
|
||||||
CompilerStack::MetadataHash::IPFS,
|
CompilerStack::MetadataHash::IPFS,
|
||||||
CompilerStack::MetadataHash::Bzzr1,
|
CompilerStack::MetadataHash::Bzzr1,
|
||||||
CompilerStack::MetadataHash::None
|
CompilerStack::MetadataHash::None
|
||||||
@ -107,7 +106,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
compilerStack.setMetadataHash(metadataHash);
|
compilerStack.setMetadataHash(metadataHash);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
||||||
string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
|
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
||||||
@ -116,7 +115,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytes hash;
|
bytes hash;
|
||||||
string hashMethod;
|
std::string hashMethod;
|
||||||
if (metadataHash == CompilerStack::MetadataHash::IPFS)
|
if (metadataHash == CompilerStack::MetadataHash::IPFS)
|
||||||
{
|
{
|
||||||
hash = util::ipfsHash(metadata);
|
hash = util::ipfsHash(metadata);
|
||||||
@ -166,7 +165,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
CompilerStack::MetadataFormat::WithReleaseVersionTag,
|
||||||
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
|
||||||
})
|
})
|
||||||
for (auto metadataHash: set<CompilerStack::MetadataHash>{
|
for (auto metadataHash: std::set<CompilerStack::MetadataHash>{
|
||||||
CompilerStack::MetadataHash::IPFS,
|
CompilerStack::MetadataHash::IPFS,
|
||||||
CompilerStack::MetadataHash::Bzzr1,
|
CompilerStack::MetadataHash::Bzzr1,
|
||||||
CompilerStack::MetadataHash::None
|
CompilerStack::MetadataHash::None
|
||||||
@ -180,7 +179,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
compilerStack.setMetadataHash(metadataHash);
|
compilerStack.setMetadataHash(metadataHash);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
||||||
string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
|
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
||||||
@ -189,7 +188,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytes hash;
|
bytes hash;
|
||||||
string hashMethod;
|
std::string hashMethod;
|
||||||
if (metadataHash == CompilerStack::MetadataHash::IPFS)
|
if (metadataHash == CompilerStack::MetadataHash::IPFS)
|
||||||
{
|
{
|
||||||
hash = util::ipfsHash(metadata);
|
hash = util::ipfsHash(metadata);
|
||||||
@ -250,7 +249,7 @@ BOOST_AUTO_TEST_CASE(metadata_eof_experimental)
|
|||||||
compilerStack.setOptimiserSettings(true);
|
compilerStack.setOptimiserSettings(true);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
||||||
string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
|
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);
|
||||||
@ -288,7 +287,7 @@ BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
|
|||||||
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
string const& serialisedMetadata = compilerStack.metadata("A");
|
std::string const& serialisedMetadata = compilerStack.metadata("A");
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -329,7 +328,7 @@ BOOST_AUTO_TEST_CASE(metadata_relevant_sources_imports)
|
|||||||
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
string const& serialisedMetadata = compilerStack.metadata("C");
|
std::string const& serialisedMetadata = compilerStack.metadata("C");
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -357,7 +356,7 @@ BOOST_AUTO_TEST_CASE(metadata_useLiteralContent)
|
|||||||
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
compilerStack.setOptimiserSettings(solidity::test::CommonOptions::get().optimize);
|
||||||
compilerStack.useMetadataLiteralSources(_literal);
|
compilerStack.useMetadataLiteralSources(_literal);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
string metadata_str = compilerStack.metadata("test");
|
std::string metadata_str = compilerStack.metadata("test");
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(metadata_str, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(metadata_str, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -407,7 +406,7 @@ BOOST_AUTO_TEST_CASE(metadata_viair)
|
|||||||
BOOST_CHECK(compilerStack.cborMetadata("test") == compilerStack.cborMetadata("test", _viaIR));
|
BOOST_CHECK(compilerStack.cborMetadata("test") == compilerStack.cborMetadata("test", _viaIR));
|
||||||
BOOST_CHECK(compilerStack.cborMetadata("test") != compilerStack.cborMetadata("test", !_viaIR));
|
BOOST_CHECK(compilerStack.cborMetadata("test") != compilerStack.cborMetadata("test", !_viaIR));
|
||||||
|
|
||||||
map<string, string> const parsedCBORMetadata = requireParsedCBORMetadata(
|
std::map<std::string, std::string> const parsedCBORMetadata = requireParsedCBORMetadata(
|
||||||
compilerStack.runtimeObject("test").bytecode,
|
compilerStack.runtimeObject("test").bytecode,
|
||||||
CompilerStack::MetadataFormat::WithReleaseVersionTag
|
CompilerStack::MetadataFormat::WithReleaseVersionTag
|
||||||
);
|
);
|
||||||
@ -431,7 +430,7 @@ BOOST_AUTO_TEST_CASE(metadata_revert_strings)
|
|||||||
compilerStack.setRevertStringBehaviour(RevertStrings::Strip);
|
compilerStack.setRevertStringBehaviour(RevertStrings::Strip);
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
string const& serialisedMetadata = compilerStack.metadata("A");
|
std::string const& serialisedMetadata = compilerStack.metadata("A");
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -447,7 +446,7 @@ BOOST_AUTO_TEST_CASE(metadata_optimiser_sequence)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
vector<tuple<string, string>> sequences =
|
std::vector<std::tuple<std::string, std::string>> sequences =
|
||||||
{
|
{
|
||||||
// {"<optimizer sequence>", "<optimizer cleanup sequence>"}
|
// {"<optimizer sequence>", "<optimizer cleanup sequence>"}
|
||||||
{"", ""},
|
{"", ""},
|
||||||
@ -456,7 +455,7 @@ BOOST_AUTO_TEST_CASE(metadata_optimiser_sequence)
|
|||||||
{"dhfoDgvulfnTUtnIf", "fDn"}
|
{"dhfoDgvulfnTUtnIf", "fDn"}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto check = [sourceCode](string const& _optimizerSequence, string const& _optimizerCleanupSequence)
|
auto check = [sourceCode](std::string const& _optimizerSequence, std::string const& _optimizerCleanupSequence)
|
||||||
{
|
{
|
||||||
OptimiserSettings optimizerSettings = OptimiserSettings::minimal();
|
OptimiserSettings optimizerSettings = OptimiserSettings::minimal();
|
||||||
optimizerSettings.runYulOptimiser = true;
|
optimizerSettings.runYulOptimiser = true;
|
||||||
@ -469,7 +468,7 @@ BOOST_AUTO_TEST_CASE(metadata_optimiser_sequence)
|
|||||||
|
|
||||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
string const& serialisedMetadata = compilerStack.metadata("C");
|
std::string const& serialisedMetadata = compilerStack.metadata("C");
|
||||||
Json::Value metadata;
|
Json::Value metadata;
|
||||||
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
BOOST_REQUIRE(util::jsonParseStrict(serialisedMetadata, metadata));
|
||||||
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
BOOST_CHECK(solidity::test::isValidMetadata(metadata));
|
||||||
@ -477,8 +476,8 @@ BOOST_AUTO_TEST_CASE(metadata_optimiser_sequence)
|
|||||||
BOOST_CHECK(metadata["settings"]["optimizer"]["details"].isMember("yulDetails"));
|
BOOST_CHECK(metadata["settings"]["optimizer"]["details"].isMember("yulDetails"));
|
||||||
BOOST_CHECK(metadata["settings"]["optimizer"]["details"]["yulDetails"].isMember("optimizerSteps"));
|
BOOST_CHECK(metadata["settings"]["optimizer"]["details"]["yulDetails"].isMember("optimizerSteps"));
|
||||||
|
|
||||||
string const metadataOptimizerSteps = metadata["settings"]["optimizer"]["details"]["yulDetails"]["optimizerSteps"].asString();
|
std::string const metadataOptimizerSteps = metadata["settings"]["optimizer"]["details"]["yulDetails"]["optimizerSteps"].asString();
|
||||||
string const expectedMetadataOptimiserSteps = _optimizerSequence + ":" + _optimizerCleanupSequence;
|
std::string const expectedMetadataOptimiserSteps = _optimizerSequence + ":" + _optimizerCleanupSequence;
|
||||||
BOOST_CHECK_EQUAL(metadataOptimizerSteps, expectedMetadataOptimiserSteps);
|
BOOST_CHECK_EQUAL(metadataOptimizerSteps, expectedMetadataOptimiserSteps);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -493,7 +492,7 @@ BOOST_AUTO_TEST_CASE(metadata_license_missing)
|
|||||||
contract C {
|
contract C {
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
|
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_license_gpl3)
|
BOOST_AUTO_TEST_CASE(metadata_license_gpl3)
|
||||||
@ -544,7 +543,7 @@ BOOST_AUTO_TEST_CASE(metadata_license_bidi_marks)
|
|||||||
"// NOTE: The text above is reversed using Unicode directional marks. In raw form it would look like this:\n"
|
"// NOTE: The text above is reversed using Unicode directional marks. In raw form it would look like this:\n"
|
||||||
"// <LRO>0.3-LPG :reifitnedI-esneciL-XDPS<PDF>\n"
|
"// <LRO>0.3-LPG :reifitnedI-esneciL-XDPS<PDF>\n"
|
||||||
"contract C {}\n";
|
"contract C {}\n";
|
||||||
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
|
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_license_bottom)
|
BOOST_AUTO_TEST_CASE(metadata_license_bottom)
|
||||||
@ -579,7 +578,7 @@ BOOST_AUTO_TEST_CASE(metadata_license_in_string)
|
|||||||
bytes license = "// SPDX-License-Identifier: GPL-3.0";
|
bytes license = "// SPDX-License-Identifier: GPL-3.0";
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
|
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_license_in_contract)
|
BOOST_AUTO_TEST_CASE(metadata_license_in_contract)
|
||||||
@ -589,7 +588,7 @@ BOOST_AUTO_TEST_CASE(metadata_license_in_contract)
|
|||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
|
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_license_missing_colon)
|
BOOST_AUTO_TEST_CASE(metadata_license_missing_colon)
|
||||||
@ -598,7 +597,7 @@ BOOST_AUTO_TEST_CASE(metadata_license_missing_colon)
|
|||||||
// SPDX-License-Identifier GPL-3.0
|
// SPDX-License-Identifier GPL-3.0
|
||||||
contract C {}
|
contract C {}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
|
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(metadata_license_multiline)
|
BOOST_AUTO_TEST_CASE(metadata_license_multiline)
|
||||||
|
@ -21,13 +21,12 @@
|
|||||||
|
|
||||||
#include <range/v3/action/remove_if.hpp>
|
#include <range/v3/action/remove_if.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
|
|
||||||
SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, EVMVersion{})
|
SMTCheckerTest::SMTCheckerTest(std::string const& _filename): SyntaxTest(_filename, EVMVersion{})
|
||||||
{
|
{
|
||||||
auto contract = m_reader.stringSetting("SMTContract", "");
|
auto contract = m_reader.stringSetting("SMTContract", "");
|
||||||
if (!contract.empty())
|
if (!contract.empty())
|
||||||
@ -37,7 +36,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
if (extCallsMode)
|
if (extCallsMode)
|
||||||
m_modelCheckerSettings.externalCalls = *extCallsMode;
|
m_modelCheckerSettings.externalCalls = *extCallsMode;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT external calls mode."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT external calls mode."));
|
||||||
|
|
||||||
auto const& showUnproved = m_reader.stringSetting("SMTShowUnproved", "yes");
|
auto const& showUnproved = m_reader.stringSetting("SMTShowUnproved", "yes");
|
||||||
if (showUnproved == "no")
|
if (showUnproved == "no")
|
||||||
@ -45,7 +44,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
else if (showUnproved == "yes")
|
else if (showUnproved == "yes")
|
||||||
m_modelCheckerSettings.showUnproved = true;
|
m_modelCheckerSettings.showUnproved = true;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT \"show unproved\" choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT \"show unproved\" choice."));
|
||||||
|
|
||||||
auto const& showUnsupported = m_reader.stringSetting("SMTShowUnsupported", "yes");
|
auto const& showUnsupported = m_reader.stringSetting("SMTShowUnsupported", "yes");
|
||||||
if (showUnsupported == "no")
|
if (showUnsupported == "no")
|
||||||
@ -53,14 +52,14 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
else if (showUnsupported == "yes")
|
else if (showUnsupported == "yes")
|
||||||
m_modelCheckerSettings.showUnsupported = true;
|
m_modelCheckerSettings.showUnsupported = true;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT \"show unsupported\" choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT \"show unsupported\" choice."));
|
||||||
|
|
||||||
m_modelCheckerSettings.solvers = smtutil::SMTSolverChoice::None();
|
m_modelCheckerSettings.solvers = smtutil::SMTSolverChoice::None();
|
||||||
auto const& choice = m_reader.stringSetting("SMTSolvers", "z3");
|
auto const& choice = m_reader.stringSetting("SMTSolvers", "z3");
|
||||||
if (choice == "none")
|
if (choice == "none")
|
||||||
m_modelCheckerSettings.solvers = smtutil::SMTSolverChoice::None();
|
m_modelCheckerSettings.solvers = smtutil::SMTSolverChoice::None();
|
||||||
else if (!m_modelCheckerSettings.solvers.setSolver(choice))
|
else if (!m_modelCheckerSettings.solvers.setSolver(choice))
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT solver choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT solver choice."));
|
||||||
|
|
||||||
m_modelCheckerSettings.solvers &= ModelChecker::availableSolvers();
|
m_modelCheckerSettings.solvers &= ModelChecker::availableSolvers();
|
||||||
|
|
||||||
@ -71,13 +70,13 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
if (targets)
|
if (targets)
|
||||||
m_modelCheckerSettings.targets = *targets;
|
m_modelCheckerSettings.targets = *targets;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT targets."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT targets."));
|
||||||
|
|
||||||
auto engine = ModelCheckerEngine::fromString(m_reader.stringSetting("SMTEngine", "all"));
|
auto engine = ModelCheckerEngine::fromString(m_reader.stringSetting("SMTEngine", "all"));
|
||||||
if (engine)
|
if (engine)
|
||||||
m_modelCheckerSettings.engine = *engine;
|
m_modelCheckerSettings.engine = *engine;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT engine choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT engine choice."));
|
||||||
|
|
||||||
if (m_modelCheckerSettings.solvers.none() || m_modelCheckerSettings.engine.none())
|
if (m_modelCheckerSettings.solvers.none() || m_modelCheckerSettings.engine.none())
|
||||||
m_shouldRun = false;
|
m_shouldRun = false;
|
||||||
@ -88,10 +87,10 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
else if (ignoreCex == "yes")
|
else if (ignoreCex == "yes")
|
||||||
m_ignoreCex = true;
|
m_ignoreCex = true;
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT counterexample choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT counterexample choice."));
|
||||||
|
|
||||||
static auto removeInv = [](vector<SyntaxTestError>&& errors) {
|
static auto removeInv = [](std::vector<SyntaxTestError>&& errors) {
|
||||||
vector<SyntaxTestError> filtered;
|
std::vector<SyntaxTestError> filtered;
|
||||||
for (auto&& e: errors)
|
for (auto&& e: errors)
|
||||||
if (e.errorId != 1180_error)
|
if (e.errorId != 1180_error)
|
||||||
filtered.emplace_back(e);
|
filtered.emplace_back(e);
|
||||||
@ -106,10 +105,10 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename): SyntaxTest(_filename, E
|
|||||||
else if (ignoreInv == "yes")
|
else if (ignoreInv == "yes")
|
||||||
m_modelCheckerSettings.invariants = ModelCheckerInvariants::None();
|
m_modelCheckerSettings.invariants = ModelCheckerInvariants::None();
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid SMT invariant choice."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid SMT invariant choice."));
|
||||||
|
|
||||||
auto const& ignoreOSSetting = m_reader.stringSetting("SMTIgnoreOS", "none");
|
auto const& ignoreOSSetting = m_reader.stringSetting("SMTIgnoreOS", "none");
|
||||||
for (string const& os: ignoreOSSetting | ranges::views::split(',') | ranges::to<vector<string>>())
|
for (std::string const& os: ignoreOSSetting | ranges::views::split(',') | ranges::to<std::vector<std::string>>())
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (os == "macos")
|
if (os == "macos")
|
||||||
@ -139,11 +138,11 @@ void SMTCheckerTest::filterObtainedErrors()
|
|||||||
SyntaxTest::filterObtainedErrors();
|
SyntaxTest::filterObtainedErrors();
|
||||||
m_unfilteredErrorList = m_errorList;
|
m_unfilteredErrorList = m_errorList;
|
||||||
|
|
||||||
static auto removeCex = [](vector<SyntaxTestError>& errors) {
|
static auto removeCex = [](std::vector<SyntaxTestError>& errors) {
|
||||||
for (auto& e: errors)
|
for (auto& e: errors)
|
||||||
if (
|
if (
|
||||||
auto cexPos = e.message.find("\\nCounterexample");
|
auto cexPos = e.message.find("\\nCounterexample");
|
||||||
cexPos != string::npos
|
cexPos != std::string::npos
|
||||||
)
|
)
|
||||||
e.message = e.message.substr(0, cexPos);
|
e.message = e.message.substr(0, cexPos);
|
||||||
};
|
};
|
||||||
@ -155,7 +154,7 @@ void SMTCheckerTest::filterObtainedErrors()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMTCheckerTest::printUpdatedExpectations(ostream &_stream, const string &_linePrefix) const {
|
void SMTCheckerTest::printUpdatedExpectations(std::ostream &_stream, const std::string &_linePrefix) const {
|
||||||
if (!m_unfilteredErrorList.empty())
|
if (!m_unfilteredErrorList.empty())
|
||||||
printErrorList(_stream, m_unfilteredErrorList, _linePrefix, false);
|
printErrorList(_stream, m_unfilteredErrorList, _linePrefix, false);
|
||||||
else
|
else
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
@ -42,16 +41,16 @@ BOOST_AUTO_TEST_SUITE(SemVerMatcher)
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
SemVerMatchExpression parseExpression(string const& _input)
|
SemVerMatchExpression parseExpression(std::string const& _input)
|
||||||
{
|
{
|
||||||
CharStream stream(_input, "");
|
CharStream stream(_input, "");
|
||||||
Scanner scanner{stream};
|
Scanner scanner{stream};
|
||||||
vector<string> literals;
|
std::vector<std::string> literals;
|
||||||
vector<Token> tokens;
|
std::vector<Token> tokens;
|
||||||
while (scanner.currentToken() != Token::EOS)
|
while (scanner.currentToken() != Token::EOS)
|
||||||
{
|
{
|
||||||
auto token = scanner.currentToken();
|
auto token = scanner.currentToken();
|
||||||
string literal = scanner.currentLiteral();
|
std::string literal = scanner.currentLiteral();
|
||||||
if (literal.empty() && TokenTraits::toString(token))
|
if (literal.empty() && TokenTraits::toString(token))
|
||||||
literal = TokenTraits::toString(token);
|
literal = TokenTraits::toString(token);
|
||||||
literals.push_back(literal);
|
literals.push_back(literal);
|
||||||
@ -100,7 +99,7 @@ BOOST_AUTO_TEST_CASE(exception_on_invalid_version_in_semverversion_constructor)
|
|||||||
BOOST_AUTO_TEST_CASE(positive_range)
|
BOOST_AUTO_TEST_CASE(positive_range)
|
||||||
{
|
{
|
||||||
// Positive range tests
|
// Positive range tests
|
||||||
vector<pair<string, string>> tests = {
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
{"*", "1.2.3-foo"},
|
{"*", "1.2.3-foo"},
|
||||||
{"1.0.0 - 2.0.0", "1.2.3"},
|
{"1.0.0 - 2.0.0", "1.2.3"},
|
||||||
{"1.0.0", "1.0.0"},
|
{"1.0.0", "1.0.0"},
|
||||||
@ -198,7 +197,7 @@ BOOST_AUTO_TEST_CASE(positive_range)
|
|||||||
BOOST_AUTO_TEST_CASE(negative_range)
|
BOOST_AUTO_TEST_CASE(negative_range)
|
||||||
{
|
{
|
||||||
// Negative range tests
|
// Negative range tests
|
||||||
vector<pair<string, string>> tests = {
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
{"^0^1", "0.0.0"},
|
{"^0^1", "0.0.0"},
|
||||||
{"^0^1", "1.0.0"},
|
{"^0^1", "1.0.0"},
|
||||||
{"1.0.0 - 2.0.0", "2.2.3"},
|
{"1.0.0 - 2.0.0", "2.2.3"},
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::yul;
|
using namespace solidity::yul;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
@ -43,9 +42,10 @@ using namespace solidity::util::formatting;
|
|||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace boost::algorithm;
|
using namespace boost::algorithm;
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
using namespace std::string_literals;
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
ostream& solidity::frontend::test::operator<<(ostream& _output, RequiresYulOptimizer _requiresYulOptimizer)
|
std::ostream& solidity::frontend::test::operator<<(std::ostream& _output, RequiresYulOptimizer _requiresYulOptimizer)
|
||||||
{
|
{
|
||||||
switch (_requiresYulOptimizer)
|
switch (_requiresYulOptimizer)
|
||||||
{
|
{
|
||||||
@ -57,10 +57,10 @@ ostream& solidity::frontend::test::operator<<(ostream& _output, RequiresYulOptim
|
|||||||
}
|
}
|
||||||
|
|
||||||
SemanticTest::SemanticTest(
|
SemanticTest::SemanticTest(
|
||||||
string const& _filename,
|
std::string const& _filename,
|
||||||
langutil::EVMVersion _evmVersion,
|
langutil::EVMVersion _evmVersion,
|
||||||
optional<uint8_t> _eofVersion,
|
std::optional<uint8_t> _eofVersion,
|
||||||
vector<boost::filesystem::path> const& _vmPaths,
|
std::vector<boost::filesystem::path> const& _vmPaths,
|
||||||
bool _enforceGasCost,
|
bool _enforceGasCost,
|
||||||
u256 _enforceGasCostMinValue
|
u256 _enforceGasCostMinValue
|
||||||
):
|
):
|
||||||
@ -73,9 +73,9 @@ SemanticTest::SemanticTest(
|
|||||||
m_enforceGasCost(_enforceGasCost),
|
m_enforceGasCost(_enforceGasCost),
|
||||||
m_enforceGasCostMinValue(std::move(_enforceGasCostMinValue))
|
m_enforceGasCostMinValue(std::move(_enforceGasCostMinValue))
|
||||||
{
|
{
|
||||||
static set<string> const compileViaYulAllowedValues{"also", "true", "false"};
|
static std::set<std::string> const compileViaYulAllowedValues{"also", "true", "false"};
|
||||||
static set<string> const yulRunTriggers{"also", "true"};
|
static std::set<std::string> const yulRunTriggers{"also", "true"};
|
||||||
static set<string> const legacyRunTriggers{"also", "false", "default"};
|
static std::set<std::string> const legacyRunTriggers{"also", "false", "default"};
|
||||||
|
|
||||||
m_requiresYulOptimizer = m_reader.enumSetting<RequiresYulOptimizer>(
|
m_requiresYulOptimizer = m_reader.enumSetting<RequiresYulOptimizer>(
|
||||||
"requiresYulOptimizer",
|
"requiresYulOptimizer",
|
||||||
@ -91,14 +91,14 @@ SemanticTest::SemanticTest(
|
|||||||
if (m_runWithABIEncoderV1Only && !solidity::test::CommonOptions::get().useABIEncoderV1)
|
if (m_runWithABIEncoderV1Only && !solidity::test::CommonOptions::get().useABIEncoderV1)
|
||||||
m_shouldRun = false;
|
m_shouldRun = false;
|
||||||
|
|
||||||
string compileViaYul = m_reader.stringSetting("compileViaYul", "also");
|
std::string compileViaYul = m_reader.stringSetting("compileViaYul", "also");
|
||||||
if (m_runWithABIEncoderV1Only && compileViaYul != "false")
|
if (m_runWithABIEncoderV1Only && compileViaYul != "false")
|
||||||
BOOST_THROW_EXCEPTION(runtime_error(
|
BOOST_THROW_EXCEPTION(std::runtime_error(
|
||||||
"ABIEncoderV1Only tests cannot be run via yul, "
|
"ABIEncoderV1Only tests cannot be run via yul, "
|
||||||
"so they need to also specify ``compileViaYul: false``"
|
"so they need to also specify ``compileViaYul: false``"
|
||||||
));
|
));
|
||||||
if (!util::contains(compileViaYulAllowedValues, compileViaYul))
|
if (!util::contains(compileViaYulAllowedValues, compileViaYul))
|
||||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid compileViaYul value: " + compileViaYul + "."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid compileViaYul value: " + compileViaYul + "."));
|
||||||
m_testCaseWantsYulRun = util::contains(yulRunTriggers, compileViaYul);
|
m_testCaseWantsYulRun = util::contains(yulRunTriggers, compileViaYul);
|
||||||
m_testCaseWantsLegacyRun = util::contains(legacyRunTriggers, compileViaYul);
|
m_testCaseWantsLegacyRun = util::contains(legacyRunTriggers, compileViaYul);
|
||||||
|
|
||||||
@ -118,19 +118,19 @@ SemanticTest::SemanticTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, Builtin> SemanticTest::makeBuiltins()
|
std::map<std::string, Builtin> SemanticTest::makeBuiltins()
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"isoltest_builtin_test",
|
"isoltest_builtin_test",
|
||||||
[](FunctionCall const&) -> optional<bytes>
|
[](FunctionCall const&) -> std::optional<bytes>
|
||||||
{
|
{
|
||||||
return toBigEndian(u256(0x1234));
|
return toBigEndian(u256(0x1234));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"isoltest_side_effects_test",
|
"isoltest_side_effects_test",
|
||||||
[](FunctionCall const& _call) -> optional<bytes>
|
[](FunctionCall const& _call) -> std::optional<bytes>
|
||||||
{
|
{
|
||||||
if (_call.arguments.parameters.empty())
|
if (_call.arguments.parameters.empty())
|
||||||
return toBigEndian(0);
|
return toBigEndian(0);
|
||||||
@ -140,7 +140,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"balance",
|
"balance",
|
||||||
[this](FunctionCall const& _call) -> optional<bytes>
|
[this](FunctionCall const& _call) -> std::optional<bytes>
|
||||||
{
|
{
|
||||||
soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected.");
|
soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected.");
|
||||||
h160 address;
|
h160 address;
|
||||||
@ -153,7 +153,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"storageEmpty",
|
"storageEmpty",
|
||||||
[this](FunctionCall const& _call) -> optional<bytes>
|
[this](FunctionCall const& _call) -> std::optional<bytes>
|
||||||
{
|
{
|
||||||
soltestAssert(_call.arguments.parameters.empty(), "No arguments expected.");
|
soltestAssert(_call.arguments.parameters.empty(), "No arguments expected.");
|
||||||
return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0));
|
return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0));
|
||||||
@ -161,7 +161,7 @@ map<string, Builtin> SemanticTest::makeBuiltins()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"account",
|
"account",
|
||||||
[this](FunctionCall const& _call) -> optional<bytes>
|
[this](FunctionCall const& _call) -> std::optional<bytes>
|
||||||
{
|
{
|
||||||
soltestAssert(_call.arguments.parameters.size() == 1, "Account number expected.");
|
soltestAssert(_call.arguments.parameters.size() == 1, "Account number expected.");
|
||||||
size_t accountNumber = static_cast<size_t>(stoi(_call.arguments.parameters.at(0).rawString));
|
size_t accountNumber = static_cast<size_t>(stoi(_call.arguments.parameters.at(0).rawString));
|
||||||
@ -172,15 +172,15 @@ map<string, Builtin> SemanticTest::makeBuiltins()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const
|
std::vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
return {
|
return {
|
||||||
[](FunctionCall const& _call) -> vector<string>
|
[](FunctionCall const& _call) -> std::vector<std::string>
|
||||||
{
|
{
|
||||||
if (_call.signature == "isoltest_side_effects_test")
|
if (_call.signature == "isoltest_side_effects_test")
|
||||||
{
|
{
|
||||||
vector<string> result;
|
std::vector<std::string> result;
|
||||||
for (auto const& argument: _call.arguments.parameters)
|
for (auto const& argument: _call.arguments.parameters)
|
||||||
result.emplace_back(util::toHex(argument.rawBytes));
|
result.emplace_back(util::toHex(argument.rawBytes));
|
||||||
return result;
|
return result;
|
||||||
@ -191,7 +191,7 @@ vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
string SemanticTest::formatEventParameter(optional<AnnotatedEventSignature> _signature, bool _indexed, size_t _index, bytes const& _data)
|
std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSignature> _signature, bool _indexed, size_t _index, bytes const& _data)
|
||||||
{
|
{
|
||||||
auto isPrintableASCII = [](bytes const& s)
|
auto isPrintableASCII = [](bytes const& s)
|
||||||
{
|
{
|
||||||
@ -214,7 +214,7 @@ string SemanticTest::formatEventParameter(optional<AnnotatedEventSignature> _sig
|
|||||||
abiType = ABIType(ABIType::Type::String);
|
abiType = ABIType(ABIType::Type::String);
|
||||||
if (_signature.has_value())
|
if (_signature.has_value())
|
||||||
{
|
{
|
||||||
vector<string> const& types = _indexed ? _signature->indexedTypes : _signature->nonIndexedTypes;
|
std::vector<std::string> const& types = _indexed ? _signature->indexedTypes : _signature->nonIndexedTypes;
|
||||||
if (_index < types.size())
|
if (_index < types.size())
|
||||||
{
|
{
|
||||||
if (types.at(_index) == "bool")
|
if (types.at(_index) == "bool")
|
||||||
@ -224,16 +224,16 @@ string SemanticTest::formatEventParameter(optional<AnnotatedEventSignature> _sig
|
|||||||
return BytesUtils::formatBytes(_data, abiType);
|
return BytesUtils::formatBytes(_data, abiType);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> SemanticTest::eventSideEffectHook(FunctionCall const&) const
|
std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&) const
|
||||||
{
|
{
|
||||||
vector<string> sideEffects;
|
std::vector<std::string> sideEffects;
|
||||||
vector<LogRecord> recordedLogs = ExecutionFramework::recordedLogs();
|
std::vector<LogRecord> recordedLogs = ExecutionFramework::recordedLogs();
|
||||||
for (LogRecord const& log: recordedLogs)
|
for (LogRecord const& log: recordedLogs)
|
||||||
{
|
{
|
||||||
optional<AnnotatedEventSignature> eventSignature;
|
std::optional<AnnotatedEventSignature> eventSignature;
|
||||||
if (!log.topics.empty())
|
if (!log.topics.empty())
|
||||||
eventSignature = matchEvent(log.topics[0]);
|
eventSignature = matchEvent(log.topics[0]);
|
||||||
stringstream sideEffect;
|
std::stringstream sideEffect;
|
||||||
sideEffect << "emit ";
|
sideEffect << "emit ";
|
||||||
if (eventSignature.has_value())
|
if (eventSignature.has_value())
|
||||||
sideEffect << eventSignature.value().signature;
|
sideEffect << eventSignature.value().signature;
|
||||||
@ -243,7 +243,7 @@ vector<string> SemanticTest::eventSideEffectHook(FunctionCall const&) const
|
|||||||
if (m_contractAddress != log.creator)
|
if (m_contractAddress != log.creator)
|
||||||
sideEffect << " from 0x" << log.creator;
|
sideEffect << " from 0x" << log.creator;
|
||||||
|
|
||||||
vector<string> eventStrings;
|
std::vector<std::string> eventStrings;
|
||||||
size_t index{0};
|
size_t index{0};
|
||||||
for (h256 const& topic: log.topics)
|
for (h256 const& topic: log.topics)
|
||||||
{
|
{
|
||||||
@ -268,10 +268,10 @@ vector<string> SemanticTest::eventSideEffectHook(FunctionCall const&) const
|
|||||||
return sideEffects;
|
return sideEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<AnnotatedEventSignature> SemanticTest::matchEvent(util::h256 const& hash) const
|
std::optional<AnnotatedEventSignature> SemanticTest::matchEvent(util::h256 const& hash) const
|
||||||
{
|
{
|
||||||
optional<AnnotatedEventSignature> result;
|
std::optional<AnnotatedEventSignature> result;
|
||||||
for (string& contractName: m_compiler.contractNames())
|
for (std::string& contractName: m_compiler.contractNames())
|
||||||
{
|
{
|
||||||
ContractDefinition const& contract = m_compiler.contractDefinition(contractName);
|
ContractDefinition const& contract = m_compiler.contractDefinition(contractName);
|
||||||
for (EventDefinition const* event: contract.events())
|
for (EventDefinition const* event: contract.events())
|
||||||
@ -312,7 +312,7 @@ frontend::OptimiserSettings SemanticTest::optimizerSettingsFor(RequiresYulOptimi
|
|||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePrefix, bool _formatted)
|
TestCase::TestResult SemanticTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
|
||||||
{
|
{
|
||||||
TestResult result = TestResult::Success;
|
TestResult result = TestResult::Success;
|
||||||
|
|
||||||
@ -338,8 +338,8 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestCase::TestResult SemanticTest::runTest(
|
TestCase::TestResult SemanticTest::runTest(
|
||||||
ostream& _stream,
|
std::ostream& _stream,
|
||||||
string const& _linePrefix,
|
std::string const& _linePrefix,
|
||||||
bool _formatted,
|
bool _formatted,
|
||||||
bool _isYulRun
|
bool _isYulRun
|
||||||
)
|
)
|
||||||
@ -354,12 +354,12 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
m_compileViaYul = _isYulRun;
|
m_compileViaYul = _isYulRun;
|
||||||
|
|
||||||
if (_isYulRun)
|
if (_isYulRun)
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Running via Yul: " << endl;
|
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Running via Yul: " << std::endl;
|
||||||
|
|
||||||
for (TestFunctionCall& test: m_tests)
|
for (TestFunctionCall& test: m_tests)
|
||||||
test.reset();
|
test.reset();
|
||||||
|
|
||||||
map<string, solidity::test::Address> libraries;
|
std::map<std::string, solidity::test::Address> libraries;
|
||||||
|
|
||||||
bool constructed = false;
|
bool constructed = false;
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value);
|
output = callLowLevel(test.call().arguments.rawBytes(), test.call().value.value);
|
||||||
else if (test.call().kind == FunctionCall::Kind::Builtin)
|
else if (test.call().kind == FunctionCall::Kind::Builtin)
|
||||||
{
|
{
|
||||||
optional<bytes> builtinOutput = m_builtins.at(test.call().signature)(test.call());
|
std::optional<bytes> builtinOutput = m_builtins.at(test.call().signature)(test.call());
|
||||||
if (builtinOutput.has_value())
|
if (builtinOutput.has_value())
|
||||||
{
|
{
|
||||||
m_transactionSuccessful = true;
|
m_transactionSuccessful = true;
|
||||||
@ -460,7 +460,7 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName(m_sources.mainSourceFile)));
|
test.setContractABI(m_compiler.contractABI(m_compiler.lastContractName(m_sources.mainSourceFile)));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> effects;
|
std::vector<std::string> effects;
|
||||||
for (SideEffectHook const& hook: m_sideEffectHooks)
|
for (SideEffectHook const& hook: m_sideEffectHooks)
|
||||||
effects += hook(test.call());
|
effects += hook(test.call());
|
||||||
test.setSideEffects(std::move(effects));
|
test.setSideEffects(std::move(effects));
|
||||||
@ -470,7 +470,7 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
|
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << std::endl;
|
||||||
for (TestFunctionCall const& test: m_tests)
|
for (TestFunctionCall const& test: m_tests)
|
||||||
{
|
{
|
||||||
ErrorReporter errorReporter;
|
ErrorReporter errorReporter;
|
||||||
@ -480,11 +480,11 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
TestFunctionCall::RenderMode::ExpectedValuesExpectedGas,
|
TestFunctionCall::RenderMode::ExpectedValuesExpectedGas,
|
||||||
_formatted,
|
_formatted,
|
||||||
/* _interactivePrint */ true
|
/* _interactivePrint */ true
|
||||||
) << endl;
|
) << std::endl;
|
||||||
_stream << errorReporter.format(_linePrefix, _formatted);
|
_stream << errorReporter.format(_linePrefix, _formatted);
|
||||||
}
|
}
|
||||||
_stream << endl;
|
_stream << std::endl;
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
|
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << std::endl;
|
||||||
for (TestFunctionCall const& test: m_tests)
|
for (TestFunctionCall const& test: m_tests)
|
||||||
{
|
{
|
||||||
ErrorReporter errorReporter;
|
ErrorReporter errorReporter;
|
||||||
@ -494,22 +494,22 @@ TestCase::TestResult SemanticTest::runTest(
|
|||||||
m_gasCostFailure ? TestFunctionCall::RenderMode::ExpectedValuesActualGas : TestFunctionCall::RenderMode::ActualValuesExpectedGas,
|
m_gasCostFailure ? TestFunctionCall::RenderMode::ExpectedValuesActualGas : TestFunctionCall::RenderMode::ActualValuesExpectedGas,
|
||||||
_formatted,
|
_formatted,
|
||||||
/* _interactivePrint */ true
|
/* _interactivePrint */ true
|
||||||
) << endl;
|
) << std::endl;
|
||||||
_stream << errorReporter.format(_linePrefix, _formatted);
|
_stream << errorReporter.format(_linePrefix, _formatted);
|
||||||
}
|
}
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, RED})
|
AnsiColorized(_stream, _formatted, {BOLD, RED})
|
||||||
<< _linePrefix << endl
|
<< _linePrefix << std::endl
|
||||||
<< _linePrefix << "Attention: Updates on the test will apply the detected format displayed." << endl;
|
<< _linePrefix << "Attention: Updates on the test will apply the detected format displayed." << std::endl;
|
||||||
if (_isYulRun && m_testCaseWantsLegacyRun)
|
if (_isYulRun && m_testCaseWantsLegacyRun)
|
||||||
{
|
{
|
||||||
_stream << _linePrefix << endl << _linePrefix;
|
_stream << _linePrefix << std::endl << _linePrefix;
|
||||||
AnsiColorized(_stream, _formatted, {RED_BACKGROUND}) << "Note that the test passed without Yul.";
|
AnsiColorized(_stream, _formatted, {RED_BACKGROUND}) << "Note that the test passed without Yul.";
|
||||||
_stream << endl;
|
_stream << std::endl;
|
||||||
}
|
}
|
||||||
else if (!_isYulRun && m_testCaseWantsYulRun)
|
else if (!_isYulRun && m_testCaseWantsYulRun)
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, YELLOW})
|
AnsiColorized(_stream, _formatted, {BOLD, YELLOW})
|
||||||
<< _linePrefix << endl
|
<< _linePrefix << std::endl
|
||||||
<< _linePrefix << "Note that the test also has to pass via Yul." << endl;
|
<< _linePrefix << "Note that the test also has to pass via Yul." << std::endl;
|
||||||
return TestResult::Failure;
|
return TestResult::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,9 +551,9 @@ TestCase::TestResult SemanticTest::tryRunTestWithYulOptimizer(
|
|||||||
soltestAssert(result == TestResult::Success || result == TestResult::Failure);
|
soltestAssert(result == TestResult::Success || result == TestResult::Failure);
|
||||||
|
|
||||||
AnsiColorized(_stream, _formatted, {BOLD, YELLOW})
|
AnsiColorized(_stream, _formatted, {BOLD, YELLOW})
|
||||||
<< _linePrefix << endl
|
<< _linePrefix << std::endl
|
||||||
<< _linePrefix << "requiresYulOptimizer is set to " << m_requiresYulOptimizer
|
<< _linePrefix << "requiresYulOptimizer is set to " << m_requiresYulOptimizer
|
||||||
<< " but should be " << requiresYulOptimizer << endl;
|
<< " but should be " << requiresYulOptimizer << std::endl;
|
||||||
m_requiresYulOptimizer = requiresYulOptimizer;
|
m_requiresYulOptimizer = requiresYulOptimizer;
|
||||||
return TestResult::Failure;
|
return TestResult::Failure;
|
||||||
}
|
}
|
||||||
@ -565,7 +565,7 @@ TestCase::TestResult SemanticTest::tryRunTestWithYulOptimizer(
|
|||||||
|
|
||||||
bool SemanticTest::checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const
|
bool SemanticTest::checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const
|
||||||
{
|
{
|
||||||
string setting =
|
std::string setting =
|
||||||
(_compileViaYul ? "ir"s : "legacy"s) +
|
(_compileViaYul ? "ir"s : "legacy"s) +
|
||||||
(m_optimiserSettings == OptimiserSettings::full() ? "Optimized" : "");
|
(m_optimiserSettings == OptimiserSettings::full() ? "Optimized" : "");
|
||||||
|
|
||||||
@ -592,27 +592,27 @@ bool SemanticTest::checkGasCostExpectation(TestFunctionCall& io_test, bool _comp
|
|||||||
m_gasUsed == io_test.call().expectations.gasUsed.at(setting);
|
m_gasUsed == io_test.call().expectations.gasUsed.at(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool _formatted) const
|
void SemanticTest::printSource(std::ostream& _stream, std::string const& _linePrefix, bool _formatted) const
|
||||||
{
|
{
|
||||||
if (m_sources.sources.empty())
|
if (m_sources.sources.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool outputNames = (m_sources.sources.size() - m_sources.externalSources.size() != 1 || !m_sources.sources.begin()->first.empty());
|
bool outputNames = (m_sources.sources.size() - m_sources.externalSources.size() != 1 || !m_sources.sources.begin()->first.empty());
|
||||||
|
|
||||||
set<string> externals;
|
std::set<std::string> externals;
|
||||||
for (auto const& [name, path]: m_sources.externalSources)
|
for (auto const& [name, path]: m_sources.externalSources)
|
||||||
{
|
{
|
||||||
externals.insert(name);
|
externals.insert(name);
|
||||||
string externalSource;
|
std::string externalSource;
|
||||||
if (name == path)
|
if (name == path)
|
||||||
externalSource = name;
|
externalSource = name;
|
||||||
else
|
else
|
||||||
externalSource = name + "=" + path.generic_string();
|
externalSource = name + "=" + path.generic_string();
|
||||||
|
|
||||||
if (_formatted)
|
if (_formatted)
|
||||||
_stream << _linePrefix << formatting::CYAN << "==== ExternalSource: " << externalSource << " ===="s << formatting::RESET << endl;
|
_stream << _linePrefix << formatting::CYAN << "==== ExternalSource: " << externalSource << " ===="s << formatting::RESET << std::endl;
|
||||||
else
|
else
|
||||||
_stream << _linePrefix << "==== ExternalSource: " << externalSource << " ===="s << endl;
|
_stream << _linePrefix << "==== ExternalSource: " << externalSource << " ===="s << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& [name, source]: m_sources.sources)
|
for (auto const& [name, source]: m_sources.sources)
|
||||||
@ -625,9 +625,9 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
|
|||||||
|
|
||||||
if (outputNames)
|
if (outputNames)
|
||||||
_stream << _linePrefix << formatting::CYAN << "==== Source: " << name
|
_stream << _linePrefix << formatting::CYAN << "==== Source: " << name
|
||||||
<< " ====" << formatting::RESET << endl;
|
<< " ====" << formatting::RESET << std::endl;
|
||||||
|
|
||||||
vector<char const*> sourceFormatting(source.length(), formatting::RESET);
|
std::vector<char const*> sourceFormatting(source.length(), formatting::RESET);
|
||||||
_stream << _linePrefix << sourceFormatting.front() << source.front();
|
_stream << _linePrefix << sourceFormatting.front() << source.front();
|
||||||
for (size_t i = 1; i < source.length(); i++)
|
for (size_t i = 1; i < source.length(); i++)
|
||||||
{
|
{
|
||||||
@ -637,7 +637,7 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
|
|||||||
_stream << source[i];
|
_stream << source[i];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_stream << formatting::RESET << endl;
|
_stream << formatting::RESET << std::endl;
|
||||||
if (i + 1 < source.length())
|
if (i + 1 < source.length())
|
||||||
_stream << _linePrefix << sourceFormatting[i];
|
_stream << _linePrefix << sourceFormatting[i];
|
||||||
}
|
}
|
||||||
@ -647,50 +647,50 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outputNames)
|
if (outputNames)
|
||||||
_stream << _linePrefix << "==== Source: " + name << " ====" << endl;
|
_stream << _linePrefix << "==== Source: " + name << " ====" << std::endl;
|
||||||
stringstream stream(source);
|
std::stringstream stream(source);
|
||||||
string line;
|
std::string line;
|
||||||
while (getline(stream, line))
|
while (getline(stream, line))
|
||||||
_stream << _linePrefix << line << endl;
|
_stream << _linePrefix << line << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticTest::printUpdatedExpectations(ostream& _stream, string const&) const
|
void SemanticTest::printUpdatedExpectations(std::ostream& _stream, std::string const&) const
|
||||||
{
|
{
|
||||||
for (TestFunctionCall const& test: m_tests)
|
for (TestFunctionCall const& test: m_tests)
|
||||||
_stream << test.format(
|
_stream << test.format(
|
||||||
"",
|
"",
|
||||||
m_gasCostFailure ? TestFunctionCall::RenderMode::ExpectedValuesActualGas : TestFunctionCall::RenderMode::ActualValuesExpectedGas,
|
m_gasCostFailure ? TestFunctionCall::RenderMode::ExpectedValuesActualGas : TestFunctionCall::RenderMode::ActualValuesExpectedGas,
|
||||||
/* _highlight = */ false
|
/* _highlight = */ false
|
||||||
) << endl;
|
) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticTest::printUpdatedSettings(ostream& _stream, string const& _linePrefix)
|
void SemanticTest::printUpdatedSettings(std::ostream& _stream, std::string const& _linePrefix)
|
||||||
{
|
{
|
||||||
auto& settings = m_reader.settings();
|
auto& settings = m_reader.settings();
|
||||||
if (settings.empty() && m_requiresYulOptimizer == RequiresYulOptimizer::False)
|
if (settings.empty() && m_requiresYulOptimizer == RequiresYulOptimizer::False)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_stream << _linePrefix << "// ====" << endl;
|
_stream << _linePrefix << "// ====" << std::endl;
|
||||||
if (m_requiresYulOptimizer != RequiresYulOptimizer::False)
|
if (m_requiresYulOptimizer != RequiresYulOptimizer::False)
|
||||||
_stream << _linePrefix << "// requiresYulOptimizer: " << m_requiresYulOptimizer << endl;
|
_stream << _linePrefix << "// requiresYulOptimizer: " << m_requiresYulOptimizer << std::endl;
|
||||||
|
|
||||||
for (auto const& [settingName, settingValue]: settings)
|
for (auto const& [settingName, settingValue]: settings)
|
||||||
if (settingName != "requiresYulOptimizer")
|
if (settingName != "requiresYulOptimizer")
|
||||||
_stream << _linePrefix << "// " << settingName << ": " << settingValue<< endl;
|
_stream << _linePrefix << "// " << settingName << ": " << settingValue<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticTest::parseExpectations(istream& _stream)
|
void SemanticTest::parseExpectations(std::istream& _stream)
|
||||||
{
|
{
|
||||||
m_tests += TestFileParser{_stream, m_builtins}.parseFunctionCalls(m_lineOffset);
|
m_tests += TestFileParser{_stream, m_builtins}.parseFunctionCalls(m_lineOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SemanticTest::deploy(
|
bool SemanticTest::deploy(
|
||||||
string const& _contractName,
|
std::string const& _contractName,
|
||||||
u256 const& _value,
|
u256 const& _value,
|
||||||
bytes const& _arguments,
|
bytes const& _arguments,
|
||||||
map<string, solidity::test::Address> const& _libraries
|
std::map<std::string, solidity::test::Address> const& _libraries
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto output = compileAndRunWithoutCheck(m_sources.sources, _value, _contractName, _arguments, _libraries, m_sources.mainSourceFile);
|
auto output = compileAndRunWithoutCheck(m_sources.sources, _value, _contractName, _arguments, _libraries, m_sources.mainSourceFile);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
@ -90,7 +89,7 @@ BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityEndToEndTestExecutionFram
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(creation_code_optimizer)
|
BOOST_AUTO_TEST_CASE(creation_code_optimizer)
|
||||||
{
|
{
|
||||||
string codeC = R"(
|
std::string codeC = R"(
|
||||||
contract C {
|
contract C {
|
||||||
constructor(uint x) {
|
constructor(uint x) {
|
||||||
if (x == 0xFFFFFFFFFFFFFFFF42)
|
if (x == 0xFFFFFFFFFFFFFFFF42)
|
||||||
@ -98,7 +97,7 @@ BOOST_AUTO_TEST_CASE(creation_code_optimizer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
string codeD = R"(
|
std::string codeD = R"(
|
||||||
contract D {
|
contract D {
|
||||||
function f() public pure returns (bytes memory) {
|
function f() public pure returns (bytes memory) {
|
||||||
return type(C).creationCode;
|
return type(C).creationCode;
|
||||||
@ -170,7 +169,7 @@ BOOST_AUTO_TEST_CASE(recursive_calls)
|
|||||||
)";
|
)";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
function<u256(u256)> recursive_calls_cpp = [&recursive_calls_cpp](u256 const& n) -> u256
|
std::function<u256(u256)> recursive_calls_cpp = [&recursive_calls_cpp](u256 const& n) -> u256
|
||||||
{
|
{
|
||||||
if (n <= 1)
|
if (n <= 1)
|
||||||
return 1;
|
return 1;
|
||||||
@ -742,7 +741,7 @@ BOOST_AUTO_TEST_CASE(mapping_state_inc_dec)
|
|||||||
)";
|
)";
|
||||||
|
|
||||||
u256 value;
|
u256 value;
|
||||||
map<u256, u256> table;
|
std::map<u256, u256> table;
|
||||||
auto f = [&](u256 const& _x) -> u256
|
auto f = [&](u256 const& _x) -> u256
|
||||||
{
|
{
|
||||||
value = _x;
|
value = _x;
|
||||||
@ -775,7 +774,7 @@ BOOST_AUTO_TEST_CASE(multi_level_mapping)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
map<u256, map<u256, u256>> table;
|
std::map<u256, std::map<u256, u256>> table;
|
||||||
auto f = [&](u256 const& _x, u256 const& _y, u256 const& _z) -> u256
|
auto f = [&](u256 const& _x, u256 const& _y, u256 const& _z) -> u256
|
||||||
{
|
{
|
||||||
if (_z == 0) return table[_x][_y];
|
if (_z == 0) return table[_x][_y];
|
||||||
@ -810,7 +809,7 @@ BOOST_AUTO_TEST_CASE(constructor)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
map<u256, uint8_t> data;
|
std::map<u256, uint8_t> data;
|
||||||
data[7] = 8;
|
data[7] = 8;
|
||||||
auto get = [&](u256 const& _x) -> u256
|
auto get = [&](u256 const& _x) -> u256
|
||||||
{
|
{
|
||||||
@ -1069,7 +1068,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls)
|
|||||||
compileAndRun(sourceCode, 0, "Main");
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
|
BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
|
||||||
BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
|
BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
|
||||||
ABI_CHECK(callContractFunction("callHelper(bytes2,bool)", string("\0a", 2), true), encodeArgs(string("\0a\0\0\0", 5)));
|
ABI_CHECK(callContractFunction("callHelper(bytes2,bool)", std::string("\0a", 2), true), encodeArgs(std::string("\0a\0\0\0", 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(constructor_with_long_arguments)
|
BOOST_AUTO_TEST_CASE(constructor_with_long_arguments)
|
||||||
@ -1085,8 +1084,8 @@ BOOST_AUTO_TEST_CASE(constructor_with_long_arguments)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
string a = "01234567890123gabddunaouhdaoneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012cdef";
|
std::string a = "01234567890123gabddunaouhdaoneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012oneudapcgadi4567890789012oneudapcgadi45678907890123456789abcd123456787890123456789abcd90123456789012345678901234567890123456789aboneudapcgadi4567890789012cdef";
|
||||||
string b = "AUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PY";
|
std::string b = "AUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PYAUTAHIACIANOTUHAOCUHAOEUNAOEHUNTHDYDHPYDRCPYDRSTITOEUBXHUDGO>PY";
|
||||||
|
|
||||||
compileAndRun(sourceCode, 0, "Main", encodeArgs(
|
compileAndRun(sourceCode, 0, "Main", encodeArgs(
|
||||||
u256(0x40),
|
u256(0x40),
|
||||||
@ -1141,7 +1140,7 @@ BOOST_AUTO_TEST_CASE(blockhash)
|
|||||||
while (blockNumber() < u256(255))
|
while (blockNumber() < u256(255))
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(true));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(true));
|
||||||
|
|
||||||
vector<u256> hashes;
|
std::vector<u256> hashes;
|
||||||
// ``blockhash()`` is only valid for the last 256 blocks, otherwise zero
|
// ``blockhash()`` is only valid for the last 256 blocks, otherwise zero
|
||||||
hashes.emplace_back(0);
|
hashes.emplace_back(0);
|
||||||
for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++)
|
for (u256 i = blockNumber() - u256(255); i <= blockNumber(); i++)
|
||||||
@ -1263,7 +1262,7 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall)
|
|||||||
|
|
||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
string source = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n" + string(sourceCode);
|
std::string source = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n" + std::string(sourceCode);
|
||||||
|
|
||||||
compileAndRun(source, 0, "Receiver");
|
compileAndRun(source, 0, "Receiver");
|
||||||
h160 const c_receiverAddress = m_contractAddress;
|
h160 const c_receiverAddress = m_contractAddress;
|
||||||
@ -1354,7 +1353,7 @@ BOOST_AUTO_TEST_CASE(library_call_protection)
|
|||||||
ABI_CHECK(callContractFunction("np(Lib.S storage)", 0), encodeArgs());
|
ABI_CHECK(callContractFunction("np(Lib.S storage)", 0), encodeArgs());
|
||||||
ABI_CHECK(callContractFunction("v(Lib.S storage)", 0), encodeArgs(m_sender));
|
ABI_CHECK(callContractFunction("v(Lib.S storage)", 0), encodeArgs(m_sender));
|
||||||
ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
|
ABI_CHECK(callContractFunction("pu()"), encodeArgs(2));
|
||||||
compileAndRun(sourceCode, 0, "Test", bytes(), map<string, h160>{{":Lib", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "Test", bytes(), std::map<std::string, h160>{{":Lib", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("s()"), encodeArgs(0));
|
ABI_CHECK(callContractFunction("s()"), encodeArgs(0));
|
||||||
ABI_CHECK(callContractFunction("np()"), encodeArgs(m_sender));
|
ABI_CHECK(callContractFunction("np()"), encodeArgs(m_sender));
|
||||||
ABI_CHECK(callContractFunction("s()"), encodeArgs(3));
|
ABI_CHECK(callContractFunction("s()"), encodeArgs(3));
|
||||||
@ -1420,7 +1419,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length)
|
|||||||
ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4));
|
ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4));
|
||||||
|
|
||||||
// Some additional unpadded data
|
// Some additional unpadded data
|
||||||
bytes unpadded = asBytes(string("abc"));
|
bytes unpadded = asBytes(std::string("abc"));
|
||||||
ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7));
|
ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7));
|
||||||
ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7));
|
ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7));
|
||||||
ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7));
|
ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7));
|
||||||
@ -1535,7 +1534,7 @@ BOOST_AUTO_TEST_CASE(struct_referencing)
|
|||||||
compileAndRun(sourceCode, 0, "L");
|
compileAndRun(sourceCode, 0, "L");
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3));
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(4));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(4));
|
||||||
compileAndRun(sourceCode, 0, "C", bytes(), map<string, h160>{ {":L", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "C", bytes(), std::map<std::string, h160>{ {":L", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(2));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(2));
|
||||||
ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5));
|
ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5));
|
||||||
@ -1583,7 +1582,7 @@ BOOST_AUTO_TEST_CASE(enum_referencing)
|
|||||||
compileAndRun(sourceCode, 0, "L");
|
compileAndRun(sourceCode, 0, "L");
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(1));
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(3));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(3));
|
||||||
compileAndRun(sourceCode, 0, "C", bytes(), map<string, h160>{{":L", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "C", bytes(), std::map<std::string, h160>{{":L", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(3));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(3));
|
||||||
ABI_CHECK(callContractFunction("g()"), encodeArgs(3));
|
ABI_CHECK(callContractFunction("g()"), encodeArgs(3));
|
||||||
ABI_CHECK(callContractFunction("h()"), encodeArgs(1));
|
ABI_CHECK(callContractFunction("h()"), encodeArgs(1));
|
||||||
@ -1612,8 +1611,8 @@ BOOST_AUTO_TEST_CASE(bytes_in_arguments)
|
|||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
|
|
||||||
string innercalldata1 = asString(util::selectorFromSignatureH32("f(uint256,uint256)").asBytes() + encodeArgs(8, 9));
|
std::string innercalldata1 = asString(util::selectorFromSignatureH32("f(uint256,uint256)").asBytes() + encodeArgs(8, 9));
|
||||||
string innercalldata2 = asString(util::selectorFromSignatureH32("g(uint256)").asBytes() + encodeArgs(3));
|
std::string innercalldata2 = asString(util::selectorFromSignatureH32("g(uint256)").asBytes() + encodeArgs(3));
|
||||||
bytes calldata = encodeArgs(
|
bytes calldata = encodeArgs(
|
||||||
12, 32 * 4, u256(32 * 4 + 32 + (innercalldata1.length() + 31) / 32 * 32), 13,
|
12, 32 * 4, u256(32 * 4 + 32 + (innercalldata1.length() + 31) / 32 * 32), 13,
|
||||||
u256(innercalldata1.length()), innercalldata1,
|
u256(innercalldata1.length()), innercalldata1,
|
||||||
@ -1765,20 +1764,20 @@ BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Main");
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
string s1(
|
std::string s1(
|
||||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||||
);
|
);
|
||||||
string s2(
|
std::string s2(
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||||
);
|
);
|
||||||
vector<size_t> lengths{0, 30, 32, 63, 64, 65, 210, 300};
|
std::vector<size_t> lengths{0, 30, 32, 63, 64, 65, 210, 300};
|
||||||
for (auto l1: lengths)
|
for (auto l1: lengths)
|
||||||
for (auto l2: lengths)
|
for (auto l2: lengths)
|
||||||
{
|
{
|
||||||
@ -1813,8 +1812,8 @@ BOOST_AUTO_TEST_CASE(accessor_involving_strings)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Main");
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
std::string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||||
string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ");
|
std::string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ");
|
||||||
bytes s1Data = encodeArgs(u256(s1.length()), s1);
|
bytes s1Data = encodeArgs(u256(s1.length()), s1);
|
||||||
bytes s2Data = encodeArgs(u256(s2.length()), s2);
|
bytes s2Data = encodeArgs(u256(s2.length()), s2);
|
||||||
u256 b = 765;
|
u256 b = 765;
|
||||||
@ -1846,9 +1845,9 @@ BOOST_AUTO_TEST_CASE(bytes_in_function_calls)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Main");
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
std::string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||||
string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ");
|
std::string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ");
|
||||||
vector<size_t> lengths{0, 31, 64, 65};
|
std::vector<size_t> lengths{0, 31, 64, 65};
|
||||||
for (auto l1: lengths)
|
for (auto l1: lengths)
|
||||||
for (auto l2: lengths)
|
for (auto l2: lengths)
|
||||||
{
|
{
|
||||||
@ -1888,8 +1887,8 @@ BOOST_AUTO_TEST_CASE(return_bytes_internal)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Main");
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
std::string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||||
vector<size_t> lengths{0, 31, 64, 65};
|
std::vector<size_t> lengths{0, 31, 64, 65};
|
||||||
for (auto l1: lengths)
|
for (auto l1: lengths)
|
||||||
{
|
{
|
||||||
bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1));
|
bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1));
|
||||||
@ -1951,7 +1950,7 @@ BOOST_AUTO_TEST_CASE(calldata_struct_function_type)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(calldata_array_dynamic_three_dimensional)
|
BOOST_AUTO_TEST_CASE(calldata_array_dynamic_three_dimensional)
|
||||||
{
|
{
|
||||||
vector<vector<vector<u256>>> data {
|
std::vector<std::vector<std::vector<u256>>> data {
|
||||||
{
|
{
|
||||||
{ 0x010A01, 0x010A02, 0x010A03 },
|
{ 0x010A01, 0x010A02, 0x010A03 },
|
||||||
{ 0x010B01, 0x010B02, 0x010B03 }
|
{ 0x010B01, 0x010B02, 0x010B03 }
|
||||||
@ -1970,12 +1969,12 @@ BOOST_AUTO_TEST_CASE(calldata_array_dynamic_three_dimensional)
|
|||||||
if (!outerDynamicallySized && !middleDynamicallySized && !innerDynamicallySized)
|
if (!outerDynamicallySized && !middleDynamicallySized && !innerDynamicallySized)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string arrayType = "uint256";
|
std::string arrayType = "uint256";
|
||||||
arrayType += innerDynamicallySized ? "[]" : "[3]";
|
arrayType += innerDynamicallySized ? "[]" : "[3]";
|
||||||
arrayType += middleDynamicallySized ? "[]" : "[2]";
|
arrayType += middleDynamicallySized ? "[]" : "[2]";
|
||||||
arrayType += outerDynamicallySized ? "[]" : "[2]";
|
arrayType += outerDynamicallySized ? "[]" : "[2]";
|
||||||
|
|
||||||
string sourceCode = R"(
|
std::string sourceCode = R"(
|
||||||
pragma abicoder v2;
|
pragma abicoder v2;
|
||||||
contract C {
|
contract C {
|
||||||
function test()" + arrayType + R"( calldata a) external returns (uint256) {
|
function test()" + arrayType + R"( calldata a) external returns (uint256) {
|
||||||
@ -2049,16 +2048,16 @@ BOOST_AUTO_TEST_CASE(literal_strings)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Test");
|
compileAndRun(sourceCode, 0, "Test");
|
||||||
string longStr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
std::string longStr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
||||||
string medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
std::string medium = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||||
string shortStr = "123";
|
std::string shortStr = "123";
|
||||||
string hello = "Hello, World!";
|
std::string hello = "Hello, World!";
|
||||||
|
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeDyn(hello));
|
ABI_CHECK(callContractFunction("f()"), encodeDyn(hello));
|
||||||
ABI_CHECK(callContractFunction("long()"), encodeDyn(longStr));
|
ABI_CHECK(callContractFunction("long()"), encodeDyn(longStr));
|
||||||
ABI_CHECK(callContractFunction("medium()"), encodeDyn(medium));
|
ABI_CHECK(callContractFunction("medium()"), encodeDyn(medium));
|
||||||
ABI_CHECK(callContractFunction("short()"), encodeDyn(shortStr));
|
ABI_CHECK(callContractFunction("short()"), encodeDyn(shortStr));
|
||||||
ABI_CHECK(callContractFunction("empty()"), encodeDyn(string()));
|
ABI_CHECK(callContractFunction("empty()"), encodeDyn(std::string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(initialise_string_constant)
|
BOOST_AUTO_TEST_CASE(initialise_string_constant)
|
||||||
@ -2070,8 +2069,8 @@ BOOST_AUTO_TEST_CASE(initialise_string_constant)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Test");
|
compileAndRun(sourceCode, 0, "Test");
|
||||||
string longStr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
std::string longStr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
||||||
string shortStr = "abcdef";
|
std::string shortStr = "abcdef";
|
||||||
|
|
||||||
ABI_CHECK(callContractFunction("long()"), encodeDyn(longStr));
|
ABI_CHECK(callContractFunction("long()"), encodeDyn(longStr));
|
||||||
ABI_CHECK(callContractFunction("short()"), encodeDyn(shortStr));
|
ABI_CHECK(callContractFunction("short()"), encodeDyn(shortStr));
|
||||||
@ -2087,7 +2086,7 @@ BOOST_AUTO_TEST_CASE(string_as_mapping_key)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
vector<string> strings{
|
std::vector<std::string> strings{
|
||||||
"Hello, World!",
|
"Hello, World!",
|
||||||
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
||||||
"",
|
"",
|
||||||
@ -2123,7 +2122,7 @@ BOOST_AUTO_TEST_CASE(string_as_public_mapping_key)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Test");
|
compileAndRun(sourceCode, 0, "Test");
|
||||||
vector<string> strings{
|
std::vector<std::string> strings{
|
||||||
"Hello, World!",
|
"Hello, World!",
|
||||||
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
||||||
"",
|
"",
|
||||||
@ -2156,7 +2155,7 @@ BOOST_AUTO_TEST_CASE(nested_string_as_public_mapping_key)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "Test");
|
compileAndRun(sourceCode, 0, "Test");
|
||||||
vector<string> strings{
|
std::vector<std::string> strings{
|
||||||
"Hello, World!",
|
"Hello, World!",
|
||||||
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
"Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111",
|
||||||
"",
|
"",
|
||||||
@ -2211,13 +2210,13 @@ BOOST_AUTO_TEST_CASE(nested_mixed_string_as_public_mapping_key)
|
|||||||
|
|
||||||
struct Index
|
struct Index
|
||||||
{
|
{
|
||||||
string s1;
|
std::string s1;
|
||||||
int s2;
|
int s2;
|
||||||
int s3;
|
int s3;
|
||||||
string s4;
|
std::string s4;
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<Index> data{
|
std::vector<Index> data{
|
||||||
{ "aabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcbc", 4, 23, "efg" },
|
{ "aabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcbc", 4, 23, "efg" },
|
||||||
{ "tiaron", 456, 63245, "908apzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapz" },
|
{ "tiaron", 456, 63245, "908apzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapz" },
|
||||||
{ "", 2345, 12934, "665i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i5iart" },
|
{ "", 2345, 12934, "665i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i65i5iart" },
|
||||||
@ -2264,7 +2263,7 @@ BOOST_AUTO_TEST_CASE(library_call)
|
|||||||
)";
|
)";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode, 0, "Lib");
|
compileAndRun(sourceCode, 0, "Lib");
|
||||||
compileAndRun(sourceCode, 0, "Test", bytes(), map<string, h160>{{":Lib", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "Test", bytes(), std::map<std::string, h160>{{":Lib", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(33) * 9));
|
ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(33) * 9));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -2281,7 +2280,7 @@ BOOST_AUTO_TEST_CASE(library_function_external)
|
|||||||
)";
|
)";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode, 0, "Lib");
|
compileAndRun(sourceCode, 0, "Lib");
|
||||||
compileAndRun(sourceCode, 0, "Test", bytes(), map<string, h160>{{":Lib", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "Test", bytes(), std::map<std::string, h160>{{":Lib", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), "abcde"), encodeArgs("c"));
|
ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), "abcde"), encodeArgs("c"));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -2315,9 +2314,9 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_external)
|
|||||||
)";
|
)";
|
||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
|
std::string prefix = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n";
|
||||||
compileAndRun(prefix + libSourceCode, 0, "Lib");
|
compileAndRun(prefix + libSourceCode, 0, "Lib");
|
||||||
compileAndRun(prefix + sourceCode, 0, "Test", bytes(), map<string, h160>{{":Lib", m_contractAddress}});
|
compileAndRun(prefix + sourceCode, 0, "Test", bytes(), std::map<std::string, h160>{{":Lib", m_contractAddress}});
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(2), u256(0), u256(84), u256(46), u256(0), u256(198)));
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(2), u256(0), u256(84), u256(46), u256(0), u256(198)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2432,7 +2431,7 @@ BOOST_AUTO_TEST_CASE(short_strings)
|
|||||||
)";
|
)";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode, 0, "A");
|
compileAndRun(sourceCode, 0, "A");
|
||||||
ABI_CHECK(callContractFunction("data1()"), encodeDyn(string("123")));
|
ABI_CHECK(callContractFunction("data1()"), encodeDyn(std::string("123")));
|
||||||
ABI_CHECK(callContractFunction("lengthChange()"), encodeArgs(u256(0)));
|
ABI_CHECK(callContractFunction("lengthChange()"), encodeArgs(u256(0)));
|
||||||
BOOST_CHECK(storageEmpty(m_contractAddress));
|
BOOST_CHECK(storageEmpty(m_contractAddress));
|
||||||
ABI_CHECK(callContractFunction("deleteElements()"), encodeArgs(u256(0)));
|
ABI_CHECK(callContractFunction("deleteElements()"), encodeArgs(u256(0)));
|
||||||
@ -2458,7 +2457,7 @@ BOOST_AUTO_TEST_CASE(calldata_offset)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "CB", encodeArgs(u256(0x20), u256(0x00)));
|
compileAndRun(sourceCode, 0, "CB", encodeArgs(u256(0x20), u256(0x00)));
|
||||||
ABI_CHECK(callContractFunction("last()", encodeArgs()), encodeDyn(string("nd")));
|
ABI_CHECK(callContractFunction("last()", encodeArgs()), encodeDyn(std::string("nd")));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
|
BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
|
||||||
@ -2525,7 +2524,7 @@ BOOST_AUTO_TEST_CASE(inline_long_string_return)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
string strLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
std::string strLong = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong));
|
ABI_CHECK(callContractFunction("f()"), encodeDyn(strLong));
|
||||||
}
|
}
|
||||||
@ -2775,8 +2774,8 @@ BOOST_AUTO_TEST_CASE(shift_bytes)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("left(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs("901234567890" + string(8, 0)));
|
ABI_CHECK(callContractFunction("left(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs("901234567890" + std::string(8, 0)));
|
||||||
ABI_CHECK(callContractFunction("right(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs(string(8, 0) + "123456789012"));
|
ABI_CHECK(callContractFunction("right(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs(std::string(8, 0) + "123456789012"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(contracts_separated_with_comment)
|
BOOST_AUTO_TEST_CASE(contracts_separated_with_comment)
|
||||||
@ -3152,12 +3151,12 @@ BOOST_AUTO_TEST_CASE(bare_call_return_data)
|
|||||||
{
|
{
|
||||||
if (solidity::test::CommonOptions::get().evmVersion().supportsReturndata())
|
if (solidity::test::CommonOptions::get().evmVersion().supportsReturndata())
|
||||||
{
|
{
|
||||||
vector<string> calltypes = {"call", "delegatecall"};
|
std::vector<std::string> calltypes = {"call", "delegatecall"};
|
||||||
if (solidity::test::CommonOptions::get().evmVersion().hasStaticCall())
|
if (solidity::test::CommonOptions::get().evmVersion().hasStaticCall())
|
||||||
calltypes.emplace_back("staticcall");
|
calltypes.emplace_back("staticcall");
|
||||||
for (string const& calltype: calltypes)
|
for (std::string const& calltype: calltypes)
|
||||||
{
|
{
|
||||||
string sourceCode = R"DELIMITER(
|
std::string sourceCode = R"DELIMITER(
|
||||||
contract A {
|
contract A {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
@ -3256,14 +3255,14 @@ BOOST_AUTO_TEST_CASE(bare_call_return_data)
|
|||||||
)DELIMITER";
|
)DELIMITER";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bool()"))), encodeArgs(true, 0x40, 0x20, true));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_bool()"))), encodeArgs(true, 0x40, 0x20, true));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_int32()"))), encodeArgs(true, 0x40, 0x20, u256(-32)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_int32()"))), encodeArgs(true, 0x40, 0x20, u256(-32)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_uint32()"))), encodeArgs(true, 0x40, 0x20, u256(0x3232)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_uint32()"))), encodeArgs(true, 0x40, 0x20, u256(0x3232)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_int256()"))), encodeArgs(true, 0x40, 0x20, u256(-256)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_int256()"))), encodeArgs(true, 0x40, 0x20, u256(-256)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_uint256()"))), encodeArgs(true, 0x40, 0x20, u256(0x256256)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_uint256()"))), encodeArgs(true, 0x40, 0x20, u256(0x256256)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bytes4()"))), encodeArgs(true, 0x40, 0x20, u256(0xabcd0012) << (28*8)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_bytes4()"))), encodeArgs(true, 0x40, 0x20, u256(0xabcd0012) << (28*8)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_multi()"))), encodeArgs(true, 0x40, 0x60, false, u256(0x3232), u256(0xabcd0012) << (28*8)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_multi()"))), encodeArgs(true, 0x40, 0x60, false, u256(0x3232), u256(0xabcd0012) << (28*8)));
|
||||||
ABI_CHECK(callContractFunction("f(string)", encodeDyn(string("return_bytes()"))), encodeArgs(true, 0x40, 0x60, 0x20, 0x02, encode(bytes{0x42,0x21}, false)));
|
ABI_CHECK(callContractFunction("f(string)", encodeDyn(std::string("return_bytes()"))), encodeArgs(true, 0x40, 0x60, 0x20, 0x02, encode(bytes{0x42,0x21}, false)));
|
||||||
ABI_CHECK(callContractFunction("check_bool()"), encodeArgs(true));
|
ABI_CHECK(callContractFunction("check_bool()"), encodeArgs(true));
|
||||||
ABI_CHECK(callContractFunction("check_int32()"), encodeArgs(true));
|
ABI_CHECK(callContractFunction("check_int32()"), encodeArgs(true));
|
||||||
ABI_CHECK(callContractFunction("check_uint32()"), encodeArgs(true));
|
ABI_CHECK(callContractFunction("check_uint32()"), encodeArgs(true));
|
||||||
@ -3315,7 +3314,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked)
|
|||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
|
std::string prefix = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n";
|
||||||
compileAndRun(prefix + sourceCode, 0, "C");
|
compileAndRun(prefix + sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f0()"), encodeArgs(0x20, 0));
|
ABI_CHECK(callContractFunction("f0()"), encodeArgs(0x20, 0));
|
||||||
ABI_CHECK(callContractFunction("f1()"), encodeArgs(0x20, 2, "\x01\x02"));
|
ABI_CHECK(callContractFunction("f1()"), encodeArgs(0x20, 2, "\x01\x02"));
|
||||||
@ -3392,7 +3391,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_storage)
|
|||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
|
std::string prefix = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n";
|
||||||
compileAndRun(prefix + sourceCode, 0, "C");
|
compileAndRun(prefix + sourceCode, 0, "C");
|
||||||
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
|
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
|
||||||
bytes encoded = encodeArgs(0x20, 0x122, "\x01" + asString(payload) + "\x02");
|
bytes encoded = encodeArgs(0x20, 0x122, "\x01" + asString(payload) + "\x02");
|
||||||
@ -3465,7 +3464,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_memory)
|
|||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
|
std::string prefix = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n";
|
||||||
compileAndRun(prefix + sourceCode, 0, "C");
|
compileAndRun(prefix + sourceCode, 0, "C");
|
||||||
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
|
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
|
||||||
bytes encoded = encodeArgs(0x20, 0x122, "\x01" + asString(payload) + "\x02");
|
bytes encoded = encodeArgs(0x20, 0x122, "\x01" + asString(payload) + "\x02");
|
||||||
@ -3511,11 +3510,11 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_functionPtr)
|
|||||||
for (auto v2: {false, true})
|
for (auto v2: {false, true})
|
||||||
{
|
{
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
|
std::string prefix = "pragma abicoder " + std::string(v2 ? "v2" : "v1") + ";\n";
|
||||||
compileAndRun(prefix + sourceCode, 0, "C");
|
compileAndRun(prefix + sourceCode, 0, "C");
|
||||||
string directEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "02"));
|
std::string directEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "02"));
|
||||||
ABI_CHECK(callContractFunction("testDirect()"), encodeArgs(0x20, directEncoding.size(), directEncoding));
|
ABI_CHECK(callContractFunction("testDirect()"), encodeArgs(0x20, directEncoding.size(), directEncoding));
|
||||||
string arrayEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "0000000000000000" "02"));
|
std::string arrayEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "0000000000000000" "02"));
|
||||||
ABI_CHECK(callContractFunction("testFixedArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
|
ABI_CHECK(callContractFunction("testFixedArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
|
||||||
ABI_CHECK(callContractFunction("testDynamicArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
|
ABI_CHECK(callContractFunction("testDynamicArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
|
||||||
)
|
)
|
||||||
@ -3557,11 +3556,11 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_structs)
|
|||||||
bytes structEnc = encodeArgs(int(0x12), u256(-7), int(2), int(3), u256(-7), u256(-8));
|
bytes structEnc = encodeArgs(int(0x12), u256(-7), int(2), int(3), u256(-7), u256(-8));
|
||||||
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
|
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16,uint8[2],int16[]))")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("E((uint8,int16,uint8[2],int16[]))")));
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
||||||
ABI_CHECK(callContractFunction("testMemory()"), encodeArgs());
|
ABI_CHECK(callContractFunction("testMemory()"), encodeArgs());
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16,uint8[2],int16[]))")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("E((uint8,int16,uint8[2],int16[]))")));
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -3592,7 +3591,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_nestedArray)
|
|||||||
bytes structEnc = encodeArgs(1, 2, 3, 0, 0, 0, 0, 4);
|
bytes structEnc = encodeArgs(1, 2, 3, 0, 0, 0, 0, 4);
|
||||||
ABI_CHECK(callContractFunction("testNestedArrays()"), encodeArgs());
|
ABI_CHECK(callContractFunction("testNestedArrays()"), encodeArgs());
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16)[2][][3])")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("E((uint8,int16)[2][][3])")));
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -3622,11 +3621,11 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_arrayOfStrings)
|
|||||||
bytes arrayEncoding = encodeArgs("abc", "0123456789012345678901234567890123456789");
|
bytes arrayEncoding = encodeArgs("abc", "0123456789012345678901234567890123456789");
|
||||||
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
|
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E(string[])")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("E(string[])")));
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(arrayEncoding)));
|
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(arrayEncoding)));
|
||||||
ABI_CHECK(callContractFunction("testMemory()"), encodeArgs());
|
ABI_CHECK(callContractFunction("testMemory()"), encodeArgs());
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E(string[])")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("E(string[])")));
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(arrayEncoding)));
|
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(arrayEncoding)));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -3712,7 +3711,7 @@ BOOST_AUTO_TEST_CASE(contract_name)
|
|||||||
ABI_CHECK(callContractFunction("name()"), argsD);
|
ABI_CHECK(callContractFunction("name()"), argsD);
|
||||||
ABI_CHECK(callContractFunction("name2()"), argsC);
|
ABI_CHECK(callContractFunction("name2()"), argsC);
|
||||||
|
|
||||||
string longName = "ThisIsAVeryLongContractNameExceeding256bits";
|
std::string longName = "ThisIsAVeryLongContractNameExceeding256bits";
|
||||||
compileAndRun(sourceCode, 0, longName);
|
compileAndRun(sourceCode, 0, longName);
|
||||||
bytes argsLong = encodeArgs(u256(0x20), u256(longName.length()), longName);
|
bytes argsLong = encodeArgs(u256(0x20), u256(longName.length()), longName);
|
||||||
ABI_CHECK(callContractFunction("name()"), argsLong);
|
ABI_CHECK(callContractFunction("name()"), argsLong);
|
||||||
@ -3738,13 +3737,13 @@ BOOST_AUTO_TEST_CASE(event_wrong_abi_name)
|
|||||||
)";
|
)";
|
||||||
ALSO_VIA_YUL(
|
ALSO_VIA_YUL(
|
||||||
compileAndRun(sourceCode, 0, "ClientReceipt", bytes());
|
compileAndRun(sourceCode, 0, "ClientReceipt", bytes());
|
||||||
compileAndRun(sourceCode, 0, "Test", bytes(), map<string, h160>{{":ClientReceipt", m_contractAddress}});
|
compileAndRun(sourceCode, 0, "Test", bytes(), std::map<std::string, h160>{{":ClientReceipt", m_contractAddress}});
|
||||||
|
|
||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
BOOST_REQUIRE_EQUAL(numLogs(), 1);
|
BOOST_REQUIRE_EQUAL(numLogs(), 1);
|
||||||
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
|
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
|
||||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 3);
|
BOOST_REQUIRE_EQUAL(numLogTopics(0), 3);
|
||||||
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Deposit(address,bytes32,uint256)")));
|
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(std::string("Deposit(address,bytes32,uint256)")));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,13 +39,12 @@ using namespace solidity::frontend;
|
|||||||
using namespace solidity::frontend::test;
|
using namespace solidity::frontend::test;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
bytes SolidityExecutionFramework::multiSourceCompileContract(
|
bytes SolidityExecutionFramework::multiSourceCompileContract(
|
||||||
map<string, string> const& _sourceCode,
|
std::map<std::string, std::string> const& _sourceCode,
|
||||||
optional<string> const& _mainSourceName,
|
std::optional<std::string> const& _mainSourceName,
|
||||||
string const& _contractName,
|
std::string const& _contractName,
|
||||||
map<string, Address> const& _libraryAddresses
|
std::map<std::string, Address> const& _libraryAddresses
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (_mainSourceName.has_value())
|
if (_mainSourceName.has_value())
|
||||||
@ -81,23 +80,23 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
|
|||||||
.printErrorInformation(m_compiler.errors());
|
.printErrorInformation(m_compiler.errors());
|
||||||
BOOST_ERROR("Compiling contract failed");
|
BOOST_ERROR("Compiling contract failed");
|
||||||
}
|
}
|
||||||
string contractName(_contractName.empty() ? m_compiler.lastContractName(_mainSourceName) : _contractName);
|
std::string contractName(_contractName.empty() ? m_compiler.lastContractName(_mainSourceName) : _contractName);
|
||||||
evmasm::LinkerObject obj = m_compiler.object(contractName);
|
evmasm::LinkerObject obj = m_compiler.object(contractName);
|
||||||
BOOST_REQUIRE(obj.linkReferences.empty());
|
BOOST_REQUIRE(obj.linkReferences.empty());
|
||||||
if (m_showMetadata)
|
if (m_showMetadata)
|
||||||
cout << "metadata: " << m_compiler.metadata(contractName) << endl;
|
std::cout << "metadata: " << m_compiler.metadata(contractName) << std::endl;
|
||||||
return obj.bytecode;
|
return obj.bytecode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes SolidityExecutionFramework::compileContract(
|
bytes SolidityExecutionFramework::compileContract(
|
||||||
string const& _sourceCode,
|
std::string const& _sourceCode,
|
||||||
string const& _contractName,
|
std::string const& _contractName,
|
||||||
map<string, Address> const& _libraryAddresses
|
std::map<std::string, Address> const& _libraryAddresses
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return multiSourceCompileContract(
|
return multiSourceCompileContract(
|
||||||
{{"", _sourceCode}},
|
{{"", _sourceCode}},
|
||||||
nullopt,
|
std::nullopt,
|
||||||
_contractName,
|
_contractName,
|
||||||
_libraryAddresses
|
_libraryAddresses
|
||||||
);
|
);
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
@ -78,13 +77,13 @@ private:
|
|||||||
|
|
||||||
Declaration const& resolveDeclaration(
|
Declaration const& resolveDeclaration(
|
||||||
SourceUnit const& _sourceUnit,
|
SourceUnit const& _sourceUnit,
|
||||||
vector<string> const& _namespacedName,
|
std::vector<std::string> const& _namespacedName,
|
||||||
NameAndTypeResolver const& _resolver
|
NameAndTypeResolver const& _resolver
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASTNode const* scope = &_sourceUnit;
|
ASTNode const* scope = &_sourceUnit;
|
||||||
// bracers are required, cause msvc couldn't handle this macro in for statement
|
// bracers are required, cause msvc couldn't handle this macro in for statement
|
||||||
for (string const& namePart: _namespacedName)
|
for (std::string const& namePart: _namespacedName)
|
||||||
{
|
{
|
||||||
auto declarations = _resolver.resolveName(namePart, scope);
|
auto declarations = _resolver.resolveName(namePart, scope);
|
||||||
BOOST_REQUIRE(!declarations.empty());
|
BOOST_REQUIRE(!declarations.empty());
|
||||||
@ -95,12 +94,12 @@ Declaration const& resolveDeclaration(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bytes compileFirstExpression(
|
bytes compileFirstExpression(
|
||||||
string const& _sourceCode,
|
std::string const& _sourceCode,
|
||||||
vector<vector<string>> _functions = {},
|
std::vector<std::vector<std::string>> _functions = {},
|
||||||
vector<vector<string>> _localVariables = {}
|
std::vector<std::vector<std::string>> _localVariables = {}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
string sourceCode = "pragma solidity >=0.0; // SPDX-License-Identifier: GPL-3\n" + _sourceCode;
|
std::string sourceCode = "pragma solidity >=0.0; // SPDX-License-Identifier: GPL-3\n" + _sourceCode;
|
||||||
CharStream stream(sourceCode, "");
|
CharStream stream(sourceCode, "");
|
||||||
|
|
||||||
ASTPointer<SourceUnit> sourceUnit;
|
ASTPointer<SourceUnit> sourceUnit;
|
||||||
@ -114,12 +113,12 @@ bytes compileFirstExpression(
|
|||||||
}
|
}
|
||||||
catch (boost::exception const& _e)
|
catch (boost::exception const& _e)
|
||||||
{
|
{
|
||||||
string msg = "Parsing source code failed with:\n" + boost::diagnostic_information(_e);
|
std::string msg = "Parsing source code failed with:\n" + boost::diagnostic_information(_e);
|
||||||
BOOST_FAIL(msg);
|
BOOST_FAIL(msg);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
string msg = "Parsing source code failed with:\n" + boost::current_exception_diagnostic_information();
|
std::string msg = "Parsing source code failed with:\n" + boost::current_exception_diagnostic_information();
|
||||||
BOOST_FAIL(msg);
|
BOOST_FAIL(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +150,7 @@ bytes compileFirstExpression(
|
|||||||
context.setArithmetic(Arithmetic::Wrapping);
|
context.setArithmetic(Arithmetic::Wrapping);
|
||||||
size_t parametersSize = _localVariables.size(); // assume they are all one slot on the stack
|
size_t parametersSize = _localVariables.size(); // assume they are all one slot on the stack
|
||||||
context.adjustStackOffset(static_cast<int>(parametersSize));
|
context.adjustStackOffset(static_cast<int>(parametersSize));
|
||||||
for (vector<string> const& variable: _localVariables)
|
for (std::vector<std::string> const& variable: _localVariables)
|
||||||
context.addVariable(
|
context.addVariable(
|
||||||
dynamic_cast<VariableDeclaration const&>(resolveDeclaration(*sourceUnit, variable, resolver)),
|
dynamic_cast<VariableDeclaration const&>(resolveDeclaration(*sourceUnit, variable, resolver)),
|
||||||
static_cast<unsigned>(parametersSize--)
|
static_cast<unsigned>(parametersSize--)
|
||||||
@ -162,7 +161,7 @@ bytes compileFirstExpression(
|
|||||||
solidity::test::CommonOptions::get().optimize
|
solidity::test::CommonOptions::get().optimize
|
||||||
).compile(*extractor.expression());
|
).compile(*extractor.expression());
|
||||||
|
|
||||||
for (vector<string> const& function: _functions)
|
for (std::vector<std::string> const& function: _functions)
|
||||||
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(
|
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(
|
||||||
resolveDeclaration(*sourceUnit, function, resolver)
|
resolveDeclaration(*sourceUnit, function, resolver)
|
||||||
));
|
));
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::evmasm;
|
using namespace solidity::evmasm;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
@ -79,9 +78,9 @@ public:
|
|||||||
size_t optimizedSize = numInstructions(m_optimizedBytecode);
|
size_t optimizedSize = numInstructions(m_optimizedBytecode);
|
||||||
BOOST_CHECK_MESSAGE(
|
BOOST_CHECK_MESSAGE(
|
||||||
_optimizeRuns < 50 || optimizedSize < nonOptimizedSize,
|
_optimizeRuns < 50 || optimizedSize < nonOptimizedSize,
|
||||||
string("Optimizer did not reduce bytecode size. Non-optimized size: ") +
|
std::string("Optimizer did not reduce bytecode size. Non-optimized size: ") +
|
||||||
to_string(nonOptimizedSize) + " - optimized size: " +
|
std::to_string(nonOptimizedSize) + " - optimized size: " +
|
||||||
to_string(optimizedSize)
|
std::to_string(optimizedSize)
|
||||||
);
|
);
|
||||||
m_optimizedContract = m_contractAddress;
|
m_optimizedContract = m_contractAddress;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
namespace solidity::frontend::test
|
namespace solidity::frontend::test
|
||||||
@ -37,7 +36,7 @@ BOOST_FIXTURE_TEST_SUITE(ViewPureChecker, AnalysisFramework)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(environment_access)
|
BOOST_AUTO_TEST_CASE(environment_access)
|
||||||
{
|
{
|
||||||
vector<string> view{
|
std::vector<std::string> view{
|
||||||
"block.coinbase",
|
"block.coinbase",
|
||||||
"block.timestamp",
|
"block.timestamp",
|
||||||
"block.difficulty",
|
"block.difficulty",
|
||||||
@ -57,7 +56,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
|
|||||||
|
|
||||||
// ``block.blockhash`` and ``blockhash`` are tested separately below because their usage will
|
// ``block.blockhash`` and ``blockhash`` are tested separately below because their usage will
|
||||||
// produce warnings that can't be handled in a generic way.
|
// produce warnings that can't be handled in a generic way.
|
||||||
vector<string> pure{
|
std::vector<std::string> pure{
|
||||||
"msg.data",
|
"msg.data",
|
||||||
"msg.data[0]",
|
"msg.data[0]",
|
||||||
"msg.sig",
|
"msg.sig",
|
||||||
@ -65,7 +64,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
|
|||||||
"block",
|
"block",
|
||||||
"tx"
|
"tx"
|
||||||
};
|
};
|
||||||
for (string const& x: view)
|
for (std::string const& x: view)
|
||||||
{
|
{
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(
|
||||||
"contract C { function f() pure public { " + x + "; } }",
|
"contract C { function f() pure public { " + x + "; } }",
|
||||||
@ -73,7 +72,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
|
|||||||
"Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires \"view\""
|
"Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires \"view\""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (string const& x: pure)
|
for (std::string const& x: pure)
|
||||||
{
|
{
|
||||||
CHECK_WARNING(
|
CHECK_WARNING(
|
||||||
"contract C { function f() view public { " + x + "; } }",
|
"contract C { function f() view public { " + x + "; } }",
|
||||||
@ -97,7 +96,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(address_staticcall)
|
BOOST_AUTO_TEST_CASE(address_staticcall)
|
||||||
{
|
{
|
||||||
string text = R"(
|
std::string text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function i() view public returns (bool) {
|
function i() view public returns (bool) {
|
||||||
(bool success,) = address(0x4242).staticcall("");
|
(bool success,) = address(0x4242).staticcall("");
|
||||||
@ -114,7 +113,7 @@ BOOST_AUTO_TEST_CASE(address_staticcall)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(assembly_staticcall)
|
BOOST_AUTO_TEST_CASE(assembly_staticcall)
|
||||||
{
|
{
|
||||||
string text = R"(
|
std::string text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function i() view public {
|
function i() view public {
|
||||||
assembly { pop(staticcall(gas(), 1, 2, 3, 4, 5)) }
|
assembly { pop(staticcall(gas(), 1, 2, 3, 4, 5)) }
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,6 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
|
|
||||||
@ -226,12 +225,12 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
|
|||||||
BOOST_CHECK_EQUAL(normalizedPath.root_directory(), "/");
|
BOOST_CHECK_EQUAL(normalizedPath.root_directory(), "/");
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
string root = workDir.root_path().string();
|
std::string root = workDir.root_path().string();
|
||||||
soltestAssert(root.length() == 3 && root[1] == ':' && root[2] == '\\', "");
|
soltestAssert(root.length() == 3 && root[1] == ':' && root[2] == '\\', "");
|
||||||
|
|
||||||
for (auto convert: {boost::to_lower_copy<string>, boost::to_upper_copy<string>})
|
for (auto convert: {boost::to_lower_copy<std::string>, boost::to_upper_copy<std::string>})
|
||||||
{
|
{
|
||||||
boost::filesystem::path workDirWin = convert(root, locale()) / workDir.relative_path();
|
boost::filesystem::path workDirWin = convert(root, std::locale()) / workDir.relative_path();
|
||||||
normalizedPath = FileReader::normalizeCLIPathForVFS(
|
normalizedPath = FileReader::normalizeCLIPathForVFS(
|
||||||
workDirWin,
|
workDirWin,
|
||||||
resolveSymlinks
|
resolveSymlinks
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -47,7 +46,7 @@ BOOST_AUTO_TEST_CASE(calculate)
|
|||||||
BOOST_CHECK_THROW(getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaeK"), InvalidAddress);
|
BOOST_CHECK_THROW(getChecksummedAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaeK"), InvalidAddress);
|
||||||
|
|
||||||
// the official test suite from EIP-55
|
// the official test suite from EIP-55
|
||||||
vector<string> cases {
|
std::vector<std::string> cases {
|
||||||
// all upper case
|
// all upper case
|
||||||
"0x52908400098527886E0F7030069857D2E4169EE7",
|
"0x52908400098527886E0F7030069857D2E4169EE7",
|
||||||
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
|
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
|
||||||
@ -103,10 +102,10 @@ BOOST_AUTO_TEST_CASE(homocaps_valid)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(homocaps_invalid)
|
BOOST_AUTO_TEST_CASE(homocaps_invalid)
|
||||||
{
|
{
|
||||||
string upper = "0x00AA0000000012400000000DDEEFF000000000BB";
|
std::string upper = "0x00AA0000000012400000000DDEEFF000000000BB";
|
||||||
BOOST_CHECK(passesAddressChecksum(upper, false));
|
BOOST_CHECK(passesAddressChecksum(upper, false));
|
||||||
BOOST_CHECK(!passesAddressChecksum(upper, true));
|
BOOST_CHECK(!passesAddressChecksum(upper, true));
|
||||||
string lower = "0x11aa000000000000000d00cc00000000000000bb";
|
std::string lower = "0x11aa000000000000000d00cc00000000000000bb";
|
||||||
BOOST_CHECK(passesAddressChecksum(lower, false));
|
BOOST_CHECK(passesAddressChecksum(lower, false));
|
||||||
BOOST_CHECK(!passesAddressChecksum(lower, true));
|
BOOST_CHECK(!passesAddressChecksum(lower, true));
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
|
|
||||||
// TODO: Fix Boost...
|
// TODO: Fix Boost...
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
|
|
||||||
#define TEST_CASE_NAME (boost::unit_test::framework::current_test_case().p_name)
|
#define TEST_CASE_NAME (boost::unit_test::framework::current_test_case().p_name)
|
||||||
@ -68,31 +67,31 @@ BOOST_AUTO_TEST_CASE(readFileAsString_symlink)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readUntilEnd_no_ending_newline)
|
BOOST_AUTO_TEST_CASE(readUntilEnd_no_ending_newline)
|
||||||
{
|
{
|
||||||
istringstream inputStream("ABC\ndef");
|
std::istringstream inputStream("ABC\ndef");
|
||||||
BOOST_TEST(readUntilEnd(inputStream) == "ABC\ndef");
|
BOOST_TEST(readUntilEnd(inputStream) == "ABC\ndef");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readUntilEnd_with_ending_newline)
|
BOOST_AUTO_TEST_CASE(readUntilEnd_with_ending_newline)
|
||||||
{
|
{
|
||||||
istringstream inputStream("ABC\ndef\n");
|
std::istringstream inputStream("ABC\ndef\n");
|
||||||
BOOST_TEST(readUntilEnd(inputStream) == "ABC\ndef\n");
|
BOOST_TEST(readUntilEnd(inputStream) == "ABC\ndef\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readUntilEnd_cr_lf_newline)
|
BOOST_AUTO_TEST_CASE(readUntilEnd_cr_lf_newline)
|
||||||
{
|
{
|
||||||
istringstream inputStream("ABC\r\ndef");
|
std::istringstream inputStream("ABC\r\ndef");
|
||||||
BOOST_TEST(readUntilEnd(inputStream) == "ABC\r\ndef");
|
BOOST_TEST(readUntilEnd(inputStream) == "ABC\r\ndef");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readUntilEnd_empty)
|
BOOST_AUTO_TEST_CASE(readUntilEnd_empty)
|
||||||
{
|
{
|
||||||
istringstream inputStream("");
|
std::istringstream inputStream("");
|
||||||
BOOST_TEST(readUntilEnd(inputStream) == "");
|
BOOST_TEST(readUntilEnd(inputStream) == "");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(readBytes_past_end)
|
BOOST_AUTO_TEST_CASE(readBytes_past_end)
|
||||||
{
|
{
|
||||||
istringstream inputStream("abc");
|
std::istringstream inputStream("abc");
|
||||||
BOOST_CHECK_EQUAL(readBytes(inputStream, 0), "");
|
BOOST_CHECK_EQUAL(readBytes(inputStream, 0), "");
|
||||||
BOOST_CHECK_EQUAL(readBytes(inputStream, 1), "a");
|
BOOST_CHECK_EQUAL(readBytes(inputStream, 1), "a");
|
||||||
BOOST_CHECK_EQUAL(readBytes(inputStream, 20), "bc");
|
BOOST_CHECK_EQUAL(readBytes(inputStream, 20), "bc");
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -37,16 +36,16 @@ BOOST_AUTO_TEST_CASE(test_small)
|
|||||||
BOOST_CHECK_EQUAL(ipfsHashBase58({}), "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH");
|
BOOST_CHECK_EQUAL(ipfsHashBase58({}), "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58("x"), "QmULKig5Fxrs2sC4qt9nNduucXfb92AFYQ6Hi3YRqDmrYC");
|
BOOST_CHECK_EQUAL(ipfsHashBase58("x"), "QmULKig5Fxrs2sC4qt9nNduucXfb92AFYQ6Hi3YRqDmrYC");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58("Solidity\n"), "QmSsm9M7PQRBnyiz1smizk8hZw3URfk8fSeHzeTo3oZidS");
|
BOOST_CHECK_EQUAL(ipfsHashBase58("Solidity\n"), "QmSsm9M7PQRBnyiz1smizk8hZw3URfk8fSeHzeTo3oZidS");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(200ul, char(0))), "QmSXR1N23uWzsANi8wpxMPw5dmmhqBVUAb4hUrHVLpNaMr");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(std::string(200ul, char(0))), "QmSXR1N23uWzsANi8wpxMPw5dmmhqBVUAb4hUrHVLpNaMr");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(10250ul, char(0))), "QmVJJBB3gKKBWYC9QTywpH8ZL1bDeTDJ17B63Af5kino9i");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(std::string(10250ul, char(0))), "QmVJJBB3gKKBWYC9QTywpH8ZL1bDeTDJ17B63Af5kino9i");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(100000ul, char(0))), "QmYgKa25YqEGpQmmZtPPFMNK3kpqqneHk6nMSEUYryEX1C");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(std::string(100000ul, char(0))), "QmYgKa25YqEGpQmmZtPPFMNK3kpqqneHk6nMSEUYryEX1C");
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(121071ul, char(0))), "QmdMdRshQmqvyc92N82r7AKYdUF5FRh4DJo6GtrmEk3wgj");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(std::string(121071ul, char(0))), "QmdMdRshQmqvyc92N82r7AKYdUF5FRh4DJo6GtrmEk3wgj");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_medium)
|
BOOST_AUTO_TEST_CASE(test_medium)
|
||||||
{
|
{
|
||||||
size_t length = 131071;
|
size_t length = 131071;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmSxYSToKHsPqqRdRnsM9gmr3EYS6dakhVaHgbFdgYQWi6");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmSxYSToKHsPqqRdRnsM9gmr3EYS6dakhVaHgbFdgYQWi6");
|
||||||
@ -55,7 +54,7 @@ BOOST_AUTO_TEST_CASE(test_medium)
|
|||||||
BOOST_AUTO_TEST_CASE(test_largest_unchunked)
|
BOOST_AUTO_TEST_CASE(test_largest_unchunked)
|
||||||
{
|
{
|
||||||
size_t length = 1024 * 256 - 1;
|
size_t length = 1024 * 256 - 1;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmbNDspMkzkMFKyS3eCJGedG7GWRQHSCzJCZLjxP7wyVAx");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmbNDspMkzkMFKyS3eCJGedG7GWRQHSCzJCZLjxP7wyVAx");
|
||||||
@ -64,7 +63,7 @@ BOOST_AUTO_TEST_CASE(test_largest_unchunked)
|
|||||||
BOOST_AUTO_TEST_CASE(test_smallest_chunked)
|
BOOST_AUTO_TEST_CASE(test_smallest_chunked)
|
||||||
{
|
{
|
||||||
size_t length = 1024 * 256 + 1;
|
size_t length = 1024 * 256 + 1;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmbVuw4C4vcmVKqxoWtgDVobvcHrSn51qsmQmyxjk4sB2Q");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmbVuw4C4vcmVKqxoWtgDVobvcHrSn51qsmQmyxjk4sB2Q");
|
||||||
@ -73,7 +72,7 @@ BOOST_AUTO_TEST_CASE(test_smallest_chunked)
|
|||||||
BOOST_AUTO_TEST_CASE(test_large)
|
BOOST_AUTO_TEST_CASE(test_large)
|
||||||
{
|
{
|
||||||
size_t length = 1310710;
|
size_t length = 1310710;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmNg7BJo8gEMDK8yGQbHEwPtycesnE6FUULX5iVd5TAL9f");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmNg7BJo8gEMDK8yGQbHEwPtycesnE6FUULX5iVd5TAL9f");
|
||||||
@ -82,7 +81,7 @@ BOOST_AUTO_TEST_CASE(test_large)
|
|||||||
BOOST_AUTO_TEST_CASE(test_largest_one_level)
|
BOOST_AUTO_TEST_CASE(test_largest_one_level)
|
||||||
{
|
{
|
||||||
size_t length = 45613056; // 1024 * 256 * 174;
|
size_t length = 45613056; // 1024 * 256 * 174;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmY4HSz1oVGdUzb8poVYPLsoqBZjH6LZrtgnme9wWn2Qko");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmY4HSz1oVGdUzb8poVYPLsoqBZjH6LZrtgnme9wWn2Qko");
|
||||||
@ -91,7 +90,7 @@ BOOST_AUTO_TEST_CASE(test_largest_one_level)
|
|||||||
BOOST_AUTO_TEST_CASE(test_smallest_multi_level)
|
BOOST_AUTO_TEST_CASE(test_smallest_multi_level)
|
||||||
{
|
{
|
||||||
size_t length = 45613057; // 1024 * 256 * 174 + 1;
|
size_t length = 45613057; // 1024 * 256 * 174 + 1;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmehMASWcBsX7VcEQqs6rpR5AHoBfKyBVEgmkJHjpPg8jq");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmehMASWcBsX7VcEQqs6rpR5AHoBfKyBVEgmkJHjpPg8jq");
|
||||||
@ -100,7 +99,7 @@ BOOST_AUTO_TEST_CASE(test_smallest_multi_level)
|
|||||||
BOOST_AUTO_TEST_CASE(test_multi_level_tree)
|
BOOST_AUTO_TEST_CASE(test_multi_level_tree)
|
||||||
{
|
{
|
||||||
size_t length = 46661632;
|
size_t length = 46661632;
|
||||||
string data;
|
std::string data;
|
||||||
data.resize(length, 0);
|
data.resize(length, 0);
|
||||||
BOOST_REQUIRE_EQUAL(data.size(), length);
|
BOOST_REQUIRE_EQUAL(data.size(), length);
|
||||||
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmaTb1sT9hrSXJLmf8bxJ9NuwndiHuMLsgNLgkS2eXu3Xj");
|
BOOST_CHECK_EQUAL(ipfsHashBase58(data), "QmaTb1sT9hrSXJLmf8bxJ9NuwndiHuMLsgNLgkS2eXu3Xj");
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -34,61 +33,61 @@ BOOST_AUTO_TEST_SUITE(IterateReplacing, *boost::unit_test::label("nooptions"))
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(no_replacement)
|
BOOST_AUTO_TEST_CASE(no_replacement)
|
||||||
{
|
{
|
||||||
vector<string> v{"abc", "def", "ghi"};
|
std::vector<std::string> v{"abc", "def", "ghi"};
|
||||||
function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
|
std::function<std::optional<std::vector<std::string>>(std::string&)> f = [](std::string&) -> std::optional<std::vector<std::string>> { return {}; };
|
||||||
iterateReplacing(v, f);
|
iterateReplacing(v, f);
|
||||||
vector<string> expectation{"abc", "def", "ghi"};
|
std::vector<std::string> expectation{"abc", "def", "ghi"};
|
||||||
BOOST_CHECK(v == expectation);
|
BOOST_CHECK(v == expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(empty_input)
|
BOOST_AUTO_TEST_CASE(empty_input)
|
||||||
{
|
{
|
||||||
vector<string> v;
|
std::vector<std::string> v;
|
||||||
function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
|
std::function<std::optional<std::vector<std::string>>(std::string&)> f = [](std::string&) -> std::optional<std::vector<std::string>> { return {}; };
|
||||||
iterateReplacing(v, f);
|
iterateReplacing(v, f);
|
||||||
vector<string> expectation;
|
std::vector<std::string> expectation;
|
||||||
BOOST_CHECK(v == expectation);
|
BOOST_CHECK(v == expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(delete_some)
|
BOOST_AUTO_TEST_CASE(delete_some)
|
||||||
{
|
{
|
||||||
vector<string> v{"abc", "def", "ghi"};
|
std::vector<std::string> v{"abc", "def", "ghi"};
|
||||||
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
|
std::function<std::optional<std::vector<std::string>>(std::string&)> f = [](std::string& _s) -> std::optional<std::vector<std::string>> {
|
||||||
if (_s == "def")
|
if (_s == "def")
|
||||||
return vector<string>();
|
return std::vector<std::string>();
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
iterateReplacing(v, f);
|
iterateReplacing(v, f);
|
||||||
vector<string> expectation{"abc", "ghi"};
|
std::vector<std::string> expectation{"abc", "ghi"};
|
||||||
BOOST_CHECK(v == expectation);
|
BOOST_CHECK(v == expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(inject_some_start)
|
BOOST_AUTO_TEST_CASE(inject_some_start)
|
||||||
{
|
{
|
||||||
vector<string> v{"abc", "def", "ghi"};
|
std::vector<std::string> v{"abc", "def", "ghi"};
|
||||||
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
|
std::function<std::optional<std::vector<std::string>>(std::string&)> f = [](std::string& _s) -> std::optional<std::vector<std::string>> {
|
||||||
if (_s == "abc")
|
if (_s == "abc")
|
||||||
return vector<string>{"x", "y"};
|
return std::vector<std::string>{"x", "y"};
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
iterateReplacing(v, f);
|
iterateReplacing(v, f);
|
||||||
vector<string> expectation{"x", "y", "def", "ghi"};
|
std::vector<std::string> expectation{"x", "y", "def", "ghi"};
|
||||||
BOOST_CHECK(v == expectation);
|
BOOST_CHECK(v == expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(inject_some_end)
|
BOOST_AUTO_TEST_CASE(inject_some_end)
|
||||||
{
|
{
|
||||||
vector<string> v{"abc", "def", "ghi"};
|
std::vector<std::string> v{"abc", "def", "ghi"};
|
||||||
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
|
std::function<std::optional<std::vector<std::string>>(std::string&)> f = [](std::string& _s) -> std::optional<std::vector<std::string>> {
|
||||||
if (_s == "ghi")
|
if (_s == "ghi")
|
||||||
return vector<string>{"x", "y"};
|
return std::vector<std::string>{"x", "y"};
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
iterateReplacing(v, f);
|
iterateReplacing(v, f);
|
||||||
vector<string> expectation{"abc", "def", "x", "y"};
|
std::vector<std::string> expectation{"abc", "def", "x", "y"};
|
||||||
BOOST_CHECK(v == expectation);
|
BOOST_CHECK(v == expectation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -35,7 +34,7 @@ BOOST_AUTO_TEST_SUITE(JsonTest, *boost::unit_test::label("nooptions"))
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(json_types)
|
BOOST_AUTO_TEST_CASE(json_types)
|
||||||
{
|
{
|
||||||
auto check = [](Json::Value value, string const& expectation) {
|
auto check = [](Json::Value value, std::string const& expectation) {
|
||||||
BOOST_CHECK(jsonCompactPrint(value) == expectation);
|
BOOST_CHECK(jsonCompactPrint(value) == expectation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -75,7 +74,7 @@ BOOST_AUTO_TEST_CASE(test_dldistance)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_alternatives_list)
|
BOOST_AUTO_TEST_CASE(test_alternatives_list)
|
||||||
{
|
{
|
||||||
vector<string> strings;
|
std::vector<std::string> strings;
|
||||||
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "");
|
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "");
|
||||||
strings.emplace_back("a");
|
strings.emplace_back("a");
|
||||||
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\"");
|
BOOST_CHECK_EQUAL(quotedAlternativesList(strings), "\"a\"");
|
||||||
@ -89,20 +88,20 @@ BOOST_AUTO_TEST_CASE(test_alternatives_list)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_human_readable_join)
|
BOOST_AUTO_TEST_CASE(test_human_readable_join)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({})), "");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({})), "");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"})), "a");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a"})), "a");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"})), "a, b");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b"})), "a, b");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"})), "a, b, c");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b", "c"})), "a, b, c");
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({}), "; "), "");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({}), "; "), "");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"}), "; "), "a");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a"}), "; "), "a");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"}), "; "), "a; b");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b"}), "; "), "a; b");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"}), "; "), "a; b; c");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b", "c"}), "; "), "a; b; c");
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({}), "; ", " or "), "");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({}), "; ", " or "), "");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a"}), "; ", " or "), "a");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a"}), "; ", " or "), "a");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b"}), "; ", " or "), "a or b");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b"}), "; ", " or "), "a or b");
|
||||||
BOOST_CHECK_EQUAL(joinHumanReadable(vector<string>({"a", "b", "c"}), "; ", " or "), "a; b or c");
|
BOOST_CHECK_EQUAL(joinHumanReadable(std::vector<std::string>({"a", "b", "c"}), "; ", " or "), "a; b or c");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_format_number_readable)
|
BOOST_AUTO_TEST_CASE(test_format_number_readable)
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -37,12 +36,12 @@ BOOST_AUTO_TEST_SUITE(SwarmHash, *boost::unit_test::label("nooptions"))
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
string bzzr0HashHex(string const& _input)
|
std::string bzzr0HashHex(std::string const& _input)
|
||||||
{
|
{
|
||||||
return toHex(bzzr0Hash(_input).asBytes());
|
return toHex(bzzr0Hash(_input).asBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
string bzzr1HashHex(bytes const& _input)
|
std::string bzzr1HashHex(bytes const& _input)
|
||||||
{
|
{
|
||||||
return toHex(bzzr1Hash(_input).asBytes());
|
return toHex(bzzr1Hash(_input).asBytes());
|
||||||
}
|
}
|
||||||
@ -59,17 +58,17 @@ bytes sequence(size_t _length)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_zeros)
|
BOOST_AUTO_TEST_CASE(test_zeros)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string()), string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string()), std::string("011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x1000 - 1, 0)), string("32f0faabc4265ac238cd945087133ce3d7e9bb2e536053a812b5373c54043adb"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x1000 - 1, 0)), std::string("32f0faabc4265ac238cd945087133ce3d7e9bb2e536053a812b5373c54043adb"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x1000, 0)), string("411dd45de7246e94589ff5888362c41e85bd3e582a92d0fda8f0e90b76439bec"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x1000, 0)), std::string("411dd45de7246e94589ff5888362c41e85bd3e582a92d0fda8f0e90b76439bec"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x1000 + 1, 0)), string("69754a0098432bbc2e84fe1205276870748a61a065ab6ef44d6a2e7b13ce044d"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x1000 + 1, 0)), std::string("69754a0098432bbc2e84fe1205276870748a61a065ab6ef44d6a2e7b13ce044d"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x2000 - 1, 0)), string("69ad3c581043404f775ffa8d6f1b25ad4a9ee812971190e90209c0966116a321"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x2000 - 1, 0)), std::string("69ad3c581043404f775ffa8d6f1b25ad4a9ee812971190e90209c0966116a321"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x2000, 0)), string("f00222373ff82d0a178dc6271c78953e9c88f74130a52d401f5ec51475f63c43"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x2000, 0)), std::string("f00222373ff82d0a178dc6271c78953e9c88f74130a52d401f5ec51475f63c43"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x2000 + 1, 0)), string("86d6773e79e02fd8145ee1aedba89ace0c15f2566db1249654000039a9a134bf"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x2000 + 1, 0)), std::string("86d6773e79e02fd8145ee1aedba89ace0c15f2566db1249654000039a9a134bf"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x80000, 0)), string("cc0854fe2c6b98e920d5c14b1a88e6d4223e55b8f78883f60939aa2485e361bf"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x80000, 0)), std::string("cc0854fe2c6b98e920d5c14b1a88e6d4223e55b8f78883f60939aa2485e361bf"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x80020, 0)), string("ee9ffca246e70d3704740ba4df450fa6988d14a1c2439c7e734c7a77a4eb6fd3"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x80020, 0)), std::string("ee9ffca246e70d3704740ba4df450fa6988d14a1c2439c7e734c7a77a4eb6fd3"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(0x800020, 0)), string("78b90b20c90559fb904535181a7c28929ea2f30a2329dbc25232de579709f12f"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(0x800020, 0)), std::string("78b90b20c90559fb904535181a7c28929ea2f30a2329dbc25232de579709f12f"));
|
||||||
BOOST_CHECK_EQUAL(bzzr0HashHex(string(2095104, 0)), string("a9958184589fc11b4027a4c233e777ebe2e99c66f96b74aef2a0638a94dd5439"));
|
BOOST_CHECK_EQUAL(bzzr0HashHex(std::string(2095104, 0)), std::string("a9958184589fc11b4027a4c233e777ebe2e99c66f96b74aef2a0638a94dd5439"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(bzz_hash_short)
|
BOOST_AUTO_TEST_CASE(bzz_hash_short)
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace boost::test_tools;
|
using namespace boost::test_tools;
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
@ -58,8 +57,8 @@ BOOST_AUTO_TEST_CASE(TemporaryDirectory_should_delete_its_directory_even_if_not_
|
|||||||
BOOST_TEST(boost::filesystem::is_directory(dirPath));
|
BOOST_TEST(boost::filesystem::is_directory(dirPath));
|
||||||
|
|
||||||
{
|
{
|
||||||
ofstream tmpFile((dirPath / "test-file.txt").string());
|
std::ofstream tmpFile((dirPath / "test-file.txt").string());
|
||||||
tmpFile << "Delete me!" << endl;
|
tmpFile << "Delete me!" << std::endl;
|
||||||
}
|
}
|
||||||
soltestAssert(boost::filesystem::is_regular_file(dirPath / "test-file.txt"), "");
|
soltestAssert(boost::filesystem::is_regular_file(dirPath / "test-file.txt"), "");
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -35,13 +34,13 @@ BOOST_AUTO_TEST_SUITE(UTF8, *boost::unit_test::label("nooptions"))
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool isValidUTF8(string const& _value)
|
bool isValidUTF8(std::string const& _value)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
return validateUTF8(asString(fromHex(_value)), pos);
|
return validateUTF8(asString(fromHex(_value)), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInvalidUTF8(string const& _value, size_t _expectedPos)
|
bool isInvalidUTF8(std::string const& _value, size_t _expectedPos)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
if (validateUTF8(asString(fromHex(_value)), pos))
|
if (validateUTF8(asString(fromHex(_value)), pos))
|
||||||
@ -94,7 +93,7 @@ BOOST_AUTO_TEST_CASE(invalid)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(corpus)
|
BOOST_AUTO_TEST_CASE(corpus)
|
||||||
{
|
{
|
||||||
string source = R"(
|
std::string source = R"(
|
||||||
κόσμε
|
κόσμε
|
||||||
|
|
||||||
hélló
|
hélló
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace solidity::util::test
|
namespace solidity::util::test
|
||||||
{
|
{
|
||||||
@ -34,14 +33,14 @@ BOOST_AUTO_TEST_SUITE(WhiskersTest, *boost::unit_test::label("nooptions"))
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(no_templates)
|
BOOST_AUTO_TEST_CASE(no_templates)
|
||||||
{
|
{
|
||||||
string templ = "this text does not contain templates";
|
std::string templ = "this text does not contain templates";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ).render(), templ);
|
BOOST_CHECK_EQUAL(Whiskers(templ).render(), templ);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(basic_replacement)
|
BOOST_AUTO_TEST_CASE(basic_replacement)
|
||||||
{
|
{
|
||||||
string templ = "a <b> x <c> -> <d>.";
|
std::string templ = "a <b> x <c> -> <d>.";
|
||||||
string result = Whiskers(templ)
|
std::string result = Whiskers(templ)
|
||||||
("b", "BE")
|
("b", "BE")
|
||||||
("c", "CE")
|
("c", "CE")
|
||||||
("d", "DE")
|
("d", "DE")
|
||||||
@ -51,43 +50,43 @@ BOOST_AUTO_TEST_CASE(basic_replacement)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(tag_unavailable)
|
BOOST_AUTO_TEST_CASE(tag_unavailable)
|
||||||
{
|
{
|
||||||
string templ = "<b>";
|
std::string templ = "<b>";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(list_unavailable)
|
BOOST_AUTO_TEST_CASE(list_unavailable)
|
||||||
{
|
{
|
||||||
string templ = "<#b></b>";
|
std::string templ = "<#b></b>";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_type_collision)
|
BOOST_AUTO_TEST_CASE(name_type_collision)
|
||||||
{
|
{
|
||||||
string templ = "<b><#b></b>";
|
std::string templ = "<b><#b></b>";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
m("b", "x");
|
m("b", "x");
|
||||||
BOOST_CHECK_THROW(m("b", vector<map<string, string>>{}), WhiskersError);
|
BOOST_CHECK_THROW(m("b", std::vector<std::map<std::string, std::string>>{}), WhiskersError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(conditional)
|
BOOST_AUTO_TEST_CASE(conditional)
|
||||||
{
|
{
|
||||||
string templ = "<?b>X</b>";
|
std::string templ = "<?b>X</b>";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X");
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(conditional_with_else)
|
BOOST_AUTO_TEST_CASE(conditional_with_else)
|
||||||
{
|
{
|
||||||
string templ = "<?b>X<!b>Y</b>";
|
std::string templ = "<?b>X<!b>Y</b>";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X");
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "Y");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "Y");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(broken_conditional_with_else)
|
BOOST_AUTO_TEST_CASE(broken_conditional_with_else)
|
||||||
{
|
{
|
||||||
string templ = "<?b>X<!bY</b>";
|
std::string templ = "<?b>X<!bY</b>";
|
||||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||||
|
|
||||||
templ = "<?bX<!b>Y</b>";
|
templ = "<?bX<!b>Y</b>";
|
||||||
@ -99,7 +98,7 @@ BOOST_AUTO_TEST_CASE(broken_conditional_with_else)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(broken_conditional_value_with_else)
|
BOOST_AUTO_TEST_CASE(broken_conditional_value_with_else)
|
||||||
{
|
{
|
||||||
string templ = "<?+b>X<!+bY</+b>";
|
std::string templ = "<?+b>X<!+bY</+b>";
|
||||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||||
|
|
||||||
templ = "<?+bX<!+b>Y</+b>";
|
templ = "<?+bX<!+b>Y</+b>";
|
||||||
@ -111,7 +110,7 @@ BOOST_AUTO_TEST_CASE(broken_conditional_value_with_else)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(broken_list_parameter)
|
BOOST_AUTO_TEST_CASE(broken_list_parameter)
|
||||||
{
|
{
|
||||||
string templ = "<#b><a></b";
|
std::string templ = "<#b><a></b";
|
||||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||||
|
|
||||||
templ = "<#b<a></b>";
|
templ = "<#b<a></b>";
|
||||||
@ -120,7 +119,7 @@ BOOST_AUTO_TEST_CASE(broken_list_parameter)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(conditional_plus_params)
|
BOOST_AUTO_TEST_CASE(conditional_plus_params)
|
||||||
{
|
{
|
||||||
string templ = " - <?b>_<r><!b>^<t></b> - ";
|
std::string templ = " - <?b>_<r><!b>^<t></b> - ";
|
||||||
Whiskers m1(templ);
|
Whiskers m1(templ);
|
||||||
m1("b", true);
|
m1("b", true);
|
||||||
m1("r", "R");
|
m1("r", "R");
|
||||||
@ -136,10 +135,10 @@ BOOST_AUTO_TEST_CASE(conditional_plus_params)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(conditional_plus_list)
|
BOOST_AUTO_TEST_CASE(conditional_plus_list)
|
||||||
{
|
{
|
||||||
string templ = " - <?b>_<#l><x></l><!b><#l><y></l></b> - ";
|
std::string templ = " - <?b>_<#l><x></l><!b><#l><y></l></b> - ";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
m("b", false);
|
m("b", false);
|
||||||
vector<map<string, string>> list(2);
|
std::vector<std::map<std::string, std::string>> list(2);
|
||||||
list[0]["x"] = "1";
|
list[0]["x"] = "1";
|
||||||
list[0]["y"] = "a";
|
list[0]["y"] = "a";
|
||||||
list[1]["x"] = "2";
|
list[1]["x"] = "2";
|
||||||
@ -150,21 +149,21 @@ BOOST_AUTO_TEST_CASE(conditional_plus_list)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(string_as_conditional)
|
BOOST_AUTO_TEST_CASE(string_as_conditional)
|
||||||
{
|
{
|
||||||
string templ = "<?+b>+<b><!+b>-</+b>";
|
std::string templ = "<?+b>+<b><!+b>-</+b>";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "abc").render(), "+abc");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "abc").render(), "+abc");
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "").render(), "-");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "").render(), "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(string_as_conditional_wrong)
|
BOOST_AUTO_TEST_CASE(string_as_conditional_wrong)
|
||||||
{
|
{
|
||||||
string templ = "<?+b>+<b></b>";
|
std::string templ = "<?+b>+<b></b>";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "abc").render(), "<?+b>+abc</b>");
|
BOOST_CHECK_EQUAL(Whiskers(templ)("b", "abc").render(), "<?+b>+abc</b>");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(complicated_replacement)
|
BOOST_AUTO_TEST_CASE(complicated_replacement)
|
||||||
{
|
{
|
||||||
string templ = "a <b> x <complicated> \n <nested>>.";
|
std::string templ = "a <b> x <complicated> \n <nested>>.";
|
||||||
string result = Whiskers(templ)
|
std::string result = Whiskers(templ)
|
||||||
("b", "BE")
|
("b", "BE")
|
||||||
("complicated", "CO<M>PL")
|
("complicated", "CO<M>PL")
|
||||||
("nested", "NEST")
|
("nested", "NEST")
|
||||||
@ -174,53 +173,53 @@ BOOST_AUTO_TEST_CASE(complicated_replacement)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(non_existing_list)
|
BOOST_AUTO_TEST_CASE(non_existing_list)
|
||||||
{
|
{
|
||||||
string templ = "a <#b></b>";
|
std::string templ = "a <#b></b>";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
BOOST_CHECK_THROW(m.render(), WhiskersError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(empty_list)
|
BOOST_AUTO_TEST_CASE(empty_list)
|
||||||
{
|
{
|
||||||
string templ = "a <#b></b>x";
|
std::string templ = "a <#b></b>x";
|
||||||
string result = Whiskers(templ)("b", vector<Whiskers::StringMap>{}).render();
|
std::string result = Whiskers(templ)("b", std::vector<Whiskers::StringMap>{}).render();
|
||||||
BOOST_CHECK_EQUAL(result, "a x");
|
BOOST_CHECK_EQUAL(result, "a x");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(list)
|
BOOST_AUTO_TEST_CASE(list)
|
||||||
{
|
{
|
||||||
string templ = "a<#b>( <g> - <h> )</b>x";
|
std::string templ = "a<#b>( <g> - <h> )</b>x";
|
||||||
vector<map<string, string>> list(2);
|
std::vector<std::map<std::string, std::string>> list(2);
|
||||||
list[0]["g"] = "GE";
|
list[0]["g"] = "GE";
|
||||||
list[0]["h"] = "H";
|
list[0]["h"] = "H";
|
||||||
list[1]["g"] = "2GE";
|
list[1]["g"] = "2GE";
|
||||||
list[1]["h"] = "2H";
|
list[1]["h"] = "2H";
|
||||||
string result = Whiskers(templ)("b", list).render();
|
std::string result = Whiskers(templ)("b", list).render();
|
||||||
BOOST_CHECK_EQUAL(result, "a( GE - H )( 2GE - 2H )x");
|
BOOST_CHECK_EQUAL(result, "a( GE - H )( 2GE - 2H )x");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(recursive_list)
|
BOOST_AUTO_TEST_CASE(recursive_list)
|
||||||
{
|
{
|
||||||
// Check that templates resulting from lists are not expanded again
|
// Check that templates resulting from lists are not expanded again
|
||||||
string templ = "a<#b> 1<g>3 </b><x>";
|
std::string templ = "a<#b> 1<g>3 </b><x>";
|
||||||
vector<map<string, string>> list(1);
|
std::vector<std::map<std::string, std::string>> list(1);
|
||||||
list[0]["g"] = "<x>";
|
list[0]["g"] = "<x>";
|
||||||
string result = Whiskers(templ)("x", "X")("b", list).render();
|
std::string result = Whiskers(templ)("x", "X")("b", list).render();
|
||||||
BOOST_CHECK_EQUAL(result, "a 1<x>3 X");
|
BOOST_CHECK_EQUAL(result, "a 1<x>3 X");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(list_can_access_upper)
|
BOOST_AUTO_TEST_CASE(list_can_access_upper)
|
||||||
{
|
{
|
||||||
string templ = "<#b>(<a>)</b>";
|
std::string templ = "<#b>(<a>)</b>";
|
||||||
vector<map<string, string>> list(2);
|
std::vector<std::map<std::string, std::string>> list(2);
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
string result = m("a", "A")("b", list).render();
|
std::string result = m("a", "A")("b", list).render();
|
||||||
BOOST_CHECK_EQUAL(result, "(A)(A)");
|
BOOST_CHECK_EQUAL(result, "(A)(A)");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(parameter_collision)
|
BOOST_AUTO_TEST_CASE(parameter_collision)
|
||||||
{
|
{
|
||||||
string templ = "a <#b></b>";
|
std::string templ = "a <#b></b>";
|
||||||
vector<map<string, string>> list(1);
|
std::vector<std::map<std::string, std::string>> list(1);
|
||||||
list[0]["a"] = "x";
|
list[0]["a"] = "x";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_THROW(m("a", "X")("b", list), WhiskersError);
|
BOOST_CHECK_THROW(m("a", "X")("b", list), WhiskersError);
|
||||||
@ -229,14 +228,14 @@ BOOST_AUTO_TEST_CASE(parameter_collision)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(invalid_param)
|
BOOST_AUTO_TEST_CASE(invalid_param)
|
||||||
{
|
{
|
||||||
string templ = "a <b >";
|
std::string templ = "a <b >";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_THROW(m("b ", "X"), WhiskersError);
|
BOOST_CHECK_THROW(m("b ", "X"), WhiskersError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(invalid_param_rendered)
|
BOOST_AUTO_TEST_CASE(invalid_param_rendered)
|
||||||
{
|
{
|
||||||
string templ = "a <b >";
|
std::string templ = "a <b >";
|
||||||
Whiskers m(templ);
|
Whiskers m(templ);
|
||||||
BOOST_CHECK_EQUAL(m.render(), templ);
|
BOOST_CHECK_EQUAL(m.render(), templ);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user