tools/client/test_east_wind_reward.mjs (4797B)
1 import assert from 'node:assert/strict'; 2 import fs from 'node:fs/promises'; 3 import {createRequire} from 'node:module'; 4 import {GameTest} from './game_test.mjs'; 5 6 const {chromium} = createRequire(import.meta.url)('playwright'); 7 const [url, output] = process.argv.slice(2); 8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ 9 '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 10 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 11 let game; 12 const evidence = {}; 13 try { 14 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 15 await context.addCookies([{name: 'ao_client', value: 'east-wind', url}]); 16 const page = await context.newPage(); 17 game = await GameTest.attach(page); 18 const server = async () => (await page.request.get(url + '/test-state')).json(); 19 await page.goto(url); 20 await game.ready(); 21 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 22 await game.snapshot(); 23 evidence.before = await server(); 24 assert.equal(evidence.before.completed, false); 25 assert.equal(evidence.before.inventory.Credits, 3); 26 assert.equal(game.local().stats[60], 6); 27 const selection = Buffer.alloc(20); 28 [2018, 160216, 160217, 2, 0].forEach((value, index) => selection.writeUInt32BE(value, index * 4)); 29 assert(game.events.some(event => event.direction === 'framereceived' && Buffer.from(event.hex, 'hex').includes(selection))); 30 await game.key('KeyI'); 31 await game.page.keyboard.press('Control+1'); 32 await game.save(output + '/promised'); 33 34 // Return the saved collected book through the original native item-on-booth action. 35 await game.click(789, 45); 36 await game.click(...await game.pick(56001, 3221228472), 'right'); 37 await game.wait('promised East Wind delivered once', state => game.local(state).stats[61] === 1003 && 38 game.local(state).inventory.some(item => item.templates.includes(160216)) && 39 !game.local(state).inventory.some(item => item.id === 2 || item.id === 3)); 40 evidence.delivered = await server(); 41 assert.equal(evidence.delivered.completed, true); 42 assert.deepEqual(evidence.delivered.inventory.Items, [evidence.before.inventory.Items[0], 43 {ID: 4, Type: 51018, Template: 160216, Quality: 2, Slot: 65, Count: 1, Ammo: 0}]); 44 await game.save(output + '/delivered'); 45 46 // Equality refuses wear locally; one normal raw skill point qualifies the same reward. 47 const sequence = game.sequence; 48 await game.click(738, 45, 'right'); 49 await game.save(output + '/wear-rejected'); 50 assert(!game.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24')); 51 assert.deepEqual((await server()).inventory, evidence.delivered.inventory); 52 await game.key('KeyU'); 53 await game.click(300, 272); 54 await game.save(output + '/skill-before'); 55 await game.click(835, 286); 56 await game.click(445, 622); 57 await game.wait('normally trained 2h Edged', state => game.local(state).stats[105] === 9 && game.local(state).stats[53] === 188); 58 await game.click(738, 45, 'right'); 59 await game.wait('same rewarded Katana worn', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 6)); 60 assert.equal((await server()).rating, 9); 61 assert.equal(game.local().stats[22], 9); 62 await game.save(output + '/worn'); 63 await game.click(867, 206, 'right'); 64 await game.wait('same reward removed', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 49)); 65 await game.wait('removal action finished', state => !game.local(state).actions.includes(3)); 66 await game.click(738, 45, 'right'); 67 await game.wait('same reward re-worn', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 6)); 68 evidence.worn = await server(); 69 await fs.writeFile(output + '/ledger.json', JSON.stringify(evidence.worn, null, 2) + '\n'); 70 71 await page.reload(); 72 await game.ready(); 73 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 74 await game.snapshot(); 75 assert.deepEqual(game.local().inventory.map(item => [item.id,item.slot,item.quality,...item.templates]), 76 [[4,6,2,160216,160217],[1,48,1,209283,209283]]); 77 assert.equal(game.local().stats[22], 9); 78 evidence.reloaded = await server(); 79 assert.deepEqual(evidence.reloaded, evidence.worn); 80 assert.deepEqual(game.errors, []); 81 console.log('PASS: period reward advertisement, native hand-in, equality refusal, 12-IP training and same-instance wear/page recovery'); 82 } finally { 83 try { 84 await fs.mkdir(output, {recursive: true}); 85 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 86 if (game) await game.save(output + '/final'); 87 } finally { await browser.close(); } 88 }