int main(int argc, char** argv){ int g[] = { 2}; int c[] = { 2}; vector<int> gas(g, g + sizeof(g) / sizeof(int)); vector<int> cost(c, c + sizeof(c) / sizeof(int)); Solution s; int id = s.canCompleteCircuit(gas, cost); cout << ((id == -1) ? string("CANNOT! ") : string("Can ")) << id << endl; return 0; }
QVariant MoveProfileCommand::operator()(const QVariantMap &request) { if(!request.contains("uri")||!request.contains("context")||!request.contains("id")||!request.contains("password")) { return QVariant::fromValue(false); } BitProfileStore::Iterator it = _store.find(request["uri"].toString()); if(it==_store.end()) { return QVariant::fromValue(false); } BitProfile::ProfileDescriptor descriptor = *it; BitProfile::ProfileAdministrator admin = BitProfile::ProfileAdministrator::FromDescriptor(_provider, descriptor); BitProfile::Resolver resolver(_provider, GetBitprofileNetwork(_settings)); BitProfile::Registrar registrar = resolver.lookupRegistrar(request["context"].toString().toStdString()); if(registrar.isNull()) { return QVariant::fromValue(false); } BigInt price(request.contains("price") ? request["price"].toString().toStdString(): "0"); admin.setGasPrice(price); registrar.setGasPrice(price); std::string name = request["id"].toString().toStdString(); std::string password = request["password"].toString().toStdString(); BigInt gas(request.contains("gas")?request["gas"].toString().toStdString():"0"); BitProfile::Profile::URI uri(registrar.getURI(), name); if(!admin.move(registrar, name, password, gas)) { return QVariant::fromValue(false); } else { if(!_store.rename(admin.getProfile().getURI(), uri)) { return QVariant::fromValue(false); } } return QVariant::fromValue(QString(uri.toString().c_str())); }
int main(int argc, const char *argv[]) { slll::Parser p("square(a) { return a * a } pow(a, b) { result := 1 while b > 0 { result = result * a b = b - 1 } return result } main() { print_int(square(1337)) print_nl() print_int(pow(5, 3)) print_nl() print2(5, 3) } "); auto tree = p.Parse(); std::ofstream file; file.open("out.S"); slll::GASVisitor gas(file); //slll::GASVisitor gas(std::cout); tree->AcceptVisitor(&gas); file.close(); std::system("pause"); return 0; }
void doVMTests(json_spirit::mValue& v, bool _fillin) { processCommandLineOptions(); for (auto& i: v.get_obj()) { cnote << i.first; mObject& o = i.second.get_obj(); BOOST_REQUIRE(o.count("env") > 0); BOOST_REQUIRE(o.count("pre") > 0); BOOST_REQUIRE(o.count("exec") > 0); FakeExtVM fev; fev.importEnv(o["env"].get_obj()); fev.importState(o["pre"].get_obj()); if (_fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode; } bytes output; u256 gas; bool vmExceptionOccured = false; auto startTime = std::chrono::high_resolution_clock::now(); try { auto vm = eth::VMFactory::create(fev.gas); output = vm->go(fev, fev.simpleTrace()).toBytes(); gas = vm->gas(); } catch (VMException const& _e) { cnote << "Safe VM Exception"; vmExceptionOccured = true; } catch (Exception const& _e) { cnote << "VM did throw an exception: " << diagnostic_information(_e); BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); } catch (std::exception const& _e) { cnote << "VM did throw an exception: " << _e.what(); BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); } auto endTime = std::chrono::high_resolution_clock::now(); auto argc = boost::unit_test::framework::master_test_suite().argc; auto argv = boost::unit_test::framework::master_test_suite().argv; for (auto i = 0; i < argc; ++i) { if (std::string(argv[i]) == "--show-times") { auto testDuration = endTime - startTime; cnote << "Execution time: " << std::chrono::duration_cast<std::chrono::milliseconds>(testDuration).count() << " ms"; break; } } // delete null entries in storage for the sake of comparison for (auto &a: fev.addresses) { vector<u256> keystoDelete; for (auto &s: get<2>(a.second)) { if (s.second == 0) keystoDelete.push_back(s.first); } for (auto const key: keystoDelete ) { get<2>(a.second).erase(key); } } if (_fillin) { o["env"] = mValue(fev.exportEnv()); o["exec"] = mValue(fev.exportExec()); if (!vmExceptionOccured) { o["post"] = mValue(fev.exportState()); o["callcreates"] = fev.exportCallCreates(); o["out"] = "0x" + toHex(output); fev.push(o, "gas", gas); o["logs"] = exportLog(fev.sub.logs); } } else { if (o.count("post") > 0) // No exceptions expected { BOOST_CHECK(!vmExceptionOccured); BOOST_REQUIRE(o.count("post") > 0); BOOST_REQUIRE(o.count("callcreates") > 0); BOOST_REQUIRE(o.count("out") > 0); BOOST_REQUIRE(o.count("gas") > 0); BOOST_REQUIRE(o.count("logs") > 0); dev::test::FakeExtVM test; test.importState(o["post"].get_obj()); test.importCallCreates(o["callcreates"].get_array()); test.sub.logs = importLog(o["logs"].get_array()); checkOutput(output, o); BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); auto& expectedAddrs = test.addresses; auto& resultAddrs = fev.addresses; for (auto&& expectedPair : expectedAddrs) { auto& expectedAddr = expectedPair.first; auto resultAddrIt = resultAddrs.find(expectedAddr); if (resultAddrIt == resultAddrs.end()) BOOST_ERROR("Missing expected address " << expectedAddr); else { auto& expectedState = expectedPair.second; auto& resultState = resultAddrIt->second; BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState)); BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState)); BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code"); checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr); } } checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses); BOOST_CHECK(test.callcreates == fev.callcreates); checkLog(fev.sub.logs, test.sub.logs); } else // Exception expected BOOST_CHECK(vmExceptionOccured); } } }