Ejemplo n.º 1
0
        public void TestMakeTransaction2()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.MakeTransaction(new byte[] { }, UInt160.Zero, new TransactionAttribute[] { });

            action.ShouldThrow <ArgumentException>();

            Contract      contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 });
            WalletAccount account  = wallet.CreateAccount(contract, glkey.PrivateKey);

            account.Lock = false;

            // Fake balance
            var snapshot = store.GetSnapshot();
            var key      = NativeContract.LINK.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Tlp5AccountState().ToByteArray()
            });

            entry.Value = new Tlp5AccountState()
            {
                Balance = 1000000 * NativeContract.LINK.Factor
            }
            .ToByteArray();

            var tx = wallet.MakeTransaction(new byte[] { }, account.ScriptHash, new TransactionAttribute[] { });

            tx.Should().NotBeNull();

            tx = wallet.MakeTransaction(new byte[] { }, null, new TransactionAttribute[] { });
            tx.Should().NotBeNull();

            entry.Value = new TrustToken.AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
        }
Ejemplo n.º 2
0
        public void TestMakeTransaction1()
        {
            MyWallet      wallet   = new MyWallet();
            Contract      contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 });
            WalletAccount account  = wallet.CreateAccount(contract, glkey.PrivateKey);

            account.Lock = false;

            Action action = () => wallet.MakeTransaction(new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.LINK.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            }, UInt160.Zero);

            action.ShouldThrow <ArgumentException>();

            action = () => wallet.MakeTransaction(new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.LINK.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            }, account.ScriptHash);
            action.ShouldThrow <InvalidOperationException>();

            action = () => wallet.MakeTransaction(new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = UInt160.Zero,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            }, account.ScriptHash);
            action.ShouldThrow <InvalidOperationException>();

            // Fake balance
            var snapshot = store.GetSnapshot();
            var key      = NativeContract.LINK.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Tlp5AccountState().ToByteArray()
            });

            entry.Value = new Tlp5AccountState()
            {
                Balance = 10000 * NativeContract.LINK.Factor
            }
            .ToByteArray();

            key   = NativeContract.TRUST.CreateStorageKey(20, account.ScriptHash);
            entry = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Tlp5AccountState().ToByteArray()
            });
            entry.Value = new TrustToken.AccountState()
            {
                Balance = 10000 * NativeContract.TRUST.Factor
            }
            .ToByteArray();

            var tx = wallet.MakeTransaction(new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.LINK.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            });

            tx.Should().NotBeNull();

            tx = wallet.MakeTransaction(new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.TRUST.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            });
            tx.Should().NotBeNull();

            entry.Value = new TrustToken.AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
        }