Skip to content

Commit

Permalink
implemented call to verify function in user contract and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishad-M-I-M committed Nov 12, 2022
1 parent 6226338 commit ac4ba0d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/services/user_contract_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,34 @@ class UserContractService{
return _setUserProperty("setGender", gender, contractAddress: contractAddress, privateKey: privateKey);
}

Future<String> verify(String verifierContractAddress, String token, {required String contractAddress, required String privateKey}) async{
EthereumAddress contract = EthereumAddress.fromHex(contractAddress);
EthereumAddress verifierContract = EthereumAddress.fromHex(verifierContractAddress);
EthPrivateKey credentials = EthPrivateKey.fromHex(privateKey);

Object abi = await _abiJSON;

DeployedContract smartContract = DeployedContract(ContractAbi.fromJson(jsonEncode(abi), "User"), contract);
ContractFunction verifyFunction = smartContract.function("verify");

Web3Client web3client = Web3Client(Config.rpcUrl, http.Client(), socketConnector: (){
return IOWebSocketChannel.connect(Config.wsUrl).cast<String>();
});

try{
var transactionId = await web3client.sendTransaction(
credentials,
Transaction.callContract(contract: smartContract, function: verifyFunction, parameters: [verifierContract, contract, token])
);
return transactionId;
}
catch(e){
throw Exception("Failed due to $e");
}
finally{
web3client.dispose();
}
}

Object getAbiJson() {
return _abiJSON;
Expand Down
11 changes: 11 additions & 0 deletions test/services/user_contract_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void main(){
expect(result, {"Name": "test3", "Email": "test@example.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("0x1Ff8Ebe435cdD925EE58388c78a6b21f650247B6", "12345", privateKey: "0xdb7a1fc3433dbe9d11b53357927dbfc80e3f9d5c211c6c29ce49acca3633dbf3", contractAddress: "0x547fda582EeEc9574BFF8Aa768786C15702AE0fD");
expect(transactionId, startsWith("0x"));
});

group('User contract functons', (){
final service = UserContractService();
Expand Down Expand Up @@ -76,5 +82,10 @@ void main(){

});

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

0 comments on commit ac4ba0d

Please sign in to comment.