예제 #1
0
        public async Task SendTransactionAsync_Test()
        {
            var toAddress  = GenesisAddress;
            var methodName = ContractMethodName;
            var param      = Hash.FromString("AElf.ContractNames.Vote");

            var transaction = await Client.GenerateTransaction(_address, toAddress, methodName, param);

            var txWithSign = Client.SignTransaction(PrivateKey, transaction);

            var result = await Client.SendTransactionAsync(new SendTransactionInput
            {
                RawTransaction = txWithSign.ToByteArray().ToHex()
            });

            result.ShouldNotBeNull();
            _testOutputHelper.WriteLine(result.TransactionId);
        }
예제 #2
0
        public async Task SendRawTransactionAsync_Test()
        {
            var toAddress = GenesisAddress;
            var status    = await Client.GetChainStatusAsync();

            var height    = status.BestChainHeight;
            var blockHash = status.BestChainHash;

            var createRaw = await Client.CreateRawTransactionAsync(new CreateRawTransactionInput
            {
                From       = _address,
                To         = toAddress,
                MethodName = ContractMethodName,
                Params     = new JObject
                {
                    ["value"] = Hash.FromString("AElf.ContractNames.Token").Value.ToBase64()
                }.ToString(),
                RefBlockNumber = height,
                RefBlockHash   = blockHash
            });

            createRaw.RawTransaction.ShouldNotBeEmpty();

            var transactionId = Hash.FromRawBytes(ByteArrayHelper.HexStringToByteArray(createRaw.RawTransaction));
            var signature     = GetSignatureWith(PrivateKey, transactionId.ToByteArray()).ToHex();

            var rawTransactionResult = await Client.SendRawTransactionAsync(new SendRawTransactionInput
            {
                Transaction       = createRaw.RawTransaction,
                Signature         = signature,
                ReturnTransaction = true
            });

            Assert.True(rawTransactionResult != null);

            var result = JsonConvert.SerializeObject(rawTransactionResult, Formatting.Indented);

            _testOutputHelper.WriteLine(result);
        }
예제 #3
0
        public async Task ExecuteTransactionAsync_Test()
        {
            var toAddress  = GenesisAddress;
            var methodName = ContractMethodName;
            var param      = Hash.FromString("AElf.ContractNames.TokenConverter");

            var transaction = await Client.GenerateTransaction(_address, toAddress, methodName, param);

            var txWithSign = Client.SignTransaction(PrivateKey, transaction);

            var transactionResult = await Client.ExecuteTransactionAsync(new ExecuteTransactionDto
            {
                RawTransaction = txWithSign.ToByteArray().ToHex()
            });

            Assert.True(transactionResult != null);

            var addressResult = Address.Parser.ParseFrom(ByteArrayHelper.HexStringToByteArray(transactionResult));
            var address       = await Client.GetContractAddressByName(param);

            Assert.True(address == addressResult);
        }
예제 #4
0
        public async Task CreateRawTransactionAsync_Test()
        {
            var address = GenesisAddress;
            var status  = await Client.GetChainStatusAsync();

            var height    = status.BestChainHeight;
            var blockHash = status.BestChainHash;

            var createRaw = await Client.CreateRawTransactionAsync(new CreateRawTransactionInput
            {
                From       = _address,
                To         = address,
                MethodName = ContractMethodName,
                Params     = new JObject
                {
                    ["value"] = Hash.FromString("AElf.ContractNames.Token").Value.ToBase64()
                }.ToString(),
                RefBlockNumber = height,
                RefBlockHash   = blockHash
            });

            createRaw.RawTransaction.ShouldNotBeEmpty();
        }
예제 #5
0
        public async Task SendTransactionsAsync_Test()
        {
            var toAddress  = GenesisAddress;
            var methodName = ContractMethodName;
            var param1     = Hash.FromString("AElf.ContractNames.Token");
            var param2     = Hash.FromString("AElf.ContractNames.Vote");

            var parameters = new List <Hash> {
                param1, param2
            };
            var transactions = new List <Transaction>();

            foreach (var param in parameters)
            {
                var tx = await Client.GenerateTransaction(_address, toAddress, methodName, param);

                var txWithSign = Client.SignTransaction(PrivateKey, tx);

                transactions.Add(txWithSign);
            }

            var result1 = await Client.SendTransactionAsync(new SendTransactionInput
            {
                RawTransaction = transactions[0].ToByteArray().ToHex()
            });

            Assert.True(result1 != null);

            var result2 = await Client.SendTransactionAsync(new SendTransactionInput
            {
                RawTransaction = transactions[1].ToByteArray().ToHex()
            });

            Assert.True(result2 != null);
            _testOutputHelper.WriteLine(result1.TransactionId + "\r\n" + result2.TransactionId);
        }
예제 #6
0
        public async Task ExecuteRawTransactionAsync_Test()
        {
            var address = GenesisAddress;
            var status  = await Client.GetChainStatusAsync();

            var height    = status.BestChainHeight;
            var blockHash = status.BestChainHash;

            var createRaw = await Client.CreateRawTransactionAsync(new CreateRawTransactionInput
            {
                From       = _address,
                To         = address,
                MethodName = ContractMethodName,
                Params     = new JObject
                {
                    ["value"] = Hash.FromString("AElf.ContractNames.Consensus").Value.ToBase64()
                }.ToString(),
                RefBlockNumber = height,
                RefBlockHash   = blockHash
            });

            var transactionId        = Hash.FromRawBytes(ByteArrayHelper.HexStringToByteArray(createRaw.RawTransaction));
            var signature            = GetSignatureWith(PrivateKey, transactionId.ToByteArray()).ToHex();
            var rawTransactionResult = await Client.ExecuteRawTransactionAsync(new ExecuteRawTransactionDto
            {
                RawTransaction = createRaw.RawTransaction,
                Signature      = signature
            });

            rawTransactionResult.ShouldNotBeEmpty();
            var consensusAddress =
                (await Client.GetContractAddressByName(Hash.FromString("AElf.ContractNames.Consensus")))
                .GetFormatted();

            Assert.True(rawTransactionResult == $"\"{consensusAddress}\"");
        }