Esempio n. 1
0
    public static async Task <TestToken> CreateAsync(NetworkCredentials networkCredentials, Action <TestToken> customize = null, params TestAccount[] associate)
    {
        var wholeTokens = (ulong)(Generator.Integer(10, 20) * 100000);
        var decimals    = (uint)Generator.Integer(2, 5);
        var circulation = wholeTokens * (ulong)Math.Pow(10, decimals);
        var maxSupply   = (long)(circulation * Generator.Double(2.1, 2.8));
        var fx          = new TestToken
        {
            Network = networkCredentials
        };

        fx.Network.Output?.WriteLine("STARTING SETUP: Test Token Instance");
        (fx.AdminPublicKey, fx.AdminPrivateKey)           = Generator.KeyPair();
        (fx.GrantPublicKey, fx.GrantPrivateKey)           = Generator.KeyPair();
        (fx.SuspendPublicKey, fx.SuspendPrivateKey)       = Generator.KeyPair();
        (fx.PausePublicKey, fx.PausePrivateKey)           = Generator.KeyPair();
        (fx.ConfiscatePublicKey, fx.ConfiscatePrivateKey) = Generator.KeyPair();
        (fx.SupplyPublicKey, fx.SupplyPrivateKey)         = Generator.KeyPair();
        (fx.RoyaltiesPublicKey, fx.RoyaltiesPrivateKey)   = Generator.KeyPair();
        fx.Payer           = networkCredentials.Payer;
        fx.Client          = networkCredentials.NewClient();
        fx.TreasuryAccount = await TestAccount.CreateAsync(networkCredentials);

        fx.RenewAccount = await TestAccount.CreateAsync(networkCredentials);

        fx.Params = new CreateTokenParams
        {
            Name                  = Generator.Code(50),
            Symbol                = Generator.UppercaseAlphaCode(20),
            Circulation           = circulation,
            Decimals              = decimals,
            Ceiling               = maxSupply,
            Treasury              = fx.TreasuryAccount.Record.Address,
            Administrator         = fx.AdminPublicKey,
            GrantKycEndorsement   = fx.GrantPublicKey,
            SuspendEndorsement    = fx.SuspendPublicKey,
            PauseEndorsement      = fx.PausePublicKey,
            ConfiscateEndorsement = fx.ConfiscatePublicKey,
            SupplyEndorsement     = fx.SupplyPublicKey,
            RoyaltiesEndorsement  = fx.RoyaltiesPublicKey,
            InitializeSuspended   = false,
            Expiration            = Generator.TruncatedFutureDate(2000, 3000),
            RenewAccount          = fx.RenewAccount.Record.Address,
            RenewPeriod           = TimeSpan.FromDays(90),
            Signatory             = new Signatory(fx.AdminPrivateKey, fx.RenewAccount.PrivateKey, fx.TreasuryAccount.PrivateKey),
            Memo                  = "Test Token: " + Generator.Code(20)
        };
        customize?.Invoke(fx);
        fx.Record = await fx.Client.RetryKnownNetworkIssues(async client =>
        {
            return(await fx.Client.CreateTokenWithRecordAsync(fx.Params, ctx =>
            {
                ctx.Memo = "TestToken Setup: " + fx.Params.Symbol ?? "(null symbol)";
            }));
        });

        Assert.Equal(ResponseCode.Success, fx.Record.Status);
        await fx.AssociateAccounts(associate);

        networkCredentials.Output?.WriteLine("SETUP COMPLETED: Test Token Instance");
        return(fx);
    }