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