Example #1
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);
        }
Example #2
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}\"");
        }