コード例 #1
0
        public async Task GetBalanceAsync_WithValidAddressAndProperty_ShouldReturnExpectedData()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            await GrantTokensAsync(property, owner, owner, new PropertyAmount(100));

            Node.Generate(1);

            // Act.
            var(balance, reserved) = await Subject.GetBalanceAsync(owner, property, CancellationToken.None);

            // Assert.
            Assert.Equal(new PropertyAmount(100), balance);
            Assert.Equal(PropertyAmount.Zero, reserved);
        }
コード例 #2
0
        public async Task GetPayloadAsync_WithExodusTransaction_ShouldReturnItPayload()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            issuer.Ecosystem   = Ecosystem.Main;
            issuer.Type        = PropertyType.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);

            Node.Generate(1);

            // Act.
            var result = await Subject.GetPayloadAsync(tx.GetHash(), CancellationToken.None);

            // Assert.
            Assert.Equal(
                "0000003601000100000000436F6D70616E79005072697661746500536174616E6720436F72706F726174696F6E0068747470733A2F2F736174616E672E636F6D0050726F76696465732063727970746F63757272656E637920736F6C7574696F6E732E00",
                BitConverter.ToString(result).Replace("-", "")
                );
        }
コード例 #3
0
        public async Task GetTransactionAsync_WithExodusTransaction_ShouldReturnCorrectData()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            var tx = await issuer.IssueManagedAsync(owner);

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

            // Act.
            var result = await Subject.GetTransactionAsync(tx.GetHash(), CancellationToken.None);

            // Assert.
            Assert.Equal(103, result.Block);
            Assert.Equal(block, result.BlockHash);
            Assert.NotEqual(default(DateTimeOffset), result.BlockTime);
            Assert.Equal(1, result.Confirmations);
            Assert.NotEqual(Money.Zero, result.Fee);
            Assert.Null(result.InvalidReason);
            Assert.True(result.IsMine);
            Assert.Null(result.ReferenceAddress);
            Assert.Equal(owner, result.SendingAddress);
            Assert.Equal(tx.GetHash(), result.TxId);
            Assert.Equal("Create Property - Manual", result.Type);
            Assert.Equal(54, result.TypeInt);
            Assert.True(result.Valid);
            Assert.Equal(0, result.Version);
        }
コード例 #4
0
        public async Task PopulateExodusInformationAsync_WithMemPoolTx_ShouldThrow()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            await GrantTokensAsync(property, owner, owner, new PropertyAmount(100));

            Node.Generate(1);

            var tx = await SendTokensAsync(property, owner, receiver, new PropertyAmount(10));

            // Act.
            await Assert.ThrowsAsync <ArgumentException>(
                "tx",
                () => Subject.PopulateExodusInformationAsync(tx, CancellationToken.None)
                );
        }
コード例 #5
0
        public async Task SendAsync_WithValidTx_ShouldGetMined()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            var tx = await issuer.CreateManagedIssuingTransactionAsync(owner);

            // Act.
            var hash = await Subject.SendAsync(tx, CancellationToken.None);

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

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

            using (var rpc = await Factory.CreateChainInformationRpcAsync(CancellationToken.None))
            {
                var block = await rpc.GetBlockAsync(mined, CancellationToken.None);

                Assert.Contains(block.Transactions, t => t.GetHash() == hash);
            }
        }
コード例 #6
0
        public async Task SendAsync_WithReferenceAmount_ShouldOutputByThatAmount()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            await GrantTokensAsync(property, owner, owner, new PropertyAmount(100));

            Node.Generate(1);

            // Act.
            var tx = await Subject.SendAsync(
                owner,
                receiver,
                property,
                PropertyAmount.One,
                Money.Coins(0.01m),
                CancellationToken.None
                );

            await SendTransactionAsync(tx);

            Node.Generate(1);

            // Assert.
            var output = tx.Outputs.Single(o => o.ScriptPubKey.GetDestinationAddress(Network) == receiver);

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

            using (var rpc = await Factory.CreateExodusInformationRpcAsync(CancellationToken.None))
            {
                var(amount, reserved) = await rpc.GetBalanceAsync(receiver, property, CancellationToken.None);

                Assert.Equal(PropertyAmount.One, amount);
                Assert.Equal(PropertyAmount.Zero, reserved);
            }
        }
コード例 #7
0
        public async Task GrantAsync_WithValidArgs_ShouldGrantSuccess(string note)
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            var create = await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            // Act.
            var tx = await Subject.GrantAsync(
                property,
                owner,
                receiver,
                new PropertyAmount(100),
                note,
                CancellationToken.None
                );

            await SendTransactionAsync(tx);

            Node.Generate(1);

            // Assert.
            using (var rpc = await Factory.CreateExodusInformationRpcAsync(CancellationToken.None))
            {
                var grant = await rpc.GetGrantsAsync(property, CancellationToken.None);

                Assert.Equal(create.GetHash(), grant.CreationTransaction);
                Assert.Single(grant.Histories);
                Assert.Equal(property.Id, grant.Id);
                Assert.Equal(owner, grant.Issuer);
                Assert.Equal(issuer.Name, grant.Name);
                Assert.Equal(new PropertyAmount(100), grant.TotalTokens);

                Assert.Equal(new PropertyAmount(100), grant.Histories.Single().Amount);
                Assert.Equal(tx.GetHash(), grant.Histories.Single().Transaction);
                Assert.Equal(PropertyGrantType.Grant, grant.Histories.Single().Type);
            }
        }
コード例 #8
0
        public async Task GetBlockAsync_WithExodusTransaction_ShouldPopulateRelatedProperties()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            await GrantTokensAsync(property, owner, owner, new PropertyAmount(100));

            Node.Generate(1);

            await SendTokensAsync(property, owner, receiver, new PropertyAmount(1));

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

            // Act.
            var result1 = await Subject.GetBlockAsync(hash, CancellationToken.None);

            var result2 = await Subject.GetBlockAsync(height, CancellationToken.None);

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

            var exodus1 = result1.Transactions[0].GetExodusTransaction();
            var exodus2 = result1.Transactions[1].GetExodusTransaction();

            Assert.Null(exodus1);
            Assert.NotNull(exodus2);

            Assert.Equal(SimpleSendV0.StaticId, exodus2.Id);
        }
コード例 #9
0
        public async Task GetGrantsAsync_WithValidProperty_ShouldReturnCorrectData()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            var create = await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            var grant = await GrantTokensAsync(property, owner, receiver, PropertyAmount.One);

            Node.Generate(1);

            // Act.
            var result = await Subject.GetGrantsAsync(property, CancellationToken.None);

            // Assert.
            Assert.Equal(create.GetHash(), result.CreationTransaction);
            Assert.Single(result.Histories);
            Assert.Equal(property.Id, result.Id);
            Assert.Equal(owner, result.Issuer);
            Assert.Equal(issuer.Name, result.Name);
            Assert.Equal(PropertyAmount.One, result.TotalTokens);

            Assert.Equal(PropertyAmount.One, result.Histories.Single().Amount);
            Assert.Equal(grant, result.Histories.Single().Transaction);
            Assert.Equal(PropertyGrantType.Grant, result.Histories.Single().Type);
        }
コード例 #10
0
        public async Task PopulateExodusInformationAsync_WithSupportedTx_ShouldPopulate()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var receiver = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            var property = await GetPropertyAsync(issuer.Name);

            await GrantTokensAsync(property, owner, owner, new PropertyAmount(100));

            Node.Generate(1);

            var tx = await SendTokensAsync(property, owner, receiver, PropertyAmount.One);

            Node.Generate(1);

            // Act.
            await Subject.PopulateExodusInformationAsync(tx, CancellationToken.None);

            // Assert.
            var exodus = (SimpleSendV0)tx.GetExodusTransaction();

            Assert.Equal(PropertyAmount.One, exodus.Amount);
            Assert.Equal(property.Id, exodus.Property);
            Assert.Equal(receiver, exodus.Receiver);
            Assert.Equal(owner, exodus.Sender);
        }
コード例 #11
0
        public async Task PopulateExodusInformationAsync_WithUnsupportedTx_ShouldNotPopulate()
        {
            // Arrange.
            var owner = await GenerateNewAddressAsync();

            var issuer = new PropertyIssuer(Factory);

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

            Node.Generate(1);

            var tx = await issuer.IssueManagedAsync(owner);

            Node.Generate(1);

            // Act.
            await Subject.PopulateExodusInformationAsync(tx, CancellationToken.None);

            // Assert.
            Assert.Null(tx.GetExodusTransaction());
        }