コード例 #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 TransferAsset(
                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);
        }
コード例 #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 TransferAsset(
                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));
        }
コード例 #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 TransferAsset(
                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);
        }
コード例 #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 TransferAsset(
                sender: _sender,
                recipient: _recipient,
                amount: _currency * 100000
                );

            Assert.Throws <InsufficientBalanceException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = prevState,
                    Signer         = _sender,
                    Rehearsal      = false,
                    BlockIndex     = 1,
                });
            });
        }
コード例 #5
0
        public void ExecuteWithUnactivatedRecipient()
        {
            var activatedAddress = new ActivatedAccountsState().AddAccount(new PrivateKey().ToAddress());
            var balance          = ImmutableDictionary <(Address, Currency), FungibleAssetValue> .Empty
                                   .Add((_sender, _currency), _currency * 1000)
                                   .Add((_recipient, _currency), _currency * 10);

            var state = ImmutableDictionary <Address, IValue> .Empty
                        .Add(_sender.Derive(ActivationKey.DeriveKey), true.Serialize())
                        .Add(Addresses.ActivatedAccount, activatedAddress.Serialize());

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

            Assert.Equal(_sender, ex.Sender);
            Assert.Equal(_recipient, ex.Recipient);
        }
コード例 #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 TransferAsset(
                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);
        }