示例#1
0
        public async Task CanUpdateContractBytecode()
        {
            await using var fx = await GreetingContract.CreateAsync(_network);

            await using var fx2 = await StatefulContract.SetupAsync(_network);

            var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams
            {
                Contract = fx.ContractRecord.Contract,
                File     = fx2.FileRecord.File
            });

            var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract);

            Assert.NotNull(info);
            Assert.Equal(fx.ContractRecord.Contract, info.Contract);
            Assert.Equal(fx.ContractRecord.Contract, info.Address);
            Assert.Equal(fx.ContractParams.Administrator, info.Administrator);
            Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod);
            Assert.Equal(fx.Memo, info.Memo);

            // Call a method that was not part of the original contract to check update.
            // Note, this is a bug with the network, the call returned success but we are still
            // able to call the old contract method which should no longer exist.
            var callRecord = await fx.Client.CallContractWithRecordAsync(new CallContractParams
            {
                Contract     = fx.ContractRecord.Contract,
                Gas          = 30_000,
                FunctionName = "greet",
            });
示例#2
0
        public async Task CreateWithoutRequiredContractParamsThrowsError()
        {
            await using var fx = await StatefulContract.SetupAsync(_network);

            fx.ContractParams.Arguments = null;
            var ex = await Assert.ThrowsAsync <TransactionException>(async() => {
                await fx.Client.CreateContractAsync(fx.ContractParams);
            });

            Assert.StartsWith("Unable to create contract, status: ContractRevertExecuted", ex.Message);
            Assert.Equal(ResponseCode.ContractRevertExecuted, ex.Status);
        }
示例#3
0
        public async Task CanUpdateContractBytecode()
        {
            await using var fx = await GreetingContract.CreateAsync(_network);

            await using var fx2 = await StatefulContract.SetupAsync(_network);

            var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams
            {
                Contract = fx.ContractRecord.Contract,
                File     = fx2.FileRecord.File
            });

            var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract);

            Assert.NotNull(info);
            Assert.Equal(fx.ContractRecord.Contract, info.Contract);
            Assert.Equal(fx.ContractRecord.Contract, info.Address);
            Assert.Equal(fx.ContractParams.Administrator, info.Administrator);
            Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod);
            Assert.Equal(fx.Memo, info.Memo);
            Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance);

            // Call a method that was not part of the original contract to check update.
            // Note, this is a bug with the network, the call returned success but we are still
            // able to call the old contract method which should no longer exist.
            var callRecord = await fx.Client.CallContractWithRecordAsync(new CallContractParams
            {
                Contract     = fx.ContractRecord.Contract,
                Gas          = await _network.TinybarsFromGas(400),
                FunctionName = "greet",
            });

            Assert.NotNull(callRecord);
            Assert.Equal(ResponseCode.Success, record.Status);
            Assert.Empty(callRecord.CallResult.Error);
            Assert.Equal("Hello, world!", callRecord.CallResult.Result.As <string>());
        }