예제 #1
0
    public static async Task <TestAsset> CreateAsync(NetworkCredentials networkCredentials, Action <TestAsset> customize = null, params TestAccount[] associate)
    {
        var maxSupply = (long)(Generator.Integer(10, 20) * 1000);
        var fx        = new TestAsset
        {
            Network = networkCredentials
        };

        fx.Network.Output?.WriteLine("STARTING SETUP: Test Asset 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.RoyaltiesPublickKey, 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.Metadata = Enumerable.Range(1, Generator.Integer(3, 9)).Select(_ => Generator.SHA384Hash()).ToArray();
        fx.Params   = new CreateAssetParams
        {
            Name                  = Generator.Code(50),
            Symbol                = Generator.UppercaseAlphaCode(20),
            Treasury              = fx.TreasuryAccount.Record.Address,
            Ceiling               = maxSupply,
            Administrator         = fx.AdminPublicKey,
            GrantKycEndorsement   = fx.GrantPublicKey,
            SuspendEndorsement    = fx.SuspendPublicKey,
            PauseEndorsement      = fx.PausePublicKey,
            ConfiscateEndorsement = fx.ConfiscatePublicKey,
            SupplyEndorsement     = fx.SupplyPublicKey,
            RoyaltiesEndorsement  = fx.RoyaltiesPublickKey,
            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 Asset: " + Generator.Code(20)
        };
        customize?.Invoke(fx);
        fx.Record = await fx.Client.RetryKnownNetworkIssues(async client =>
        {
            return(await fx.Client.CreateTokenWithRecordAsync(fx.Params, ctx =>
            {
                ctx.Memo = "TestAsset Setup: " + fx.Params.Symbol ?? "(null symbol)";
            }));
        });

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

        if (fx.Metadata is not null && fx.Metadata.Length > 0)
        {
            fx.MintRecord = await fx.Client.MintAssetWithRecordAsync(fx.Record.Token, fx.Metadata, fx.SupplyPrivateKey);
        }
        networkCredentials.Output?.WriteLine("SETUP COMPLETED: Test Asset Instance");
        return(fx);
    }