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

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