Exemple #1
0
 /// <summary>
 /// Called when the session has ended
 /// </summary>
 /// <param name="terminationReason">Termination reson</param>
 internal async Task OnEndedAsync(SessionTermination terminationReason)
 {
     if (Dialog != null)
     {
         await Dialog.OnSessionEndedAsync(terminationReason).ConfigureAwait(false);
     }
 }
        public async Task CreateSessionBetweenVASPs()
        {
            int sessionTerminationCounter = 0;
            SessionTermination sessionTerminationDelegate = @event => { sessionTerminationCounter++; };

            (VaspInformation vaspInfoPerson, VaspContractInfo vaspContractInfoPerson) = await VaspInformationBuilder.CreateForNaturalPersonAsync(
                NodeClient.EthereumRpc,
                Settings.VaspSmartContractAddressPerson,
                Settings.NaturalPersonIds,
                Settings.PlaceOfBirth);

            VaspClient originator = VaspClient.Create(
                vaspInfoPerson,
                vaspContractInfoPerson,
                Settings.PersonHandshakePrivateKeyHex,
                Settings.PersonSignaturePrivateKeyHex,
                NodeClient.EthereumRpc,
                NodeClient.WhisperRpc,
                _fakeEnsProvider,
                _signService,
                NodeClient.TransportClient);

            (VaspInformation vaspInfoJuridical, VaspContractInfo vaspContractInfoJuridical) = await VaspInformationBuilder.CreateForJuridicalPersonAsync(
                NodeClient.EthereumRpc,
                Settings.VaspSmartContractAddressJuridical,
                Settings.JuridicalIds);

            VaspClient beneficiary = VaspClient.Create(
                vaspInfoJuridical,
                vaspContractInfoJuridical,
                Settings.JuridicalHandshakePrivateKeyHex,
                Settings.JuridicalSignaturePrivateKeyHex,
                NodeClient.EthereumRpc,
                NodeClient.WhisperRpc,
                _fakeEnsProvider,
                _signService,
                NodeClient.TransportClient);

            var originatorVaan  = VirtualAssetssAccountNumber.Create(vaspInfoPerson.GetVaspCode(), "524ee3fb082809");
            var beneficiaryVaan = VirtualAssetssAccountNumber.Create(vaspInfoJuridical.GetVaspCode(), "524ee3fb082809");

            IVaspMessageHandler messageHandler = new VaspMessageHandlerCallbacks(
                (vaspInfo) =>
            {
                return(Task.FromResult(true));
            },
                (request, currentSession) =>
            {
                var message = new TransferReplyMessage(currentSession.SessionId, TransferReplyMessage.TransferReplyMessageCode.TransferAccepted,
                                                       request.Originator,
                                                       new Beneficiary("Mr. Test", request.Beneficiary.VAAN),
                                                       new TransferReply(
                                                           request.Transfer.VirtualAssetType,
                                                           request.Transfer.TransferType,
                                                           request.Transfer.Amount,
                                                           "0x0"),
                                                       request.VASP);

                return(Task.FromResult(message));
            },
                (dispatch, currentSession) =>
            {
                var message = new TransferConfirmationMessage(currentSession.SessionId,
                                                              TransferConfirmationMessage.TransferConfirmationMessageCode.TransferConfirmed,
                                                              dispatch.Originator,
                                                              dispatch.Beneficiary,
                                                              dispatch.Transfer,
                                                              dispatch.Transaction,
                                                              dispatch.VASP);

                return(Task.FromResult(message));
            });

            beneficiary.RunListener(messageHandler);

            originator.SessionTerminated  += sessionTerminationDelegate;
            beneficiary.SessionTerminated += sessionTerminationDelegate;

            // change enum to string and add constants
            //beneficiary.TransferRequest += request => new TransferReply(VirtualAssetType.ETH, TransferType.BlockchainTransfer, "10", "1223");
            //beneficiary.TransferDispatch += message => new TransferConfirmationMessage();

            var originatorDoc = Originator.CreateOriginatorForNaturalPerson(
                "Test van der Test",
                originatorVaan,
                new PostalAddress(
                    "StreetX",
                    44,
                    "AddressLineX",
                    "510051",
                    "TownX",
                    Country.List["DE"]),
                new PlaceOfBirth(DateTime.Today.AddYears(-30), "TownX", Country.List["DE"]),
                new NaturalPersonId[]
            {
                new NaturalPersonId("Id", NaturalIdentificationType.NationalIdentityNumber, Country.List["DE"]),
            });
            var session = await originator.CreateSessionAsync(originatorDoc, beneficiaryVaan);

            var transferReply = await session.TransferRequestAsync(new TransferInstruction()
            {
                VirtualAssetTransfer = new VirtualAssetTransfer()
                {
                    TransferType     = TransferType.BlockchainTransfer,
                    VirtualAssetType = VirtualAssetType.ETH,
                    TransferAmount   = "1000000000000000000"
                }
            });

            var transferConformation =
                await session.TransferDispatchAsync(transferReply.Transfer, new Transaction("0xtxhash", DateTime.UtcNow, "0x0...a"));

            Assert.Equal(1, originator.GetActiveSessions().Count);
            Assert.True(originator.GetActiveSessions().First() is OriginatorSession);

            Assert.Equal(1, beneficiary.GetActiveSessions().Count);
            Assert.True(beneficiary.GetActiveSessions().First() is BeneficiarySession);

            await session.TerminateAsync(TerminationMessage.TerminationMessageCode.SessionClosedTransferOccured);

            session.Wait();
            originator.Dispose();
            beneficiary.Dispose();

            Assert.Equal(2, sessionTerminationCounter);


            _testOutputHelper.WriteLine("End of test");
        }
Exemple #3
0
 /// <summary>
 /// Called when a session is terminated
 /// </summary>
 /// <param name="terminationReason">reason for termination</param>
 /// <returns></returns>
 public Task OnSessionEndedAsync(SessionTermination terminationReason)
 {
     return(Task.FromResult(false));
 }