Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / whatsapp / W5Slice1MexRouterTest.kt

W5Slice1MexRouterTest.kt60 lines · 2.4 KiBRaw
1package com.vayunmathur.communicate.whatsapp
2
3import androidx.test.ext.junit.runners.AndroidJUnit4
4import com.vayunmathur.communicate.data.whatsapp.mex.MexPersistedQueryProvider
5import com.vayunmathur.communicate.data.whatsapp.mex.WhatsAppMex
6import com.vayunmathur.communicate.data.whatsapp.registration.WhatsAppPqPreKey
7import com.vayunmathur.communicate.data.whatsapp.registration.WhatsAppRegistrationConstants
8import kotlinx.coroutines.test.runTest
9import org.junit.runner.RunWith
10import kotlin.test.Test
11import kotlin.test.assertEquals
12import kotlin.test.assertFalse
13import kotlin.test.assertTrue
14
15/**
16 * Slice 1 (w5): MEX offline router + PQ signing-input framing + persist-id asset.
17 * Robolectric (needs Context/assets + Android Log).
18 *
19 * - WhatsAppMex.call with the client disconnected and an uncaptured op returns
20 * typed `no_persisted_id:<op>` without touching the network.
21 * - WhatsAppPqPreKey.signingInput is pure framing (0x08 || pub).
22 * - The bundled mex_persist_ids.json parses and carries the three seeded ops.
23 */
24@RunWith(AndroidJUnit4::class)
25class W5Slice1MexRouterTest {
26
27 @Test
28 fun mexCall_uncapturedOp_returnsNoPersistedId() = runTest {
29 val r = WhatsAppMex.call(
30 context = androidx.test.core.app.ApplicationProvider.getApplicationContext(),
31 operationName = "DefinitelyNotACapturedOp",
32 variablesJson = "{}",
33 )
34 assertFalse(r.isSuccess)
35 assertEquals("no_persisted_id:DefinitelyNotACapturedOp", r.transportError)
36 }
37
38 @Test
39 fun signingInput_prefixesKyberTypeByte() {
40 val pub = ByteArray(1568) { it.toByte() }
41 val input = WhatsAppPqPreKey.signingInput(pub)
42 assertEquals(1569, input.size)
43 assertEquals(WhatsAppRegistrationConstants.KEY_TYPE_KYBER, input[0])
44 assertTrue(input.copyOfRange(1, input.size).contentEquals(pub))
45 }
46
47 @Test
48 fun persistIdsAsset_hasSeededOps() {
49 val ctx: android.content.Context =
50 androidx.test.core.app.ApplicationProvider.getApplicationContext()
51 MexPersistedQueryProvider.invalidate()
52 try {
53 assertEquals("27462649126753603", MexPersistedQueryProvider.docIdFor(ctx, "QueryGroupInfo"))
54 assertEquals("7225825540870559", MexPersistedQueryProvider.docIdFor(ctx, "UsernameSetMutation"))
55 assertEquals(null, MexPersistedQueryProvider.docIdFor(ctx, "NoSuchOp"))
56 } finally {
57 MexPersistedQueryProvider.invalidate()
58 }
59 }
60}