24 lines
3.1 KiB
C++
24 lines
3.1 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "modern/content/toto_quote.hpp"
|
|
#include "modern/content/ui_contract.hpp"
|
|
#include "formats/executable_layout.hpp"
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace bmh;using namespace bmh::modern;
|
|
namespace {
|
|
using J=cli::Json;using O=J::Object;using A=J::Array;
|
|
const J& at(const J& v,const char* key){return v.object()->at(key);}
|
|
void check(bool yes,const char* why){if(!yes)throw std::runtime_error(why);}
|
|
J draft(int stake,int count){A rows;for(int c=0;c<count;++c){A row;for(int r=0;r<11;++r)row.push_back(r==c?0:1);rows.push_back(row);}return O{{"stake",ui_money(stake)},{"columns",rows}};}
|
|
std::string error(const J& q){return at(q,"errorCode").string()?*at(q,"errorCode").string():"";}
|
|
}
|
|
int main()try{
|
|
ModernState g;g.manager_teams={0};g.manager_records.assign(0xb0c,0);g.memory.add_block(::bmh::layout::Coupon,5*0x14);g.memory.add_block(::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField,44);g.memory.add_block(::bmh::layout::CareerSession_DispatchToto_RuntimeField,1);g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField,11);
|
|
const auto q=quote_toto_draft(g,0,draft(50000,3));check(at(q,"allowed").boolean()&&*at(q,"allowed").boolean(),"valid three-column quote rejected");check(*at(at(q,"cost"),"minor").string()=="16000000"&&*at(at(q,"fee"),"minor").string()=="1000000","quote does not use existing total/fee rules");check(g.pools.empty()&&g.memory.u32(::bmh::layout::Coupon)==0,"preview registered a coupon");
|
|
check(error(quote_toto_draft(g,0,draft(9999,1)))=="stake_out_of_range","low stake accepted");check(error(quote_toto_draft(g,0,draft(100000,5)))=="total_stake_too_high","principal limit missed");check(error(quote_toto_draft(g,0,draft(10000,7)))=="too_many_columns","column limit missed");
|
|
auto duplicate=draft(50000,2);auto &rows=std::get<A>(std::get<O>(duplicate.value).at("columns").value);rows[1]=rows[0];check(error(quote_toto_draft(g,0,duplicate))=="duplicate_column","duplicate columns accepted");
|
|
auto bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["currency"]="USD";check(!parse_toto_draft(bad),"wrong currency accepted");bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["minor"]="1000000garbage";check(!parse_toto_draft(bad),"partial money parsed");bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["minor"]="1000001";check(!parse_toto_draft(bad),"fractional euro accepted");
|
|
const auto clear=quote_toto_draft(g,0,draft(0,0));check(*at(clear,"allowed").boolean()&&*at(clear,"clearing").boolean()&&*at(at(clear,"cost"),"minor").string()=="0","withdrawal does not follow existing clear path");check(!parse_toto_draft(draft(0,1)),"zero stake with tips accepted");g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField,9);check(error(quote_toto_draft(g,0,draft(10000,1)))=="toto_coupon_requires_eleven_matches","closed programme accepted");
|
|
std::cout<<"Toto preview: real rules, fee, duplicate columns, strict money, clear and read purity passed\n";return 0;
|
|
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
|