public async Task Should_Wait_For_Collection()
        {
            var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            var request = TestClient.Create(_logger).Net
                          .WaitForCollectionAsync(new ParamsOfWaitForCollection
            {
                Collection = "transactions",
                Filter     = new
                {
                    now = new { gt = now }
                }.ToJson(),
                Result = "id now"
            });

            await Task.Delay(TimeSpan.FromSeconds(1));

            var task = _client.GetGramsFromGiverAsync(TonClientNodeSe.GiverAddress);

            var result = await request;

            Assert.NotNull(result);

            await task;
        }
Esempio n. 2
0
        public static async Task <string> DeployWithGiverAsync(this ITonClient client, ParamsOfEncodeMessage @params, ulong?value = null)
        {
            var msg = await client.Abi.EncodeMessageAsync(@params);

            await client.GetGramsFromGiverAsync(msg.Address, value);

            await client.Processing.ProcessMessageAsync(new ParamsOfProcessMessage
            {
                MessageEncodeParams = @params,
                SendEvents          = false
            });

            return(msg.Address);
        }
        public async Task Should_Wait_For_Message()
        {
            var(abi, tvc) = TestClient.Package("Events");
            var keys = await _client.Crypto.GenerateRandomSignKeysAsync();

            var encoded = await _client.Abi.EncodeMessageAsync(new ParamsOfEncodeMessage
            {
                Abi       = abi,
                DeploySet = new DeploySet
                {
                    Tvc = tvc
                },
                CallSet = new CallSet
                {
                    FunctionName = "constructor",
                    Header       = new FunctionHeader
                    {
                        Pubkey = keys.Public
                    }
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                }
            });

            await _client.GetGramsFromGiverAsync(encoded.Address);

            var events = new List <ProcessingEvent>();

            Task ProcessingCallback(ProcessingEvent @event, int code)
            {
                Assert.Equal(100, code);
                Assert.NotNull(@event);
                events.Add(@event);
                return(Task.CompletedTask);
            }

            var result = await _client.Processing.SendMessageAsync(new ParamsOfSendMessage
            {
                Message    = encoded.Message,
                Abi        = abi,
                SendEvents = true
            }, ProcessingCallback);

            try
            {
                var output = await _client.Processing.WaitForTransactionAsync(new ParamsOfWaitForTransaction
                {
                    Message      = encoded.Message,
                    ShardBlockId = result.ShardBlockId,
                    SendEvents   = true,
                    Abi          = abi
                }, ProcessingCallback);

                Assert.NotNull(output);
                Assert.Empty(output.OutMessages);
                Assert.NotNull(output.Decoded.Output);
                Assert.NotNull(output.Decoded.OutMessages);
                Assert.Empty(output.Decoded.OutMessages);
                Assert.Null(output.Decoded.Output);
            }
            catch (TonClientException /* message expired */)
            {
            }

            using var enumerator = events.GetEnumerator();
            Assert.True(enumerator.MoveNext());
            Assert.IsType <ProcessingEvent.WillFetchFirstBlock>(enumerator.Current);
            Assert.True(enumerator.MoveNext());
            Assert.IsType <ProcessingEvent.WillSend>(enumerator.Current);
            Assert.True(enumerator.MoveNext());
            Assert.IsType <ProcessingEvent.DidSend>(enumerator.Current);
            Assert.True(enumerator.MoveNext());
            do
            {
                Assert.IsType <ProcessingEvent.WillFetchNextBlock>(enumerator.Current);
            } while (enumerator.MoveNext());
        }