示例#1
0
        public void TestGetBalance()
        {
            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;

            // 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();

            wallet.GetBalance(UInt160.Zero, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(0, 0));
            wallet.GetBalance(NativeContract.LINK.Hash, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(1000000000000, 8));

            entry.Value = new Tlp5AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
        }
示例#2
0
        public void TestCreateAccount3()
        {
            MyWallet wallet   = new MyWallet();
            Contract contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 });

            wallet.CreateAccount(contract, glkey).Should().NotBeNull();
        }
示例#3
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateAccount(UInt160.Parse("522a2b818c308c7a2c77cfdda11763fe043bfb40"));
            WalletAccount account = wallet.GetAccount(ECCurve.Secp256r1.G);

            account.ScriptHash.Should().Be(UInt160.Parse("0x522a2b818c308c7a2c77cfdda11763fe043bfb40"));
        }
示例#4
0
        public void TestCreateAccount2()
        {
            MyWallet      wallet   = new MyWallet();
            Contract      contract = Contract.Create(new ContractParameterType[] { ContractParameterType.Boolean }, new byte[] { 1 });
            WalletAccount account  = wallet.CreateAccount(contract, UT_Crypto.generateCertainKey(32).PrivateKey);

            account.Should().NotBeNull();

            wallet  = new MyWallet();
            account = wallet.CreateAccount(contract, (byte[])(null));
            account.Should().NotBeNull();
        }
示例#5
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();
        }
示例#6
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();
        }
示例#7
0
        public void TestCreateAccount4()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateAccount(UInt160.Zero).Should().NotBeNull();
        }
示例#8
0
        public void TestCreateAccount1()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateAccount(new byte[32]).Should().NotBeNull();
        }