public static void ClassInit(TestContext context) { byte[] privateKey = new byte[32]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(privateKey); } keyPair = new KeyPair(privateKey); testScriptHash = Contract.CreateSignatureContract(keyPair.PublicKey).ScriptHash; nep2key = keyPair.Export("123", ProtocolSettings.Default.AddressVersion, 2, 1, 1); }
public void TestGetAccount() { bool result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); uut.Unlock("123"); uut.CreateAccount(keyPair.PrivateKey); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); WalletAccount account = uut.GetAccount(testScriptHash); Assert.AreEqual(Contract.CreateSignatureRedeemScript(keyPair.PublicKey).ToScriptHash().ToAddress(ProtocolSettings.Default.AddressVersion), account.Address); }
public void TestGetAccounts() { Dictionary <UInt160, KeyPair> keys = new(); uut.Unlock("123"); byte[] privateKey = new byte[32]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(privateKey); } KeyPair key = new(privateKey); keys.Add(Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash(), key); keys.Add(Contract.CreateSignatureRedeemScript(keyPair.PublicKey).ToScriptHash(), keyPair); uut.CreateAccount(key.PrivateKey); uut.CreateAccount(keyPair.PrivateKey); foreach (var account in uut.GetAccounts()) { if (!keys.ContainsKey(account.ScriptHash)) { Assert.Fail(); } } }
public void TestCreateAccountBySmartContract() { byte[] privateKey = new byte[32]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(privateKey); } KeyPair key = new KeyPair(privateKey); VerificationContract contract = new VerificationContract { Script = Contract.CreateSignatureRedeemScript(key.PublicKey), ParameterList = new[] { ContractParameterType.Signature } }; var account = wallet.CreateAccount(contract, key); var dbAccount = wallet.GetAccount(account.ScriptHash); account.Should().Be(dbAccount); byte[] privateKey2 = new byte[32]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(privateKey2); } KeyPair key2 = new KeyPair(privateKey2); Contract contract2 = new Contract { Script = Contract.CreateSignatureRedeemScript(key2.PublicKey), ParameterList = new[] { ContractParameterType.Signature } }; var account2 = wallet.CreateAccount(contract2, key2); var dbAccount2 = wallet.GetAccount(account2.ScriptHash); account2.Should().Be(dbAccount2); wallet.DeleteAccount(account.ScriptHash); wallet.DeleteAccount(account2.ScriptHash); }