コード例 #1
0
        public async Task Should_Subscribe_For_Transactions_With_Address()
        {
            var keys = await _client.Crypto.GenerateRandomSignKeysAsync();

            var deployParams = new ParamsOfEncodeMessage
            {
                Abi       = TestClient.Abi("Hello"),
                DeploySet = new DeploySet
                {
                    Tvc = TestClient.Tvc("Hello")
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                },
                CallSet = new CallSet
                {
                    FunctionName = "constructor"
                }
            };

            var msg = await _client.Abi.EncodeMessageAsync(deployParams);

            var address        = msg.Address;
            var transactionIds = new List <string>();

            var handle = await _client.Net.SubscribeCollectionAsync(new ParamsOfSubscribeCollection
            {
                Collection = "transactions",
                Filter     = new
                {
                    account_addr = new { eq = address },
                    status       = new { eq = 3 } // Finalized
                }.ToJson(),
                Result = "id account_addr"
            }, (json, result) =>
            {
                Assert.Equal(100, result);
                Assert.NotNull(json);
                Assert.NotNull(json["result"]);
                Assert.Equal(address, json.SelectToken("result.account_addr"));
                transactionIds.Add((string)json.SelectToken("result.id"));
                return(Task.CompletedTask);
            });

            await _client.DeployWithGiverAsync(deployParams);

            // give some time for subscription to receive all data
            await Task.Delay(TimeSpan.FromSeconds(1));

            Assert.Equal(2, transactionIds.Distinct().Count());

            await _client.Net.UnsubscribeAsync(handle);
        }
コード例 #2
0
        public async Task Test_Fees()
        {
            var(abi, tvc) = TestClient.Package("GiverV2", 2);
            var keys = await _client.Crypto.GenerateRandomSignKeysAsync();

            var address = await _client.DeployWithGiverAsync(new ParamsOfEncodeMessage
            {
                Abi       = abi,
                DeploySet = new DeploySet
                {
                    Tvc = tvc
                },
                CallSet = new CallSet
                {
                    FunctionName = "constructor"
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                }
            });

            var @params = new ParamsOfEncodeMessage
            {
                Abi     = abi,
                Address = address,
                CallSet = new CallSet
                {
                    FunctionName = "sendTransaction",
                    Input        = new
                    {
                        dest   = address,
                        value  = 100000000u,
                        bounce = false
                    }.ToJson()
                },
                Signer = new Signer.Keys
                {
                    KeysProperty = keys
                }
            };

            var account = (await _client.FetchAccountAsync(address))["boc"]?.ToString();
            var message = await _client.Abi.EncodeMessageAsync(@params);

            var localResult = await _client.Tvm.RunExecutorAsync(new ParamsOfRunExecutor
            {
                Account = new AccountForExecutor.Account
                {
                    Boc = account
                },
                Message = message.Message
            });

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

            Assert.Equal(localResult.Fees.GasFee, runResult.Fees.GasFee);
            Assert.Equal(localResult.Fees.OutMsgsFwdFee, runResult.Fees.OutMsgsFwdFee);
            Assert.Equal(localResult.Fees.InMsgFwdFee, runResult.Fees.InMsgFwdFee);
            Assert.Equal(localResult.Fees.TotalOutput, runResult.Fees.TotalOutput);
            Assert.Equal(localResult.Fees.TotalOutput, new BigInteger(100000000u));
            Assert.Equal(localResult.Fees.TotalAccountFees - localResult.Fees.StorageFee,
                         localResult.Fees.TotalAccountFees - localResult.Fees.StorageFee);
            Assert.True(runResult.Fees.StorageFee >= localResult.Fees.StorageFee);
            Assert.True(runResult.Fees.OutMsgsFwdFee > 0);
            Assert.True(runResult.Fees.InMsgFwdFee > 0);
            Assert.True(runResult.Fees.TotalAccountFees > 0);
        }