Exemple #1
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();
        }
Exemple #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();
        }
Exemple #3
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();
        }
Exemple #4
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();
        }
Exemple #5
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"));
        }
Exemple #6
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"));
        }
Exemple #7
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"));
        }
Exemple #8
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"));
        }
Exemple #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"));
        }
Exemple #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"));
        }
Exemple #11
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();
        }
Exemple #12
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();
        }
Exemple #13
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();
        }
Exemple #14
0
        public void TestCreateAccount4()
        {
            MyWallet wallet = new MyWallet();

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

            wallet.CreateAccount(new byte[32]).Should().NotBeNull();
        }
Exemple #16
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();
        }
Exemple #17
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();
        }