Ejemplo n.º 1
0
        public async Task TestMessagesGetLoadedFromTangle()
        {
            var repository = new InMemoryIotaRepository();

            var messenger = new TangleMessenger(repository);

            var receiver = new Address("GUEOJUOWOWYEXYLZXNQUYMLMETF9OOGASSKUZZWUJNMSHLFLYIDIVKXKLTLZPMNNJCYVSRZABFKCAVVIW");
            var payload  = TryteString.FromUtf8String("Hi. I'm a test").Concat(new TryteString(Constants.End.Value));

            await messenger.SendMessageAsync(new Message(MessageType.RequestContact, payload, receiver));

            var sentMessages = await messenger.GetMessagesByAddressAsync(receiver);

            Assert.AreEqual("Hi. I'm a test", sentMessages[0].Payload.ToUtf8String());
        }
Ejemplo n.º 2
0
        public async Task TestTransactionIsCachedShouldMergeWithMessagesFromTangle()
        {
            var repository       = new InMemoryIotaRepository();
            var transactionCache = new MemoryTransactionCache();

            var messenger = new TangleMessenger(repository, transactionCache);

            var receiver = new Address("GUEOJUOWOWYEXYLZXNQUYMLMETF9OOGASSKUZZWUJNMSHLFLYIDIVKXKLTLZPMNNJCYVSRZABFKCAVVIW");
            var payload  = TryteString.FromUtf8String("Hi. I'm a test");

            var messageOne = new Message(payload, receiver);
            var bundle     = new Bundle();

            bundle.AddTransfer(
                new Transfer
            {
                Address = messageOne.Receiver, Message = messageOne.Payload, Tag = Constants.Tag, Timestamp = Timestamp.UnixSecondsTimestamp
            });

            bundle.Finalize();
            bundle.Sign();
            await repository.SendTrytesAsync(bundle.Transactions);

            await transactionCache.SaveTransactionAsync(
                new TransactionCacheItem
            {
                Address           = receiver,
                TransactionHash   = new Hash(Seed.Random().Value),
                TransactionTrytes = new TransactionTrytes(TryteString.FromUtf8String("Hi. I'm a test").Value)
            });

            var sentMessages = await messenger.GetMessagesByAddressAsync(receiver);

            Assert.AreEqual(2, sentMessages.Count);
            Assert.AreEqual("Hi. I'm a test", sentMessages[0].Payload.ToUtf8String());
            Assert.AreEqual("Hi. I'm a test", sentMessages[1].Payload.ToUtf8String());
        }