Skip to content

Commit

Permalink
Merge pull request #1731 from ardriveapp/dev
Browse files Browse the repository at this point in the history
PE-6069: Release ArDrive v2.42.1
  • Loading branch information
thiagocarvalhodev authored May 1, 2024
2 parents b5d6146 + 426c478 commit 0c1d15c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 93 deletions.
2 changes: 2 additions & 0 deletions android/fastlane/metadata/android/en-US/changelogs/124.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes an issue where the tutorial is incorrectly displayed for users with existing public drives when logging in via ArConnect.
- Fixes a login failure issue that occurred when switching wallets on the login page.
8 changes: 1 addition & 7 deletions lib/authentication/ardrive_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ class ArDriveAuthImpl implements ArDriveAuth {

User? _currentUser;

@visibleForTesting
String? firstPrivateDriveTxId;

// getters and setters
@override
User get currentUser {
Expand Down Expand Up @@ -233,7 +230,6 @@ class ArDriveAuthImpl implements ArDriveAuth {
await _secureKeyValueStore.remove('password');
await _secureKeyValueStore.remove('biometricEnabled');
currentUser = null;
firstPrivateDriveTxId = null;
await _disconnectFromArConnect();
_userStreamController.add(null);
}
Expand Down Expand Up @@ -339,12 +335,10 @@ class ArDriveAuthImpl implements ArDriveAuth {
}

Future<String?> _getFirstPrivateDriveTxId(Wallet wallet) async {
firstPrivateDriveTxId ??= await _arweave.getFirstPrivateDriveTxId(
return _arweave.getFirstPrivateDriveTxId(
wallet,
maxRetries: profileQueryMaxRetries,
);

return firstPrivateDriveTxId;
}

@override
Expand Down
10 changes: 8 additions & 2 deletions lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,14 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
if (await _arDriveAuth.userHasPassword(wallet)) {
emit(PromptPassword(wallet: wallet, showWalletCreated: false));
} else {
emit(CreateNewPassword(
wallet: wallet, showTutorials: true, showWalletCreated: false));
final hasDrives = await _arDriveAuth.isExistingUser(wallet);
emit(
CreateNewPassword(
wallet: wallet,
showTutorials: !hasDrives,
showWalletCreated: false,
),
);
}
} catch (e) {
emit(previousState);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Secure, permanent storage

publish_to: 'none'

version: 2.42.0
version: 2.42.1

environment:
sdk: '>=3.2.0 <4.0.0'
Expand Down
82 changes: 0 additions & 82 deletions test/authentication/ardrive_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ void main() {

expect(() => arDriveAuth.currentUser,
throwsA(isA<AuthenticationUserIsNotLoggedInException>()));
expect(arDriveAuth.firstPrivateDriveTxId, isNull);
verify(() => mockSecureKeyValueStore.remove('password')).called(1);
verify(() => mockSecureKeyValueStore.remove('biometricEnabled'))
.called(1);
Expand Down Expand Up @@ -640,7 +639,6 @@ void main() {

await arDriveAuth.logout();

expect(arDriveAuth.firstPrivateDriveTxId, isNull);
expect(() => arDriveAuth.currentUser,
throwsA(isA<AuthenticationUserIsNotLoggedInException>()));
verify(() => mockSecureKeyValueStore.remove('password')).called(1);
Expand Down Expand Up @@ -751,86 +749,6 @@ void main() {
await arDriveAuth.logout();
});
});
group('getFirstPrivateDriveTxId method', () {
final loggedUser = User(
password: 'password',
wallet: wallet,
walletAddress: 'walletAddress',
walletBalance: BigInt.one,
cipherKey: SecretKey([]),
profileType: ProfileType.json,
);

/// For this test we'll call the same method twice to validate if the
/// getFirstPrivateDriveTxId is called only once
test(
'should call getFirstPrivateDriveTxId only once when has private drives and login with sucess. ',
() async {
// arrange
when(() => mockArweaveService.getFirstPrivateDriveTxId(
wallet,
maxRetries: any(named: 'maxRetries'),
)).thenAnswer((_) async => 'some_id');

when(() => mockBiometricAuthentication.isEnabled())
.thenAnswer((_) async => false);

when(
() => mockArDriveCrypto.deriveDriveKey(
wallet,
any(),
any(),
),
).thenAnswer((invocation) => Future.value(SecretKey([])));

when(() => mockUserRepository.hasUser())
.thenAnswer((invocation) => Future.value(true));

when(() => mockArweaveService.getLatestDriveEntityWithId(any(),
driveKey: any(named: 'driveKey'),
maxRetries: any(named: 'maxRetries'),
driveOwner: any(named: 'driveOwner')))
.thenAnswer((invocation) => Future.value(DriveEntity(
id: 'some_id',
rootFolderId: 'some_id',
)));

when(() => mockUserRepository.deleteUser())
.thenAnswer((invocation) async {});

when(() => mockUserRepository.saveUser(
'password', ProfileType.json, wallet))
.thenAnswer((invocation) => Future.value(null));

when(() => mockUserRepository.getUser('password'))
.thenAnswer((invocation) async => loggedUser);

await arDriveAuth.login(wallet, 'password', ProfileType.json);
await arDriveAuth.login(wallet, 'password', ProfileType.json);

verify(
() => mockArweaveService.getFirstPrivateDriveTxId(
wallet,
maxRetries: any(named: 'maxRetries'),
),
).called(1);
});

test(
'should call getFirstPrivateDriveTxId only once when has private drives and login with sucess. ',
() async {
when(() => mockArweaveService.getFirstPrivateDriveTxId(wallet,
maxRetries: any(named: 'maxRetries')))
.thenAnswer((_) async => 'some_id');

await arDriveAuth.userHasPassword(wallet);
await arDriveAuth.userHasPassword(wallet);

verify(() => mockArweaveService.getFirstPrivateDriveTxId(wallet,
maxRetries: any(named: 'maxRetries'))).called(1);
});
});
});

group('getWalletAddress method', () {
Expand Down
35 changes: 34 additions & 1 deletion test/authentication/login/blocs/login_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,40 @@ void main() {
.thenAnswer((invocation) => Future.value(true));
when(() => mockArConnectService.getWalletAddress())
.thenAnswer((invocation) => Future.value('walletAddress'));
// new user
// new user but has public drives
when(() => mockArDriveAuth.isExistingUser(any()))
.thenAnswer((invocation) => Future.value(true));
when(() => mockArDriveAuth.userHasPassword(any()))
.thenAnswer((invocation) => Future.value(false));
},
act: (bloc) async {
bloc.add(const AddWalletFromArConnect());
},
expect: () => [
LoginLoading(),
predicate<CreateNewPassword>((cnp) {
return cnp.showWalletCreated == false &&
cnp.mnemonic == null &&
cnp.showTutorials == false;
})
],
);

blocTest(
'should emit a state to create new password when user never logged on ardrive and show tutorials if user has no drives',
build: () {
return createBloc();
},
setUp: () {
when(() => mockArConnectService.connect())
.thenAnswer((invocation) => Future.value(null));
when(() => mockArConnectService.checkPermissions())
.thenAnswer((invocation) => Future.value(true));
when(() => mockArConnectService.getWalletAddress())
.thenAnswer((invocation) => Future.value('walletAddress'));
// new user and no drives
when(() => mockArDriveAuth.isExistingUser(any()))
.thenAnswer((invocation) => Future.value(false));
when(() => mockArDriveAuth.userHasPassword(any()))
.thenAnswer((invocation) => Future.value(false));
},
Expand Down

0 comments on commit 0c1d15c

Please sign in to comment.