Пример #1
0
        private static async Task <GreetingContract> InternalSetupAsync(NetworkCredentials networkCredentials)
        {
            var fx = new GreetingContract();

            fx.Network        = networkCredentials;
            fx.TestInstanceId = Generator.Code(10);
            fx.Memo           = "Greeting Contract Create: Instantiating Contract Instance " + fx.TestInstanceId;
            fx.FileParams     = new CreateFileParams
            {
                Expiration   = DateTime.UtcNow.AddSeconds(7890000),
                Endorsements = new Endorsement[] { networkCredentials.PublicKey },
                Contents     = Encoding.UTF8.GetBytes(GREETING_CONTRACT_BYTECODE)
            };
            fx.Client     = networkCredentials.NewClient();
            fx.FileRecord = await fx.Client.CreateFileWithRecordAsync(fx.FileParams, ctx =>
            {
                ctx.Memo = "Greeting Contract Create: Uploading Contract File " + fx.TestInstanceId;
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.ContractParams = new CreateContractParams
            {
                File          = fx.FileRecord.File,
                Administrator = networkCredentials.PublicKey,
                Gas           = await networkCredentials.TinybarsFromGas(200),
                RenewPeriod   = TimeSpan.FromSeconds(7890000),
            };
            return(fx);
        }
Пример #2
0
        private static async Task <GreetingContract> InternalSetupAsync(NetworkCredentials networkCredentials)
        {
            var fx = new GreetingContract();

            fx.Network    = networkCredentials;
            fx.Memo       = "Greeting Contract Create: Instantiating Contract Instance " + Generator.Code(10);
            fx.FileParams = new CreateFileParams
            {
                Expiration   = Generator.TruncatedFutureDate(12, 24),
                Endorsements = new Endorsement[] { networkCredentials.PublicKey },
                Contents     = Encoding.UTF8.GetBytes(GREETING_CONTRACT_BYTECODE)
            };
            fx.Client     = networkCredentials.NewClient();
            fx.FileRecord = await fx.Client.CreateFileWithRecordAsync(fx.FileParams, ctx =>
            {
                ctx.Memo = "Greeting Contract Create: Uploading Contract File " + Generator.Code(10);
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.ContractParams = new CreateContractParams
            {
                File          = fx.FileRecord.File,
                Administrator = networkCredentials.PublicKey,
                Gas           = 217_000,
                RenewPeriod   = TimeSpan.FromDays(Generator.Integer(2, 4))
            };
            return(fx);
        }
Пример #3
0
        public static async Task <GreetingContract> CreateAsync(NetworkCredentials networkCredentials, Action <GreetingContract> customize = null)
        {
            var fx = new GreetingContract();

            networkCredentials.Output?.WriteLine("STARTING SETUP: Creating Greeting Contract Instance");
            (fx.PublicKey, fx.PrivateKey) = Generator.KeyPair();
            fx.Network        = networkCredentials;
            fx.TestInstanceId = Generator.Code(10);
            fx.Memo           = "Greeting Contract Create: Instantiating Contract Instance " + fx.TestInstanceId;
            fx.FileParams     = new CreateFileParams
            {
                Expiration   = DateTime.UtcNow.AddSeconds(7890000),
                Endorsements = new Endorsement[] { networkCredentials.PublicKey },
                Contents     = Encoding.UTF8.GetBytes(GREETING_CONTRACT_BYTECODE)
            };
            fx.Client     = networkCredentials.NewClient();
            fx.FileRecord = await fx.Client.CreateFileWithRecordAsync(fx.FileParams, ctx =>
            {
                ctx.Memo = "Greeting Contract Create: Uploading Contract File " + fx.TestInstanceId;
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.ContractParams = new CreateContractParams
            {
                File          = fx.FileRecord.File,
                Administrator = fx.PublicKey,
                Signatory     = fx.PrivateKey,
                Gas           = await networkCredentials.TinybarsFromGas(200),
                RenewPeriod   = TimeSpan.FromSeconds(7890000),
            };
            customize?.Invoke(fx);
            fx.ContractRecord = await fx.Client.CreateContractWithRecordAsync(fx.ContractParams, ctx =>
            {
                ctx.Memo = fx.Memo;
            });

            Assert.Equal(ResponseCode.Success, fx.ContractRecord.Status);
            fx.Network.Output?.WriteLine("SETUP COMPLETED: Greeting Contract Instance Created");
            return(fx);
        }