Beispiel #1
0
        public void TestVerifyPassword()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.VerifyPassword("Test");

            action.Should().NotThrow();
        }
Beispiel #2
0
        public void TestGetAccount2()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.GetAccount(UInt160.Zero);

            action.ShouldNotThrow();
        }
Beispiel #3
0
        public void TestGetAccounts()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.GetAccounts();

            action.Should().NotThrow();
        }
Beispiel #4
0
        public void TestContains()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.Contains(UInt160.Zero);

            action.Should().NotThrow();
        }
Beispiel #5
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();
        }
Beispiel #6
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 = Blockchain.Singleton.GetSnapshot();
            var key      = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Nep5AccountState().ToByteArray()
            });

            entry.Value = new Nep5AccountState()
            {
                Balance = 10000 * NativeContract.GAS.Factor
            }
            .ToByteArray();
            snapshot.Commit();

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

            entry.Value = new Nep5AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
            snapshot.Commit();
        }
Beispiel #7
0
        public void TestMakeTransaction2()
        {
            var      snapshot = TestBlockchain.GetTestSnapshot();
            MyWallet wallet   = new MyWallet();
            Action   action   = () => wallet.MakeTransaction(snapshot, new byte[] { }, null, null, Array.Empty <TransactionAttribute>());

            action.Should().Throw <InvalidOperationException>();

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

            account.Lock = false;

            // Fake balance
            var key   = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));

            entry.GetInteroperable <AccountState>().Balance = 1000000 * NativeContract.GAS.Factor;
            snapshot.Commit();

            var tx = wallet.MakeTransaction(snapshot, new byte[] { }, account.ScriptHash, new[] { new Signer()
                                                                                                  {
                                                                                                      Account = account.ScriptHash,
                                                                                                      Scopes  = WitnessScope.CalledByEntry
                                                                                                  } }, new TransactionAttribute[] { });

            tx.Should().NotBeNull();

            tx = wallet.MakeTransaction(snapshot, new byte[] { }, null, null, Array.Empty <TransactionAttribute>());
            tx.Should().NotBeNull();

            entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
            entry.GetInteroperable <AccountState>().Balance = 0;
            snapshot.Commit();
        }
Beispiel #8
0
        public void TestMakeTransaction2()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.MakeTransaction(new byte[] { }, UInt160.Zero, new TransactionAttribute[] { });

            action.Should().Throw <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 = Blockchain.Singleton.GetSnapshot();
            var key      = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.Storages.GetAndChange(key, () => new StorageItem(new AccountState()));

            entry.GetInteroperable <AccountState>().Balance = 1000000 * NativeContract.GAS.Factor;
            snapshot.Commit();

            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 = snapshot.Storages.GetAndChange(key, () => new StorageItem(new AccountState()));
            entry.GetInteroperable <AccountState>().Balance = 0;
            snapshot.Commit();
        }
Beispiel #9
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

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

            account.ScriptHash.Should().Be(UInt160.Parse("0xb3f1526d9f9670df1a21a5953d5296c3a9c9173c"));
        }
Beispiel #10
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"));
        }
Beispiel #11
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

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

            account.ScriptHash.Should().Be(UInt160.Parse("0xf55f6873ae944cf4ec9626e8855b8554e798a7d1"));
        }
Beispiel #12
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

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

            account.ScriptHash.Should().Be(UInt160.Parse("0xc43d04da83afcf7df3b2908c169cfbfbf7512d7f"));
        }
Beispiel #13
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

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

            account.ScriptHash.Should().Be(UInt160.Parse("0xd92defaf95bf5307ffbc3ab1c5cdf7ddfc1b89b3"));
        }
Beispiel #14
0
        public void TestGetAccount1()
        {
            MyWallet wallet = new MyWallet();

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

            account.ScriptHash.Should().Be(UInt160.Parse("0x7e471cf52f27edc291e29ec8f2d1ea2d210d6725"));
        }
Beispiel #15
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();
        }
Beispiel #16
0
        public void TestGetAvailable()
        {
            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 = TestBlockchain.GetTestSnapshot();
            var key      = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));

            entry.GetInteroperable <AccountState>().Balance = 10000 * NativeContract.GAS.Factor;
            snapshot.Commit();

            wallet.GetAvailable(snapshot, NativeContract.GAS.Hash).Should().Be(new BigDecimal(new BigInteger(1000000000000M), 8));

            entry = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
            entry.GetInteroperable <AccountState>().Balance = 0;
            snapshot.Commit();
        }
Beispiel #17
0
        public void TestMakeTransaction2()
        {
            MyWallet wallet = new MyWallet();
            Action   action = () => wallet.MakeTransaction(new byte[] { }, UInt160.Zero, new TransactionAttribute[] { });

            action.Should().Throw <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.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry    = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Nep5AccountState().ToByteArray()
            });

            entry.Value = new Nep5AccountState()
            {
                Balance = 1000000 * NativeContract.GAS.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 NeoToken.AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
        }
Beispiel #18
0
        public void TestCreateAccount1()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateAccount(new byte[32]).Should().NotBeNull();
        }
Beispiel #19
0
        public void TestImport2()
        {
            MyWallet wallet = new MyWallet();

            wallet.Import(nep2Key, "pwd", 0, 0, 0).Should().NotBeNull();
        }
Beispiel #20
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.GAS.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(1, 8)
                }
            }, UInt160.Zero);

            action.Should().Throw <ArgumentException>();

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

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

            // Fake balance
            var snapshot = Blockchain.Singleton.GetSnapshot();
            var key      = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry1   = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Nep5AccountState().ToByteArray()
            });

            entry1.Value = new Nep5AccountState()
            {
                Balance = 10000 * NativeContract.GAS.Factor
            }
            .ToByteArray();

            key = NativeContract.NEO.CreateStorageKey(20, account.ScriptHash);
            var entry2 = snapshot.Storages.GetAndChange(key, () => new StorageItem
            {
                Value = new Nep5AccountState().ToByteArray()
            });

            entry2.Value = new NeoToken.AccountState()
            {
                Balance = 10000 * NativeContract.NEO.Factor
            }
            .ToByteArray();

            snapshot.Commit();

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

            tx.Should().NotBeNull();

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

            entry1.Value = new Nep5AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
            entry2.Value = new NeoToken.AccountState()
            {
                Balance = 0
            }
            .ToByteArray();
            snapshot.Commit();
        }
Beispiel #21
0
        public void TestImport1()
        {
            MyWallet wallet = new MyWallet();

            wallet.Import("L3tgppXLgdaeqSGSFw1Go3skBiy8vQAM7YMXvTHsKQtE16PBncSU").Should().NotBeNull();
        }
Beispiel #22
0
        public void TestMakeTransaction1()
        {
            var           snapshot = TestBlockchain.GetTestSnapshot();
            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(snapshot, new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.GAS.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(BigInteger.One, 8),
                    Data       = "Dec 12th"
                }
            }, UInt160.Zero);

            action.Should().Throw <InvalidOperationException>();

            action = () => wallet.MakeTransaction(snapshot, new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.GAS.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(BigInteger.One, 8),
                    Data       = "Dec 12th"
                }
            }, account.ScriptHash);
            action.Should().Throw <InvalidOperationException>();

            action = () => wallet.MakeTransaction(snapshot, new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = UInt160.Zero,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(BigInteger.One, 8),
                    Data       = "Dec 12th"
                }
            }, account.ScriptHash);
            action.Should().Throw <InvalidOperationException>();

            // Fake balance
            var key    = NativeContract.GAS.CreateStorageKey(20, account.ScriptHash);
            var entry1 = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));

            entry1.GetInteroperable <AccountState>().Balance = 10000 * NativeContract.GAS.Factor;

            key = NativeContract.NEO.CreateStorageKey(20, account.ScriptHash);
            var entry2 = snapshot.GetAndChange(key, () => new StorageItem(new NeoToken.NeoAccountState()));

            entry2.GetInteroperable <NeoToken.NeoAccountState>().Balance = 10000 * NativeContract.NEO.Factor;

            snapshot.Commit();

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

            tx.Should().NotBeNull();

            tx = wallet.MakeTransaction(snapshot, new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NativeContract.NEO.Hash,
                    ScriptHash = account.ScriptHash,
                    Value      = new BigDecimal(BigInteger.One, 8),
                    Data       = "Dec 12th"
                }
            });
            tx.Should().NotBeNull();

            entry1 = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
            entry2 = snapshot.GetAndChange(key, () => new StorageItem(new AccountState()));
            entry1.GetInteroperable <AccountState>().Balance             = 0;
            entry2.GetInteroperable <NeoToken.NeoAccountState>().Balance = 0;
            snapshot.Commit();
        }
Beispiel #23
0
        public void TestCreateAccount4()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateAccount(UInt160.Zero).Should().NotBeNull();
        }
Beispiel #24
0
        public void TestGetName()
        {
            MyWallet wallet = new MyWallet();

            wallet.Name.Should().Be("MyWallet");
        }
Beispiel #25
0
        public void TestGetVersion()
        {
            MyWallet wallet = new MyWallet();

            wallet.Version.Should().Be(Version.Parse("0.0.1"));
        }