Skip to content

Commit 503b219

Browse files
authored
add unit test
1 parent be13c5f commit 503b219

File tree

1 file changed

+68
-0
lines changed
  • android/fakewallet/src/androidTest/java/com/solana/mobilewalletadapter/fakewallet

1 file changed

+68
-0
lines changed

android/fakewallet/src/androidTest/java/com/solana/mobilewalletadapter/fakewallet/MainActivityTest.kt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,74 @@ class MainActivityTest {
461461
assertTrue(signer.verifySignature(authResult.signInResult!!.signature))
462462
}
463463

464+
@Test
465+
fun authorizationFlow_SuccessfulReauthorizeSingleAccountMultiAuth() {
466+
// given
467+
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
468+
469+
val identity1Uri = Uri.parse("https://test1.com")
470+
val identity1Name = "Test 1"
471+
val identity2Uri = Uri.parse("https://test2.com")
472+
val identity2Name = "Test 2"
473+
val iconUri = Uri.parse("favicon.ico")
474+
val chain = ProtocolContract.CHAIN_SOLANA_TESTNET
475+
476+
// simulate client side scenarios
477+
val localAssociation1 = LocalAssociationScenario(Scenario.DEFAULT_CLIENT_TIMEOUT_MS)
478+
val associationIntent1 = LocalAssociationIntentCreator.createAssociationIntent(
479+
null,
480+
localAssociation1.port,
481+
localAssociation1.session
482+
)
483+
484+
val localAssociation2 = LocalAssociationScenario(Scenario.DEFAULT_CLIENT_TIMEOUT_MS)
485+
val associationIntent2 = LocalAssociationIntentCreator.createAssociationIntent(
486+
null,
487+
localAssociation2.port,
488+
localAssociation2.session
489+
)
490+
491+
// when
492+
ActivityScenario.launch<MainActivity>(associationIntent1)
493+
494+
// First, simulate client 1 authorizing
495+
// trigger authorization from client 1
496+
var mwaClient = localAssociation1.start().get()
497+
val authorization1 = mwaClient.authorize(identity1Uri, iconUri, identity1Name, chain,
498+
null, null, null, null)
499+
500+
uiDevice.wait(Until.hasObject(By.res(FAKEWALLET_PACKAGE, "authorize")), WINDOW_CHANGE_TIMEOUT)
501+
502+
onView(withId(R.id.btn_authorize))
503+
.check(matches(isDisplayed())).perform(click())
504+
505+
val accounts = authorization1.get().accounts.map { it.publicKey }
506+
localAssociation1.close().get()
507+
508+
// Now, authorize client 2 for the same account (publickey) that was used with client 1
509+
ActivityScenario.launch<MainActivity>(associationIntent2)
510+
511+
// trigger authorization from client 2
512+
mwaClient = localAssociation2.start().get()
513+
val authorization2 = mwaClient.authorize(identity2Uri, iconUri, identity2Name, chain,
514+
null, null, accounts.toTypedArray(), null)
515+
516+
uiDevice.wait(Until.hasObject(By.res(FAKEWALLET_PACKAGE, "authorize")), WINDOW_CHANGE_TIMEOUT)
517+
518+
onView(withId(R.id.btn_authorize))
519+
.check(matches(isDisplayed())).perform(click())
520+
521+
val authResult = authorization2.get()
522+
523+
// reauthorize - this is needed to trigger the auth lookup
524+
val reauthResult = mwaClient.authorize(identity2Uri, iconUri, identity2Name, chain,
525+
authResult.authToken, null, accounts.toTypedArray(), null).get()
526+
527+
// then
528+
assertNotNull(reauthResult)
529+
assertTrue(reauthResult.authToken == authResult.authToken)
530+
}
531+
464532
@Test
465533
fun signingFlow_SuccessfulSignMessagesMultiAccount() {
466534
// given

0 commit comments

Comments
 (0)