コード例 #1
0
        public async Task TransactionReadOnlyExecutionServiceExtensions_Test()
        {
            var chain = await BlockchainService.GetChainAsync();

            var context = new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            var transaction = OsTestHelper.GenerateTransaction(SampleAddress.AddressList[0],
                                                               SmartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name),
                                                               "GetBalance", new GetBalanceInput
            {
                Owner  = SampleAddress.AddressList[0],
                Symbol = "ELF"
            });

            var result = await TransactionReadOnlyExecutionService.ExecuteAsync <GetBalanceOutput>(context, transaction,
                                                                                                   TimestampHelper.GetUtcNow(),
                                                                                                   true);

            result.Balance.ShouldBe(0);
            result.Symbol.ShouldBe("ELF");

            //without such method and call
            transaction.MethodName = "NotExist";
            await Should.ThrowAsync <SmartContractExecutingException>(async() =>
            {
                await TransactionReadOnlyExecutionService.ExecuteAsync <GetBalanceOutput>(context, transaction,
                                                                                          TimestampHelper.GetUtcNow(),
                                                                                          true);
            });
        }
コード例 #2
0
        public async Task GetFileDescriptorsAsync_Test()
        {
            var chain = await BlockchainService.GetChainAsync();

            var context = new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            };
            var tokenAddress =
                SmartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name);
            var fileDescriptor =
                (await TransactionReadOnlyExecutionService.GetFileDescriptorsAsync(context, tokenAddress)).ToList();

            fileDescriptor.Count.ShouldBeGreaterThan(0);
            fileDescriptor.ShouldAllBe(o => o.Name.Contains("proto"));
        }