public async Task GetBalanceAsync_WithValidAddressAndProperty_ShouldReturnExpectedData()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            this.Node.Generate(1);

            var property = await this.GetPropertyAsync(issuer.Name);

            await this.GrantTokensAsync(property, owner, owner, new TokenAmount(100));

            this.Node.Generate(1);

            // Act.
            var result = await this.Subject.GetBalanceAsync(owner, property);

            // Assert.
            Assert.Equal(100, result.Balance.Value);
            Assert.Equal(0, result.Reserved.Value);
        }
        public async Task PublishAsync_WithValidTransaction_ShouldPublishSuccessfullyToNetwork()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var tx = Transaction.Parse(await issuer.IssueManagedAsync(owner), this.Client.Network);

            // Act.
            var hash = await this.Subject.PublishAsync(tx);

            var mined = this.Node.Generate(1).Single();

            // Assert.
            Assert.Equal(tx.GetHash(), hash);

            await using (var client = await this.Factory.CreateChainInformationClientAsync())
            {
                var block = await client.GetBlockAsync(mined);

                Assert.NotNull(block);
                Assert.Contains(block !.Transactions, t => t.GetHash() == hash);
            }
        }
        public async Task GetPayloadAsync_WithElysiumTransaction_ShouldReturnItPayload()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            issuer.Type        = PropertyType.Production;
            issuer.TokenType   = TokenType.Indivisible;
            issuer.Current     = null;
            issuer.Category    = "Company";
            issuer.Subcategory = "Private";
            issuer.Name        = "Satang Corporation";
            issuer.Url         = "https://satang.com";
            issuer.Description = "Provides cryptocurrency solutions.";

            var tx = await issuer.IssueManagedAsync(owner);

            this.Node.Generate(1);

            // Act.
            var result = await this.Subject.GetPayloadAsync(uint256.Parse(tx));

            // Assert.
            Assert.NotNull(result);
            Assert.Equal(
                "0000003601000100000000436F6D70616E79005072697661746500536174616E6720436F72706F726174696F6E0068747470733A2F2F736174616E672E636F6D0050726F76696465732063727970746F63757272656E637920736F6C7574696F6E732E00",
                BitConverter.ToString(result.Value.ToArray()).Replace("-", ""));
        }
예제 #4
0
        public async Task PopulateElysiumInformationAsync_WithUnconfirmedTransaction_ShouldThrow()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var receiver = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var         hash = uint256.Parse(await issuer.IssueManagedAsync(owner));
            Transaction?tx;

            await using (var client = await this.Factory.CreateChainInformationClientAsync())
            {
                tx = await client.GetTransactionAsync(hash);
            }

            Assert.NotNull(tx);

            // Act.
            var ex = await Assert.ThrowsAsync <ArgumentException>(
                "tx",
                () => Subject.PopulateElysiumInformationAsync(tx !));

            // Assert.
            Assert.Equal("The transaction is not confirmed. (Parameter 'tx')", ex.Message);
        }
예제 #5
0
        public async Task GrantTokensAsync_WithValidArgs_ShouldGrantSuccess()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var receiver = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var create = uint256.Parse(await issuer.IssueManagedAsync(owner));

            this.Node.Generate(1);

            var property = await this.GetPropertyAsync(issuer.Name);

            // Act.
            var tx = await Subject.GrantTokensAsync(
                property,
                owner,
                receiver,
                new TokenAmount(100),
                "abc");

            this.Node.Generate(1);

            // Assert.
            await using (var client = await this.Factory.CreateElysiumInformationClientAsync())
            {
                var grant = await client.GetGrantsAsync(property);

                var history = Assert.Single(grant.GrantHistories);

                Assert.Equal(create, grant.PropertyCreationTransaction);
                Assert.Equal(property.Id, grant.PropertyId);
                Assert.Equal(owner, grant.PropertyIssuer);
                Assert.Equal(issuer.Name, grant.PropertyName);
                Assert.Equal(100, grant.TotalTokens.Value);

                Assert.Equal(100, history.Amount.Value);
                Assert.Equal(uint256.Parse(tx), history.Transaction);
                Assert.Equal(TokenGrantType.Grant, history.Type);
            }
        }
예제 #6
0
        public async Task SendTokensAsync_WithReferenceAmount_ShouldOutputByThatAmount()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var receiver = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(10));

            this.Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            this.Node.Generate(1);

            var property = await this.GetPropertyAsync(issuer.Name);

            await this.GrantTokensAsync(property, owner, owner, new TokenAmount(100));

            this.Node.Generate(1);

            // Act.
            var result = await Subject.SendTokensAsync(
                property,
                owner,
                receiver,
                new TokenAmount(1),
                Money.Coins(0.01m));

            var block = this.Node.Generate(1).Single();

            // Assert.
            var tx     = (await this.GetTransactionsAsync(block)).Single(t => t.GetHash() == uint256.Parse(result));
            var output = tx.Outputs.Single(o => o.ScriptPubKey.GetDestinationAddress(this.Network) == receiver);

            Assert.Equal(Money.Coins(0.01m), output.Value);

            await using (var client = await this.Factory.CreateElysiumInformationClientAsync())
            {
                var balance = await client.GetBalanceAsync(receiver, property);

                Assert.Equal(1, balance.Balance.Value);
                Assert.Equal(0, balance.Reserved.Value);
            }
        }
예제 #7
0
        public async Task PopulateElysiumInformationAsync_WithValidElysiumTransaction_ShouldPopulate()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var hash = uint256.Parse(await issuer.IssueManagedAsync(owner));

            this.Node.Generate(1);

            Transaction?tx;

            await using (var client = await this.Factory.CreateChainInformationClientAsync())
            {
                tx = await client.GetTransactionAsync(hash);
            }

            Assert.NotNull(tx);

            // Act.
            await this.Subject.PopulateElysiumInformationAsync(tx !);

            // Assert.
            var elysium = Assert.IsType <CreateManagedPropertyV0>(tx !.GetElysiumTransaction());

            Assert.NotNull(elysium);
            Assert.Equal(issuer.Category, elysium.Category);
            Assert.Equal(issuer.Description, elysium.Description);
            Assert.Equal(CreateManagedPropertyV0.StaticId, elysium.Id);
            Assert.Equal(issuer.Name, elysium.Name);
            Assert.Null(elysium.PreviousId);
            Assert.Null(elysium.Receiver);
            Assert.Equal(owner, elysium.Sender);
            Assert.Equal(issuer.Subcategory, elysium.Subcategory);
            Assert.Equal(issuer.TokenType, elysium.TokenType);
            Assert.Equal(issuer.Type, elysium.Type);
            Assert.Equal(0, elysium.Version);
            Assert.Equal(issuer.Url, elysium.Website);
        }
예제 #8
0
        public async Task GetTransactionAsync_WithValidHash_ShouldReturnCorrespondingTransaction()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var hash = uint256.Parse(await issuer.IssueManagedAsync(owner));

            // Act.
            var result = await this.Subject.GetTransactionAsync(hash);

            // Assert.
            Assert.NotNull(result);
            Assert.Equal(hash, result !.GetHash());
        }
        public async Task GetGrantsAsync_WithValidProperty_ShouldReturnCorrectData()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var receiver = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var create = await issuer.IssueManagedAsync(owner);

            this.Node.Generate(1);

            var property = await this.GetPropertyAsync(issuer.Name);

            var grant = await this.GrantTokensAsync(property, owner, receiver, new TokenAmount(1));

            this.Node.Generate(1);

            // Act.
            var result = await this.Subject.GetGrantsAsync(property);

            // Assert.
            var history = Assert.Single(result.GrantHistories);

            Assert.Equal(uint256.Parse(create), result.PropertyCreationTransaction);
            Assert.Equal(property.Id, result.PropertyId);
            Assert.Equal(owner, result.PropertyIssuer);
            Assert.Equal(issuer.Name, result.PropertyName);
            Assert.Equal(1, result.TotalTokens.Value);

            Assert.Equal(1, history.Amount.Value);
            Assert.Equal(uint256.Parse(grant), history.Transaction);
            Assert.Equal(TokenGrantType.Grant, history.Type);
        }
        public async Task GetTransactionAsync_WithElysiumTransaction_ShouldReturnCorrectData()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            var tx    = uint256.Parse(await issuer.IssueManagedAsync(owner));
            var block = this.Node.Generate(1).Single();

            // Act.
            var result = await this.Subject.GetTransactionAsync(tx);

            // Assert.
            Assert.NotNull(result);
            Assert.NotEqual(Money.Zero, result !.Fee);
            Assert.True(result.Owned);
            Assert.Null(result.ReferenceAddress);
            Assert.Equal(owner, result.SendingAddress);
            Assert.Equal(tx, result.Id);
            Assert.Equal("Create Property - Manual", result.Name);
            Assert.Equal(54, result.Type);
            Assert.Equal(0, result.Version);

            var confirmation = result.Confirmation;

            Assert.NotNull(confirmation);
            Assert.Equal(103, confirmation !.Block);
            Assert.Equal(block, confirmation.BlockHash);
            Assert.Equal(1, confirmation.BlockIndex);
            Assert.NotEqual(default(DateTime), confirmation.BlockTime);
            Assert.Equal(1, confirmation.Count);
            Assert.Null(confirmation.InvalidReason);
            Assert.True(confirmation.Valid);
        }
예제 #11
0
        public async Task GetBlockAsync_WithElysiumTransaction_ElysiumTransactionPropertyShouldNotBeNull()
        {
            // Arrange.
            var owner = await this.GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(this.Factory);

            this.Node.Generate(101);
            await this.FundAddressAsync(owner, Money.Coins(1));

            this.Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            var hash   = this.Node.Generate(1).Single();
            var height = 103;

            // Act.
            var result1 = await this.Subject.GetBlockAsync(hash);

            var result2 = await this.Subject.GetBlockAsync(height);

            // Assert.
            Assert.NotNull(result1);
            Assert.NotNull(result2);

            Assert.Equal(result1 !.GetHash(), result2 !.GetHash());
            Assert.Equal(2, result1.Transactions.Count);

            var elysium1 = result1.Transactions[0].GetElysiumTransaction();
            var elysium2 = result1.Transactions[1].GetElysiumTransaction();

            Assert.Null(elysium1);
            Assert.NotNull(elysium2);

            Assert.Equal(CreateManagedPropertyV0.StaticId, elysium2 !.Id);
        }