Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

backendTest.ts 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. import { Injector } from "../src/backend/Injector/Injector";
  2. import { FrontworkAdmin } from "../src/backend/Admin/Admin";
  3. import { T2, Tiers } from "../src/backend/Types/Items";
  4. import { RPCSocket, ConnectedSocket } from "rpclibrary";
  5. import { FrontcraftIfc, Auth, User, FrontcraftFeatureIfc, Raid, Character, Rank, Class, Race, Spec, Signup } from "../src/backend/Types/Types";
  6. import { SpecT } from "../src/backend/Types/PlayerSpecs";
  7. import { ItemManager } from "src/backend/Components/Item/ItemManager";
  8. type protoAccount<C extends Class = Class> = {
  9. name: string,
  10. pwHash?: string
  11. rank: Rank,
  12. race: Race,
  13. class: C,
  14. spec: SpecT[C]
  15. }
  16. const trialsAndUp = {
  17. ADMIN: true,
  18. Guildmaster: true,
  19. Officer: true,
  20. Classleader: true,
  21. Raider: true,
  22. Trial: true,
  23. Social: false,
  24. Guest: false
  25. }
  26. const adminsOnly = {
  27. ADMIN: true,
  28. Guildmaster: true,
  29. Officer: true,
  30. Classleader: false,
  31. Raider: false,
  32. Trial: false,
  33. Social: false,
  34. Guest: false
  35. }
  36. const defaultPermissions = [
  37. {
  38. rpcname: 'signup', ...trialsAndUp
  39. }, {
  40. rpcname: 'reset', ...adminsOnly
  41. }, {
  42. rpcname: 'modifyPermissions', ...adminsOnly
  43. }, {
  44. rpcname: 'manageGuild', ...adminsOnly
  45. }, {
  46. rpcname: 'managePriorities', ...adminsOnly
  47. }, {
  48. rpcname: 'softreserveCurrency', ...adminsOnly
  49. }, {
  50. rpcname: 'manageRaid', ...adminsOnly
  51. }, {
  52. rpcname: 'manageUser', ...adminsOnly
  53. }]
  54. const testAccounts: protoAccount[] = [
  55. {
  56. name: 'Rain',
  57. race: 'Human',
  58. class: 'Warrior',
  59. spec: 'Protection',
  60. rank: 'Guildmaster'
  61. }, {
  62. name: 'Celinda',
  63. class: 'Warrior',
  64. race: 'Night Elf',
  65. spec: 'Protection',
  66. rank: 'Officer'
  67. }, {
  68. name: 'Silver',
  69. class: 'Druid',
  70. race: 'Night Elf',
  71. spec: 'Restoration',
  72. rank: 'Trial'
  73. }, {
  74. name: 'Dagger',
  75. race: 'Dwarf',
  76. class: 'Rogue',
  77. spec: 'Assassination',
  78. rank: 'Classleader'
  79. }, {
  80. name: 'Hope',
  81. class: 'Paladin',
  82. race: 'Human',
  83. spec: 'Holy',
  84. rank: 'Classleader'
  85. }, {
  86. name: 'Shrekd',
  87. class: 'Warrior',
  88. race: 'Dwarf',
  89. spec: 'Fury',
  90. rank: 'Classleader'
  91. }, {
  92. name: 'Teeniweeni',
  93. class: 'Warlock',
  94. race: 'Gnome',
  95. spec: 'Demonology',
  96. rank: 'Classleader'
  97. }, {
  98. name: 'Hagibaba',
  99. class: 'Priest',
  100. race: 'Human',
  101. spec: 'Discipline',
  102. rank: 'Classleader'
  103. }, {
  104. name: 'Muffinbreak',
  105. class: 'Mage',
  106. race: 'Gnome',
  107. spec: 'Arcane',
  108. rank: 'Classleader'
  109. },
  110. ]
  111. describe('Frontcraft', () => {
  112. let auth: Auth,
  113. adminUser: User,
  114. server: FrontworkAdmin,
  115. client: ConnectedSocket<FrontcraftIfc>,
  116. adminClient: ConnectedSocket<FrontcraftFeatureIfc>,
  117. raids: Raid[] = [],
  118. users: { [username in string]: { account: User, character: Character, auth: Auth, signup?: Signup, item?: string } } = {}
  119. const createAccount = (user: User) => {
  120. return client.UserManager.createUser(user)
  121. }
  122. const createAccountAndUser = async (acc: protoAccount) => {
  123. const account = await createAccount({
  124. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //sha256("a")
  125. rank: acc.rank,
  126. username: acc.name,
  127. })
  128. const auth = await client.UserManager.login(acc.name, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
  129. const id = await client.CharacterManager.getSpecId(acc.class, acc.spec)
  130. const char = await client.CharacterManager.createCharacter(auth.token.value, {
  131. charactername: acc.name,
  132. specid: id,
  133. userid: account.id!,
  134. race: acc.race
  135. })
  136. return {
  137. account: account,
  138. character: char,
  139. auth: auth
  140. }
  141. }
  142. before(function (done) {
  143. this.timeout(10000);
  144. server = Injector.resolve<FrontworkAdmin>(FrontworkAdmin)
  145. server.start().then((_server) => {
  146. RPCSocket.makeSocket<FrontcraftIfc>(20000, 'localhost').then(_client => {
  147. client = _client
  148. createAccount({
  149. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //hash("a")
  150. rank: 'ADMIN',
  151. username: 'a',
  152. MC: 2
  153. }).then(adminUser => {
  154. client.UserManager.login(adminUser.username, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb').then(auth => {
  155. const sock = new RPCSocket<FrontcraftFeatureIfc>(
  156. auth.port,
  157. "localhost"
  158. )
  159. sock.connect(auth.token.value).then(cli => {
  160. adminClient = cli
  161. sock.hook('kick', () => {
  162. console.log("I got kicked");
  163. })
  164. sock.hook('getUserData', () => auth)
  165. sock.hook('navigate', (where: string) => {
  166. console.log("Nagivate client to " + where);
  167. })
  168. sock.on('error', (e) => {
  169. console.log('Socket error', e)
  170. })
  171. done()
  172. })
  173. })
  174. })
  175. })
  176. }).catch(done)
  177. })
  178. after(() => {
  179. client.close()
  180. adminClient.close()
  181. server.stop()
  182. })
  183. it('can set permissions', (done) => {
  184. Promise.all(
  185. defaultPermissions.map(perm => adminClient.modifyPermissions.setPermission(perm)),
  186. ).then(_ => {
  187. done()
  188. })
  189. })
  190. it('create raids', (done) => {
  191. let insertRaid = <Raid>{
  192. description: "Test raid 1",
  193. title: 'BWL :D',
  194. start: Date.now().toString(),
  195. tier: 'BWL'
  196. }
  197. adminClient.manageRaid.createRaid(insertRaid).then(() => {
  198. client.RaidManager.getRaids().then((r) => {
  199. if (r[0].title === insertRaid.title
  200. && r[0].description === insertRaid.description
  201. && r[0].tier === "BWL") {
  202. raids.push(r[0])
  203. done()
  204. }
  205. }).catch(done)
  206. }).catch(done)
  207. })
  208. it('create users', (done) => {
  209. Promise.all(testAccounts.map(acc => createAccountAndUser(acc))).then(accs => {
  210. if (accs.length === testAccounts.length) {
  211. accs.forEach(acc => {
  212. users[acc.account.username] = acc
  213. })
  214. done()
  215. }
  216. }).catch(done)
  217. })
  218. it('should sign up', (done) => {
  219. Promise.all(Object.values(users).map((user) =>
  220. adminClient.signup.sign(user.auth.token.value, user.character, raids[0], false, true, ""+Math.floor(Math.random()*10000)).catch(done)
  221. )).then(_ => {
  222. adminClient.signup.getSignups(raids[0]).then(s => {
  223. if (s.length == testAccounts.length) {
  224. s.forEach(sign => {
  225. users[sign.username].signup = sign
  226. })
  227. done()
  228. } else {
  229. done("Unexpected number of signups: " + s.length)
  230. }
  231. })
  232. })
  233. })
  234. it('calculate priorities', (done) => {
  235. const makePrio = async (itemname: string, spec?: Spec, race?: Race, mod: number = 0, description: string = "") => {
  236. let specid
  237. if (spec)
  238. specid = await client.CharacterManager.getSpecId(spec.class, <any>spec.specname)
  239. await adminClient.managePriorities.setPriority(itemname, {
  240. specid: specid,
  241. race: race,
  242. modifier: mod,
  243. description: description
  244. })
  245. }
  246. Promise.all([
  247. makePrio(
  248. 'Quick Strike Ring',
  249. { class: 'Warrior', specname: 'Fury' },
  250. undefined, 2, "str-to-ap bias"
  251. ),
  252. makePrio(
  253. 'Quick Strike Ring',
  254. { class: 'Druid', specname: 'Feral (DPS)' },
  255. undefined, 2, "str-to-ap bias"
  256. ),
  257. makePrio(
  258. 'Bracers of Arcane Accuracy',
  259. { class: 'Warlock', specname: 'Demonology' },
  260. undefined, 2, "hit bias"
  261. ),
  262. makePrio(
  263. 'Bracers of Arcane Accuracy',
  264. { class: 'Warlock', specname: 'Affliction' },
  265. undefined, 2, "hit bias"
  266. ),
  267. makePrio(
  268. 'Bracers of Arcane Accuracy',
  269. { class: 'Warlock', specname: 'Destruction' },
  270. undefined, 2, "hit bias"
  271. ),
  272. makePrio(
  273. 'Bracers of Arcane Accuracy',
  274. { class: 'Mage', specname: 'Arcane' },
  275. undefined, 1, "hit bias"
  276. ),
  277. makePrio(
  278. 'Bracers of Arcane Accuracy',
  279. { class: 'Mage', specname: 'Frost' },
  280. undefined, 1, "hit bias"
  281. ),
  282. makePrio(
  283. 'Bracers of Arcane Accuracy',
  284. { class: 'Mage', specname: 'Fire' },
  285. undefined, 1, "hit bias"
  286. ),
  287. makePrio(
  288. 'Maladath, Runed Blade of the Black Flight',
  289. undefined,
  290. "Human", -2, "[1] Non-Human"
  291. ),
  292. makePrio(
  293. 'Maladath, Runed Blade of the Black Flight',
  294. { class: 'Rogue', specname: 'Combat' },
  295. undefined, 2, "Weapon skill bias"
  296. ),
  297. makePrio(
  298. 'Maladath, Runed Blade of the Black Flight',
  299. { class: 'Warrior', specname: 'Fury' },
  300. 'Human', 4, "+2 Fury Warrior (weapon skill bias), +2 to offset [1]"
  301. ),
  302. makePrio(
  303. 'Maladath, Runed Blade of the Black Flight',
  304. { class: 'Warrior', specname: 'Protection' },
  305. 'Human', 5, "+3 Prot Warrior, +2 to offset [1]"
  306. ),
  307. makePrio(
  308. 'Cloak of Firemaw',
  309. { class: 'Rogue', specname: 'Assassination' },
  310. undefined, 2, "agi-to-ap bias"
  311. ),
  312. makePrio(
  313. 'Cloak of Firemaw',
  314. { class: 'Rogue', specname: 'Combat' },
  315. undefined, 2, "agi-to-ap bias"
  316. ),
  317. makePrio(
  318. 'Cloak of Firemaw',
  319. { class: 'Rogue', specname: 'Subtlety' },
  320. undefined, 2, "agi-to-ap bias"
  321. ),
  322. makePrio(
  323. 'Band of Forced Concentration',
  324. { class: 'Warlock', specname: 'Demonology' },
  325. undefined, 2, "hit bias"
  326. ),
  327. makePrio(
  328. 'Band of Forced Concentration',
  329. { class: 'Warlock', specname: 'Affliction' },
  330. undefined, 2, "hit bias"
  331. ),
  332. makePrio(
  333. 'Band of Forced Concentration',
  334. { class: 'Warlock', specname: 'Destruction' },
  335. undefined, 2, "hit bias"
  336. ),
  337. makePrio(
  338. 'Band of Forced Concentration',
  339. { class: 'Mage', specname: 'Arcane' },
  340. undefined, 1, "hit bias"
  341. ),
  342. makePrio(
  343. 'Band of Forced Concentration',
  344. { class: 'Mage', specname: 'Frost' },
  345. undefined, 1, "hit bias"
  346. ),
  347. makePrio(
  348. 'Band of Forced Concentration',
  349. { class: 'Mage', specname: 'Fire' },
  350. undefined, 1, "hit bias"
  351. ),
  352. makePrio(
  353. 'Crul\'shorukh, Edge of Chaos',
  354. undefined,
  355. "Human", -2, "Non-human"
  356. ),
  357. makePrio(
  358. 'Crul\'shorukh, Edge of Chaos',
  359. { class: 'Warrior', specname: 'Fury' },
  360. undefined, 2, "nice dps bias"
  361. ),
  362. makePrio(
  363. 'Drake Talon Pauldrons',
  364. { class: 'Warrior', specname:'Protection'},
  365. undefined, 2, 'dodge + stats-to-threat bias'
  366. ),
  367. makePrio(
  368. 'Helm of Endless Rage',
  369. { class: 'Warrior', specname:'Protection'},
  370. undefined, 2, 'stats-to-threat bias'
  371. ),
  372. makePrio(
  373. 'Drake Fang Talisman',
  374. { class: 'Warrior', specname: 'Protection' },
  375. undefined, 5, "hit bias"
  376. ),
  377. makePrio(
  378. 'Drake Fang Talisman',
  379. { class: 'Rogue', specname: 'Assassination' },
  380. undefined, 4, "hit bias"
  381. ),
  382. makePrio(
  383. 'Drake Fang Talisman',
  384. { class: 'Rogue', specname: 'Combat' },
  385. undefined, 4, "hit bias"
  386. ),
  387. makePrio(
  388. 'Drake Fang Talisman',
  389. { class: 'Rogue', specname: 'Subtlety' },
  390. undefined, 4, "hit bias"
  391. ),
  392. makePrio(
  393. 'Drake Fang Talisman',
  394. { class: 'Warrior', specname: 'Fury' },
  395. undefined, 2, "hit bias"
  396. ),
  397. makePrio(
  398. 'Drake Fang Talisman',
  399. { class: 'Druid', specname: 'Feral (DPS)' },
  400. undefined, 2, "hit bias"
  401. ),
  402. makePrio(
  403. 'Circle of Applied Force',
  404. { class: 'Warrior', specname: 'Fury' },
  405. undefined, 2, "str-to-ap bias"
  406. ),
  407. makePrio(
  408. 'Circle of Applied Force',
  409. { class: 'Druid', specname: 'Feral (DPS)' },
  410. undefined, 3, "str-to-ap bias + agi-to-ap bias"
  411. ),
  412. makePrio(
  413. 'Empowered Leggings',
  414. { class: 'Paladin', specname: 'Holy' },
  415. undefined, 2, "crit bias"
  416. ),
  417. makePrio(
  418. 'Empowered Leggings',
  419. { class: 'Druid', specname: 'Restoration' },
  420. undefined, 2, "crit bias"
  421. ),
  422. makePrio(
  423. 'Boots of the Shadow Flame',
  424. { class: 'Rogue', specname: 'Assassination' },
  425. undefined, 2, "hit bias"
  426. ),
  427. makePrio(
  428. 'Boots of the Shadow Flame',
  429. { class: 'Rogue', specname: 'Combat' },
  430. undefined, 2, "hit bias"
  431. ),
  432. makePrio(
  433. 'Boots of the Shadow Flame',
  434. { class: 'Rogue', specname: 'Subtlety' },
  435. undefined, 2, "hit bias"
  436. ),
  437. makePrio(
  438. 'Boots of the Shadow Flame',
  439. { class: 'Druid', specname: 'Feral (DPS)' },
  440. undefined, 2, "hit bias"
  441. ),
  442. makePrio(
  443. 'Neltharion\'s Tear',
  444. { class: 'Warlock', specname: 'Demonology' },
  445. undefined, 4, "hit bias"
  446. ),
  447. makePrio(
  448. 'Neltharion\'s Tear',
  449. { class: 'Warlock', specname: 'Affliction' },
  450. undefined, 4, "hit bias"
  451. ),
  452. makePrio(
  453. 'Neltharion\'s Tear',
  454. { class: 'Warlock', specname: 'Destruction' },
  455. undefined, 4, "hit bias"
  456. ),
  457. makePrio(
  458. 'Neltharion\'s Tear',
  459. { class: 'Mage', specname: 'Arcane' },
  460. undefined, 2, "hit bias"
  461. ),
  462. makePrio(
  463. 'Neltharion\'s Tear',
  464. { class: 'Mage', specname: 'Frost' },
  465. undefined, 2, "hit bias"
  466. ),
  467. makePrio(
  468. 'Neltharion\'s Tear',
  469. { class: 'Mage', specname: 'Fire' },
  470. undefined, 2, "hit bias"
  471. ),
  472. makePrio(
  473. 'Cloak of Draconic Might',
  474. { class: 'Warrior', specname: 'Fury' },
  475. undefined, 2, "str-to-ap bias"
  476. ),
  477. makePrio(
  478. 'Cloak of Draconic Might',
  479. { class: 'Druid', specname: 'Feral (DPS)' },
  480. undefined, 3, "str-to-ap + agi-to-ap bias"
  481. ),
  482. ]).then(() => {
  483. const user = Object.values(users)[0]
  484. client.ItemManager.calculatePriorities("Maladath, Runed Blade of the Black Flight", user.character).then(sum => {
  485. if (sum === 3)
  486. done()
  487. else
  488. console.log("Expected prio on maladath to be 4, but was:", sum, user.character);
  489. })
  490. })
  491. })
  492. it('buy token', (done) => {
  493. Promise.all(Object.values(users).map(async (user) => {
  494. const itemname = "Maladath, Runed Blade of the Black Flight" //T1[Math.floor(T1.length*Math.random())]
  495. const modifier = await client.ItemManager.calculatePriorities(itemname, user.character)
  496. const token = await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  497. users[user.account.username].item = itemname
  498. if (!token) return false
  499. return modifier + 2 === token.level
  500. })).then(success => {
  501. if (success.reduce((prev, curr) => prev && curr, true)) done()
  502. })
  503. })
  504. it('not buy token without currency', (done) => {
  505. const user = Object.values(users)[0]
  506. const itemname = "Maladath, Runed Blade of the Black Flight"
  507. client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!).then(token => {
  508. if (!token)
  509. done()
  510. else {
  511. console.log("Unexpected token", token);
  512. }
  513. })
  514. })
  515. it('upgrade token', (done) => {
  516. const user = Object.values(users)[0]
  517. const itemname = "Maladath, Runed Blade of the Black Flight"
  518. client.ItemManager.getItem(itemname).then(async item => {
  519. await adminClient.softreserveCurrency.incrementCurrency(user.account, item!.tier, 2)
  520. const before = await client.ItemManager.getToken(user.character, item!)
  521. if (!before || before.level !== 5) {
  522. console.log("expected level to be 5", before ? before.level : '?');
  523. return
  524. }
  525. done()
  526. })
  527. })
  528. it('should buy more tokens', (done) => {
  529. Promise.all(Object.values(users).map(async (user) => {
  530. await adminClient.softreserveCurrency.incrementCurrency(user.account, raids[0].tier, 1)
  531. return await client.ItemManager
  532. .buyToken(
  533. user.auth.token.value,
  534. user.character.charactername,
  535. T2[Math.floor(T2.length * Math.random())],
  536. user.signup!
  537. )
  538. })).then(_ => {
  539. done()
  540. })
  541. })
  542. it('start raid', (done) => {
  543. client.RaidManager.getRaids().then((r) => {
  544. adminClient.manageRaid.startRaid(raids[0]).then(async data => {
  545. const dbRaids = await client.RaidManager.getRaids()
  546. if (dbRaids.length === 0) {
  547. await client.UserManager.getUser(testAccounts[0].name).then(dbUser => {
  548. if (dbUser && dbUser.BWL === 1) {
  549. adminClient.signup.getSignups(raids[0]).then(signups => {
  550. if (signups.length === 0) {
  551. done()
  552. } else {
  553. console.log(signups);
  554. }
  555. })
  556. }
  557. else {
  558. console.log("Bad user currency", dbUser);
  559. }
  560. })
  561. }
  562. })
  563. })
  564. })
  565. it('reset system', (done) => {
  566. adminClient.reset.wipeCurrencyAndItems().then(() => {
  567. client.UserManager.getUser(testAccounts[0].name).then(user => {
  568. if (user && user.MC === 1) {
  569. client.ItemManager.getTokens(users[testAccounts[0].name.toLowerCase()].character, ['BWL'], true).then(tokens => {
  570. if (tokens!.length === 0) {
  571. done()
  572. } else {
  573. console.log(tokens);
  574. }
  575. })
  576. } else {
  577. console.log(user)
  578. }
  579. })
  580. })
  581. })
  582. it('implements loot system correctly', (done) => {
  583. const ONE_WEEK = 4800000000
  584. const Raid = (week: number, tier: string) => {
  585. return <Raid>{
  586. description: tier + " Test raid 1",
  587. title: tier,
  588. start: (week * ONE_WEEK + Date.now()).toString(),
  589. tier: tier
  590. }
  591. }
  592. const user = Object.values(users)[0]
  593. const createRaid = adminClient.manageRaid.createRaid
  594. const sign = async (raid: Raid, late = false) => await adminClient.signup.sign(user.auth.token.value, user.character, raid, late, false)
  595. const buyToken = async (signup: Signup, itemname: string) => await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, signup)
  596. const getCurrency = async (tier: Tiers) => {
  597. const dbUser = await client.UserManager.getUser(user.account.username)
  598. return dbUser[tier]
  599. }
  600. createRaid(Raid(0, 'BWL')).then(async (BWL0: Raid) => {
  601. const T2_0 = await client.ItemManager.getItem(T2[0])
  602. const signupBWL0 = await sign(BWL0)
  603. let BWL = await getCurrency(BWL0.tier)
  604. let token = await buyToken(signupBWL0, T2[0])
  605. const BWLAfter = await getCurrency(BWL0.tier)
  606. if (!token
  607. || BWL - BWLAfter != 1) {
  608. console.log("Bad Token status", BWL0, signupBWL0, BWL, BWLAfter)
  609. done(new Error("Bad Token status 0"))
  610. return
  611. }
  612. let reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  613. let streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  614. if (reserves!.length != 1){
  615. console.log("Expected reserves to be of length 1", reserves);
  616. done(new Error("Bad token status"))
  617. }
  618. if(streaks!.length != 0){
  619. console.log("Expected streaks to be of length 0", streaks);
  620. done(new Error("Bad token status"))
  621. }
  622. if(reserves![0].itemname !== T2_0!.itemname){
  623. console.log("Expected reserve to to be of item "+T2_0!.itemname, reserves![0]);
  624. done(new Error("Bad token status"))
  625. }
  626. if(reserves![0].level !== 2){
  627. console.log("Expected reserve to to be of level "+2, reserves![0].level);
  628. done(new Error("Bad Token status"))
  629. }
  630. await adminClient.manageRaid.startRaid(BWL0)
  631. reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  632. streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  633. if (reserves!.length != 0
  634. || streaks!.length != 1
  635. || streaks![0].itemname !== T2[0]
  636. || streaks![0].level !== 1) {
  637. console.log("Bad Token status 2", reserves, streaks);
  638. done(new Error("Bad Token status 2"))
  639. return
  640. }
  641. const BWL1 = await createRaid(Raid(1, 'BWL'))
  642. let signupBWL1 = await sign(BWL1)
  643. BWL = await getCurrency(BWL1.tier)
  644. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  645. let afterUnsign = await getCurrency(BWL1.tier)
  646. if (BWL !== afterUnsign) {
  647. console.log("Expected currency to be equal", BWL, afterUnsign)
  648. done(new Error("Expected currency to be equal"))
  649. return
  650. }
  651. signupBWL1 = await sign(BWL1)
  652. BWL = await getCurrency(BWL1.tier)
  653. await buyToken(signupBWL1, T2[1])
  654. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  655. afterUnsign = await getCurrency(BWL1.tier)
  656. if (BWL !== afterUnsign) {
  657. console.log("Expected currency to be equal", BWL, afterUnsign)
  658. done(new Error("Expected currency to be equal"))
  659. return
  660. }
  661. signupBWL1 = await sign(BWL1)
  662. await buyToken(signupBWL1, T2[1])
  663. reserves = await client.ItemManager.getTokens(user.character, [BWL1.tier], true)
  664. streaks = await client.ItemManager.getTokens(user.character, [BWL1.tier], false)
  665. if (reserves!.length != 1
  666. || streaks!.length != 0
  667. || reserves![0].itemname !== T2[1]
  668. || reserves![0].level !== 2) {
  669. console.log("Bad Token status 3", reserves, streaks);
  670. done(new Error("Bad Token status 3"))
  671. return
  672. }
  673. BWL = await getCurrency(BWL1.tier)
  674. const data = await adminClient.manageRaid.startRaid(BWL1)
  675. const afterStart = await getCurrency(BWL1.tier)
  676. if (BWL != 0 || afterStart != 1) {
  677. console.log("Wrong currency values", BWL, afterStart)
  678. done(new Error("Wrong currency values"))
  679. return
  680. }
  681. done()
  682. }).catch(e => {
  683. console.log(e);
  684. done(e)
  685. })
  686. })
  687. })