You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backendTest.ts 26KB

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