Ejemplo n.º 1
0
        public void ExecuteWithInvalidSigner()
        {
            var balance = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                          .Add((_sender, _currency), _currency * 1000)
                          .Add((_recipient, _currency), _currency * 10);

            var prevState = new State(
                balance: balance
                );
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _recipient,
                amount: _currency * 100
                );

            var exc = Assert.Throws <InvalidTransferSignerException>(() =>
            {
                _ = action.Execute(new ActionContext()
                {
                    PreviousStates = prevState,
                    // 송금자가 직접 사인하지 않으면 실패해야 합니다.
                    Signer     = _recipient,
                    Rehearsal  = false,
                    BlockIndex = 1,
                });
            });

            Assert.Equal(exc.Sender, _sender);
            Assert.Equal(exc.Recipient, _recipient);
            Assert.Equal(exc.TxSigner, _recipient);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            var balance = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                          .Add((_sender, _currency), _currency * 1000)
                          .Add((_recipient, _currency), _currency * 10);

            var prevState = new State(
                balance: balance
                );
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _recipient,
                amount: _currency * 100
                );
            IAccountStateDelta nextState = action.Execute(new ActionContext()
            {
                PreviousStates = prevState,
                Signer         = _sender,
                Rehearsal      = false,
                BlockIndex     = 1,
            });

            Assert.Equal(_currency * 900, nextState.GetBalance(_sender, _currency));
            Assert.Equal(_currency * 110, nextState.GetBalance(_recipient, _currency));
        }
Ejemplo n.º 3
0
        public void ExecuteWithMinterAsRecipient()
        {
            var currencyByRecipient = new Currency("NCG", 2, _sender);
            var balance             = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                                      .Add((_sender, currencyByRecipient), _currency * 1000)
                                      .Add((_recipient, currencyByRecipient), _currency * 10);

            var prevState = new State(
                balance: balance
                );
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _recipient,
                amount: currencyByRecipient * 100
                );
            var ex = Assert.Throws <InvalidTransferMinterException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = prevState,
                    Signer         = _sender,
                    Rehearsal      = false,
                    BlockIndex     = 1,
                });
            });

            Assert.Equal(new[] { _sender }, ex.Minters);
            Assert.Equal(_sender, ex.Sender);
            Assert.Equal(_recipient, ex.Recipient);
        }
Ejemplo n.º 4
0
        public void ExecuteWithInsufficientBalance()
        {
            var balance = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                          .Add((_sender, _currency), _currency * 1000)
                          .Add((_recipient, _currency), _currency * 10);

            var prevState = new State(
                balance: balance
                );
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _recipient,
                amount: _currency * 100000
                );

            Assert.Throws <InsufficientBalanceException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = prevState,
                    Signer         = _sender,
                    Rehearsal      = false,
                    BlockIndex     = 1,
                });
            });
        }
Ejemplo n.º 5
0
        public void Rehearsal()
        {
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _recipient,
                amount: _currency * 100
                );

            IAccountStateDelta nextState = action.Execute(new ActionContext()
            {
                PreviousStates = new State(ImmutableDictionary <Address, IValue> .Empty),
                Signer         = default,
Ejemplo n.º 6
0
        public void ExecuteWithInvalidRecipient()
        {
            var balance = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                          .Add((_sender, _currency), _currency * 1000);

            var prevState = new State(
                balance: balance
                );
            // Should not allow TransferAsset with same sender and recipient.
            var action = new TransferAsset0(
                sender: _sender,
                recipient: _sender,
                amount: _currency * 100
                );

            // No exception should be thrown when its index is less then 380000.
            _ = action.Execute(new ActionContext()
            {
                PreviousStates = prevState,
                Signer         = _sender,
                Rehearsal      = false,
                BlockIndex     = 1,
            });

            var exc = Assert.Throws <InvalidTransferRecipientException>(() =>
            {
                _ = action.Execute(new ActionContext()
                {
                    PreviousStates = prevState,
                    Signer         = _sender,
                    Rehearsal      = false,
                    BlockIndex     = 380001,
                });
            });

            Assert.Equal(exc.Sender, _sender);
            Assert.Equal(exc.Recipient, _sender);
        }