Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few refinements #39

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pages/login_history_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class _LoginHistoryPageState extends State<LoginHistoryPage> {
return const CoveredLoading();
} else if (state is HistoryLoaded) {
return Column(
children: state.records.map((e) {
children: (state.records.isEmpty)?
[SizedBox(height: MediaQuery.of(context).size.height*0.8, child: const Center(child: Text("No Data Found"),))]
:state.records.map((e) {
return HistoryRecord(
txhash: e.txhash,
verifierName: e.verifierName,
Expand Down
32 changes: 16 additions & 16 deletions lib/pages/signup_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ class _SignUpPageState extends State<SignUpPage> {
child: Button('Sign Up', onPressed: () {
if (_validateInputs()){
_signupBloc.add(SubmitSignupEvent(
name: _nameController.text,
email: _emailController.text,
dob: _dobController.text,
country: _countryController.text,
phone: _mobileNumberController.text,
gender: _genderController.text
name: _nameController.text.trim(),
email: _emailController.text.trim(),
dob: _dobController.text.trim(),
country: _countryController.text.trim(),
phone: _mobileNumberController.text.trim(),
gender: _genderController.text.trim()
));
}
}),
Expand Down Expand Up @@ -152,8 +152,8 @@ class _SignUpPageState extends State<SignUpPage> {
ElevatedButton(
onPressed: () {
_signupBloc.add(RecoverySubmitEvent(
privateKey: _privateKeyController.text,
contractAddress: _contractAddressController.text));
privateKey: _privateKeyController.text.trim(),
contractAddress: _contractAddressController.text.trim()));
Navigator.pop(context);
},
child: const Text('Submit'))
Expand All @@ -167,28 +167,28 @@ class _SignUpPageState extends State<SignUpPage> {
final emailPattern = RegExp(r"^[a-zA-Z0-9_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$");
final phoneNumberPattern = RegExp(r"^\+[0-9]{10,11}$");
//check for empty fields
if (_nameController.text == ""){
if (_nameController.text.trim() == ""){
message = "Name field cannot be empty";
}
else if (_emailController.text == ""){
else if (_emailController.text.trim() == ""){
message = "Email field cannot be empty";
}
else if (_dobController.text == "") {
else if (_dobController.text.trim() == "") {
message = "Date of Birth field cannot be empty";
}
else if (_countryController.text == ""){
else if (_countryController.text.trim() == ""){
message = "Country field cannot be empty";
}
else if (_mobileNumberController.text == ""){
else if (_mobileNumberController.text.trim() == ""){
message = "Mobile number field cannot be empty";
}
else if (_genderController.text == ""){
else if (_genderController.text.trim() == ""){
message = "Gender field cannot be empty";
}
else if(! emailPattern.hasMatch(_emailController.text)){
else if(! emailPattern.hasMatch(_emailController.text.trim())){
message = "Not a valid email address";
}
else if(! phoneNumberPattern.hasMatch(_mobileNumberController.text)){
else if(! phoneNumberPattern.hasMatch(_mobileNumberController.text.trim())){
message = "Mobile number is not in valid format";
}

Expand Down
75 changes: 14 additions & 61 deletions test/services/user_contract_service_test.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import 'dart:developer';

import 'package:iblock/services/user_contract_service.dart';
import 'package:test/test.dart';

// NOTE: given addresses here are from local ganache blockchain server.
// Since contract address is received via mail can write a automated test.
// Had to use some valid private keys and contract addresses from ganache
void main(){
test('Testing for abi file', () async{
final service = UserContractService();
Object abi = await service.getAbi();
log(abi.toString());
print(abi.toString());
});

test('Testing deployment of user contract', () async{
final service = UserContractService();
var result = await service.deploy(name: "test", email: "test@example.com", dob: "2000/01/01", country: "Sri Lanka", mobile: "+9412345678", gender: "Male");
var result = await service.deploy(name: "test", email: "mailer.iblock@gmail.com", dob: "2000/01/01", country: "Sri Lanka", mobile: "+9412345678", gender: "Male");

log(result.toString());
print(result.toString());
expect(result['private-key'], startsWith("0x"));
});

test('Test fetching details from user contract: called by owner', () async{
final service = UserContractService();
var result = await service.getAll("0x547fda582EeEc9574BFF8Aa768786C15702AE0fD",
"0xdb7a1fc3433dbe9d11b53357927dbfc80e3f9d5c211c6c29ce49acca3633dbf3");
log(result.toString());
expect(result, {"Name": "test", "Email": "test@example.com", "Date of Birth": "2000/01/01", "Country": "Sri Lanka", "Phone": "+9412345678", "Gender": "Male"});
var result = await service.getAll("0x9f7fa19Fe3b2df58E1F0a7E0020dDF011a19F608",
"0xdd2237c254fcd9a0a0c948ef56c71c814687dfbef57bfb173716f9c26437567d");
print(result.toString());
expect(result, {"Name": "test", "Email": "mailer.iblock@gmail.com", "Date of Birth": "2000/01/01", "Country": "Sri Lanka", "Phone": "+9412345678", "Gender": "Male"});
});

test('Test fetching details from user contract: called by other', () async{
Expand All @@ -35,61 +36,13 @@ void main(){

test('Test Setting Name: by the owner', () async{
final service = UserContractService();
await service.setName("test3", privateKey: "0xdb7a1fc3433dbe9d11b53357927dbfc80e3f9d5c211c6c29ce49acca3633dbf3", contractAddress: "0x547fda582EeEc9574BFF8Aa768786C15702AE0fD");
await service.setName("test5", privateKey: "0xdd2237c254fcd9a0a0c948ef56c71c814687dfbef57bfb173716f9c26437567d", contractAddress: "0x9f7fa19Fe3b2df58E1F0a7E0020dDF011a19F608");

var result = await service.getAll("0x547fda582EeEc9574BFF8Aa768786C15702AE0fD",
"0xdb7a1fc3433dbe9d11b53357927dbfc80e3f9d5c211c6c29ce49acca3633dbf3");
var result = await service.getAll("0x9f7fa19Fe3b2df58E1F0a7E0020dDF011a19F608",
"0xdd2237c254fcd9a0a0c948ef56c71c814687dfbef57bfb173716f9c26437567d");

expect(result, {"Name": "test3", "Email": "test@example.com", "Date of Birth": "2000/01/01", "Country": "Sri Lanka", "Phone": "+9412345678", "Gender": "Male"});
expect(result, {"Name": "test5", "Email": "mailer.iblock@gmail.com", "Date of Birth": "2000/01/01", "Country": "Sri Lanka", "Phone": "+9412345678", "Gender": "Male"});

});

test('Testing verify function', () async{
final service = UserContractService();
String transactionId = await service.verify("0xf32cfe97272a46291BF81f85dBb01797f0249635", "123456", privateKey: "0xaf116e5a7fe877b8882ad736395d0371a4f5e822160f16d57e285dfe9132e5b6", contractAddress: "0x9b03DB9C86BE02628558D45356E2220f16BCB6c9");
log(transactionId);
expect(transactionId, startsWith("0x"));
});

group('User contract functons', (){
final service = UserContractService();
late final String privateKey;
late final String contractAddress;
test('Testing deployment of user contract', () async{

var result = await service.deploy(name: "user1", email: "user1@iblock.com", dob: "2000/01/01", country: "Sri Lanka", mobile: "+9412345678", gender: "Male");

log(result.toString());
privateKey = result['private-key'] as String;
contractAddress = result['contract-address'] as String;
});

test('Test fetching details from user contra ct: called by owner', () async{
final service = UserContractService();
var result = await service.getAll(contractAddress, privateKey);
log(result.toString());
expect(result, {"Name": "user1", "Email": "user1@iblock.com", "Date of Birth": "2000/01/01", "Country": "Sri Lanka", "Phone": "+9412345678", "Gender": "Male"});
});

test('Test Setting Name: by the owner', () async{
final service = UserContractService();
await service.setName("user2", contractAddress: contractAddress, privateKey: privateKey);
await service.setEmail("user2@iblock.com", contractAddress: contractAddress, privateKey: privateKey);
await service.setCountry("India", contractAddress: contractAddress, privateKey: privateKey);
await service.setGender("Female", contractAddress: contractAddress, privateKey: privateKey);
await service.setMobile("+123456789", contractAddress: contractAddress, privateKey: privateKey);


var result = await service.getAll(contractAddress, privateKey);

expect(result, {"Name": "user2", "Email": "user2@iblock.com", "Date of Birth": "2000/01/01", "Country": "India", "Phone": "+123456789", "Gender": "Female"});

});

test('Testing verify function', () async{
final service = UserContractService();
String transactionId = await service.verify("0x1Ff8Ebe435cdD925EE58388c78a6b21f650247B6", "12345", privateKey: privateKey, contractAddress: contractAddress);
expect(transactionId, startsWith("0x"));
});
});
}